Project

General

Profile

« Previous | Next » 

Revision 5e339d32

Added by Patrick Plitzner about 5 years ago

ref #8044 Add "Move to..." menu to term editor

View differences:

eu.etaxonomy.taxeditor.store/fragment.e4xmi
63 63
      <handlers xmi:id="_b8sJAIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.DeleteTermBaseHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.DeleteTermBaseHandlerE4" command="_Z_XgsIdQEeecZ4F2Y9Z0Og"/>
64 64
      <handlers xmi:id="_B7cTkIfSEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.CreateDefinedTermHandlerE4.newDefinedTerm" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.CreateDefinedTermHandlerE4" command="_GTbAcIfSEeecZ4F2Y9Z0Og"/>
65 65
      <handlers xmi:id="_NqtXEIfSEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.CreateDefinedTermHandlerE4.newKindOfTerm" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.CreateDefinedTermHandlerE4" command="_LMwG4IfSEeecZ4F2Y9Z0Og"/>
66
      <handlers xmi:id="_yPjL8EAVEembfJNLZI9wiA" elementId="eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.MoveDefinedTermHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.MoveDefinedTermHandler" command="_d6YpoEAVEembfJNLZI9wiA"/>
66 67
      <menus xsi:type="menu:PopupMenu" xmi:id="_CoJioIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.popupmenu.termeditor">
67 68
        <children xsi:type="menu:Menu" xmi:id="_DR1Y0IdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.menu.menulabel0" label="%menu.label.0">
68 69
          <children xsi:type="menu:HandledMenuItem" xmi:id="_N22PsIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.commandlabel12" label="%command.label.12" command="_5mFFMIdPEeecZ4F2Y9Z0Og"/>
......
72 73
          </children>
73 74
        </children>
74 75
        <children xsi:type="menu:HandledMenuItem" xmi:id="_W94ssIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.commandlabel14" label="%command.label.14" command="_Z_XgsIdQEeecZ4F2Y9Z0Og"/>
76
        <children xsi:type="menu:HandledMenuItem" xmi:id="_aHm7kEAVEembfJNLZI9wiA" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.moveto" label="Move term" command="_d6YpoEAVEembfJNLZI9wiA"/>
75 77
      </menus>
76 78
    </elements>
77 79
    <elements xsi:type="basic:PartDescriptor" xmi:id="_HBpj0KkNEeejedk4mZQIGw" elementId="eu.etaxonomy.taxeditor.view.dataimport.e4.SpecimenImportViewE4" label="%view.name.7" allowMultiple="true" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.dataimport.e4.SpecimenImportViewE4">
......
152 154
    <elements xsi:type="commands:Command" xmi:id="_xyZ4oPhmEei8uPv-H2wqnw" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.exportTreeOntology" commandName="%command.commandname.14"/>
153 155
    <elements xsi:type="commands:Command" xmi:id="_qYxw8D85EemTy7SLZkowuQ" elementId="eu.etaxonomy.taxeditor.store.command.OpenDatabaseRepairWizard" commandName="Open Cache Updater"/>
154 156
    <elements xsi:type="commands:Command" xmi:id="_VUQY0D86EemTy7SLZkowuQ" elementId="eu.etaxonomy.taxeditor.store.command.openSortIndexUpdaterWizard" commandName="Open Sort Index Updater"/>
157
    <elements xsi:type="commands:Command" xmi:id="_d6YpoEAVEembfJNLZI9wiA" elementId="eu.etaxonomy.taxeditor.editor.definedTerms.moveTerm" commandName="Move Term"/>
155 158
  </fragments>
156 159
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="xpath:/">
157 160
    <elements xsi:type="commands:Handler" xmi:id="_rVEdIGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/MoveDefinedTermHandler.java
1
/**
2
 * Copyright (C) 2009 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.definedterm.e4.handler;
10

  
11
import java.util.ArrayList;
12
import java.util.Collections;
13
import java.util.List;
14
import java.util.Set;
15

  
16
import javax.inject.Named;
17

  
18
import org.eclipse.core.commands.operations.IUndoContext;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.e4.core.di.annotations.CanExecute;
21
import org.eclipse.e4.core.di.annotations.Execute;
22
import org.eclipse.e4.ui.di.UISynchronize;
23
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
24
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
25
import org.eclipse.e4.ui.services.IServiceConstants;
26
import org.eclipse.jface.viewers.IStructuredSelection;
27
import org.eclipse.jface.wizard.WizardDialog;
28
import org.eclipse.swt.widgets.Shell;
29

  
30
import eu.etaxonomy.cdm.model.location.Country;
31
import eu.etaxonomy.cdm.persistence.dto.TermDto;
32
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
33
import eu.etaxonomy.taxeditor.editor.definedterm.operation.MoveDefinedTermOperation;
34
import eu.etaxonomy.taxeditor.featuretree.TermChooseWizard;
35
import eu.etaxonomy.taxeditor.model.AbstractUtility;
36
import eu.etaxonomy.taxeditor.model.MessagingUtils;
37
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
38
import eu.etaxonomy.taxeditor.store.StoreUtil;
39

  
40
/**
41
 *
42
 * @author pplitzner
43
 * @date 06.03.2019
44
 *
45
 */
46
public class MoveDefinedTermHandler {
47

  
48
    @Execute
49
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
50
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
51
            @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
52
            MHandledMenuItem menuItem,
53
            UISynchronize sync) {
54
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
55
        if(StoreUtil.promptCheckIsDirty(termEditor)){
56
            return;
57
        }
58

  
59
        TermDto selectedTerm = (TermDto) selection.getFirstElement();
60

  
61
        TermChooseWizard wizard = new TermChooseWizard(selectedTerm.getTermType());
62
        WizardDialog dialog = new WizardDialog(shell, wizard);
63

  
64
        List<TermDto> selectedTerms = new ArrayList<>();
65
        if (dialog.open() == IStatus.OK) {
66
            selectedTerms = wizard.getSelectedTerms();
67
        }
68

  
69
        if(selectedTerms.size()!=1){
70
            MessagingUtils.warningDialog("Move not possible", this, "You have to select one single target term");
71
            return;
72
        }
73

  
74
        TermDto target = selectedTerms.get(0);
75
        String label = menuItem.getLocalizedLabel();
76
        IUndoContext undoContext = StoreUtil.getUndoContext();
77
        Set<TermDto> movedTerms = Collections.singleton(selectedTerm);
78
        AbstractPostOperation operation =
79
                new MoveDefinedTermOperation(label,
80
                        undoContext,
81
                        target,
82
                        movedTerms,
83
                        termEditor);
84
        AbstractUtility.executeOperation(operation, sync);
85

  
86
    }
87

  
88
    @CanExecute
89
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
90
            MHandledMenuItem menuItem){
91
        boolean canExecute = false;
92
        Object firstElement = selection.getFirstElement();
93
        canExecute = selection.size()==1
94
                && firstElement instanceof TermDto
95
                // TODO temporary fix for #7933
96
                && !((TermDto) firstElement).getVocabularyUuid().equals(Country.uuidCountryVocabulary);
97
        menuItem.setVisible(canExecute);
98
        return canExecute;
99
    }
100

  
101
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/MoveDefinedTermOperation.java
37 37
	private final AbstractTermDto targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to
38 38
	private final int currentLocation;
39 39

  
40
	public MoveDefinedTermOperation(String label,
41
	        IUndoContext undoContext,
42
	        AbstractTermDto target,
43
	        Collection<TermDto> sourceTerms,
44
	        IPostOperationEnabled postOperationEnabled) {
45
	    this(label, undoContext, target, sourceTerms, postOperationEnabled, ViewerDropAdapter.LOCATION_ON);
46
	}
40 47
	public MoveDefinedTermOperation(String label,
41 48
	        IUndoContext undoContext,
42 49
	        AbstractTermDto target,

Also available in: Unified diff