Skip to content

Commit

Permalink
simplify divisionType radio buttons
Browse files Browse the repository at this point in the history
now that swt radio buttons events are filtered
see e44e162
  • Loading branch information
guiv42 committed Jun 22, 2024
1 parent e44e162 commit 85d77d5
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ public void setChecked(boolean checked) {
((CheckMenuItem) this.getControl()).setSelected(checked);
}

public boolean hasSelectionListener() {
return (!this.selectionListener.isEmpty());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ public void setChecked(boolean checked) {
((RadioMenuItem) this.getControl()).setSelected(checked);
}

public boolean hasSelectionListener() {
return (!this.selectionListener.isEmpty());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@ public void setChecked(boolean checked) {
this.getControl().setSelection(checked);
}

public boolean hasSelectionListener() {
return (!this.selectionListener.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ public interface UIMenuCheckableItem extends UIMenuActionItem {

void setChecked(boolean checked);

boolean hasSelectionListener();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class TGEditToolBarSectionDuration extends TGEditToolBarSection {

private List<UIToolCheckableItem> durationToolItems;
private List<UIMenuCheckableItem> divisionTypeMenuItems;
private List<TGActionProcessorListener> divisionTypeProcessors;

private Map<Integer, String> durationNameKeys;
private Map<Integer, String> durationActions;
Expand Down Expand Up @@ -88,10 +87,10 @@ public void onSelect(UISelectionEvent event) {
});

this.divisionTypeMenuItems = new ArrayList<UIMenuCheckableItem>();
this.divisionTypeProcessors = new ArrayList<TGActionProcessorListener>();
for( int i = 0 ; i < TGDivisionType.DIVISION_TYPES.length ; i ++ ){
this.divisionTypeMenuItems.add(this.createDivisionTypeMenuItem(TGDivisionType.DIVISION_TYPES[i]));
this.divisionTypeProcessors.add(this.createDivisionTypeAction(TGDivisionType.DIVISION_TYPES[i]));
UIMenuCheckableItem item = this.createDivisionTypeMenuItem(TGDivisionType.DIVISION_TYPES[i]);
this.divisionTypeMenuItems.add(item);
item.addSelectionListener(this.createDivisionTypeAction(TGDivisionType.DIVISION_TYPES[i]));
}
}

Expand Down Expand Up @@ -230,25 +229,12 @@ private UIMenuCheckableItem createDivisionTypeMenuItem(TGDivisionType divisionTy
return uiMenuItem;
}

/* radio buttons generate events both when they are selected AND unselected (at least in SWT configuration)
* the only relevant event is when radio button is selected by user
* so, only keep selectionListener defined for non-selected radio buttons
*/

private void updateDivisionTypeMenuItems(TGDivisionType selection, boolean running) {
for(int i=0; i< this.divisionTypeMenuItems.size(); i++) {
UIMenuCheckableItem uiMenuItem = this.divisionTypeMenuItems.get(i);
TGDivisionType divisionType = uiMenuItem.getData(TGDivisionType.class.getName());
if (divisionType.isEqual(selection)) {
uiMenuItem.setChecked(true);
if (uiMenuItem.hasSelectionListener()) {
uiMenuItem.removeSelectionListener(this.divisionTypeProcessors.get(i));
}
} else {
uiMenuItem.setChecked(false);
if (!uiMenuItem.hasSelectionListener()) {
uiMenuItem.addSelectionListener(this.divisionTypeProcessors.get(i));
}
}
uiMenuItem.setChecked(divisionType.isEqual(selection));
}
this.divisionTypeItem.setImage(this.getIconManager().getDivisionType(selection.getEnters()));
}
Expand Down

0 comments on commit 85d77d5

Please sign in to comment.