Double click listener on vaadin calendar - java

I am working on a vaadin project where I am using a vaadin calendar add-on. The calender component has event re-size, event click on its Basic Event component, and event drag on its calender cells , means when we drag on calender cells, it generates an event. Now, I want that when ever I double click on calender's cell, it generates an event, and I can listen to that event and perform my functionality.
Any Help?

You can use following functionality on the ClickEvent:
public void itemClick(ItemClickEvent event) {
if (event.isDoubleClick()) {
...
}
}

It's stil not possible in vesion 7.1.12.
There's an open bug here : http://dev.vaadin.com/ticket/12408

Related

How can I show a confirm dialog with Vaadin 23 when the user clicks on back button?

how can I show a dialog to stay or leave the current page with Vaadin 23, when a user clicks back button on browser?
Regards
It depends what you wish to achieve.
See this older discussion: Vaadin onbeforeunload event
Generally: use the onBeforeUnload javascript even for this
https://www.w3schools.com/tags/ev_onbeforeunload.asp
This is executed when the user would go away from your vaadin app, but not when using the back button inside your vaadin app.
For these you can use the navigation lifecycle events as documented here
https://vaadin.com/docs/latest/routing/lifecycle
Not sure if it also catches, when a user leaves your app...
Assuming you mean, that is it possible to prevent the navigation happening, you simply can't do that. If disabling back button is important for you, the only way is to enforce your users to use the application via desktop shortcut which starts the app using --app paramater (if using Chrome). This is not a limitation in Vaadin, but a general restriction in browser behavior.
There is already a possibility to handle Browser Back Button Event on Vaadin (https://vaadin.com/docs/v14/flow/routing/tutorial-routing-lifecycle):
public class SignupForm extends Div implements BeforeLeaveObserver {
#Override
public void beforeLeave(BeforeLeaveEvent event) {
if (this.hasChanges()) {
ContinueNavigationAction action = event.postpone();
ConfirmDialog.build("Are you sure you want"+
" to leave this page?")
.ifAccept(action::proceed)
.show();
}
}
private boolean hasChanges() {
// no-op implementation
return true;
}
}
This code works once but when you click on Cancel on Confirm Dialog so that you want to stay on current page and click again on Back Button on Browser, than you don't see any Confirm Dialog again... I can not understand, why...

Vaadin Calendar event selected style change on click

I am trying to change the style of an event in the Vaadin Calendar component when clicking on it. This is what I do:
eventCalendar.setHandler((CalendarComponentEvents.EventClick event) -> {
/* some code to iterate the container and remove selected style from other events*/
((BasicEvent) event.getCalendarEvent()).setStyleName("event-selected");
});
But nothing happens. The class is not added.
Some hours later, two observations saved the day:
Firstly, setting the style name on the event itself does not trigger a refresh, so we just need to add eventCalendar.markAsDirty() to the handler method.
Secondly, setStyleName doesn't add a CSS class with that name to the Calendar Event element. It adds a class with the .v-calendar-event- prefix (e.g. in my example that would become .v-calendar-event-event-selected.
So, the solution was to make the following update to the UI class:
eventCalendar.setHandler((CalendarComponentEvents.EventClick event) -> {
/* some code to iterate the container and remove selected style from other events*/
((BasicEvent) event.getCalendarEvent()).setStyleName("selected");
eventCalendar.markAsDirty();
});
and add the following class to the styles.scss, inside the root name of the Vaadin theme:
.v-calendar-event-selected{
/*however I wanted the selected event to look like*/
}

Any listeners available for JXMonthView's traversable buttons?

Working with JXMonthView, it is possible to set it as "Traversable," which means that left and right arrows appear next to the month name in the header. They allow for the user to select a different month to view, effectively traversing through the calendar year.
I would like to put an event listener on those arrows so that each time they are clicked, the flagged dates will be refreshed. Currently, this only happens when the user clicks on a date in JXMonthView, which changes the current selection, which fires the refresh. Does anyone know how to access those individual traversing buttons and add a listener to them?
You can listen to firstDisplayedDay property change.
According to the source code, BasicMonthViewUI.nextMonth() or previousMonth() invokes monthView.setFirstDisplayedDay which in turn invokes firePropertyChange("firstDisplayedDay", oldDate, getFirstDisplayedDay());.
For example:
monthView.addPropertyChangeListener(new PropertyChangeListener() {
#Override
public void propertyChange(PropertyChangeEvent e) {
if ("firstDisplayedDay".equals(e.getPropertyName())) {
System.out.println("updated");
}
}
});

How to force a Value change on a Vaadin RichTextArea component

I have developed a custom component consist of a layout and two labels within it. This layout is draggable. The code is similar to this :
DragAndDropWrapper boxWrap= new DragAndDropWrapper(layout);
mainLayout.addComponent(boxWrap);
After that I have a RichTextArea that allows the layout to be dropped in it. With this code.
RichTextArea richText= new RichTextArea;
DragAndDropWrapper dndWrapper = new DragAndDropWrapper(richText);
dndWrapper.setDropHandler(new DropHandler() {
public void drop(DragAndDropEvent event) {
//Do whatever you want when something is dropped
}
//Criterio de aceptacion
public AcceptCriterion getAcceptCriterion() {
return AcceptAll.get();
}
});
The code works fine. But when I drop the layout within the RichTextArea y want to get the Text written in this area and add some text but the method richText.getValue() is not updated unless I change the focus to another component or tab out. I guess there is not being communication with the server side so the value is not updated. Is there any way to force a a focus change when mousedown on the layout? I tried with JavaScript but i dont know how to add a onmousedown="function()" attribute to the layout component. I also tried extending RichTextArea and implementing the MouseListener or something or a TextChangeListener, but nothing works.
Any clue? Thank you.
PS: The component cannot be different from a RichTextArea.
Have you set richText.setImmediate(true); ?

How to check if the tab selected is changed in java

As far as i have seen the event:
(1) private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {}
Checks whether a new tab is added or an exiting tab is deleted or not.
On googling , i found this code:
(2) ChangeListener changeListener = new ChangeListener() {
public void stateChanged(ChangeEvent changeEvent) {
// my code
}
};
jTabbedPane1.addChangeListener(changeListener);
I guess since it uses stateChanged event , it should do what the same a my first code.
By t way even after using both the codes i could not get the required resuts(ie An event that could be invoked when user changes the tab).
Can anyone suggest me a good event [i am using netbeans GUI environment] for effective action. (I dont want any mouseEvents)
Edit:
I want the following code to be excecuted if the tab changes:
String send3=( jTabbedPane1.getSelectedComponent().getComponentAt(0,0)).getName();
The above code dynamically gets the name of jTextarea (in the current tab) which is created dynamically in the jTabbedPanel.
I just checked my own source code where addChangeListener() works fine. The event is fired whenever the tab is changed by the user or programatically. In stateChanged() itself, the now selected tab is determined by
JTabbedPane p = (JTabbedPane)e.getSource();
int idx = p.getSelectedIndex();

Categories