Revision 95272d6e
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix; |
10 | 10 |
|
11 | 11 |
import java.io.File; |
12 |
import java.io.FileInputStream; |
|
13 |
import java.io.IOException; |
|
14 | 12 |
import java.util.ArrayList; |
15 | 13 |
import java.util.Collection; |
16 | 14 |
import java.util.HashMap; |
... | ... | |
27 | 25 |
import org.eclipse.core.runtime.IProgressMonitor; |
28 | 26 |
import org.eclipse.core.runtime.jobs.Job; |
29 | 27 |
import org.eclipse.jface.layout.GridDataFactory; |
30 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
31 | 28 |
import org.eclipse.jface.viewers.ComboViewer; |
32 |
import org.eclipse.jface.viewers.LabelProvider; |
|
33 | 29 |
import org.eclipse.jface.viewers.StructuredSelection; |
34 | 30 |
import org.eclipse.jface.window.Window; |
35 | 31 |
import org.eclipse.nebula.widgets.nattable.NatTable; |
... | ... | |
43 | 39 |
import org.eclipse.nebula.widgets.nattable.data.IDataProvider; |
44 | 40 |
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider; |
45 | 41 |
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; |
46 |
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand; |
|
47 | 42 |
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler; |
48 | 43 |
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer; |
49 | 44 |
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel; |
... | ... | |
73 | 68 |
import org.eclipse.nebula.widgets.nattable.layer.config.DefaultRowHeaderStyleConfiguration; |
74 | 69 |
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent; |
75 | 70 |
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack; |
76 |
import org.eclipse.nebula.widgets.nattable.persistence.PersistenceHelper; |
|
77 |
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommand; |
|
78 |
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler; |
|
79 |
import org.eclipse.nebula.widgets.nattable.persistence.command.IStateChangedListener; |
|
80 |
import org.eclipse.nebula.widgets.nattable.persistence.command.StateChangeEvent; |
|
81 |
import org.eclipse.nebula.widgets.nattable.persistence.gui.PersistenceDialog; |
|
82 | 71 |
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; |
83 | 72 |
import org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration; |
84 | 73 |
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent; |
... | ... | |
96 | 85 |
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer; |
97 | 86 |
import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel; |
98 | 87 |
import org.eclipse.nebula.widgets.nattable.tree.TreeLayer; |
99 |
import org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand; |
|
100 |
import org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandAllCommand; |
|
101 | 88 |
import org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration; |
102 | 89 |
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder; |
103 | 90 |
import org.eclipse.nebula.widgets.nattable.util.GUIHelper; |
... | ... | |
112 | 99 |
import org.eclipse.swt.layout.RowLayout; |
113 | 100 |
import org.eclipse.swt.widgets.Button; |
114 | 101 |
import org.eclipse.swt.widgets.Composite; |
115 |
import org.eclipse.swt.widgets.Label; |
|
116 | 102 |
|
117 | 103 |
import ca.odell.glazedlists.BasicEventList; |
118 | 104 |
import ca.odell.glazedlists.EventList; |
... | ... | |
120 | 106 |
import ca.odell.glazedlists.TreeList; |
121 | 107 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState; |
122 | 108 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
109 |
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService; |
|
123 | 110 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
124 | 111 |
import eu.etaxonomy.cdm.api.service.IProgressMonitorService; |
125 |
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService; |
|
126 | 112 |
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO; |
127 | 113 |
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor; |
128 | 114 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
129 | 115 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
116 |
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet; |
|
130 | 117 |
import eu.etaxonomy.cdm.model.description.Feature; |
131 | 118 |
import eu.etaxonomy.cdm.model.description.FeatureNode; |
132 | 119 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
... | ... | |
134 | 121 |
import eu.etaxonomy.cdm.model.description.QuantitativeData; |
135 | 122 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
136 | 123 |
import eu.etaxonomy.cdm.model.description.State; |
137 |
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet; |
|
138 | 124 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
139 | 125 |
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper; |
140 | 126 |
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataCellEditor; |
... | ... | |
177 | 163 |
|
178 | 164 |
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>(); |
179 | 165 |
|
180 |
private Properties natTableState; |
|
181 |
|
|
182 | 166 |
private EventList<Object> descriptions; |
183 | 167 |
|
184 | 168 |
private Collection<SpecimenNodeWrapper> specimenCache = null; |
... | ... | |
189 | 173 |
|
190 | 174 |
private ViewportLayer viewportLayer; |
191 | 175 |
|
192 |
private Label wsLabel; |
|
193 |
|
|
194 | 176 |
private List<Feature> features; |
195 | 177 |
|
196 |
private DisplayPersistenceDialogCommandHandler displayPersistenceDialogCommandHandler; |
|
197 |
|
|
198 | 178 |
private CharacterMatrixPart part; |
199 | 179 |
|
200 | 180 |
private AbstractLayer topMostLayer; |
... | ... | |
207 | 187 |
|
208 | 188 |
private boolean isTreeView = true; |
209 | 189 |
|
190 |
private CharacterMatrixToolbar toolbar; |
|
191 |
|
|
210 | 192 |
|
211 | 193 |
public CharacterMatrix(Composite parent, CharacterMatrixPart part) { |
212 | 194 |
super(parent, SWT.NONE); |
... | ... | |
224 | 206 |
} |
225 | 207 |
|
226 | 208 |
private void createToolBar(){ |
227 |
Composite toolbarComposite = new Composite(this, SWT.NONE); |
|
228 |
toolbarComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
|
229 |
toolbarComposite.setLayout(new GridLayout(9, false)); |
|
230 |
|
|
231 |
wsLabel = new Label(toolbarComposite, SWT.NONE); |
|
232 |
|
|
233 |
Button btnToggleTree = new Button(toolbarComposite, SWT.PUSH); |
|
234 |
Button btnToggleFlat = new Button(toolbarComposite, SWT.PUSH); |
|
235 |
Button btnCollapseAll = new Button(toolbarComposite, SWT.PUSH); |
|
236 |
Button btnExpandAll = new Button(toolbarComposite, SWT.PUSH); |
|
237 |
Button btnFreezeSuppInfo = new Button(toolbarComposite, SWT.TOGGLE); |
|
238 |
ComboViewer comboStates = new ComboViewer(toolbarComposite, SWT.DROP_DOWN); |
|
239 |
Button btnManageState = new Button(toolbarComposite, SWT.PUSH); |
|
240 |
Button btnExcelExport = new Button(toolbarComposite, SWT.PUSH); |
|
241 |
|
|
242 |
/** |
|
243 |
* Toogle tree button |
|
244 |
*/ |
|
245 |
btnToggleTree.setImage(ImageResources.getImage(ImageResources.HIERARCHICAL)); |
|
246 |
btnToggleTree.setToolTipText(Messages.CharacterMatrix_SHOW_HIERARCHY); |
|
247 |
btnToggleTree.setSelection(true); |
|
248 |
btnToggleTree.setEnabled(false); |
|
249 |
btnToggleTree.addSelectionListener(new SelectionAdapter() { |
|
250 |
@Override |
|
251 |
public void widgetSelected(SelectionEvent e) { |
|
252 |
toggleTreeFlat(true, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo); |
|
253 |
} |
|
254 |
}); |
|
255 |
|
|
256 |
/** |
|
257 |
* Toogle flat button |
|
258 |
*/ |
|
259 |
btnToggleFlat.setImage(ImageResources.getImage(ImageResources.FLAT)); |
|
260 |
btnToggleFlat.setToolTipText(Messages.CharacterMatrix_SHOW_FLAT_LIST); |
|
261 |
btnToggleFlat.addSelectionListener(new SelectionAdapter() { |
|
262 |
@Override |
|
263 |
public void widgetSelected(SelectionEvent e) { |
|
264 |
toggleTreeFlat(false, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo); |
|
265 |
} |
|
266 |
}); |
|
267 |
|
|
268 |
/** |
|
269 |
* |
|
270 |
* Collapse button |
|
271 |
*/ |
|
272 |
btnCollapseAll.setImage(ImageResources.getImage(ImageResources.COLLAPSE_ALL)); |
|
273 |
btnCollapseAll.setToolTipText(Messages.CharacterMatrix_COLLAPSE); |
|
274 |
btnCollapseAll.addSelectionListener(new SelectionAdapter() { |
|
275 |
@Override |
|
276 |
public void widgetSelected(SelectionEvent e) { |
|
277 |
natTable.doCommand(new TreeCollapseAllCommand()); |
|
278 |
} |
|
279 |
}); |
|
280 |
|
|
281 |
/** |
|
282 |
* Expand button |
|
283 |
*/ |
|
284 |
btnExpandAll.setImage(ImageResources.getImage(ImageResources.EXPAND_ALL)); |
|
285 |
btnExpandAll.setToolTipText(Messages.CharacterMatrix_EXPAND); |
|
286 |
btnExpandAll.addSelectionListener(new SelectionAdapter() { |
|
287 |
@Override |
|
288 |
public void widgetSelected(SelectionEvent e) { |
|
289 |
natTable.doCommand(new TreeExpandAllCommand()); |
|
290 |
} |
|
291 |
}); |
|
292 |
|
|
293 |
/** |
|
294 |
* Freeze supplemental info button |
|
295 |
*/ |
|
296 |
btnFreezeSuppInfo.setImage(ImageResources.getImage(ImageResources.LOCK_ICON)); |
|
297 |
btnFreezeSuppInfo.setToolTipText(Messages.CharacterMatrix_LOCK_COLUMNS); |
|
298 |
btnFreezeSuppInfo.setSelection(true); |
|
299 |
btnFreezeSuppInfo.addSelectionListener(new SelectionAdapter() { |
|
300 |
@Override |
|
301 |
public void widgetSelected(SelectionEvent e) { |
|
302 |
boolean isSelected = btnFreezeSuppInfo.getSelection(); |
|
303 |
freezeSupplementalColumns(isSelected); |
|
304 |
btnFreezeSuppInfo.setImage(isSelected? |
|
305 |
ImageResources.getImage(ImageResources.LOCK_ICON): |
|
306 |
ImageResources.getImage(ImageResources.LOCK_OPEN_ICON)); |
|
307 |
} |
|
308 |
}); |
|
309 |
|
|
310 |
/** |
|
311 |
* Table state persistence |
|
312 |
*/ |
|
313 |
natTableState = new Properties(); |
|
314 |
//load persisted state |
|
315 |
File statePropertiesFile = getStatePropertiesFile(); |
|
316 |
FileInputStream inputStream; |
|
317 |
try { |
|
318 |
inputStream = new FileInputStream(statePropertiesFile); |
|
319 |
natTableState.load(inputStream); |
|
320 |
} catch (IOException e) { |
|
321 |
MessagingUtils.info("No initial state properties file found for character matrix"); //$NON-NLS-1$ |
|
322 |
} |
|
323 |
|
|
324 |
// create a combobox for showing the available view states |
|
325 |
Collection<String> availableStates = PersistenceHelper.getAvailableStates(natTableState); |
|
326 |
comboStates.setLabelProvider(new LabelProvider(){ |
|
327 |
@Override |
|
328 |
public String getText(Object element) { |
|
329 |
if(element instanceof String && ((String) element).isEmpty()){ |
|
330 |
return Messages.CharacterMatrix_DEFAULT; |
|
331 |
} |
|
332 |
return super.getText(element); |
|
333 |
} |
|
334 |
}); |
|
335 |
comboStates.setContentProvider(new ArrayContentProvider()); |
|
336 |
comboStates.addSelectionChangedListener(e-> |
|
337 |
{ |
|
338 |
int index = comboStates.getCombo().getSelectionIndex(); |
|
339 |
if (index >= 0) { |
|
340 |
String selected = comboStates.getCombo().getItem(index); |
|
341 |
// load the state |
|
342 |
natTable.loadState(selected, natTableState); |
|
343 |
natTableState.setProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, selected); |
|
344 |
} |
|
345 |
}); |
|
346 |
comboStates.setInput(availableStates); |
|
347 |
if(comboStates.getCombo().getItemCount()>0){ |
|
348 |
comboStates.getCombo().select(0); |
|
349 |
} |
|
350 |
|
|
351 |
displayPersistenceDialogCommandHandler = new DisplayPersistenceDialogCommandHandler(natTableState, natTable); |
|
352 |
// add listener to update the combo on view state management changes |
|
353 |
displayPersistenceDialogCommandHandler.addStateChangeListener(new IStateChangedListener() { |
|
354 |
@Override |
|
355 |
public void handleStateChange(StateChangeEvent event) { |
|
356 |
comboStates.setInput(PersistenceHelper.getAvailableStates(natTableState)); |
|
357 |
selectStateItem(comboStates, event.getViewConfigName()); |
|
358 |
} |
|
359 |
}); |
|
360 |
|
|
361 |
// add button to show dialog |
|
362 |
btnManageState.setImage(ImageResources.getImage(ImageResources.SETTINGS)); |
|
363 |
btnManageState.setToolTipText(Messages.CharacterMatrix_VIEW_CONFIG); |
|
364 |
btnManageState.addSelectionListener(new SelectionAdapter() { |
|
365 |
@Override |
|
366 |
public void widgetSelected(SelectionEvent e) { |
|
367 |
natTable.doCommand(new DisplayPersistenceDialogCommand(natTable)); |
|
368 |
selectStateItem(comboStates, natTableState.get(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY).toString()); |
|
369 |
} |
|
370 |
}); |
|
371 |
|
|
372 |
/** |
|
373 |
* excel export |
|
374 |
*/ |
|
375 |
btnExcelExport.setToolTipText(Messages.CharacterMatrix_EXPORT); |
|
376 |
btnExcelExport.setImage(ImageResources.getImage(ImageResources.EXPORT)); |
|
377 |
btnExcelExport.addSelectionListener(new SelectionAdapter() { |
|
378 |
@Override |
|
379 |
public void widgetSelected(SelectionEvent e) { |
|
380 |
natTable.doCommand( |
|
381 |
new ExportCommand( |
|
382 |
natTable.getConfigRegistry(), |
|
383 |
natTable.getShell())); |
|
384 |
} |
|
385 |
}); |
|
209 |
toolbar = new CharacterMatrixToolbar(this, SWT.NONE); |
|
386 | 210 |
} |
387 | 211 |
|
388 | 212 |
private void createBottomToolbar() { |
... | ... | |
488 | 312 |
|
489 | 313 |
} |
490 | 314 |
|
491 |
private void toggleTreeFlat(boolean isTree, Button btnToggleFlat, Button btnToggleTree, Button btnCollapseAll, Button btnExpandAll, Button btnFreezeSuppInfo) {
|
|
315 |
void toggleTreeFlat(boolean isTree, Button btnToggleFlat, Button btnToggleTree, Button btnCollapseAll, Button btnExpandAll, Button btnFreezeSuppInfo) { |
|
492 | 316 |
isTreeView = isTree; |
493 | 317 |
createTable(isTree); |
494 | 318 |
btnToggleFlat.setEnabled(isTree); |
... | ... | |
519 | 343 |
|
520 | 344 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable); |
521 | 345 |
|
522 |
wsLabel.setText(descriptiveDataSet.getLabel());
|
|
523 |
wsLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
|
524 |
wsLabel.getParent().layout();
|
|
346 |
toolbar.getWsLabel().setText(descriptiveDataSet.getLabel());
|
|
347 |
toolbar.getWsLabel().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
|
348 |
toolbar.getWsLabel().getParent().layout();
|
|
525 | 349 |
|
526 | 350 |
freezeSupplementalColumns(true); |
527 | 351 |
|
... | ... | |
740 | 564 |
}); |
741 | 565 |
|
742 | 566 |
//register handler for view configuration menu |
743 |
natTable.registerCommandHandler(displayPersistenceDialogCommandHandler);
|
|
567 |
natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
|
|
744 | 568 |
} |
745 | 569 |
|
746 | 570 |
private void configureNatTable(boolean treeView, ConfigRegistry configRegistry, AbstractLayer topMostLayer, |
... | ... | |
854 | 678 |
natTable.configure(); |
855 | 679 |
} |
856 | 680 |
|
857 |
private void freezeSupplementalColumns(boolean freeze){
|
|
681 |
void freezeSupplementalColumns(boolean freeze){ |
|
858 | 682 |
if(freeze){ |
859 | 683 |
FreezeHelper.freeze(freezeLayer, viewportLayer, |
860 | 684 |
new PositionCoordinate(viewportLayer, 0, 0), |
... | ... | |
865 | 689 |
} |
866 | 690 |
} |
867 | 691 |
|
868 |
private void selectStateItem(ComboViewer comboStates, String stateName){
|
|
692 |
void selectStateItem(ComboViewer comboStates, String stateName){ |
|
869 | 693 |
String[] items = comboStates.getCombo().getItems(); |
870 | 694 |
for(int i=0;i<items.length;i++){ |
871 | 695 |
if(items[i].equals(stateName)){ |
... | ... | |
1103 | 927 |
} |
1104 | 928 |
|
1105 | 929 |
public Properties getNatTableState() { |
1106 |
return natTableState;
|
|
930 |
return toolbar.getNatTableState();
|
|
1107 | 931 |
} |
1108 | 932 |
|
1109 | 933 |
public ListDataProvider<Object> getBodyDataProvider() { |
1110 | 934 |
return bodyDataProvider; |
1111 | 935 |
} |
1112 | 936 |
|
1113 |
private File getStatePropertiesFile() {
|
|
937 |
File getStatePropertiesFile() { |
|
1114 | 938 |
return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES); |
1115 | 939 |
} |
1116 | 940 |
|
Also available in: Unified diff
Refactor CharacterMatrix code