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*/
}
Related
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");
}
}
});
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();
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
I have a CellList:
friendCellList = new CellList<PlayerDataEntity>(new PlayerCell());
friendCellList.setSelectionModel(new NoSelectionModel<PlayerDataEntity>());
I am hoping that passing the NoSelectionModel will prevent the UI from reacting to the user selecting items in the cell list. However, the user is able to select elements normally. Am I not applying the selection model correctly?
From the Javadoc of NoSelectionModel:
A selection model that does not allow selection, but fires selection change
events. Use this model if you want to know when a user selects an item, but
do not want the view to update based on the selection.
That's what it does: In the Standard theme, this will result in the row not being highlighted in blue anymore ("cellListSelectedItem" style class). However, it will still be highlighted in yellow ("cellListKeyboardSelectedItem" style class). Also, the SelectionChangeEvent will still be fired.
To turn off the SelectionChangeEvent, use
cellList.setSelectionModel(new NoSelectionModel<String>(),
DefaultSelectionEventManager.<PlayerDataEntity>createWhitelistManager());
The whitelist manager without arguments means, that you can't select any column.
If you also want to turn off the "yellow" highlighting, you should instantiate CellList with a different CellList.Resources instance:
public interface MyResources extends CellList.Resources {
#Override
#Source("com/mypackage/my.css")
Style cellListStyle();
}
...
friendCellList = new CellList<PlayerDataEntity>(new PlayerCell(),
(MyResources) GWT.create(MyResources.class);
my.css:
.cellListEvenItem {}
.cellListKeyboardSelectedItem {}
.cellListOddItem {}
.cellListSelectedItem {}
.cellListWidget {}
I've been creating a custom TabFolder extension that adds a key listener to allow quick tab switching using an ALT + # hotkey.
By adding the KeyAdapter to my TabFolder, the event handler works properly only when you have a tab header selected (in which case the ALT + ARROW_LEFT/ARROW_RIGHT also work.). I need this hot key to be active when any Widget with-in the TabFolder is active; however, it shouldn't be active if the selection is in a different tab folder or widget outside of a tab folder.
In an attempt to solve this, I wrote a simple recursive function to apply the key listener to all of the children of the tab folder:
public void applyQuickSwitchKeyBindings() {
removeKeyListener(ka);
addKeyListener(ka);
for(Control c: getChildren())
applyQuickSwitchKeyBindingsToChildren(c);
}
private void applyQuickSwitchKeyBindingsToChildren(Control c) {
if(c==null) return;
if(c instanceof Composite) {
Control[] controls = ((Composite)c).getChildren();
for(Control c2: controls)
applyQuickSwitchKeyBindingsToChildren(c2);
if(controls.length < 1) {
c.removeKeyListener(ka);
c.addKeyListener(ka);
}
}
}
Then i call the applyQuickSwitchKeyBindings() after I add the controls to each TabItem in the tab group.
The good news was that the quick switch hot key (ALT + #) worked great!
The bad news was that the original TAB ordering based on z-index is now gone. When you hit the SWT.TAB key you lose focus on your current text box and don't gain focus on anything else...
Questions:
1.) Can each control only have one KeyListener?
2.) Why is the original TAB traversal not working anymore?
Thanks in advance!
to 1) I'm pretty sure that more than one KeyListener is allowed.
to 2) I'm not sure, that depends on what you're doing in your KeyAdapter. Maybe you can post that too?
I just the tab order is broken somehow, you can reset ( or change ) it with a call to setTabList( Control[] ).
setTablList( new Control[] {
control1,
control2,
control3,
....
} );
So after more time learning and developing with SWT i've discovered my problem. When you add a listener it is applied to the widget/control you call the addXXXListener function on. So if that control is not active the listeners will not be fired.
The solution seems to be SWT's global Filter mechanism which allows you to add global application(Display) scope listeners.
Display.getCurrent().addFilter(SWT.keyPress, new KeyPressListener());
Pardon the incorrectness of this line, but if you google it you'll see what i mean.
I have also read to use this sparingly.