Project

General

Profile

« Previous | Next » 

Revision 3a465563

Added by Patrick Plitzner over 5 years ago

ref #7674 Add context menu to add taxon descriptions

View differences:

eu.etaxonomy.taxeditor.editor/fragment.e4xmi
270 270
    </elements>
271 271
    <elements xsi:type="basic:PartDescriptor" xmi:id="_rpaDsNK2EeeWSJT7vW9jsw" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart" label="%partdescriptor.label.4" tooltip="%partdescriptor.tooltip.2" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart">
272 272
      <handlers xmi:id="_d_HUYOPBEeeIH8IplZ0cuA" elementId="eu.etaxonomy.taxeditor.editor.handler.2" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.charactermatrix.handler.ExportCharacterMatrixHandler" command="_YeWagOPBEeeIH8IplZ0cuA"/>
273
      <handlers xmi:id="_mUM1cLKVEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.CreateDefaultTaxonDescriptionHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.CreateDefaultTaxonDescriptionHandler" command="_ZHC3oLKVEeikjKoOnLFm2w"/>
274
      <handlers xmi:id="_t8dAQLKVEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.CreateLiteratureTaxonDescriptionHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.CreateLiteratureTaxonDescriptionHandler" command="_fkPkkLKVEeikjKoOnLFm2w"/>
273 275
      <menus xmi:id="_PLw00OPBEeeIH8IplZ0cuA" elementId="eu.etaxonomy.taxeditor.editor.menu.characterMatrix" label="%menu.label.7">
274 276
        <children xsi:type="menu:HandledMenuItem" xmi:id="_TGK04OPBEeeIH8IplZ0cuA" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.characterMatrix.export" label="%handledmenuitem.label.12" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/export.gif" command="_YeWagOPBEeeIH8IplZ0cuA"/>
275 277
      </menus>
278
      <menus xsi:type="menu:PopupMenu" xmi:id="__10yYLKREeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix">
279
        <children xsi:type="menu:HandledMenuItem" xmi:id="_AyHbgLKSEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createdefaultdescription" label="Create default description" command="_ZHC3oLKVEeikjKoOnLFm2w"/>
280
        <children xsi:type="menu:HandledMenuItem" xmi:id="_DYlHcLKSEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createliteraturedescription" label="Create literature description" command="_fkPkkLKVEeikjKoOnLFm2w"/>
281
      </menus>
276 282
    </elements>
277 283
    <elements xsi:type="basic:PartDescriptor" xmi:id="_XcQMEN8mEee9zP45RW4C3A" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetNavigator" label="%partdescriptor.label.5" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetNavigator">
278 284
      <handlers xmi:id="_JvYVgNXoEeeLtdyzt6BEAA" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.handler.OpenCharacterMatrixHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.handler.OpenCharacterMatrixHandler" command="_FnWwMNXoEeeLtdyzt6BEAA"/>
......
369 375
    <elements xsi:type="commands:Command" xmi:id="_c3wW8FeBEeiJAP3GTkE0aQ" elementId="eu.etaxonomy.taxeditor.editor.command.descriptivedataseteditor.removeTaxon" commandName="%command.commandname.21"/>
370 376
    <elements xsi:type="commands:Command" xmi:id="_HSKdYFgXEeiQk_eTMvMviQ" elementId="eu.etaxonomy.taxeditor.editor.name.createProParteSynonym" commandName="%command.name.60"/>
371 377
    <elements xsi:type="commands:Command" xmi:id="_BgX6gFj_EeiQk_eTMvMviQ" elementId="eu.etaxonomy.taxeditor.editor.command.changeToProParteSynonym" commandName="%command.name.61"/>
378
    <elements xsi:type="commands:Command" xmi:id="_ZHC3oLKVEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.charactermatrix.command.createDefaultTaxonDescription" commandName="Create default taxon description"/>
379
    <elements xsi:type="commands:Command" xmi:id="_fkPkkLKVEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.charactermatrix.command.createLiteratureTaxonDescription" commandName="Create literature taxon description"/>
372 380
  </fragments>
373 381
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_pZmusEalEeeXMc6kSYO7Xg" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView" positionInList="after:eu.etaxonomy.taxeditor.workbench.menuseparator.navigation">
374 382
    <elements xsi:type="menu:HandledMenuItem" xmi:id="_FPIHQKNwEeebGZ23ERGMGw" elementId="eu.etaxonomy.taxeditor.editor.showViewMenu.conceptGraph" label="%view.name.3" iconURI="" tooltip="%view.name.3" command="_WPjpoDSnEeek0dKsFNy--Q">
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
29 29
import org.eclipse.core.runtime.jobs.Job;
30 30
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
31 31
import org.eclipse.e4.ui.di.UISynchronize;
32
import org.eclipse.e4.ui.services.EMenuService;
32 33
import org.eclipse.jface.layout.GridDataFactory;
33 34
import org.eclipse.jface.viewers.ComboViewer;
35
import org.eclipse.jface.viewers.IStructuredSelection;
36
import org.eclipse.jface.viewers.StructuredSelection;
34 37
import org.eclipse.nebula.widgets.nattable.NatTable;
38
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
35 39
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
36 40
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
37 41
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
42
import org.eclipse.nebula.widgets.nattable.coordinate.Range;
38 43
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
39 44
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
40 45
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
......
70 75
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
71 76
import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel;
72 77
import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
78
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
79
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
80
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
81
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
73 82
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
74 83
import org.eclipse.swt.SWT;
75 84
import org.eclipse.swt.layout.GridData;
76 85
import org.eclipse.swt.layout.GridLayout;
77 86
import org.eclipse.swt.widgets.Button;
78 87
import org.eclipse.swt.widgets.Composite;
88
import org.eclipse.swt.widgets.Menu;
79 89

  
80 90
import ca.odell.glazedlists.BasicEventList;
81 91
import ca.odell.glazedlists.EventList;
......
124 134
    @Inject
125 135
    private UISynchronize sync;
126 136

  
137
    @Inject
138
    private EMenuService menuService;
139

  
127 140
    private DescriptiveDataSet descriptiveDataSet;
128 141

  
129 142
    private NatTable natTable;
......
473 486
        //register aggregation configuration
474 487
        summaryRowLayer.addConfiguration(new AggregationConfiguration(this));
475 488

  
489
      //+++CONTEXT MENU+++
490
        menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix"); //$NON-NLS-1$
491
        // get the menu registered by EMenuService
492
        final Menu e4Menu = natTable.getMenu();
493
        // remove the menu reference from NatTable instance
494
        natTable.setMenu(null);
495
        natTable.addConfiguration(
496
                new AbstractUiBindingConfiguration() {
497
            @Override
498
            public void configureUiBindings(
499
                    UiBindingRegistry uiBindingRegistry) {
500
                // add e4 menu to NatTable
501
                new PopupMenuBuilder(natTable, e4Menu)
502
                    .build();
503

  
504
                // register the UI binding for header, corner and body region
505
                uiBindingRegistry.registerMouseDownBinding(
506
                        new MouseEventMatcher(
507
                                SWT.NONE,
508
                                null,
509
                                MouseEventMatcher.RIGHT_BUTTON),
510
                        new PopupMenuAction(e4Menu));
511
            }
512
        });
513

  
476 514
        natTable.configure();
477 515
    }
478 516

  
......
575 613
        job.schedule();
576 614
    }
577 615

  
616
    public IStructuredSelection getSelection(){
617
        Set<Range> selectedRowPositions = bodyLayer.getSelectionLayer().getSelectedRowPositions();
618
        List<Object> selectedObjects = new ArrayList<>();
619
        for (Range range : selectedRowPositions) {
620
            for(int i=range.start;i<range.end;i++){
621
                selectedObjects.add(bodyDataProvider.getRowObject(i));
622
            }
623
        }
624
        return new StructuredSelection(selectedObjects);
625
    }
626

  
578 627
    private void loadingDone() {
579 628
        this.part.loadingDone();
580 629
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixPart.java
32 32
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
33 33
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
34 34
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
35
import org.eclipse.jface.viewers.IStructuredSelection;
35 36
import org.eclipse.nebula.widgets.nattable.NatTable;
36 37
import org.eclipse.swt.SWT;
37 38
import org.eclipse.swt.custom.StackLayout;
......
146 147
        }
147 148
    }
148 149

  
150
    public IStructuredSelection getSelection(){
151
        return matrix.getSelection();
152
    }
153

  
149 154
    public void setDirty() {
150 155
        this.dirty.setDirty(true);
151 156
    }
......
166 171
        return selService;
167 172
    }
168 173

  
174
    public CharacterMatrix getMatrix() {
175
        return matrix;
176
    }
177

  
169 178
    @Persist
170 179
    @Override
171 180
    public void save(IProgressMonitor monitor) {
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateDefaultTaxonDescriptionHandler.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.editor.descriptiveDataSet.matrix.handler;
10

  
11
import eu.etaxonomy.cdm.model.common.MarkerType;
12

  
13
/**
14
 * @author pplitzner
15
 * @since Sep 7, 2018
16
 *
17
 */
18
public class CreateDefaultTaxonDescriptionHandler extends CreateTaxonDescriptionHandler{
19

  
20
    @Override
21
    protected boolean getMarkerFlag() {
22
        return true;
23
    }
24

  
25
    @Override
26
    protected MarkerType getMarkerType() {
27
        return MarkerType.USE();
28
    }
29
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateLiteratureTaxonDescriptionHandler.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.editor.descriptiveDataSet.matrix.handler;
10

  
11
import eu.etaxonomy.cdm.model.common.MarkerType;
12

  
13
/**
14
 * @author pplitzner
15
 * @since Sep 7, 2018
16
 *
17
 */
18
public class CreateLiteratureTaxonDescriptionHandler extends CreateTaxonDescriptionHandler{
19

  
20
    @Override
21
    protected boolean getMarkerFlag() {
22
        return true;
23
    }
24

  
25
    @Override
26
    protected MarkerType getMarkerType() {
27
        return MarkerType.IN_BIBLIOGRAPHY();
28
    }
29
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateTaxonDescriptionHandler.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.editor.descriptiveDataSet.matrix.handler;
10

  
11
import javax.inject.Named;
12

  
13
import org.eclipse.e4.core.di.annotations.CanExecute;
14
import org.eclipse.e4.core.di.annotations.Execute;
15
import org.eclipse.e4.ui.di.UISynchronize;
16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
18
import org.eclipse.e4.ui.services.IServiceConstants;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20

  
21
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
22
import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
23
import eu.etaxonomy.cdm.model.common.MarkerType;
24
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
25
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

  
29
/**
30
 * @author pplitzner
31
 * @since Sep 7, 2018
32
 *
33
 */
34
public abstract class CreateTaxonDescriptionHandler {
35

  
36
    @Execute
37
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, UISynchronize sync) {
38
        CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
39
        DescriptiveDataSet descriptiveDataSet = matrixPart.getDescriptiveDataSet();
40
        TaxonNode node = (TaxonNode) matrixPart.getSelection().getFirstElement();
41
        TaxonRowWrapperDTO taxonRowWrapperDTO = CdmStore.getService(IDescriptiveDataSetService.class)
42
                .createTaxonDescription(descriptiveDataSet.getUuid(), node.getUuid(), getMarkerType(), getMarkerFlag());
43
        matrixPart.getMatrix().getDescriptions().add(taxonRowWrapperDTO);
44
    }
45

  
46
    protected abstract boolean getMarkerFlag();
47

  
48

  
49
    protected abstract MarkerType getMarkerType();
50

  
51
    @CanExecute
52
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
53
            MHandledMenuItem menuItem){
54
        boolean canExecute = false;
55
        IStructuredSelection selection = ((CharacterMatrixPart)activePart.getObject()).getSelection();
56
        canExecute = selection.size()==1
57
                && selection.getFirstElement() instanceof TaxonNode;
58
        menuItem.setVisible(canExecute);
59
        return canExecute;
60
    }
61

  
62
}

Also available in: Unified diff