Project

General

Profile

« Previous | Next » 

Revision 95272d6e

Added by Patrick Plitzner almost 6 years ago

Refactor CharacterMatrix code

  • extract toolbar composite

View differences:

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

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixToolbar.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
10

  
11
import java.io.File;
12
import java.io.FileInputStream;
13
import java.io.IOException;
14
import java.util.Collection;
15
import java.util.Properties;
16

  
17
import org.eclipse.jface.viewers.ArrayContentProvider;
18
import org.eclipse.jface.viewers.ComboViewer;
19
import org.eclipse.jface.viewers.LabelProvider;
20
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand;
21
import org.eclipse.nebula.widgets.nattable.persistence.PersistenceHelper;
22
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommand;
23
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler;
24
import org.eclipse.nebula.widgets.nattable.persistence.command.IStateChangedListener;
25
import org.eclipse.nebula.widgets.nattable.persistence.command.StateChangeEvent;
26
import org.eclipse.nebula.widgets.nattable.persistence.gui.PersistenceDialog;
27
import org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand;
28
import org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandAllCommand;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.events.SelectionAdapter;
31
import org.eclipse.swt.events.SelectionEvent;
32
import org.eclipse.swt.layout.GridData;
33
import org.eclipse.swt.layout.GridLayout;
34
import org.eclipse.swt.widgets.Button;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Label;
37

  
38
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
39
import eu.etaxonomy.taxeditor.model.ImageResources;
40
import eu.etaxonomy.taxeditor.model.MessagingUtils;
41

  
42
/**
43
 * @author pplitzner
44
 * @since Jul 9, 2018
45
 *
46
 */
47
public class CharacterMatrixToolbar extends Composite {
48

  
49
    private CharacterMatrix matrix;
50
    private Label wsLabel;
51
    private DisplayPersistenceDialogCommandHandler displayPersistenceDialogCommandHandler;
52
    private Properties natTableState;
53

  
54
    public CharacterMatrixToolbar(CharacterMatrix matrix, int style) {
55
        super(matrix, style);
56
        this.matrix = matrix;
57

  
58
        init();
59
    }
60

  
61
    private void init() {
62
        setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
63
        setLayout(new GridLayout(9, false));
64

  
65
        wsLabel = new Label(this, SWT.NONE);
66

  
67
        Button btnToggleTree = new Button(this, SWT.PUSH);
68
        Button btnToggleFlat = new Button(this, SWT.PUSH);
69
        Button btnCollapseAll = new Button(this, SWT.PUSH);
70
        Button btnExpandAll = new Button(this, SWT.PUSH);
71
        Button btnFreezeSuppInfo = new Button(this, SWT.TOGGLE);
72
        ComboViewer comboStates = new ComboViewer(this, SWT.DROP_DOWN);
73
        Button btnManageState = new Button(this, SWT.PUSH);
74
        Button btnExcelExport = new Button(this, SWT.PUSH);
75

  
76
        /**
77
         * Toogle tree button
78
         */
79
        btnToggleTree.setImage(ImageResources.getImage(ImageResources.HIERARCHICAL));
80
        btnToggleTree.setToolTipText(Messages.CharacterMatrix_SHOW_HIERARCHY);
81
        btnToggleTree.setSelection(true);
82
        btnToggleTree.setEnabled(false);
83
        btnToggleTree.addSelectionListener(new SelectionAdapter() {
84
            @Override
85
            public void widgetSelected(SelectionEvent e) {
86
                matrix.toggleTreeFlat(true, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo);
87
            }
88
        });
89

  
90
        /**
91
         * Toogle flat button
92
         */
93
        btnToggleFlat.setImage(ImageResources.getImage(ImageResources.FLAT));
94
        btnToggleFlat.setToolTipText(Messages.CharacterMatrix_SHOW_FLAT_LIST);
95
        btnToggleFlat.addSelectionListener(new SelectionAdapter() {
96
            @Override
97
            public void widgetSelected(SelectionEvent e) {
98
                matrix.toggleTreeFlat(false, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo);
99
            }
100
        });
101

  
102
        /**
103
         *
104
         * Collapse button
105
         */
106
        btnCollapseAll.setImage(ImageResources.getImage(ImageResources.COLLAPSE_ALL));
107
        btnCollapseAll.setToolTipText(Messages.CharacterMatrix_COLLAPSE);
108
        btnCollapseAll.addSelectionListener(new SelectionAdapter() {
109
            @Override
110
            public void widgetSelected(SelectionEvent e) {
111
                matrix.getNatTable().doCommand(new TreeCollapseAllCommand());
112
            }
113
        });
114

  
115
        /**
116
         * Expand button
117
         */
118
        btnExpandAll.setImage(ImageResources.getImage(ImageResources.EXPAND_ALL));
119
        btnExpandAll.setToolTipText(Messages.CharacterMatrix_EXPAND);
120
        btnExpandAll.addSelectionListener(new SelectionAdapter() {
121
            @Override
122
            public void widgetSelected(SelectionEvent e) {
123
                matrix.getNatTable().doCommand(new TreeExpandAllCommand());
124
            }
125
        });
126

  
127
        /**
128
         * Freeze supplemental info button
129
         */
130
        btnFreezeSuppInfo.setImage(ImageResources.getImage(ImageResources.LOCK_ICON));
131
        btnFreezeSuppInfo.setToolTipText(Messages.CharacterMatrix_LOCK_COLUMNS);
132
        btnFreezeSuppInfo.setSelection(true);
133
        btnFreezeSuppInfo.addSelectionListener(new SelectionAdapter() {
134
            @Override
135
            public void widgetSelected(SelectionEvent e) {
136
                boolean isSelected = btnFreezeSuppInfo.getSelection();
137
                matrix.freezeSupplementalColumns(isSelected);
138
                btnFreezeSuppInfo.setImage(isSelected?
139
                                ImageResources.getImage(ImageResources.LOCK_ICON):
140
                                    ImageResources.getImage(ImageResources.LOCK_OPEN_ICON));
141
            }
142
        });
143

  
144
        /**
145
         * Table state persistence
146
         */
147
        natTableState = new Properties();
148
        //load persisted state
149
        File statePropertiesFile = matrix.getStatePropertiesFile();
150
        FileInputStream inputStream;
151
        try {
152
            inputStream = new FileInputStream(statePropertiesFile);
153
            natTableState.load(inputStream);
154
        } catch (IOException e) {
155
            MessagingUtils.info("No initial state properties file found for character matrix"); //$NON-NLS-1$
156
        }
157

  
158
        // create a combobox for showing the available view states
159
        Collection<String> availableStates = PersistenceHelper.getAvailableStates(natTableState);
160
        comboStates.setLabelProvider(new LabelProvider(){
161
            @Override
162
            public String getText(Object element) {
163
                if(element instanceof String && ((String) element).isEmpty()){
164
                    return Messages.CharacterMatrix_DEFAULT;
165
                }
166
                return super.getText(element);
167
            }
168
        });
169
        comboStates.setContentProvider(new ArrayContentProvider());
170
        comboStates.addSelectionChangedListener(e->
171
        {
172
            int index = comboStates.getCombo().getSelectionIndex();
173
            if (index >= 0) {
174
                String selected = comboStates.getCombo().getItem(index);
175
                // load the state
176
                matrix.getNatTable().loadState(selected, natTableState);
177
                natTableState.setProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, selected);
178
            }
179
        });
180
        comboStates.setInput(availableStates);
181
        if(comboStates.getCombo().getItemCount()>0){
182
            comboStates.getCombo().select(0);
183
        }
184

  
185
        displayPersistenceDialogCommandHandler = new DisplayPersistenceDialogCommandHandler(natTableState, matrix.getNatTable());
186
        // add listener to update the combo on view state management changes
187
        displayPersistenceDialogCommandHandler.addStateChangeListener(new IStateChangedListener() {
188
            @Override
189
            public void handleStateChange(StateChangeEvent event) {
190
                comboStates.setInput(PersistenceHelper.getAvailableStates(natTableState));
191
                matrix.selectStateItem(comboStates, event.getViewConfigName());
192
            }
193
        });
194

  
195
        // add button to show dialog
196
        btnManageState.setImage(ImageResources.getImage(ImageResources.SETTINGS));
197
        btnManageState.setToolTipText(Messages.CharacterMatrix_VIEW_CONFIG);
198
        btnManageState.addSelectionListener(new SelectionAdapter() {
199
            @Override
200
            public void widgetSelected(SelectionEvent e) {
201
                matrix.getNatTable().doCommand(new DisplayPersistenceDialogCommand(matrix.getNatTable()));
202
                matrix.selectStateItem(comboStates, natTableState.get(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY).toString());
203
            }
204
        });
205

  
206
        /**
207
         * excel export
208
         */
209
        btnExcelExport.setToolTipText(Messages.CharacterMatrix_EXPORT);
210
        btnExcelExport.setImage(ImageResources.getImage(ImageResources.EXPORT));
211
        btnExcelExport.addSelectionListener(new SelectionAdapter() {
212
            @Override
213
            public void widgetSelected(SelectionEvent e) {
214
                matrix.getNatTable().doCommand(
215
                        new ExportCommand(
216
                                matrix.getNatTable().getConfigRegistry(),
217
                                matrix.getNatTable().getShell()));
218
            }
219
        });
220

  
221
    }
222

  
223
    public Label getWsLabel() {
224
        return wsLabel;
225
    }
226

  
227
    public Properties getNatTableState() {
228
        return natTableState;
229
    }
230

  
231
    public DisplayPersistenceDialogCommandHandler getDisplayPersistenceDialogCommandHandler() {
232
        return displayPersistenceDialogCommandHandler;
233
    }
234
}

Also available in: Unified diff