Revision 7a8baaba
Added by Patrick Plitzner about 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixToolbar.java | ||
---|---|---|
13 | 13 |
import java.io.IOException; |
14 | 14 |
import java.util.Collection; |
15 | 15 |
import java.util.Properties; |
16 |
import java.util.function.Consumer; |
|
16 | 17 |
|
17 | 18 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
18 | 19 |
import org.eclipse.jface.viewers.ComboViewer; |
... | ... | |
29 | 30 |
import org.eclipse.swt.SWT; |
30 | 31 |
import org.eclipse.swt.events.SelectionAdapter; |
31 | 32 |
import org.eclipse.swt.events.SelectionEvent; |
33 |
import org.eclipse.swt.graphics.Image; |
|
32 | 34 |
import org.eclipse.swt.layout.GridData; |
33 | 35 |
import org.eclipse.swt.layout.GridLayout; |
34 | 36 |
import org.eclipse.swt.widgets.Button; |
... | ... | |
64 | 66 |
|
65 | 67 |
wsLabel = new Label(this, SWT.NONE); |
66 | 68 |
|
67 |
Button btnToggleToolTips = new Button(this, SWT.TOGGLE);
|
|
69 |
Button btnToggleTooltips = new Button(this, SWT.TOGGLE);
|
|
68 | 70 |
Button btnToggleTree = new Button(this, SWT.PUSH); |
69 | 71 |
Button btnToggleFlat = new Button(this, SWT.PUSH); |
70 | 72 |
Button btnCollapseAll = new Button(this, SWT.PUSH); |
... | ... | |
75 | 77 |
Button btnExcelExport = new Button(this, SWT.PUSH); |
76 | 78 |
|
77 | 79 |
/** |
78 |
* Toogle tooltips button
|
|
80 |
* Toggle tooltips button
|
|
79 | 81 |
*/ |
80 |
btnToggleToolTips.setImage(ImageResources.getImage(ImageResources.LIGHT_BULB)); |
|
81 |
btnToggleToolTips.setToolTipText("Show tooltips"); |
|
82 |
btnToggleToolTips.setSelection(true); |
|
83 |
btnToggleToolTips.setEnabled(true); |
|
84 |
btnToggleToolTips.addSelectionListener(new SelectionAdapter() { |
|
85 |
@Override |
|
86 |
public void widgetSelected(SelectionEvent e) { |
|
87 |
matrix.toogleIsShowTooltips(); |
|
88 |
} |
|
89 |
}); |
|
90 |
|
|
82 |
initButton( |
|
83 |
btnToggleTooltips, |
|
84 |
ImageResources.getImage(ImageResources.LIGHT_BULB), |
|
85 |
"Show tooltips", |
|
86 |
null, |
|
87 |
true, |
|
88 |
true, |
|
89 |
(e)->matrix.toogleIsShowTooltips() |
|
90 |
); |
|
91 | 91 |
/** |
92 | 92 |
* Toogle tree button |
93 | 93 |
*/ |
94 |
btnToggleTree.setImage(ImageResources.getImage(ImageResources.HIERARCHICAL)); |
|
95 |
btnToggleTree.setToolTipText(Messages.CharacterMatrix_SHOW_HIERARCHY); |
|
96 |
btnToggleTree.setSelection(true); |
|
97 |
btnToggleTree.setEnabled(false); |
|
98 |
btnToggleTree.addSelectionListener(new SelectionAdapter() { |
|
99 |
@Override |
|
100 |
public void widgetSelected(SelectionEvent e) { |
|
101 |
matrix.toggleTreeFlat(true, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo); |
|
102 |
} |
|
103 |
}); |
|
94 |
initButton( |
|
95 |
btnToggleTree, |
|
96 |
ImageResources.getImage(ImageResources.HIERARCHICAL), |
|
97 |
Messages.CharacterMatrix_SHOW_HIERARCHY, |
|
98 |
null, |
|
99 |
false, |
|
100 |
true, |
|
101 |
(e)->matrix.toggleTreeFlat(true, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo) |
|
102 |
); |
|
104 | 103 |
|
105 | 104 |
/** |
106 | 105 |
* Toogle flat button |
107 | 106 |
*/ |
108 |
btnToggleFlat.setImage(ImageResources.getImage(ImageResources.FLAT)); |
|
109 |
btnToggleFlat.setToolTipText(Messages.CharacterMatrix_SHOW_FLAT_LIST); |
|
110 |
btnToggleFlat.addSelectionListener(new SelectionAdapter() { |
|
111 |
@Override |
|
112 |
public void widgetSelected(SelectionEvent e) { |
|
113 |
matrix.toggleTreeFlat(false, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo); |
|
114 |
} |
|
115 |
}); |
|
107 |
initButton( |
|
108 |
btnToggleFlat, |
|
109 |
ImageResources.getImage(ImageResources.FLAT), |
|
110 |
Messages.CharacterMatrix_SHOW_FLAT_LIST, |
|
111 |
null, |
|
112 |
true, |
|
113 |
false, |
|
114 |
(e)->matrix.toggleTreeFlat(false, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo) |
|
115 |
); |
|
116 | 116 |
|
117 | 117 |
/** |
118 | 118 |
* |
119 | 119 |
* Collapse button |
120 | 120 |
*/ |
121 |
btnCollapseAll.setImage(ImageResources.getImage(ImageResources.COLLAPSE_ALL)); |
|
122 |
btnCollapseAll.setToolTipText(Messages.CharacterMatrix_COLLAPSE); |
|
123 |
btnCollapseAll.addSelectionListener(new SelectionAdapter() { |
|
124 |
@Override |
|
125 |
public void widgetSelected(SelectionEvent e) { |
|
126 |
matrix.getNatTable().doCommand(new TreeCollapseAllCommand()); |
|
127 |
} |
|
128 |
}); |
|
121 |
initButton( |
|
122 |
btnCollapseAll, |
|
123 |
ImageResources.getImage(ImageResources.COLLAPSE_ALL), |
|
124 |
Messages.CharacterMatrix_COLLAPSE, |
|
125 |
null, |
|
126 |
true, |
|
127 |
false, |
|
128 |
(e)->matrix.getNatTable().doCommand(new TreeCollapseAllCommand()) |
|
129 |
); |
|
129 | 130 |
|
130 | 131 |
/** |
131 | 132 |
* Expand button |
132 | 133 |
*/ |
133 |
btnExpandAll.setImage(ImageResources.getImage(ImageResources.EXPAND_ALL)); |
|
134 |
btnExpandAll.setToolTipText(Messages.CharacterMatrix_EXPAND); |
|
135 |
btnExpandAll.addSelectionListener(new SelectionAdapter() { |
|
136 |
@Override |
|
137 |
public void widgetSelected(SelectionEvent e) { |
|
138 |
matrix.getNatTable().doCommand(new TreeExpandAllCommand()); |
|
139 |
} |
|
140 |
}); |
|
134 |
initButton( |
|
135 |
btnExpandAll, |
|
136 |
ImageResources.getImage(ImageResources.EXPAND_ALL), |
|
137 |
Messages.CharacterMatrix_EXPAND, |
|
138 |
null, |
|
139 |
true, |
|
140 |
false, |
|
141 |
(e)->matrix.getNatTable().doCommand(new TreeExpandAllCommand()) |
|
142 |
); |
|
141 | 143 |
|
142 | 144 |
/** |
143 | 145 |
* Freeze supplemental info button |
144 | 146 |
*/ |
145 |
btnFreezeSuppInfo.setImage(ImageResources.getImage(ImageResources.LOCK_ICON)); |
|
146 |
btnFreezeSuppInfo.setToolTipText(Messages.CharacterMatrix_LOCK_COLUMNS); |
|
147 |
btnFreezeSuppInfo.setSelection(true); |
|
148 |
btnFreezeSuppInfo.addSelectionListener(new SelectionAdapter() { |
|
149 |
@Override |
|
150 |
public void widgetSelected(SelectionEvent e) { |
|
151 |
boolean isSelected = btnFreezeSuppInfo.getSelection(); |
|
152 |
matrix.freezeSupplementalColumns(isSelected); |
|
153 |
btnFreezeSuppInfo.setImage(isSelected? |
|
154 |
ImageResources.getImage(ImageResources.LOCK_ICON): |
|
155 |
ImageResources.getImage(ImageResources.LOCK_OPEN_ICON)); |
|
156 |
} |
|
157 |
}); |
|
147 |
initButton( |
|
148 |
btnFreezeSuppInfo, |
|
149 |
ImageResources.getImage(ImageResources.LOCK_ICON), |
|
150 |
Messages.CharacterMatrix_LOCK_COLUMNS, |
|
151 |
null, |
|
152 |
true, |
|
153 |
true, |
|
154 |
(e)->{ |
|
155 |
boolean isSelected = btnFreezeSuppInfo.getSelection(); |
|
156 |
matrix.freezeSupplementalColumns(isSelected); |
|
157 |
btnFreezeSuppInfo.setImage(isSelected? |
|
158 |
ImageResources.getImage(ImageResources.LOCK_ICON): |
|
159 |
ImageResources.getImage(ImageResources.LOCK_OPEN_ICON)); |
|
160 |
} |
|
161 |
); |
|
158 | 162 |
|
159 | 163 |
/** |
160 | 164 |
* Table state persistence |
... | ... | |
238 | 242 |
|
239 | 243 |
} |
240 | 244 |
|
245 |
private void initButton(Button button, Image image, String tooltipText, |
|
246 |
String label, boolean enabled, boolean selected, Consumer<SelectionEvent> widgetSelected){ |
|
247 |
if(image!=null){ |
|
248 |
button.setImage(image); |
|
249 |
} |
|
250 |
if(label!=null){ |
|
251 |
button.setText(label); |
|
252 |
} |
|
253 |
if(tooltipText!=null){ |
|
254 |
button.setToolTipText(tooltipText); |
|
255 |
} |
|
256 |
button.setSelection(selected); |
|
257 |
button.setEnabled(enabled); |
|
258 |
button.addSelectionListener(new SelectionAdapter() { |
|
259 |
@Override |
|
260 |
public void widgetSelected(SelectionEvent e) { |
|
261 |
widgetSelected.accept(e); |
|
262 |
} |
|
263 |
}); |
|
264 |
} |
|
265 |
|
|
241 | 266 |
public Label getWsLabel() { |
242 | 267 |
return wsLabel; |
243 | 268 |
} |
Also available in: Unified diff
ref #7549 Code refactoring