protected CycleButton createWatchButton() {
watchButton = new CycleButton();
watchButton.setShowText(true);
watchButton.setCls("toolbar-button");
final CheckItem watchItem = new CheckItem();
watchItem.setText(getWatchClsLabel());
watchItem.setCls("toolbar-button");
// watchItem.setIcon("images/eye.png");
watchButton.addItem(watchItem);
watchBranchItem = new CheckItem();
watchBranchItem.setText(getWatchBranchClsLabel());
watchBranchItem.setCls("toolbar-button");
// watchBranchItem.setIcon("images/eye-down.png");
watchBranchItem.setChecked(true);
watchButton.addItem(watchBranchItem);
unwatchBranchItem = new CheckItem();
unwatchBranchItem.setText(getUnwatchClsLabel());
unwatchBranchItem.setCls("toolbar-button");
watchButton.addItem(unwatchBranchItem);
//the listener is needed to override behavior of cycle button
CheckItemListener checkItemListener = new CheckItemListenerAdapter() {
@Override
public boolean doBeforeCheckChange(CheckItem item, boolean checked) {
return false;
}
};
BaseItemListener baseItemListener = new BaseItemListenerAdapter() {
@Override
public void onClick(BaseItem item, EventObject e) {
CheckItem activeItem = (CheckItem) item;
watchButton.setActiveItem(activeItem);
if (activeItem != unwatchBranchItem) {
lastSelectedWatchType = activeItem;
}
//this is optional, and can be removed if it is confusing to the user:
//if a user clicks in the watch menu on an item, we perform the operation right away to avoid one more click.
if (activeItem.equals(watchItem)) {
onWatchCls();
}
else if (activeItem.equals(watchBranchItem)) {
onWatchBranchCls();
}
else if (activeItem.equals(unwatchBranchItem)) {
onUnwatchCls();
}
}
};
watchItem.addListener(baseItemListener);
watchBranchItem.addListener(baseItemListener);
unwatchBranchItem.addListener(baseItemListener);
watchItem.addListener(checkItemListener);
watchBranchItem.addListener(checkItemListener);
unwatchBranchItem.addListener(checkItemListener);
//listener for performing the specific watch action
watchButton.addListener(new ButtonListenerAdapter() {
@Override
public void onClick(Button button, EventObject e) {
CheckItem activeItem = watchButton.getActiveItem();
if (activeItem.equals(watchItem)) {
onWatchCls();
}
else if (activeItem.equals(watchBranchItem)) {
onWatchBranchCls();
}
else if (activeItem.equals(unwatchBranchItem)) {
onUnwatchCls();
}
}
});