Project

General

Profile

« Previous | Next » 

Revision 378fbb8a

Added by Patrick Plitzner almost 6 years ago

ref #7439 Show titleCache and type in NatTable in bulk editors

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
33 33
import org.eclipse.jface.viewers.IStructuredSelection;
34 34
import org.eclipse.jface.viewers.TableViewer;
35 35
import org.eclipse.nebula.widgets.nattable.NatTable;
36
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
36 37
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
37 38
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
38
import org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor;
39 39
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
40 40
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
41 41
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
......
44 44
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
45 45
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
46 46
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
47
import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
48
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform;
49 47
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
50 48
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
51
import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
52
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
53
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
54 49
import org.eclipse.swt.SWT;
55 50
import org.eclipse.swt.layout.GridData;
56 51
import org.eclipse.swt.layout.GridLayout;
......
90 85
        IDirtyMarkable, IDerivedUnitFacadePart, IPartContentHasFactualData,
91 86
        IPartContentHasSupplementalData, IPartContentHasMedia, IE4SavablePart, ITaxonEditor {
92 87

  
93
	@Inject
88
    private static final String TYPE = "Type";
89

  
90
    @Inject
94 91
	private MDirtyable dirty;
95 92

  
96 93
    private AbstractBulkEditorInput<?> input;
......
116 113

  
117 114
    private BulkEditorQuery lastQuery = null;
118 115

  
119
    private BasicEventList<Object> list;
116
    private BasicEventList<CdmBase> list;
117

  
118
    private Composite bottomComposite;
120 119

  
121 120
    @Inject
122 121
    public BulkEditorE4() {
......
215 214
        if(input.getEntityUuid()!=null){
216 215
            performSearch(new BulkEditorQuery(input.getEntityUuid().toString(), null));
217 216
        }
218
	}
219

  
220
	/** {@inheritDoc} */
221
	@PostConstruct
222
	public void createPartControl(Composite parent, EMenuService menuService) {
223
		parent.setLayout(new GridLayout());
224

  
225
		topComposite = new Composite(parent, SWT.NONE);
226
		topComposite.setLayout(new GridLayout());
227

  
228
		GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
229
		topComposite.setLayoutData(gridData);
230

  
231
		Composite bottomComposite = new Composite(parent, SWT.NONE);
232
		bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
233
		bottomComposite.setLayout(new GridLayout());
234

  
235

  
236
		//++++NatTable++++
237
		natTable = createExampleControl(bottomComposite);
238
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
239

  
240

  
241

  
242

  
243

  
244

  
245

  
246

  
247

  
248

  
249

  
250

  
251

  
252
//		viewer = new TableViewer(bottomComposite, SWT.MULTI | SWT.FULL_SELECTION);
253

  
254
//		createColumns(viewer);
255 217

  
256
        //propagate selection
257
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
258
//        viewer.addSelectionChangedListener(selectionChangedListener);
259

  
260
        //create context menu
261
//        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
218
        //++++NatTable++++
219
        list = new BasicEventList<>();
220
        Map<String, String> propertyToLabels = new HashMap<>();
221
        propertyToLabels.put(getEditorInput().getName(), getEditorInput().getName());
222
        propertyToLabels.put(TYPE, TYPE);
223
        String[] propertyNames = new String[] { getEditorInput().getName(), TYPE };
224
        IDataProvider bodyDataProvider = new ListDataProvider<CdmBase>(list,
225
                new IColumnPropertyAccessor<CdmBase>() {
226

  
227
                    @Override
228
                    public Object getDataValue(CdmBase rowObject, int columnIndex) {
229
                        if(columnIndex==0){
230
                            return getEditorInput().getText(rowObject);
231
                        }else if(columnIndex==1){
232
                            return getEditorInput().getTypeText(rowObject);
233
                        }
234
                        return null;
235
                    }
236

  
237
                    @Override
238
                    public void setDataValue(CdmBase rowObject, int columnIndex, Object newValue) {
239
                        //no editing allowed
240
                    }
241

  
242
                    @Override
243
                    public int getColumnCount() {
244
                        return 2;
245
                    }
246

  
247
                    @Override
248
                    public String getColumnProperty(int columnIndex) {
249
                        if(columnIndex==0){
250
                            return getEditorInput().getName();
251
                        }else if(columnIndex==1){
252
                            return TYPE;
253
                        }
254
                        return null;
255
                    }
256

  
257
                    @Override
258
                    public int getColumnIndex(String propertyName) {
259
                        if(propertyName.equals(getEditorInput().getName())){
260
                            return 0;
261
                        }
262
                        else if(propertyName.equals(TYPE)){
263
                            return 1;
264
                        }
265
                        return 0;
266
                    }
267
                });
262 268

  
263
	}
264
    private IDataProvider bodyDataProvider;
265
    private String[] propertyNames;
266
    private Map<String, String> propertyToLabels;
267 269

  
268
    public NatTable createExampleControl(Composite parent) {
269
        this.bodyDataProvider = setupBodyDataProvider();
270 270
        DefaultColumnHeaderDataProvider colHeaderDataProvider = new DefaultColumnHeaderDataProvider(
271
                this.propertyNames, this.propertyToLabels);
271
                propertyNames, propertyToLabels);
272 272
        DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
273
                this.bodyDataProvider);
273
                bodyDataProvider);
274 274

  
275 275
        DataLayer dataLayer = new DataLayer(bodyDataProvider);
276
        GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(dataLayer, list);
276
        GlazedListsEventLayer<CdmBase> eventLayer = new GlazedListsEventLayer<>(dataLayer, list);
277 277
        DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(eventLayer);
278 278

  
279 279
        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(
......
290 290

  
291 291
        GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer,
292 292
                rowHeaderLayer, cornerLayer);
293
        NatTable natTable = new NatTable(parent, gridLayer);
294 293

  
295
        return natTable;
296
    }
294
        dataLayer.setColumnPercentageSizing(true);
295
        NatTable natTable = new NatTable(bottomComposite, gridLayer);
296
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
297
	}
297 298

  
298
    private IDataProvider setupBodyDataProvider() {
299
        list = new BasicEventList<>();
299
	/** {@inheritDoc} */
300
	@PostConstruct
301
	public void createPartControl(Composite parent, EMenuService menuService) {
302
		parent.setLayout(new GridLayout());
303

  
304
		topComposite = new Composite(parent, SWT.NONE);
305
		topComposite.setLayout(new GridLayout());
300 306

  
301
        this.propertyToLabels = new HashMap<>();
302
        this.propertyToLabels.put("titleCache", "Title Cache");
303
        this.propertyNames = new String[] { "titleCache" };
304
        return new ListDataProvider(list,
305
                new ReflectiveColumnPropertyAccessor(this.propertyNames));
307
		GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
308
		topComposite.setLayoutData(gridData);
306 309

  
307
    }
310
		bottomComposite = new Composite(parent, SWT.NONE);
311
		bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
312
		bottomComposite.setLayout(new GridLayout());
308 313

  
309
    public class BodyLayerStack extends AbstractLayerTransform {
314
//		viewer = new TableViewer(bottomComposite, SWT.MULTI | SWT.FULL_SELECTION);
310 315

  
311
        private SelectionLayer selectionLayer;
316
//		createColumns(viewer);
312 317

  
313
        public BodyLayerStack(IDataProvider dataProvider) {
314
            DataLayer bodyDataLayer = new DataLayer(dataProvider);
315
            ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(
316
                    bodyDataLayer);
317
            ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(
318
                    columnReorderLayer);
319
            this.selectionLayer = new SelectionLayer(columnHideShowLayer);
320
            ViewportLayer viewportLayer = new ViewportLayer(this.selectionLayer);
321
            setUnderlyingLayer(viewportLayer);
322
        }
318
        //propagate selection
319
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
320
//        viewer.addSelectionChangedListener(selectionChangedListener);
323 321

  
324
        public SelectionLayer getSelectionLayer() {
325
            return this.selectionLayer;
326
        }
327
    }
322
        //create context menu
323
//        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
324

  
325
	}
328 326

  
329 327
	@Override
330 328
	@Persist

Also available in: Unified diff