Project

General

Profile

« Previous | Next » 

Revision 0b9b379c

Added by Patrick Plitzner over 6 years ago

ref #7095 Add persistence support for nattable state

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10 10

  
11
import java.io.File;
12
import java.io.FileInputStream;
13
import java.io.FileOutputStream;
14
import java.io.IOException;
11 15
import java.util.ArrayList;
12 16
import java.util.Collection;
13 17
import java.util.Collections;
14 18
import java.util.HashMap;
15 19
import java.util.List;
16 20
import java.util.Map;
21
import java.util.Properties;
17 22
import java.util.Set;
18 23
import java.util.UUID;
19 24

  
......
59 64
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
60 65
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
61 66
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
67
import org.eclipse.nebula.widgets.nattable.persistence.PersistenceHelper;
68
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommand;
62 69
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler;
70
import org.eclipse.nebula.widgets.nattable.persistence.command.IStateChangedListener;
71
import org.eclipse.nebula.widgets.nattable.persistence.command.StateChangeEvent;
63 72
import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
64 73
import org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer;
65 74
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
......
75 84
import org.eclipse.swt.events.SelectionEvent;
76 85
import org.eclipse.swt.layout.GridLayout;
77 86
import org.eclipse.swt.widgets.Button;
87
import org.eclipse.swt.widgets.Combo;
78 88
import org.eclipse.swt.widgets.Composite;
79 89

  
80 90
import ca.odell.glazedlists.EventList;
......
101 111
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
102 112
import eu.etaxonomy.taxeditor.model.MessagingUtils;
103 113
import eu.etaxonomy.taxeditor.store.CdmStore;
114
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
104 115
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
105 116

  
106 117
/**
......
110 121
 */
111 122
public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails, IConversationEnabled, IDirtyMarkable{
112 123

  
124
    private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties";
125

  
113 126
    private static final int LEADING_COLUMN_COUNT = 4;
114 127
    private static final String TAXON_COLUMN = "taxon_column";
115 128
    private static final String COLLECTOR_COLUMN = "collector_column";
......
245 258

  
246 259
        natTable = new NatTable(parent, gridLayer, false);
247 260

  
261

  
262
        /**
263
         * CONFIGURATION
264
         */
248 265
        natTable.setConfigRegistry(configRegistry);
249 266

  
250 267

  
......
336 353

  
337 354
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
338 355

  
339
        //persist table config handler
340
        gridLayer.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
356
        /**
357
         * Table state persistence
358
         */
359
        Properties natTableState = new Properties();
360
        //load persisted state
361
        File statePropertiesFile = new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
362
        FileInputStream inputStream;
363
        try {
364
            inputStream = new FileInputStream(statePropertiesFile);
365
            natTableState.load(inputStream);
366
            natTable.loadState("", natTableState);
367
        } catch (IOException e) {
368
            MessagingUtils.error(CharacterMatrix.class, e);;e.printStackTrace();
369
        }
370

  
371
        DisplayPersistenceDialogCommandHandler handler =
372
                new DisplayPersistenceDialogCommandHandler(natTableState, natTable);
373
        gridLayer.registerCommandHandler(handler);
374
     // create a combobox for showing the available view states
375
        Combo viewStates = new Combo(parent, SWT.DROP_DOWN);
376
        viewStates.setItems(PersistenceHelper
377
                .getAvailableStates(natTableState)
378
                .toArray(new String[] {}));
379
        viewStates.addSelectionListener(new SelectionAdapter() {
341 380

  
342
        //excel export
381
            @Override
382
            public void widgetSelected(SelectionEvent e) {
383
                int index = viewStates.getSelectionIndex();
384
                if (index >= 0) {
385
                    String selected = viewStates.getItem(index);
386
                    // load the state
387
                    natTable.loadState(selected, natTableState);
388
                }
389
            }
390
        });
391

  
392
        // add listener to update the combo on view state management changes
393
        handler.addStateChangeListener(new IStateChangedListener() {
394

  
395
            @Override
396
            public void handleStateChange(StateChangeEvent event) {
397
                viewStates.setItems(PersistenceHelper
398
                        .getAvailableStates(natTableState)
399
                        .toArray(new String[] {}));
400
            }
401
        });
402

  
403
        // add button to show dialog
404
        Button manage = new Button(parent, SWT.PUSH);
405
        manage.setText("View Management");
406
        manage.addSelectionListener(new SelectionAdapter() {
407
            @Override
408
            public void widgetSelected(SelectionEvent e) {
409
                natTable.doCommand(new DisplayPersistenceDialogCommand(natTable));
410
            }
411
        });
412
        Button btnSave = new Button(parent, SWT.PUSH);
413
        btnSave.setText("Save State");
414
        btnSave.addSelectionListener(new SelectionAdapter() {
415
            @Override
416
            public void widgetSelected(SelectionEvent e) {
417
                natTable.saveState("", natTableState);
418
                try (FileOutputStream tableStateStream =
419
                        new FileOutputStream(new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES))) {
420
                    natTableState.store(tableStateStream, null);
421
                } catch (IOException ioe) {
422
                    ioe.printStackTrace();
423
                }
424
            }
425
        });
426

  
427
        /**
428
         * excel export
429
         */
343 430
        Button addColumnButton = new Button(parent, SWT.PUSH);
344 431
        addColumnButton.setText("Export");
345 432
        addColumnButton.addSelectionListener(new SelectionAdapter() {

Also available in: Unified diff