Project

General

Profile

« Previous | Next » 

Revision c5a4b091

Added by Patrick Plitzner almost 6 years ago

Refactor character matrix

  • extract cell selection config

View differences:

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

  
12
import java.util.Collection;
13

  
14
import org.eclipse.jface.viewers.StructuredSelection;
15
import org.eclipse.nebula.widgets.nattable.layer.ILayerListener;
16
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
17
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
18
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
19

  
20
/**
21
 * @author pplitzner
22
 * @date 09.07.2018
23
 *
24
 */
25
final class CellSelectionListener implements ILayerListener {
26

  
27
    private CharacterMatrixPart part;
28

  
29
    public CellSelectionListener(CharacterMatrixPart part) {
30
        super();
31
        this.part = part;
32
    }
33

  
34
    @Override
35
    public void handleLayerEvent(ILayerEvent event) {
36
        if(event instanceof CellSelectionEvent){
37
            CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
38
            int columnPosition = cellSelectionEvent.getColumnPosition();
39
            if(columnPosition>CharacterMatrix.LEADING_COLUMN_COUNT){
40
                Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
41
                StructuredSelection selection = new StructuredSelection();
42
                if(selectedCells.size()==1){
43
                    ILayerCell cell = selectedCells.iterator().next();
44
                    Object dataValue = cell.getDataValue();
45
                    if(dataValue!=null){
46
                        selection = new StructuredSelection(dataValue);
47
                    }
48
                }
49
                part.getSelectionService().setSelection(selection);
50
            }
51
        }
52
    }
53
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
25 25
import org.eclipse.core.runtime.jobs.Job;
26 26
import org.eclipse.jface.layout.GridDataFactory;
27 27
import org.eclipse.jface.viewers.ComboViewer;
28
import org.eclipse.jface.viewers.StructuredSelection;
29 28
import org.eclipse.nebula.widgets.nattable.NatTable;
30 29
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
31 30
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
......
53 52
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
54 53
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
55 54
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
56
import org.eclipse.nebula.widgets.nattable.layer.ILayerListener;
57 55
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
58
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
59
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
60 56
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
61 57
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
62
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
63 58
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
64 59
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
65 60
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
......
179 174
    private void applyStyles(){
180 175
        ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
181 176
        configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
177
        // NOTE: Getting the colors and fonts from the GUIHelper ensures that
178
        // they are disposed properly (required by SWT)
182 179
        configuration.summaryRowBgColor = GUIHelper.getColor(255, 255, 153);
183 180
        configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
184 181
        configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211);
185 182
        natTable.addConfiguration(configuration);
186
//        // NOTE: Getting the colors and fonts from the GUIHelper ensures that
187
//        // they are disposed properly (required by SWT)
188
//        DefaultNatTableStyleConfiguration natTableConfiguration = new DefaultNatTableStyleConfiguration();
189
//        natTableConfiguration.bgColor = GUIHelper.getColor(249, 172, 7);
190
//        natTableConfiguration.fgColor = GUIHelper.getColor(30, 76, 19);
191
//        natTableConfiguration.hAlign = HorizontalAlignmentEnum.LEFT;
192
//        natTableConfiguration.vAlign = VerticalAlignmentEnum.TOP;
193
////        natTableConfiguration.borderStyle = new BorderStyle(1, GUIHelper.getColor(249, 172, 7), LineStyleEnum.SOLID);
194
//
195
//        // Setup even odd row colors - row colors override the NatTable default
196
//        // colors
197
//        DefaultRowStyleConfiguration rowStyleConfiguration = new DefaultRowStyleConfiguration();
198
//        rowStyleConfiguration.oddRowBgColor = ColorResources.getColor(Resources.COLOR_LIST_ODD);
199
//        rowStyleConfiguration.evenRowBgColor = ColorResources.getColor(Resources.COLOR_LIST_EVEN);
200
//
201
//        // Setup selection styling
202
//        DefaultSelectionStyleConfiguration selectionStyle = new DefaultSelectionStyleConfiguration();
203
////        selectionStyle.selectionFont = GUIHelper.getFont(new FontData("Verdana", 8, SWT.NORMAL));
204
////        selectionStyle.selectionBgColor = GUIHelper.getColor(217, 232, 251);
205
////        selectionStyle.selectionFgColor = GUIHelper.COLOR_BLACK;
206
////        selectionStyle.anchorBorderStyle = new BorderStyle(1, GUIHelper.COLOR_DARK_GRAY, LineStyleEnum.SOLID);
207
////        selectionStyle.anchorBgColor = GUIHelper.getColor(65, 113, 43);
208
//        selectionStyle.selectedHeaderBgColor = GUIHelper.getColor(156, 209, 103);
209
//
210
//        // Add all style configurations to NatTable
211
//        natTable.addConfiguration(natTableConfiguration);
212
//        natTable.addConfiguration(rowStyleConfiguration);
213
//        natTable.addConfiguration(selectionStyle);
214
//
215
//        // Column/Row header style and custom painters
216
//        DefaultRowHeaderStyleConfiguration rowHeaderConfig = new DefaultRowHeaderStyleConfiguration();
217
//        Color rowColumnColor = GUIHelper.getColor(230, 255, 255);
218
//        rowHeaderConfig.bgColor = rowColumnColor;
219
//        natTable.addConfiguration(rowHeaderConfig);
220
//        DefaultColumnHeaderStyleConfiguration columnHeaderStyle = new DefaultColumnHeaderStyleConfiguration();
221
//        columnHeaderStyle.bgColor = rowColumnColor;
222
//        columnHeaderStyle.font = GUIHelper.getFont(new FontData("Verdana", 9, SWT.BOLD)); //$NON-NLS-1$
223
//        natTable.addConfiguration(columnHeaderStyle);
224 183

  
225 184
    }
226 185

  
......
253 212
         */
254 213
        registerHandlersAndListeners(topMostLayer);
255 214

  
215
        //grab all space
256 216
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
257 217

  
218
        //update label to current data set
258 219
        toolbar.getWsLabel().setText(descriptiveDataSet.getLabel());
259 220
        toolbar.getWsLabel().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
260 221
        toolbar.getWsLabel().getParent().layout();
261 222

  
223
        //initial freeze of supplemental columns
262 224
        freezeSupplementalColumns(true);
263 225

  
264 226
        this.layout();
......
451 413
        topMostLayer.registerCommandHandler(new ExportCommandHandler(topMostLayer));
452 414

  
453 415
        //propagate single cell selection
454
        natTable.addLayerListener(new ILayerListener() {
455
            @Override
456
            public void handleLayerEvent(ILayerEvent event) {
457
                if(event instanceof CellSelectionEvent){
458
                    CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
459
                    int columnPosition = cellSelectionEvent.getColumnPosition();
460
                    if(columnPosition>LEADING_COLUMN_COUNT){
461
                        Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
462
                        StructuredSelection selection = new StructuredSelection();
463
                        if(selectedCells.size()==1){
464
                            ILayerCell cell = selectedCells.iterator().next();
465
                            Object dataValue = cell.getDataValue();
466
                            if(dataValue!=null){
467
                                selection = new StructuredSelection(dataValue);
468
                            }
469
                        }
470
                        part.getSelectionService().setSelection(selection);
471
                    }
472
                }
473
            }
474
        });
416
        natTable.addLayerListener(new CellSelectionListener(part));
475 417

  
476 418
        //register handler for view configuration menu
477 419
        natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());

Also available in: Unified diff