Project

General

Profile

Revision e461037f

IDe461037f6e4ea8c4a18c9a54fd564adde1d66a8f
Parent 0d9f9636
Child 6ef01e0f

Added by Patrick Plitzner over 2 years ago

fix #6922 Migrate Term Editor

View differences:

eu.etaxonomy.taxeditor.store/fragment.e4xmi
39 39
        <children xsi:type="menu:HandledMenuItem" xmi:id="_BE4OUIcqEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.handledmenuitem.refresh" label="%command.label.11" command="_ShWvcIcuEee-HITNnU9cVw"/>
40 40
      </menus>
41 41
    </elements>
42
    <elements xsi:type="basic:PartDescriptor" xmi:id="_YZ2J0IdPEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedTerm" label="%editor.name" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4">
43
      <handlers xmi:id="_87dsoIdPEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.CreateTermVocabularyHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.CreateTermVocabularyHandlerE4" command="_5mFFMIdPEeecZ4F2Y9Z0Og"/>
44
      <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"/>
45
      <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"/>
46
      <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"/>
47
      <handlers xmi:id="_rW41oIfeEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.OpenDefinedTermEditorHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.OpenDefinedTermEditorHandlerE4" command="_qEMrsIdPEeecZ4F2Y9Z0Og"/>
48
      <menus xsi:type="menu:PopupMenu" xmi:id="_CoJioIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.popupmenu.termeditor">
49
        <children xsi:type="menu:Menu" xmi:id="_DR1Y0IdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.menu.menulabel0" label="%menu.label.0">
50
          <children xsi:type="menu:HandledMenuItem" xmi:id="_N22PsIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.commandlabel12" label="%command.label.12" command="_5mFFMIdPEeecZ4F2Y9Z0Og"/>
51
          <children xsi:type="menu:HandledMenuItem" xmi:id="_QOD-sIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.commandlabel13" label="%command.label.13" command="_GTbAcIfSEeecZ4F2Y9Z0Og"/>
52
          <children xsi:type="menu:HandledMenuItem" xmi:id="_R4pRMIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.kindofterm" label="Kind Of Term" command="_LMwG4IfSEeecZ4F2Y9Z0Og">
53
            <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_2G0O8IfREeecZ4F2Y9Z0Og" coreExpressionId="isShowExperimentalFeatures"/>
54
          </children>
55
        </children>
56
        <children xsi:type="menu:HandledMenuItem" xmi:id="_W94ssIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.commandlabel14" label="%command.label.14" command="_Z_XgsIdQEeecZ4F2Y9Z0Og"/>
57
      </menus>
58
    </elements>
42 59
  </fragments>
43 60
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_3rW8wCXaEeex9MwMOgUeWw" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView" positionInList="after:bulkeditor.menus.openmenu">
44 61
    <elements xsi:type="menu:HandledMenuItem" xmi:id="_K6sowCaGEeeTEd_pKXBflg" elementId="eu.etaxonomy.taxeditor.store.showViewMenu.details" label="%command.label.0" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/accessories-text-editor.png" command="_bnVKsCZxEeeQLpuomSmVoQ">
......
71 88
    <elements xsi:type="commands:Command" xmi:id="_yJiTkIctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.create" commandName="%command.name.1"/>
72 89
    <elements xsi:type="commands:Command" xmi:id="_-g_YcIctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.view.datasource.delete" commandName="%command.name.13"/>
73 90
    <elements xsi:type="commands:Command" xmi:id="_ShWvcIcuEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.update" commandName="%command.name.3"/>
91
    <elements xsi:type="commands:Command" xmi:id="_qEMrsIdPEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.openDefinedTermEditor" commandName="%command.name.5"/>
92
    <elements xsi:type="commands:Command" xmi:id="_5mFFMIdPEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedTerms.newTermVocabulary" commandName="%command.name.7"/>
93
    <elements xsi:type="commands:Command" xmi:id="_Z_XgsIdQEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedTerms.delete" commandName="%command.name.14"/>
94
    <elements xsi:type="commands:Command" xmi:id="_GTbAcIfSEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedTerms.newDefinedTerm" commandName="%command.name.6"/>
95
    <elements xsi:type="commands:Command" xmi:id="_LMwG4IfSEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm" commandName="New kind-of term"/>
74 96
  </fragments>
75 97
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
76 98
    <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"/>
99
    <elements xsi:type="commands:Handler" xmi:id="_tyCPYIdPEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.handler.0" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.handler.OpenDefinedTermEditorHandlerE4" command="_qEMrsIdPEeecZ4F2Y9Z0Og"/>
100
  </fragments>
101
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_qT4hgIfTEeecZ4F2Y9Z0Og" featurename="children" parentElementId="eu.etaxonomy.taxeditor.workbench.menu.window">
102
    <elements xsi:type="menu:Menu" xmi:id="_LT3P8IfcEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.menu.termeditor" label="Term Editor">
103
      <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_Rk37AIfcEeecZ4F2Y9Z0Og" coreExpressionId="isCdmStoreConnected"/>
104
      <children xsi:type="menu:DynamicMenuContribution" xmi:id="_HIptYIfUEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.dynamicmenucontribution.0" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermMenuE4"/>
105
      <children xsi:type="menu:MenuSeparator" xmi:id="_yRINcIfqEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.menuseparator.3"/>
106
      <children xsi:type="menu:HandledMenuItem" xmi:id="_rwfDkIftEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.termEditorMenu.featureTreeEditor" label="Feature Tree Editor" command="_bnVKsCZxEeeQLpuomSmVoQ">
107
        <parameters xmi:id="_3acJQIftEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.showView.parameter.featureTreeEditor" name="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" value="eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor"/>
108
      </children>
109
    </elements>
77 110
  </fragments>
78 111
</fragment:ModelFragments>
eu.etaxonomy.taxeditor.store/plugin.xml
248 248
   	  </view>
249 249
   </extension>
250 250
   <extension
251
         point="org.eclipse.ui.editors">
252
      <editor
253
            class="eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor"
254
            default="false"
255
            id="eu.etaxonomy.taxeditor.editor.definedTerm"
256
            name="%editor.name">
257
      </editor>
258
   </extension>
259
   <extension
260 251
         point="org.eclipse.ui.menus">
261
      <menuContribution 
262
         allPopups="false" 
263
                 locationURI="menu:eu.etaxonomy.taxeditor.workbench.menu.window?before=eu.etaxonomy.taxeditor.application.windowMenu.last"> 
264
           <dynamic 
265
                    class="eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermMenu" 
266
                   id="eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermMenu"> 
267
              <visibleWhen 
268
                      checkEnabled="true"> 
269
                  <reference 
270
                        definitionId="isCdmStoreConnected"> 
271
                  </reference> 
272
             </visibleWhen> 
273
        </dynamic> 
274
      </menuContribution>
275 252
      <menuContribution
276 253
            locationURI="menu:eu.etaxonomy.taxeditor.workbench.menu.file?after=eu.etaxonomy.taxeditor.application.filemenu.io">
277 254
         <command
......
413 390
            </control>
414 391
         </toolbar>
415 392
      </menuContribution>
416
      <menuContribution
417
            locationURI="popup:eu.etaxonomy.taxeditor.editor.definedTerm">
418
         <menu
419
               label="%menu.label.0">
420
            <command
421
                  commandId="eu.etaxonomy.taxeditor.editor.definedTerms.newTermVocabulary"
422
                  label="%command.label.12"
423
                  style="push">
424
            </command>
425
            <command
426
                  commandId="eu.etaxonomy.taxeditor.editor.definedTerms.newDefinedTerm"
427
                  label="%command.label.13"
428
                  style="push">
429
               <visibleWhen
430
                     checkEnabled="true">
431
                  <reference
432
                        definitionId="isModifiable">
433
                  </reference>
434
               </visibleWhen>
435
            </command>
436
            <command
437
                  commandId="eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm"
438
                  label="Kind Of Term"
439
                  style="push">
440
               <visibleWhen
441
                     checkEnabled="true">
442
                  <reference
443
                        definitionId="isShowExperimentalFeatures">
444
                  </reference>
445
               </visibleWhen>
446
            </command>
447
         </menu>
448
         <command
449
               commandId="eu.etaxonomy.taxeditor.editor.definedTerms.delete"
450
               label="%command.label.14"
451
               style="push">
452
            <visibleWhen
453
                  checkEnabled="true">
454
               <reference
455
                     definitionId="isModifiable">
456
               </reference>
457
            </visibleWhen>
458
         </command>
459
      </menuContribution>
460 393
   </extension>
461 394
   <extension
462 395
         point="org.eclipse.ui.handlers">
......
542 475
            name="%command.name.RE_CONNECT">
543 476
      </command>
544 477
      <command
545
            defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.OpenDefinedTermEditorHandler"
546
            id="eu.etaxonomy.taxeditor.store.openDefinedTermEditor"
547
            name="%command.name.5">
548
         <commandParameter
549
               id="eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid"
550
               name="%commandParameter.name.0"
551
               optional="true">
552
         </commandParameter>
553
      </command>
554
      <command
555
            defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.CreateDefinedTermHandler"
556
            id="eu.etaxonomy.taxeditor.editor.definedTerms.newDefinedTerm"
557
            name="%command.name.6">
558
      </command>
559
      <command
560
            defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.CreateDefinedTermHandler"
561
            id="eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm"
562
            name="New kind-of term">
563
      </command>
564
      <command
565
            defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.CreateTermVocabularyHandler"
566
            id="eu.etaxonomy.taxeditor.editor.definedTerms.newTermVocabulary"
567
            name="%command.name.7">
568
      </command>
569
      <command
570 478
            id="eu.etaxonomy.taxeditor.store.openPasswordWizzard"
571 479
            name="%command.name.10">
572 480
      </command>
......
580 488
            name="%command.name.12">
581 489
      </command>
582 490
      <command
583
            defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.DeleteTermBaseHandler"
584
            id="eu.etaxonomy.taxeditor.editor.definedTerms.delete"
585
            name="%command.name.14">
586
      </command>
587
      <command
588 491
            defaultHandler="eu.etaxonomy.taxeditor.handler.OpenInspectSessionsHandler"
589 492
            id="eu.etaxonomy.taxeditor.store.open.InspectSessionsDialog"
590 493
            name="%command.name.INSPECT_ACTIVE_SESSIONS">
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermDragListenerE4.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;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.jface.viewers.Viewer;
16
import org.eclipse.swt.dnd.DragSourceAdapter;
17
import org.eclipse.swt.dnd.DragSourceEvent;
18

  
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
21

  
22
/**
23
 *
24
 * @author pplitzner
25
 * @since Aug 22, 2017
26
 *
27
 */
28
public class DefinedTermDragListenerE4 extends DragSourceAdapter {
29

  
30
	private Viewer viewer;
31

  
32
	public DefinedTermDragListenerE4(Viewer viewer) {
33
		this.viewer = viewer;
34
	}
35

  
36
	@Override
37
	public void dragStart(DragSourceEvent event) {
38
	    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
39
	    List list = selection.toList();
40
	    for (Object object : list) {
41
            if(!(object instanceof DefinedTermBase)){
42
                event.doit = false;
43
                return;
44
            }
45
        }
46
		event.doit = true;
47
	}
48

  
49
	@Override
50
	public void dragSetData(DragSourceEvent event) {
51

  
52
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
53
		List<DefinedTermBase> definedTerms = new ArrayList<DefinedTermBase>();
54

  
55
		for (Object object : selection.toList()){
56
				definedTerms.add((DefinedTermBase)object);
57
			}
58

  
59
		if (TermTransfer.getInstance().isSupportedType(
60
				event.dataType)) {
61
			event.data = definedTerms.toArray(new DefinedTermBase[definedTerms.size()]);
62
		}
63
	}
64

  
65
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermDropAdapterE4.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;
10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13

  
14
import org.eclipse.jface.viewers.StructuredSelection;
15
import org.eclipse.jface.viewers.ViewerDropAdapter;
16
import org.eclipse.swt.dnd.DND;
17
import org.eclipse.swt.dnd.DropTargetEvent;
18
import org.eclipse.swt.dnd.TransferData;
19

  
20
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
21
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
22
import eu.etaxonomy.cdm.model.common.TermBase;
23
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
24
import eu.etaxonomy.taxeditor.editor.definedterm.operation.MoveDefinedTermOperation;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
26
import eu.etaxonomy.taxeditor.store.StoreUtil;
27

  
28
/**
29
 *
30
 * @author pplitzner
31
 * @since Aug 22, 2017
32
 *
33
 */
34
public class DefinedTermDropAdapterE4 extends ViewerDropAdapter {
35

  
36
	private final DefinedTermEditorE4 editor;
37

  
38
	protected DefinedTermDropAdapterE4(DefinedTermEditorE4 editor) {
39
		super(editor.getViewer());
40
		this.editor = editor;
41
	}
42

  
43
	@Override
44
	public boolean performDrop(Object data) {
45

  
46
		TermBase target = (TermBase) getCurrentTarget();//can be vocab
47
		int currentLocation = getCurrentLocation();
48
		Object[] droppedTerms = (Object[]) data;
49
		Collection<DefinedTermBase> sourceTerms = new ArrayList<DefinedTermBase>(); //Arrays.asList(droppedElements)
50

  
51
		for (Object droppedTerm : droppedTerms) {
52
			DefinedTermBase term = (DefinedTermBase) droppedTerm;
53
			sourceTerms.add(term);
54
		}
55

  
56
		AbstractPostOperation operation = new MoveDefinedTermOperation("Move Descriptions",
57
		        StoreUtil.getUndoContext(),
58
		        target,
59
		        sourceTerms,
60
		        editor,
61
		        currentLocation);
62
		//TODO: implement execute
63
		StoreUtil.executeOperation(operation);
64
		// select the newly moved objects
65
		editor.getViewer().setSelection(new StructuredSelection(sourceTerms.toArray(new TermBase[sourceTerms.size()])));
66

  
67
		return true;
68
	}
69

  
70
	@Override
71
	public boolean validateDrop(Object target, int operation,
72
			TransferData transferType) {
73
		boolean transferDataIsSupported = TermTransfer.getInstance().isSupportedType(transferType);
74
		// maybe don't need this - they will be all TermBase anyway
75
		return target instanceof TermBase && transferDataIsSupported;
76
	}
77

  
78
	@Override
79
	public void dragOver(DropTargetEvent event) {
80
	    super.dragOver(event);
81
	    TermBase target = (TermBase) getCurrentTarget();
82
	    if(!(target instanceof OrderedTermBase)) {
83
	        // this is to only disable insert between items
84
	        event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
85
	    }
86

  
87

  
88
	}
89

  
90
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermEditorE4.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;
10

  
11
import javax.annotation.PostConstruct;
12
import javax.annotation.PreDestroy;
13
import javax.inject.Inject;
14

  
15
import org.eclipse.e4.ui.di.Focus;
16
import org.eclipse.e4.ui.di.Persist;
17
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
18
import org.eclipse.e4.ui.services.EMenuService;
19
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
20
import org.eclipse.jface.viewers.ISelectionChangedListener;
21
import org.eclipse.jface.viewers.StructuredSelection;
22
import org.eclipse.jface.viewers.TreeViewer;
23
import org.eclipse.jface.viewers.Viewer;
24
import org.eclipse.jface.viewers.ViewerSorter;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.dnd.DND;
27
import org.eclipse.swt.dnd.Transfer;
28
import org.eclipse.swt.layout.FillLayout;
29
import org.eclipse.swt.widgets.Composite;
30

  
31
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
32
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
33
import eu.etaxonomy.cdm.model.common.CdmBase;
34
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
35
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
36
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider;
37
import eu.etaxonomy.taxeditor.editor.definedterm.TermLabelProvider;
38
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
39
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
40
import eu.etaxonomy.taxeditor.model.AbstractUtility;
41
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
42
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
43
import eu.etaxonomy.taxeditor.store.CdmStore;
44
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
45

  
46
/**
47
 *
48
 * @author pplitzner
49
 * @since Aug 22, 2017
50
 *
51
 */
52
public class DefinedTermEditorE4 implements IConversationEnabled, IDirtyMarkable, IPostOperationEnabled {
53

  
54
	public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.store.openDefinedTermEditor";
55

  
56
	protected TreeViewer viewer;
57

  
58
	protected ConversationHolder conversation;
59

  
60
    @Inject
61
    private ESelectionService selService;
62

  
63
    @Inject
64
    private MDirtyable dirty;
65

  
66
    private ISelectionChangedListener selectionChangedListener;
67
	private final int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
68

  
69
    private TermEditorInput input =null;
70

  
71
	@Inject
72
	public DefinedTermEditorE4() {
73
	}
74

  
75
	@PostConstruct
76
	public void createPartControl(Composite parent, EMenuService menuService) {
77
	    if (CdmStore.isActive()){
78
            if(conversation == null){
79
                conversation = CdmStore.createConversation();
80
            }
81
        }
82
        else{
83
            return;
84
        }
85
	    FillLayout layout = new FillLayout();
86
	    layout.marginHeight = 0;
87
	    layout.marginWidth = 0;
88
	    layout.type = SWT.VERTICAL;
89

  
90
	    parent.setLayout(layout);
91
	    viewer = new TreeViewer(parent);
92
	    viewer.getControl().setLayoutData(LayoutConstants.FILL());
93
	    viewer.setContentProvider(new TermContentProvider());
94
	    viewer.setLabelProvider(new TermLabelProvider());
95
	    viewer.setSorter(new DefinedTermSorter());
96

  
97
	    Transfer[] transfers = new Transfer[] { TermTransfer.getInstance() };
98
	    viewer.addDragSupport(dndOperations, transfers, new DefinedTermDragListenerE4(viewer));
99
	    viewer.addDropSupport(dndOperations, transfers, new DefinedTermDropAdapterE4(this));
100

  
101
	    //FIXME E4 migrate
102
	    //			setPartName(getEditorInput().getName());
103

  
104
	    //propagate selection
105
	    selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
106
	    viewer.addSelectionChangedListener(selectionChangedListener);
107

  
108
	    //create context menu
109
	    menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.store.popupmenu.termeditor");
110

  
111
	}
112

  
113
	@Override
114
	public boolean postOperation(CdmBase objectAffectedByOperation) {
115
		viewer.refresh();
116

  
117
		if(objectAffectedByOperation != null){
118
			viewer.setSelection(new StructuredSelection(objectAffectedByOperation));
119
		}
120
		setDirty(true);
121

  
122
		return true;
123
	}
124

  
125
	public void init(TermEditorInput input){
126
	    this.input = input;
127

  
128
        input.initialiseVocabularies();
129
        viewer.setInput(input.getVocabularies());
130
	}
131

  
132
	@Persist
133
	public void doSave() {
134
		getConversationHolder().commit();
135
		input.merge();
136
		setDirty(false);
137
		input.initialiseVocabularies();
138
		viewer.refresh();
139
	}
140

  
141
	public boolean isDirty() {
142
		return dirty.isDirty();
143
	}
144

  
145
	@Focus
146
	public void setFocus() {
147
	    viewer.getControl().setFocus();
148
		getConversationHolder().bind();
149
		if(input!=null){
150
		    input.bind();
151
		}
152
	}
153

  
154
	@Override
155
	public void update(CdmDataChangeMap changeEvents) {
156
	}
157

  
158
	@Override
159
	public ConversationHolder getConversationHolder() {
160
		return conversation;
161
	}
162

  
163
	@Override
164
	public void changed(Object element) {
165
		setDirty(true);
166
		viewer.update(element, null);
167
	}
168

  
169
	@Override
170
	public void forceDirty() {
171
	    changed(null);
172
	}
173

  
174
	public void setDirty(boolean dirty) {
175
		this.dirty.setDirty(dirty);
176
	}
177

  
178
	@Override
179
	public boolean onComplete() {
180
		return false;
181
	}
182

  
183
	public TreeViewer getViewer() {
184
		return viewer;
185
	}
186

  
187
	private class DefinedTermSorter extends ViewerSorter {
188

  
189
	    @Override
190
	    public int compare(Viewer viewer, Object e1, Object e2) {
191
	        // the comparison value in this method determines the
192
	        // location <-> add term method used in the MoveDefinedTermOperation
193
	        // execute call
194
	        if(e1 instanceof OrderedTermBase && e2 instanceof OrderedTermBase) {
195
	            OrderedTermBase otbe1 = (OrderedTermBase)e1;
196
	            OrderedTermBase otbe2 = (OrderedTermBase)e2;
197
	            if(otbe1.getOrderIndex() == otbe2.getOrderIndex()) {
198
	                return 0;
199
	            } else if (otbe1.getOrderIndex() < otbe2.getOrderIndex()){
200
	            	return -1;
201
	            } else{
202
	            	return 1;
203
	            }
204
	        } else {
205
	            return super.compare(viewer, e1, e2);
206
	        }
207
	    }
208
	}
209

  
210
	@PreDestroy
211
	public void dispose() {
212
	    input.dispose();
213
	}
214

  
215
    public TermEditorInput getDefinedTermEditorInput() {
216
        return input;
217
    }
218
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermMenuE4.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

  
10
package eu.etaxonomy.taxeditor.editor.definedterm.e4;
11

  
12
import java.util.ArrayList;
13
import java.util.Collections;
14
import java.util.Comparator;
15
import java.util.EnumSet;
16
import java.util.List;
17
import java.util.Set;
18

  
19
import javax.inject.Named;
20

  
21
import org.eclipse.e4.ui.di.AboutToShow;
22
import org.eclipse.e4.ui.model.application.commands.MCommand;
23
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
24
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
25
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
26
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
27
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
28
import org.eclipse.e4.ui.services.IServiceConstants;
29

  
30
import eu.etaxonomy.cdm.model.common.TermType;
31
import eu.etaxonomy.taxeditor.l10n.Messages;
32
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
34

  
35
/**
36
 *
37
 * Menu to dynamically generate menu (sub-menu) contribution items
38
 * for term types which when clicked open the defined term editor for the chosen term type
39
 *
40
 * @author pplitzner
41
 * @since Aug 23, 2017
42
 *
43
 */
44
public class DefinedTermMenuE4 {
45

  
46
    private static final String COMMAND_ID = "eu.etaxonomy.taxeditor.store.openDefinedTermEditor";
47

  
48
    /** {@inheritDoc} */
49
    @AboutToShow
50
    public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) Object selection) {
51

  
52
        if(CdmStore.isActive()){
53

  
54
            //add Feature and NamedArea to top level
55
            addChildTermsToMenuManager(items, TermType.Feature);
56
            addChildTermsToMenuManager(items, TermType.NamedArea);
57
            items.add(MMenuFactory.INSTANCE.createMenuSeparator());
58

  
59
            MMenu otherMenu = MMenuFactory.INSTANCE.createMenu();
60
            otherMenu.setLabel(Messages.DefinedTermMenu_OTHERS);
61
            items.add(otherMenu);
62

  
63
            //FIXME E4: This should be removed during e4 migration. dynamic menu should be declared in model fragment
64
            items.add(MMenuFactory.INSTANCE.createMenuSeparator());
65
//            createFeatureTreeMenuItem(menu);
66

  
67
            List<TermType> ttList = new ArrayList<TermType>(EnumSet.allOf(TermType.class));
68
            Collections.sort(ttList,new SortByTermTypeMessage());
69
            for (TermType tt : ttList)
70
            {
71
                //skip Feature and NamedArea as they have already been added to top level
72
                if(tt.equals(TermType.Feature) || tt.equals(TermType.NamedArea)){
73
                    continue;
74
                }
75
                // if term type has a parent, do not add it
76
                // it will be added in the recursive call
77
                if(tt.getKindOf() == null) {
78
                    addChildTermsToMenuManager(otherMenu.getChildren(), tt);
79
                }
80
            }
81
        }
82
	}
83

  
84
    private void addChildTermsToMenuManager(List<MMenuElement> items, TermType termType) {
85

  
86
        //FIXME : need a better way to find out if a term type can be editable (ticket 3853)
87
        if(termType.getEmptyDefinedTermBase() != null) {
88
            Set<TermType> children = termType.getGeneralizationOf();
89
            // term type has no children, so create menu item
90
            if(children.isEmpty()) {
91
                items.add(createMenuItem(termType));
92
            }
93
            else{
94
                MMenu subMenu = MMenuFactory.INSTANCE.createMenu();
95
                subMenu.setLabel(termType.getMessage(PreferencesUtil.getGlobalLanguage()));
96
                items.add(subMenu);
97
                // term type has children, so create sub menu
98
                subMenu.getChildren().add(createDefaultMenuItem(termType));
99

  
100
                subMenu.getChildren().add(MMenuFactory.INSTANCE.createMenuSeparator());
101

  
102
                // add child items to the sub menu
103
                for(TermType tt : children) {
104
                    addChildTermsToMenuManager(subMenu.getChildren(), tt);
105
                }
106
            }
107
        }
108

  
109
    }
110

  
111
	private MHandledMenuItem createMenuItem(TermType termType) {
112

  
113
	    MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();
114
        menuItem.setLabel(termType.getMessage());
115
        MCommand mCommand = MCommandsFactory.INSTANCE.createCommand();
116
        mCommand.setElementId(COMMAND_ID);
117

  
118
        //set params
119
        menuItem.getTransientData().put(COMMAND_ID+".termTypeUuid", termType.getUuid());
120

  
121
        menuItem.setCommand(mCommand);
122
        return menuItem;
123
	}
124

  
125
	private void createFeatureTreeMenuItem() {
126

  
127
//	       String commandId = "eu.etaxonomy.taxeditor.workbench.commandparameter.partName";
128
//
129
//	       MDirectMenuItem directMenuItem = MMenuFactory.INSTANCE.createDirectMenuItem();
130
//	       directMenuItem.
131
//	        MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();
132
//	        menuItem.setLabel(Messages.DefinedTermMenu_FEATURE_TREE);
133
//	        MCommand mCommand = MCommandsFactory.INSTANCE.createCommand();
134
//	        mCommand.setElementId(commandId);
135
//	        mCommand.getParameters().add(MCommandsFactory.INSTANCE.createCommandParameter().);
136
//
137
//	        MCommandParameter commandParameter = MCommandsFactory.INSTANCE.createCommandParameter();
138
//	        commandParameter.setName("eu.etaxonomy.taxeditor.workbench.commandparameter.partName");
139
//	        commandParameter.set
140
//
141
//	        //set params
142
//	        menuItem.getTransientData().put(commandId+"termTypeUuid", termType.getUuid());
143
//
144
//	        menuItem.setCommand(mCommand);
145
//	        menu.getChildren().add(menuItem);
146
//
147
//
148
//		Map<String, String> params = new HashMap<String, String>();
149
//		params.put("eu.etaxonomy.taxeditor.workbench.commandparameter.partName", //$NON-NLS-1$
150
//				"eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor"); //$NON-NLS-1$
151
//
152
//        CommandContributionItemParameter p = new CommandContributionItemParameter(
153
//                PlatformUI.getWorkbench(),
154
//                "eu.etaxonomy.taxeditor.featuretree.commandContributionItemParameter", //$NON-NLS-1$
155
//                "eu.etaxonomy.taxeditor.command.openPart", //$NON-NLS-1$
156
//                params,
157
//                null,
158
//                null,
159
//                null,
160
//                Messages.DefinedTermMenu_FEATURE_TREE,
161
//                "", //$NON-NLS-1$
162
//                "", //$NON-NLS-1$
163
//                SWT.PUSH,
164
//                "", //$NON-NLS-1$
165
//                true);
166
//
167
//
168
//
169
//        CommandContributionItem item = new CommandContributionItem(p);
170
//        return item;
171

  
172
	}
173

  
174
	private MHandledMenuItem createDefaultMenuItem(TermType termType) {
175

  
176
        MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();
177
        menuItem.setLabel(String.format(Messages.DefinedTermMenu_OTHER_S, termType.getMessage()));
178
        MCommand mCommand = MCommandsFactory.INSTANCE.createCommand();
179
        mCommand.setElementId(COMMAND_ID);
180

  
181
        //set params
182
        menuItem.getTransientData().put(COMMAND_ID+".termTypeUuid", termType.getUuid());
183

  
184
        menuItem.setCommand(mCommand);
185

  
186
        return menuItem;
187
	}
188

  
189
	private class SortByTermTypeMessage implements Comparator<TermType> {
190
	    @Override
191
        public int compare(TermType t1, TermType t2) {
192
	        if (t1.equals(t2)){
193
	            return 0;
194
	        }
195
	        int result = t1.getMessage().compareTo(t2.getMessage());
196
	        if (result == 0){
197
	            return t1.compareTo(t2);
198
	        }
199
	        return result;
200
	    }
201
	}
202

  
203

  
204
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/CreateDefinedTermHandlerE4.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 javax.inject.Named;
12

  
13
import org.eclipse.core.commands.common.NotDefinedException;
14
import org.eclipse.core.commands.operations.IUndoContext;
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.e4.core.di.annotations.Optional;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
20
import org.eclipse.e4.ui.services.IServiceConstants;
21

  
22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.common.Marker;
24
import eu.etaxonomy.cdm.model.common.MarkerType;
25
import eu.etaxonomy.cdm.model.common.TermBase;
26
import eu.etaxonomy.cdm.model.common.TermVocabulary;
27
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
28
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateDefinedTermOperation;
29
import eu.etaxonomy.taxeditor.model.AbstractUtility;
30
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
31
import eu.etaxonomy.taxeditor.store.StoreUtil;
32

  
33
/**
34
 *
35
 * @author pplitzner
36
 * @since Aug 22, 2017
37
 *
38
 */
39
public class CreateDefinedTermHandlerE4 {
40

  
41
    @Execute
42
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
43
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase, MHandledMenuItem menuItem) throws NotDefinedException {
44

  
45
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
46

  
47
        boolean addTermAsKindOf =
48
                menuItem.getCommand().getElementId().equals("eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm")?true:false;
49

  
50
        String label = menuItem.getLocalizedLabel();
51
        IUndoContext undoContext = StoreUtil.getUndoContext();
52

  
53
        AbstractPostOperation operation =
54
                new CreateDefinedTermOperation(label,
55
                        undoContext,
56
                        termBase,
57
                        termEditor.getDefinedTermEditorInput(),
58
                        termEditor, addTermAsKindOf);
59
        AbstractUtility.executeOperation(operation);
60

  
61
    }
62

  
63
    @CanExecute
64
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase){
65
        if (termBase == null){
66
            return true;
67
        }
68

  
69
        TermVocabulary vocabulary = null;
70

  
71
        if(termBase instanceof DefinedTermBase){
72
            vocabulary = ((DefinedTermBase) termBase).getVocabulary();
73
        }else if(termBase instanceof TermVocabulary){
74
            vocabulary = (TermVocabulary) termBase;
75
        }
76

  
77
        if(vocabulary == null){
78
            return true;
79
        }
80

  
81
        for(Marker vocabularyMarker : vocabulary.getMarkers()){
82
            if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
83
                return vocabularyMarker.getValue();
84
            }
85
        }
86

  
87
        return true;
88
    }
89

  
90
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/CreateTermVocabularyHandlerE4.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 javax.inject.Named;
12

  
13
import org.eclipse.core.commands.common.NotDefinedException;
14
import org.eclipse.core.commands.operations.IUndoContext;
15
import org.eclipse.e4.core.di.annotations.Execute;
16
import org.eclipse.e4.core.di.annotations.Optional;
17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20

  
21
import eu.etaxonomy.cdm.model.common.TermBase;
22
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
23
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateTermVocabularyOperation;
24
import eu.etaxonomy.taxeditor.model.AbstractUtility;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
26
import eu.etaxonomy.taxeditor.store.StoreUtil;
27

  
28
/**
29
 *
30
 * @author pplitzner
31
 * @since Aug 22, 2017
32
 *
33
 */
34
public class CreateTermVocabularyHandlerE4 {
35

  
36
    @Execute
37
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
38
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase, MMenuItem menuItem) throws NotDefinedException {
39

  
40
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
41

  
42
        String label = menuItem.getLocalizedLabel();
43
        IUndoContext undoContext = StoreUtil.getUndoContext();
44

  
45
        AbstractPostOperation operation =
46
                new CreateTermVocabularyOperation(label,
47
                        undoContext,
48
                        termEditor.getDefinedTermEditorInput(),
49
                        termEditor);
50
        AbstractUtility.executeOperation(operation);
51
    }
52
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/DeleteTermBaseHandlerE4.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 javax.inject.Named;
12

  
13
import org.eclipse.core.commands.common.NotDefinedException;
14
import org.eclipse.core.commands.operations.IUndoContext;
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.e4.core.di.annotations.Optional;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
20
import org.eclipse.e4.ui.services.IServiceConstants;
21
import org.eclipse.jface.dialogs.MessageDialog;
22

  
23
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
24
import eu.etaxonomy.cdm.model.common.Marker;
25
import eu.etaxonomy.cdm.model.common.MarkerType;
26
import eu.etaxonomy.cdm.model.common.TermBase;
27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
28
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
29
import eu.etaxonomy.taxeditor.editor.definedterm.operation.DeleteTermBaseOperation;
30
import eu.etaxonomy.taxeditor.model.AbstractUtility;
31
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
32
import eu.etaxonomy.taxeditor.store.StoreUtil;
33

  
34
/**
35
 *
36
 * @author pplitzner
37
 * @since Aug 22, 2017
38
 *
39
 */
40
public class DeleteTermBaseHandlerE4 {
41

  
42
    @Execute
43
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
44
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase, MMenuItem menuItem) throws NotDefinedException {
45

  
46
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
47

  
48
        if (termEditor.isDirty()){
49
            boolean proceed = MessageDialog.openQuestion(null,
50
                    "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
51
            if (proceed) {
52
                termEditor.doSave();
53
            } else {
54
                return;
55
            }
56
        }
57
        String label = menuItem.getLocalizedLabel();
58
        IUndoContext undoContext = StoreUtil.getUndoContext();
59
        AbstractPostOperation operation =
60
                new DeleteTermBaseOperation(label,
61
                        undoContext,
62
                        termBase,
63
                        termEditor.getDefinedTermEditorInput(),
64
                        termEditor);
65
        AbstractUtility.executeOperation(operation);
66
    }
67

  
68
    @CanExecute
69
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase){
70
        if (termBase == null){
71
            return true;
72
        }
73

  
74
        TermVocabulary vocabulary = null;
75

  
76
        if(termBase instanceof DefinedTermBase){
77
            vocabulary = ((DefinedTermBase) termBase).getVocabulary();
78
        }else if(termBase instanceof TermVocabulary){
79
            vocabulary = (TermVocabulary) termBase;
80
        }
81

  
82
        if(vocabulary == null){
83
            return true;
84
        }
85

  
86
        for(Marker vocabularyMarker : vocabulary.getMarkers()){
87
            if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
88
                return vocabularyMarker.getValue();
89
            }
90
        }
91

  
92
        return true;
93
    }
94
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/OpenDefinedTermEditorHandlerE4.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

  
10
package eu.etaxonomy.taxeditor.editor.definedterm.e4.handler;
11
import java.util.UUID;
12

  
13
import org.eclipse.e4.core.di.annotations.Execute;
14
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
15
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
16
import org.eclipse.e4.ui.workbench.modeling.EPartService;
17
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
18

  
19
import eu.etaxonomy.cdm.model.common.TermType;
20
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
21
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
22

  
23

  
24
/**
25
 *
26
 * @author pplitzner
27
 * @since Aug 22, 2017
28
 *
29
 */
30
public class OpenDefinedTermEditorHandlerE4 {
31

  
32
	@Execute
33
	public void execute(EPartService partService, MHandledMenuItem menuItem) {
34

  
35
	    String commandId = menuItem.getCommand().getElementId();
36
        UUID termTypeUuid = (UUID) menuItem.getTransientData().get(commandId+".termTypeUuid");
37

  
38
		TermEditorInput termEditorInput = new TermEditorInput(TermType.getByUuid(termTypeUuid));
39
		MPart mPart = partService.showPart("eu.etaxonomy.taxeditor.editor.definedTerm", PartState.ACTIVATE);
40
		DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) mPart.getObject();
41
		termEditor.init(termEditorInput);
42
	}
43

  
44
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/DeleteTermBaseOperation.java
22 22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23 23
import eu.etaxonomy.cdm.model.common.TermBase;
24 24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
25
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
25
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
26 26
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
27 27
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28 28
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
......
39 39

  
40 40
	private final TermEditorInput definedEditorInput;
41 41
	private final TermBase termBase;
42
	private DefinedTermEditor definedTermEditor;
43
	/**
44
	 * @param label
45
	 * @param undoContext
46
	 * @param postOperationEnabled
47
	 */
42

  
48 43
	public DeleteTermBaseOperation(String label,
49 44
			IUndoContext undoContext,
50 45
			TermBase termBase,
......
55 50
		this.definedEditorInput = definedEditorInput;
56 51
	}
57 52

  
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
60
	 */
61 53
	@Override
62 54
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
63 55
			throws ExecutionException {
64

  
65

  
66

  
67 56
		if (termBase instanceof TermVocabulary) {
68 57
			if (((TermVocabulary)termBase).getCreatedBy() == null) {
69 58
				IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "This is a CDM system vocabulary");
......
134 123
		return postExecute(termBase);
135 124
	}
136 125

  
137
	/* (non-Javadoc)
138
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
139
	 */
140 126
	@Override
141 127
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
142 128
			throws ExecutionException {
......
144 130
		return null;
145 131
	}
146 132

  
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
149
	 */
150 133
	@Override
151 134
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
152 135
			throws ExecutionException {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)