Project

General

Profile

Revision bf128d5f

IDbf128d5f65bf23ce1da82ed3ab36418f0c51547b
Parent 94d71120
Child 8309769f

Added by Patrick Plitzner about 1 year ago

ref #7439 Add e4 context menu to nattable

  • add full row selection

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.bulkeditor.e4;
11 11

  
12
import java.io.Serializable;
12 13
import java.util.HashMap;
13 14
import java.util.List;
14 15
import java.util.Map;
......
33 34
import org.eclipse.jface.viewers.IStructuredSelection;
34 35
import org.eclipse.jface.viewers.TableViewer;
35 36
import org.eclipse.nebula.widgets.nattable.NatTable;
36
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
37
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
38
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
39
import org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor;
37 40
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
38 41
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
42
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
39 43
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
40 44
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
41 45
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
......
45 49
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
46 50
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
47 51
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
52
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel;
53
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
54
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
55
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
56
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
48 57
import org.eclipse.swt.SWT;
49 58
import org.eclipse.swt.layout.GridData;
50 59
import org.eclipse.swt.layout.GridLayout;
51 60
import org.eclipse.swt.widgets.Composite;
61
import org.eclipse.swt.widgets.Menu;
52 62

  
53 63
import ca.odell.glazedlists.BasicEventList;
54 64
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
......
117 127
    private Composite bottomComposite;
118 128

  
119 129
    @Inject
130
    private EMenuService menuService;
131

  
132
    @Inject
120 133
    public BulkEditorE4() {
121 134
	}
122 135

  
......
220 233
        propertyToLabels.put(getEditorInput().getName(), getEditorInput().getName());
221 234
        propertyToLabels.put(TYPE_PROPERTY, TYPE_PROPERTY);
222 235
        String[] propertyNames = new String[] { getEditorInput().getName(), TYPE_PROPERTY };
223
        IDataProvider bodyDataProvider = new ListDataProvider<CdmBase>(list,
236
        ListDataProvider bodyDataProvider = new ListDataProvider<CdmBase>(list,
224 237
                new BulkEditorPropertyAccessor(getEditorInput()));
225 238

  
226 239

  
......
249 262
                rowHeaderLayer, cornerLayer);
250 263

  
251 264
        dataLayer.setColumnPercentageSizing(true);
252
        NatTable natTable = new NatTable(bottomComposite, gridLayer);
265
        natTable = new NatTable(bottomComposite, gridLayer, false);
266

  
267
        //create context menu
268
        menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
269
        // get the menu registered by EMenuService
270
        final Menu e4Menu = natTable.getMenu();
271

  
272
        // remove the menu reference from NatTable instance
273
        natTable.setMenu(null);
274

  
275
        //add default configuration because autoconfigure is set to false in constructor
276
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
277
        natTable.addConfiguration(
278
                new AbstractUiBindingConfiguration() {
279

  
280
            @Override
281
            public void configureUiBindings(
282
                    UiBindingRegistry uiBindingRegistry) {
283
                // add NatTable menu items
284
                // and register the DisposeListener
285
                new PopupMenuBuilder(natTable, e4Menu)
286
                    .build();
287

  
288
                // register the UI binding
289
                uiBindingRegistry.registerMouseDownBinding(
290
                        new MouseEventMatcher(
291
                                SWT.NONE,
292
                                GridRegion.BODY,
293
                                MouseEventMatcher.RIGHT_BUTTON),
294
                        new PopupMenuAction(e4Menu));
295
            }
296
        });
297

  
298
        natTable.configure();
253 299
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
300

  
301
        //full row selection
302
        bodyLayer.getSelectionLayer().setSelectionModel(new RowSelectionModel<CdmBase>(bodyLayer.getSelectionLayer(), bodyDataProvider, new IRowIdAccessor<CdmBase>() {
303

  
304
            @Override
305
            public Serializable getRowId(CdmBase rowObject) {
306
                return list.indexOf(rowObject);
307
            }
308

  
309
        }));
254 310
	}
255 311

  
256 312
	/** {@inheritDoc} */
257 313
	@PostConstruct
258
	public void createPartControl(Composite parent, EMenuService menuService) {
314
	public void createPartControl(Composite parent) {
259 315
		parent.setLayout(new GridLayout());
260 316

  
261 317
		topComposite = new Composite(parent, SWT.NONE);
......
278 334

  
279 335
        //create context menu
280 336
//        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
281

  
282 337
	}
283 338

  
284 339
	@Override

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)