Project

General

Profile

« Previous | Next » 

Revision fa33762c

Added by Patrick Plitzner almost 5 years ago

ref #7095 Add column sorting to character matrix

View differences:

eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF
39 39
 org.eclipse.e4.core.commands,
40 40
 org.eclipse.e4.core.services,
41 41
 org.eclipse.e4.core.contexts,
42
 org.eclipse.nebula.widgets.nattable.core
42
 org.eclipse.nebula.widgets.nattable.core,
43
 org.eclipse.nebula.widgets.nattable.extension.glazedlists,
44
 ca.odell.glazedlists
43 45
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
44 46
Bundle-ActivationPolicy: lazy
45 47
Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
27 27
import org.eclipse.nebula.widgets.nattable.NatTable;
28 28
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
29 29
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
30
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
30 31
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
31 32
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
32 33
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
33 34
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
34 35
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand;
35 36
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
37
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
38
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
36 39
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
37 40
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
38 41
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
......
46 49
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator;
47 50
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
48 51
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
52
import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
53
import org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer;
49 54
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
50 55
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
56
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
57
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
51 58
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
52 59
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
53 60
import org.eclipse.swt.SWT;
......
57 64
import org.eclipse.swt.widgets.Button;
58 65
import org.eclipse.swt.widgets.Composite;
59 66

  
67
import ca.odell.glazedlists.EventList;
68
import ca.odell.glazedlists.GlazedLists;
69
import ca.odell.glazedlists.SortedList;
60 70
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
61 71
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
62 72
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
......
110 120
        this.workingSet = workingSet;
111 121
        thisPart.setLabel(workingSet.getLabel());
112 122

  
123
        EventList<SpecimenDescription> descriptions = GlazedLists.eventList(getDescriptions(workingSet));
124
        SortedList<SpecimenDescription> sortedList = new SortedList<>(descriptions, null);
125

  
113 126
        // create the data provider
114 127
        SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(workingSet);
115
        IDataProvider bodyDataProvider = new ListDataProvider<SpecimenDescription>(getDescriptions(workingSet), columnPropertyAccessor);
128
        IDataProvider bodyDataProvider = new ListDataProvider<SpecimenDescription>(sortedList, columnPropertyAccessor);
116 129

  
117 130
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
118
        SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
131
        GlazedListsEventLayer<SpecimenDescription> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, sortedList);
132

  
133
        RowReorderLayer rowReorderLayer = new RowReorderLayer(eventLayer);
134
        ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(rowReorderLayer);
135
        SelectionLayer selectionLayer = new SelectionLayer(columnReorderLayer);
119 136
        ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
120 137

  
121 138
        // build the column header layer stack
......
124 141
        DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
125 142
        ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
126 143

  
144
        ConfigRegistry configRegistry = new ConfigRegistry();
145

  
146
        // add the SortHeaderLayer to the column header layer stack
147
        // as we use GlazedLists, we use the GlazedListsSortModel which
148
        // delegates the sorting to the SortedList
149
        final SortHeaderLayer sortHeaderLayer =
150
                new SortHeaderLayer<>(
151
                        columnHeaderLayer,
152
                        new GlazedListsSortModel<>(
153
                                sortedList,
154
                                columnPropertyAccessor,
155
                                configRegistry,
156
                                columnHeaderDataLayer));
157

  
127 158
        // build the row header layer stack
128 159
        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
129 160
        DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider, 40, 20);
......
132 163
        // build the corner layer stack
133 164
        ILayer cornerLayer = new CornerLayer(
134 165
                new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
135
                rowHeaderLayer, columnHeaderLayer);
166
                rowHeaderLayer, sortHeaderLayer);
136 167

  
137 168
        // create the grid layer composed with the prior created layer stacks
138
        GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
169
        GridLayer gridLayer = new GridLayer(viewportLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
139 170

  
140 171

  
141 172
        //Create a ColumnLabelAccumulator to allow adding different configuration for columns
......
145 176

  
146 177
        natTable = new NatTable(parent, gridLayer, false);
147 178

  
179
        natTable.setConfigRegistry(configRegistry);
180

  
181

  
148 182
        //add default configuration because autoconfigure is set to false in constructor
149 183
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
150 184

  
185
        // override the default sort configuration and change the mouse bindings
186
        // to sort on a single click
187
        natTable.addConfiguration(new SingleClickSortConfiguration());
188

  
189
//        natTable.addConfiguration( new DefaultSortConfiguration());
190

  
151 191
        // add custom configuration for data conversion
152 192
        viewportLayer.addConfiguration(new AbstractRegistryConfiguration() {
153 193

  
eu.etaxonomy.taxeditor.feature.platform/feature.xml
245 245
         version="0.0.0"
246 246
         unpack="false"/>
247 247

  
248
   <plugin
249
         id="ca.odell.glazedlists"
250
         download-size="0"
251
         install-size="0"
252
         version="0.0.0"
253
         unpack="false"/>
254

  
255
   <plugin
256
         id="org.eclipse.nebula.widgets.nattable.extension.glazedlists"
257
         download-size="0"
258
         install-size="0"
259
         version="0.0.0"
260
         unpack="false"/>
261

  
248 262
</feature>

Also available in: Unified diff