Project

General

Profile

« Previous | Next » 

Revision 63a2e46c

Added by Patrick Plitzner almost 6 years ago

ref #7439 Code refactoring

View differences:

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

  
11
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
12
import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
13
import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
14

  
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
17

  
18
/**
19
 * @author pplitzner
20
 * @since Jul 6, 2018
21
 *
22
 */
23
public class BulkEditorConfigLabelAccumulator implements IConfigLabelAccumulator {
24
    private ListDataProvider<CdmBase> dataProvider;
25
    private AbstractBulkEditorInput input;
26

  
27
    public BulkEditorConfigLabelAccumulator(ListDataProvider<CdmBase> dataProvider2,
28
            AbstractBulkEditorInput input2) {
29
        super();
30
        this.dataProvider = dataProvider2;
31
        this.input = input2;
32
    }
33

  
34

  
35
    @Override
36
    public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
37
        CdmBase rowObject = dataProvider.getRowObject(rowPosition);
38
        if(input.getMergeCandidates().contains(rowObject)){
39
            configLabels.addLabel(BulkEditorE4.CANDIDATE_LABEL);
40
        }
41
        else if(input.getMergeTarget()==rowObject){
42
            configLabels.addLabel(BulkEditorE4.TARGET_LABEL);
43
        }
44
    }
45
}
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
41 41
import org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommandHandler;
42 42
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
43 43
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
44
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
45 44
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
46 45
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
47 46
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
......
64 63
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
65 64
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
66 65
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
67
import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
68
import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
69 66
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
70 67
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel;
71 68
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
72 69
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
73 70
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
74
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
75 71
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
76
import org.eclipse.nebula.widgets.nattable.style.Style;
77 72
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
78 73
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
79 74
import org.eclipse.nebula.widgets.nattable.ui.matcher.CellEditorMouseEventMatcher;
80 75
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
81 76
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
82 77
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
83
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
84 78
import org.eclipse.swt.SWT;
85 79
import org.eclipse.swt.dnd.Clipboard;
86 80
import org.eclipse.swt.dnd.TextTransfer;
......
268 262
        }));
269 263

  
270 264
        //add label to deduplication rows
271
        dataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
272

  
273
            @Override
274
            public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
275
                CdmBase rowObject = bodyDataProvider.getRowObject(rowPosition);
276
                if(input.getMergeCandidates().contains(rowObject)){
277
                    configLabels.addLabel(CANDIDATE_LABEL);
278
                }
279
                else if(input.getMergeTarget()==rowObject){
280
                    configLabels.addLabel(TARGET_LABEL);
281
                }
282
            }
283
        });
265
        dataLayer.setConfigLabelAccumulator(new BulkEditorConfigLabelAccumulator(bodyDataProvider, input));
284 266

  
285 267
        //add tooltip to table
286 268
        new BulkEditorTooltip(natTable);
......
290 272

  
291 273
	    //this configuration enables cell to be editable in general
292 274
	    //necessary because we disabled this beforehand by setting autoconfigure=false
293
	    //in the GridLayer
275
	    //in the GridLayer constructor
294 276
	    ((AbstractLayer) natTable.getLayer()).addConfiguration(new DefaultEditConfiguration());
295 277

  
296 278
        natTable.addConfiguration(new AbstractUiBindingConfiguration() {
......
301 283
            }
302 284
        });
303 285

  
286
        //make cells editable to allow selecting the text
287
        natTable.addConfiguration(new AbstractRegistryConfiguration() {
288
            @Override
289
            public void configureRegistry(IConfigRegistry configRegistry) {
290
                //make cell editable
291
                configRegistry.registerConfigAttribute(
292
                        EditConfigAttributes.CELL_EDITABLE_RULE,
293
                        IEditableRule.ALWAYS_EDITABLE,
294
                        DisplayMode.EDIT);
295
                //register editor
296
                TextCellEditor editor = new TextCellEditor();
297
                editor.setEditable(false);
298
                configRegistry.registerConfigAttribute(
299
                        EditConfigAttributes.CELL_EDITOR,
300
                        editor,
301
                        DisplayMode.NORMAL);
302
            }
303
        });
304

  
304 305
        //+++CONTEXT MENU+++
305 306
        menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
306 307
        // get the menu registered by EMenuService
......
326 327
            }
327 328
        });
328 329

  
329
        //make cells editable to allow selecting the text
330
        natTable.addConfiguration(new AbstractRegistryConfiguration() {
331
            @Override
332
            public void configureRegistry(IConfigRegistry configRegistry) {
333
              //make cell editable
334
                configRegistry.registerConfigAttribute(
335
                        EditConfigAttributes.CELL_EDITABLE_RULE,
336
                        IEditableRule.ALWAYS_EDITABLE,
337
                        DisplayMode.EDIT);
338
                //register editor
339
                TextCellEditor editor = new TextCellEditor();
340
                editor.setEditable(false);
341
                configRegistry.registerConfigAttribute(
342
                        EditConfigAttributes.CELL_EDITOR,
343
                        editor,
344
                        DisplayMode.NORMAL);
345
            }
346
        });
347 330

  
348 331
        //enable sorting
349 332
        natTable.addConfiguration(new SingleClickSortConfiguration());
350 333

  
351 334
        // Custom style for deduplication labels
352
        natTable.addConfiguration(new AbstractRegistryConfiguration() {
353
            @Override
354
            public void configureRegistry(IConfigRegistry configRegistry) {
355
                Style cellStyle = new Style();
356
                cellStyle.setAttributeValue(
357
                        CellStyleAttributes.BACKGROUND_COLOR,
358
                        GUIHelper.COLOR_YELLOW);
359
                configRegistry.registerConfigAttribute(
360
                        CellConfigAttributes.CELL_STYLE, cellStyle,
361
                        DisplayMode.NORMAL, CANDIDATE_LABEL);
362

  
363
                cellStyle = new Style();
364
                cellStyle.setAttributeValue(
365
                        CellStyleAttributes.BACKGROUND_COLOR,
366
                        GUIHelper.COLOR_GREEN);
367
                configRegistry.registerConfigAttribute(
368
                        CellConfigAttributes.CELL_STYLE, cellStyle,
369
                        DisplayMode.NORMAL, TARGET_LABEL);
370

  
371
            }
372
        });
335
        natTable.addConfiguration(new LabelStyleConfiguration());
373 336

  
374 337
        //add default configuration because autoconfigure is set to false in constructor
375 338
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
......
474 437
    @Optional
475 438
    @Inject
476 439
    private void updateAfterSearch(@UIEventTopic(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED)IStructuredSelection selection){
477

  
478

  
479 440
        if(selection!=null){
480 441
            setSelection(selection);
481 442
        }
482
//        //auto resize columns
483
//        InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(
484
//                natTable, 2, natTable.getConfigRegistry(), new GCFactory(
485
//                        natTable));
486
//        natTable.doCommand(command);
487
//        command = new InitializeAutoResizeColumnsCommand(
488
//                natTable, 1, natTable.getConfigRegistry(), new GCFactory(
489
//                        natTable));
490
//        natTable.doCommand(command);
491 443
    }
492 444

  
493 445
    public void refresh(){
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/LabelStyleConfiguration.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.bulkeditor.e4;
10

  
11
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
12
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
13
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
14
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
15
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
16
import org.eclipse.nebula.widgets.nattable.style.Style;
17
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
18

  
19
/**
20
 * @author pplitzner
21
 * @since Jul 6, 2018
22
 *
23
 */
24
public final class LabelStyleConfiguration extends AbstractRegistryConfiguration {
25
    @Override
26
    public void configureRegistry(IConfigRegistry configRegistry) {
27
        Style cellStyle = new Style();
28
        cellStyle.setAttributeValue(
29
                CellStyleAttributes.BACKGROUND_COLOR,
30
                GUIHelper.COLOR_YELLOW);
31
        configRegistry.registerConfigAttribute(
32
                CellConfigAttributes.CELL_STYLE, cellStyle,
33
                DisplayMode.NORMAL, BulkEditorE4.CANDIDATE_LABEL);
34

  
35
        cellStyle = new Style();
36
        cellStyle.setAttributeValue(
37
                CellStyleAttributes.BACKGROUND_COLOR,
38
                GUIHelper.COLOR_GREEN);
39
        configRegistry.registerConfigAttribute(
40
                CellConfigAttributes.CELL_STYLE, cellStyle,
41
                DisplayMode.NORMAL, BulkEditorE4.TARGET_LABEL);
42

  
43
    }
44
}

Also available in: Unified diff