Project

General

Profile

Revision 029aa66a

ID029aa66a2a846a47f929e4656fbe112df52506a6
Parent 387ccf8f
Child a1b92e88

Added by Patrick Plitzner over 1 year ago

ref #7439 Add sorting and cell text left-align to bulk editor nat table

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
36 36
import org.eclipse.nebula.widgets.nattable.NatTable;
37 37
import org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand;
38 38
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
39
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
39 40
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
40 41
import org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor;
41 42
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
42 43
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
44
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
43 45
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
44 46
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
45 47
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
......
53 55
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel;
54 56
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
55 57
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
58
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
59
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
60
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
56 61
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
57 62
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
58 63
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
......
67 72
import org.eclipse.swt.widgets.Display;
68 73
import org.eclipse.swt.widgets.Menu;
69 74

  
75
import ca.odell.glazedlists.SortedList;
70 76
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
71 77
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
72 78
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
73 79
import eu.etaxonomy.cdm.model.common.CdmBase;
80
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
74 81
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
75 82
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
76 83
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
87 94
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
88 95
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
89 96
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
97
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
90 98
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
91 99

  
92 100
/**
......
153 161
            performSearch(new BulkEditorQuery(input.getEntityUuid().toString(), null));
154 162
        }
155 163

  
156
        //++++NatTable++++
164
        createTable();
165

  
166
        configureTable();
167

  
168
        styleTable();
169

  
170
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
171

  
172
        //propagate selection
173
        selectionChangedListener = (event -> selService.setSelection(getSelection()));
174
        RowSelectionProvider<CdmBase> selectionProvider = new RowSelectionProvider<CdmBase>(selectionLayer, bodyDataProvider, true);
175
        selectionProvider.addSelectionChangedListener(selectionChangedListener);
176
	}
177

  
178
	private void createTable(){
179
	    ConfigRegistry configRegistry = new ConfigRegistry();
180
	    //property map
157 181
        Map<String, String> propertyToLabels = new HashMap<>();
158 182
        propertyToLabels.put(getEditorInput().getName(), getEditorInput().getName());
159 183
        propertyToLabels.put(TYPE_PROPERTY, TYPE_PROPERTY);
160 184
        String[] propertyNames = new String[] { getEditorInput().getName(), TYPE_PROPERTY };
185
        //sorted list
186
        SortedList<CdmBase> sortedList = new SortedList<>(getEditorInput().getModel(), new DefaultCdmBaseComparator<CdmBase>());
161 187
        //data provider
162
        bodyDataProvider = new ListDataProvider<CdmBase>(getEditorInput().getModel(),
163
                new BulkEditorPropertyAccessor(getEditorInput()));
188
        BulkEditorPropertyAccessor columnPropertyAccessor = new BulkEditorPropertyAccessor(getEditorInput());
189
        bodyDataProvider = new ListDataProvider<CdmBase>(sortedList,
190
                columnPropertyAccessor);
164 191
        DefaultColumnHeaderDataProvider colHeaderDataProvider = new DefaultColumnHeaderDataProvider(
165 192
                propertyNames, propertyToLabels);
166 193
        DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
......
171 198
        DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(eventLayer);
172 199
        selectionLayer = bodyLayer.getSelectionLayer();
173 200
        //column
201
        DataLayer columnHeaderDataLayer = new DataLayer(colHeaderDataProvider);
174 202
        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(
175
                new DataLayer(colHeaderDataProvider),
203
                columnHeaderDataLayer,
176 204
                bodyLayer, bodyLayer.getSelectionLayer());
205
        // add the SortHeaderLayer to the column header layer stack
206
        // as we use GlazedLists, we use the GlazedListsSortModel which
207
        // delegates the sorting to the SortedList
208
        final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>(
209
                columnHeaderLayer,
210
                new GlazedListsSortModel<>(
211
                        sortedList,
212
                        columnPropertyAccessor,
213
                        configRegistry,
214
                        columnHeaderDataLayer));
177 215
        //row
178 216
        RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 50, 20),
179 217
                bodyLayer, bodyLayer.getSelectionLayer());
......
181 219
        DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(
182 220
                colHeaderDataProvider, rowHeaderDataProvider);
183 221
        CornerLayer cornerLayer = new CornerLayer(new DataLayer(
184
                cornerDataProvider), rowHeaderLayer, columnHeaderLayer);
185

  
186
        GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer,
222
                cornerDataProvider), rowHeaderLayer, sortHeaderLayer);
223
        //grid
224
        GridLayer gridLayer = new GridLayer(bodyLayer, sortHeaderLayer,
187 225
                rowHeaderLayer, cornerLayer);
226

  
188 227
        dataLayer.setColumnPercentageSizing(true);
228

  
189 229
        natTable = new NatTable(bottomComposite, gridLayer, false);
230
        natTable.setConfigRegistry(configRegistry);
190 231

  
232
        //full row selection
233
        bodyLayer.getSelectionLayer().setSelectionModel(new RowSelectionModel<CdmBase>(bodyLayer.getSelectionLayer(), bodyDataProvider, new IRowIdAccessor<CdmBase>() {
234
            @Override
235
            public Serializable getRowId(CdmBase rowObject) {
236
                return getEditorInput().getModel().indexOf(rowObject);
237
            }
238
        }));
239
	}
240

  
241
	private void configureTable(){
191 242
        //+++CONTEXT MENU+++
192 243
        menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
193 244
        // get the menu registered by EMenuService
......
225 276
            }
226 277
        });
227 278

  
279
        //enable sorting
280
        natTable.addConfiguration(new SingleClickSortConfiguration());
228 281
        //add default configuration because autoconfigure is set to false in constructor
229 282
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
230 283
        natTable.configure();
231
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
232

  
233
        //full row selection
234
        bodyLayer.getSelectionLayer().setSelectionModel(new RowSelectionModel<CdmBase>(bodyLayer.getSelectionLayer(), bodyDataProvider, new IRowIdAccessor<CdmBase>() {
235

  
236
            @Override
237
            public Serializable getRowId(CdmBase rowObject) {
238
                return getEditorInput().getModel().indexOf(rowObject);
239
            }
240

  
241
        }));
284
	}
242 285

  
243
        //propagate selection
244
        selectionChangedListener = (event -> selService.setSelection(getSelection()));
245
        RowSelectionProvider<CdmBase> selectionProvider = new RowSelectionProvider<CdmBase>(selectionLayer, bodyDataProvider, true);
246
        selectionProvider.addSelectionChangedListener(selectionChangedListener);
286
	private void styleTable(){
287
	    natTable.setTheme(new ModernNatTableThemeConfiguration());
247 288
	}
248 289

  
249 290
	/** {@inheritDoc} */

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)