Revision 7a023b3e
Added by Patrick Plitzner about 6 years ago
eu.etaxonomy.taxeditor.editor/fragment.e4xmi | ||
---|---|---|
90 | 90 |
</menus> |
91 | 91 |
</elements> |
92 | 92 |
<elements xsi:type="basic:PartDescriptor" xmi:id="_HxxDsIGxEeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4" label="%view.name" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.editor/icons/address-book-new.png" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4"> |
93 |
<handlers xmi:id="_nxGRoIGyEeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.CreateDescriptionHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.CreateDescriptionHandler" command="_gE3lwIGyEeehlNPrK_b5JA"/> |
|
94 |
<handlers xmi:id="_mOjHgIG3EeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.MoveDescriptionToOtherTaxonHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.MoveDescriptionToOtherTaxonHandler" command="_Al6c0IG4EeehlNPrK_b5JA"/> |
|
95 |
<handlers xmi:id="_aaq0UIG4EeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.MoveDescriptionElementsHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.MoveDescriptionElementsHandler" command="_QJzBcIG4EeehlNPrK_b5JA"/> |
|
96 |
<handlers xmi:id="_DgC2MIG5EeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.DeleteHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.DeleteHandler" command="_AqgMcIG5EeehlNPrK_b5JA"/> |
|
93 |
<handlers xmi:id="_nxGRoIGyEeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.CreateDescriptionHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.CreateDescriptionHandlerE4" command="_gE3lwIGyEeehlNPrK_b5JA"/> |
|
94 |
<handlers xmi:id="_mOjHgIG3EeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.MoveDescriptionToOtherTaxonHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.MoveDescriptionToOtherTaxonHandlerE4" command="_Al6c0IG4EeehlNPrK_b5JA"/> |
|
95 |
<handlers xmi:id="_aaq0UIG4EeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.MoveDescriptionElementsHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.MoveDescriptionElementsHandlerE4" command="_QJzBcIG4EeehlNPrK_b5JA"/> |
|
96 |
<handlers xmi:id="_DgC2MIG5EeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.DeleteHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.DeleteHandlerE4" command="_AqgMcIG5EeehlNPrK_b5JA"/> |
|
97 |
<handlers xmi:id="_o7njgIy0EeeQaL4TL8oz7Q" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.CreateDescriptionElementHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.CreateDescriptionElementHandlerE4" command="_8ccfgIHXEeehlNPrK_b5JA"/> |
|
98 |
<handlers xmi:id="_xJ3XUIy0EeeQaL4TL8oz7Q" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.ToggleShowOnlyIndividualAssociationsHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.ToggleShowOnlyIndividualAssociationsHandlerE4" command="_4eDWoIy0EeeQaL4TL8oz7Q"/> |
|
97 | 99 |
<menus xsi:type="menu:PopupMenu" xmi:id="_HxxDt4GxEeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.popupmenu.factualDataView"> |
98 | 100 |
<visibleWhen xsi:type="ui:CoreExpression" xmi:id="_bMfdYIG5EeehlNPrK_b5JA" coreExpressionId="isCdmStoreConnected"/> |
99 | 101 |
<children xsi:type="menu:HandledMenuItem" xmi:id="_jvmnkIGxEeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.factualData.addDescription" label="%command.label.27" command="_gE3lwIGyEeehlNPrK_b5JA"/> |
100 |
<children xsi:type="menu:DynamicMenuContribution" xmi:id="_2t3BgIHWEeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.dynamicmenucontribution.1" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.DynamicFeatureMenu"/>
|
|
102 |
<children xsi:type="menu:DynamicMenuContribution" xmi:id="_2t3BgIHWEeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.DynamicFeatureMenuE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler.DynamicFeatureMenuE4"/>
|
|
101 | 103 |
<children xsi:type="menu:MenuSeparator" xmi:id="_ij_wEIGxEeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.8"/> |
102 | 104 |
<children xsi:type="menu:HandledMenuItem" xmi:id="_mgmvkIGxEeehlNPrK_b5JA" elementId="eu.etaxonomy.taxeditor.editor.factualData.moveDescriptionToTaxon" label="%command.label.28" command="_Al6c0IG4EeehlNPrK_b5JA"> |
103 | 105 |
<visibleWhen xsi:type="ui:CoreExpression" xmi:id="_BZrDwIGyEeehlNPrK_b5JA" coreExpressionId="isDescription"/> |
... | ... | |
154 | 156 |
<elements xsi:type="commands:Command" xmi:id="_2torwIZ7EeeOc9DZcjNN7g" elementId="eu.etaxonomy.taxeditor.editor.name.createConceptRelation" commandName="%command.name.32"/> |
155 | 157 |
<elements xsi:type="commands:Command" xmi:id="_OKtWAIaDEeeOc9DZcjNN7g" elementId="eu.etaxonomy.taxeditor.editor.view.concept.command.open" commandName="%command.name.33"/> |
156 | 158 |
<elements xsi:type="commands:Command" xmi:id="_cMeq0IaHEeeOc9DZcjNN7g" elementId="eu.etaxonomy.taxeditor.editor.openBulkEditorForTaxonRelationship" commandName="Open related concept in bulk editor"/> |
159 |
<elements xsi:type="commands:Command" xmi:id="_4eDWoIy0EeeQaL4TL8oz7Q" elementId="eu.etaxonomy.taxeditor.editor.handler.showOnlyIndividualAssociations" commandName="%command.name.41"/> |
|
157 | 160 |
</fragments> |
158 | 161 |
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_pZmusEalEeeXMc6kSYO7Xg" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView"> |
159 | 162 |
<elements xsi:type="menu:HandledMenuItem" xmi:id="_tvph4EalEeeXMc6kSYO7Xg" elementId="eu.etaxonomy.taxeditor.editor.showViewMenu.characterEditor" label="Character Editor" command="_WPjpoDSnEeek0dKsFNy--Q"> |
eu.etaxonomy.taxeditor.editor/plugin.xml | ||
---|---|---|
911 | 911 |
</and> |
912 | 912 |
</activeWhen> |
913 | 913 |
</handler> |
914 |
<handler |
|
915 |
class="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.DeleteHandler" |
|
916 |
commandId="eu.etaxonomy.taxeditor.editor.view.descriptive.command.delete"> |
|
917 |
<activeWhen> |
|
918 |
<with |
|
919 |
variable="activePartId"> |
|
920 |
<or> |
|
921 |
<equals |
|
922 |
value="eu.etaxonomy.taxeditor.editor.view.descriptive"> |
|
923 |
</equals> |
|
924 |
<equals |
|
925 |
value="eu.etaxonomy.taxeditor.editor.view.media"> |
|
926 |
</equals> |
|
927 |
<equals |
|
928 |
value="eu.etaxonomy.taxeditor.editor.view.uses"> |
|
929 |
</equals> |
|
930 |
</or> |
|
931 |
</with> |
|
932 |
</activeWhen> |
|
933 |
</handler> |
|
934 | 914 |
<handler |
935 | 915 |
class="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.DeleteNodeHandler" |
936 | 916 |
commandId="eu.etaxonomy.taxeditor.key.polytomous.command.delete"> |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/CreateDescriptionElementHandler.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.view.descriptive.e4.handler; |
|
11 |
|
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import javax.inject.Named; |
|
15 |
|
|
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.api.service.ITermService; |
|
23 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
24 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
25 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
26 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
27 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4; |
|
28 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation; |
|
29 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
30 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
31 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
32 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
33 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
* @author pplitzner |
|
38 |
* @date 15.08.2017 |
|
39 |
* |
|
40 |
*/ |
|
41 |
public class CreateDescriptionElementHandler { |
|
42 |
|
|
43 |
@Execute |
|
44 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
|
45 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) DescriptionBase description, MHandledMenuItem menuItem) { |
|
46 |
|
|
47 |
String commandId = menuItem.getCommand().getElementId(); |
|
48 |
UUID uuid = (UUID) menuItem.getTransientData().get(commandId+".feature.uuid"); |
|
49 |
Feature feature = HibernateProxyHelper.deproxy(CdmStore.getService(ITermService.class).load(uuid), Feature.class); |
|
50 |
|
|
51 |
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject(); |
|
52 |
|
|
53 |
if (description != null) { |
|
54 |
AbstractPostOperation operation = null; |
|
55 |
// TODO use undo context specific to editor |
|
56 |
operation = operationCreationInstance(menuItem.getLocalizedLabel(), feature, description, factualDataPart); |
|
57 |
AbstractUtility.executeOperation(operation); |
|
58 |
} else { |
|
59 |
MessagingUtils.error(getClass(), new IllegalArgumentException("Could not determine the taxon description")); //$NON-NLS-1$ |
|
60 |
} |
|
61 |
|
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Added to make the Class more generic and limit the amount of code changes required |
|
66 |
* @param label |
|
67 |
* @param event |
|
68 |
* @param taxon |
|
69 |
* @param description |
|
70 |
* @param postOperationEnabled |
|
71 |
* @return |
|
72 |
*/ |
|
73 |
protected AbstractPostOperation operationCreationInstance(String label, Feature feature, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) { |
|
74 |
return new CreateDescriptionElementOperation(label, EditorUtil.getUndoContext(), description, feature, postOperationEnabled); |
|
75 |
} |
|
76 |
|
|
77 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/CreateDescriptionElementHandlerE4.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.view.descriptive.e4.handler; |
|
11 |
|
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import javax.inject.Named; |
|
15 |
|
|
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.api.service.ITermService; |
|
23 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
24 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
25 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
26 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
27 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4; |
|
28 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation; |
|
29 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
30 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
31 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
32 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
33 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
* @author pplitzner |
|
38 |
* @date 15.08.2017 |
|
39 |
* |
|
40 |
*/ |
|
41 |
public class CreateDescriptionElementHandlerE4 { |
|
42 |
|
|
43 |
@Execute |
|
44 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
|
45 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) DescriptionBase description, MHandledMenuItem menuItem) { |
|
46 |
|
|
47 |
String commandId = menuItem.getCommand().getElementId(); |
|
48 |
UUID uuid = (UUID) menuItem.getTransientData().get(commandId+".feature.uuid"); |
|
49 |
Feature feature = HibernateProxyHelper.deproxy(CdmStore.getService(ITermService.class).load(uuid), Feature.class); |
|
50 |
|
|
51 |
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject(); |
|
52 |
|
|
53 |
if (description != null) { |
|
54 |
AbstractPostOperation operation = null; |
|
55 |
// TODO use undo context specific to editor |
|
56 |
operation = operationCreationInstance(menuItem.getLocalizedLabel(), feature, description, factualDataPart); |
|
57 |
AbstractUtility.executeOperation(operation); |
|
58 |
} else { |
|
59 |
MessagingUtils.error(getClass(), new IllegalArgumentException("Could not determine the taxon description")); //$NON-NLS-1$ |
|
60 |
} |
|
61 |
|
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Added to make the Class more generic and limit the amount of code changes required |
|
66 |
* @param label |
|
67 |
* @param event |
|
68 |
* @param taxon |
|
69 |
* @param description |
|
70 |
* @param postOperationEnabled |
|
71 |
* @return |
|
72 |
*/ |
|
73 |
protected AbstractPostOperation operationCreationInstance(String label, Feature feature, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) { |
|
74 |
return new CreateDescriptionElementOperation(label, EditorUtil.getUndoContext(), description, feature, postOperationEnabled); |
|
75 |
} |
|
76 |
|
|
77 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/CreateDescriptionHandler.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2011 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.view.descriptive.e4.handler; |
|
10 |
|
|
11 |
import javax.inject.Named; |
|
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.MMenuItem; |
|
16 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
17 |
import org.eclipse.jface.viewers.TreeNode; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
20 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
21 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
22 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
23 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4; |
|
24 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateSpecimenDescriptionOperation; |
|
25 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation; |
|
26 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
27 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
28 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @author pplitzner |
|
33 |
* @date 15.08.2017 |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class CreateDescriptionHandler { |
|
37 |
|
|
38 |
@Execute |
|
39 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, MMenuItem menuItem) { |
|
40 |
|
|
41 |
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject(); |
|
42 |
|
|
43 |
AbstractPostOperation<?> operation; |
|
44 |
Object viewerInput = factualDataPart.getViewer().getInput(); |
|
45 |
if(viewerInput instanceof TreeNode){ |
|
46 |
viewerInput = ((TreeNode) viewerInput).getValue(); |
|
47 |
} |
|
48 |
if(viewerInput instanceof SpecimenOrObservationBase<?>){ |
|
49 |
operation = new CreateSpecimenDescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>) viewerInput, factualDataPart); |
|
50 |
AbstractUtility.executeOperation(operation); |
|
51 |
} |
|
52 |
if(viewerInput instanceof TaxonBase){ |
|
53 |
operation = createTaxonOperation(menuItem.getLocalizedLabel(), (Taxon) viewerInput, factualDataPart); |
|
54 |
AbstractUtility.executeOperation(operation); |
|
55 |
|
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
/** {@inheritDoc} */ |
|
60 |
protected CreateTaxonDescriptionOperation createTaxonOperation(String eventLabel, Taxon taxon, IPostOperationEnabled postOperationEnabled) { |
|
61 |
return new CreateTaxonDescriptionOperation(eventLabel, EditorUtil.getUndoContext(), taxon, postOperationEnabled); |
|
62 |
} |
|
63 |
|
|
64 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/CreateDescriptionHandlerE4.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2011 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.view.descriptive.e4.handler; |
|
10 |
|
|
11 |
import javax.inject.Named; |
|
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.MMenuItem; |
|
16 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
17 |
import org.eclipse.jface.viewers.TreeNode; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
20 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
21 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
22 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
23 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4; |
|
24 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateSpecimenDescriptionOperation; |
|
25 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation; |
|
26 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
27 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
28 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @author pplitzner |
|
33 |
* @date 15.08.2017 |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class CreateDescriptionHandlerE4 { |
|
37 |
|
|
38 |
@Execute |
|
39 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, MMenuItem menuItem) { |
|
40 |
|
|
41 |
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject(); |
|
42 |
|
|
43 |
AbstractPostOperation<?> operation; |
|
44 |
Object viewerInput = factualDataPart.getViewer().getInput(); |
|
45 |
if(viewerInput instanceof TreeNode){ |
|
46 |
viewerInput = ((TreeNode) viewerInput).getValue(); |
|
47 |
} |
|
48 |
if(viewerInput instanceof SpecimenOrObservationBase<?>){ |
|
49 |
operation = new CreateSpecimenDescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>) viewerInput, factualDataPart); |
|
50 |
AbstractUtility.executeOperation(operation); |
|
51 |
} |
|
52 |
if(viewerInput instanceof TaxonBase){ |
|
53 |
operation = createTaxonOperation(menuItem.getLocalizedLabel(), (Taxon) viewerInput, factualDataPart); |
|
54 |
AbstractUtility.executeOperation(operation); |
|
55 |
|
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
/** {@inheritDoc} */ |
|
60 |
protected CreateTaxonDescriptionOperation createTaxonOperation(String eventLabel, Taxon taxon, IPostOperationEnabled postOperationEnabled) { |
|
61 |
return new CreateTaxonDescriptionOperation(eventLabel, EditorUtil.getUndoContext(), taxon, postOperationEnabled); |
|
62 |
} |
|
63 |
|
|
64 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DeleteHandler.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.view.descriptive.e4.handler; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import javax.inject.Named; |
|
16 |
|
|
17 |
import org.eclipse.core.commands.operations.IUndoContext; |
|
18 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
|
19 |
import org.eclipse.e4.core.di.annotations.Execute; |
|
20 |
import org.eclipse.e4.core.di.annotations.Optional; |
|
21 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
22 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
23 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
|
24 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
25 |
import org.eclipse.jface.viewers.ISelection; |
|
26 |
import org.eclipse.jface.viewers.TreePath; |
|
27 |
import org.eclipse.jface.viewers.TreeSelection; |
|
28 |
import org.eclipse.swt.widgets.Shell; |
|
29 |
|
|
30 |
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator; |
|
31 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
32 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
33 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
|
34 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
35 |
import eu.etaxonomy.cdm.model.description.TaxonNameDescription; |
|
36 |
import eu.etaxonomy.cdm.model.media.Media; |
|
37 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
38 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
|
39 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4; |
|
40 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteDescriptionElementOperation; |
|
41 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteSpecimenDescriptionOperation; |
|
42 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteTaxonDescriptionOperation; |
|
43 |
import eu.etaxonomy.taxeditor.editor.view.media.operation.DeleteMediaOperation; |
|
44 |
import eu.etaxonomy.taxeditor.editor.view.media.operation.RemoveImageFromDescriptionElementOperation; |
|
45 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
46 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
47 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
48 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
49 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
|
50 |
import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog; |
|
51 |
|
|
52 |
/** |
|
53 |
* |
|
54 |
* @author pplitzner |
|
55 |
* @date 15.08.2017 |
|
56 |
* |
|
57 |
*/ |
|
58 |
public class DeleteHandler { |
|
59 |
|
|
60 |
@Execute |
|
61 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
|
62 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object selection, |
|
63 |
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell, MMenuItem menuItem) { |
|
64 |
|
|
65 |
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject(); |
|
66 |
|
|
67 |
Object selectionProvidingPart = factualDataPart.getSelectionProvidingPart(); |
|
68 |
ICdmEntitySessionEnabled cdmEntitySessionEnabled = null; |
|
69 |
if(selectionProvidingPart instanceof ICdmEntitySessionEnabled){ |
|
70 |
cdmEntitySessionEnabled = (ICdmEntitySessionEnabled) selectionProvidingPart; |
|
71 |
} |
|
72 |
|
|
73 |
String label = menuItem.getLocalizedLabel(); |
|
74 |
|
|
75 |
IUndoContext undoContext = EditorUtil.getUndoContext(); |
|
76 |
|
|
77 |
List<AbstractPostOperation<?>> operations = new ArrayList<AbstractPostOperation<?>>(); |
|
78 |
|
|
79 |
// for(Object object : selection.toArray()){ |
|
80 |
|
|
81 |
// TaxonDescription |
|
82 |
if(selection instanceof TaxonDescription){ |
|
83 |
operations.add(new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) selection, factualDataPart, cdmEntitySessionEnabled)); |
|
84 |
} |
|
85 |
else if(selection instanceof SpecimenDescription){ |
|
86 |
operations.add(new DeleteSpecimenDescriptionOperation(label, undoContext, (SpecimenDescription) selection, factualDataPart, cdmEntitySessionEnabled)) ; |
|
87 |
} |
|
88 |
// DescriptionElementBase |
|
89 |
else if(selection instanceof DescriptionElementBase){ |
|
90 |
operations.add(new DeleteDescriptionElementOperation(label, undoContext, (DescriptionElementBase) selection, factualDataPart, cdmEntitySessionEnabled)); |
|
91 |
} |
|
92 |
else if(selection instanceof FeatureNodeContainer){ |
|
93 |
List<DescriptionElementBase> descriptions = ((FeatureNodeContainer) selection).getDescriptionElementsForEntireBranch(); |
|
94 |
|
|
95 |
for(DescriptionElementBase description : descriptions){ |
|
96 |
operations.add(new DeleteDescriptionElementOperation(label, undoContext, description, factualDataPart, cdmEntitySessionEnabled)); |
|
97 |
} |
|
98 |
} |
|
99 |
// Media |
|
100 |
else if(selection instanceof Media){ |
|
101 |
|
|
102 |
TreeSelection treeSelection = (TreeSelection) factualDataPart.getViewer().getSelection(); |
|
103 |
|
|
104 |
TreePath[] path = treeSelection.getPathsFor(selection); |
|
105 |
|
|
106 |
DescriptionBase<?> imageGallery = (DescriptionBase<?>) path[0].getFirstSegment(); |
|
107 |
|
|
108 |
// TODO use undo context specific to editor |
|
109 |
MediaDeletionConfigurator config = new MediaDeletionConfigurator(); |
|
110 |
config.setDeleteFromDescription(true); |
|
111 |
config.setOnlyRemoveFromGallery(false); |
|
112 |
|
|
113 |
if (imageGallery instanceof SpecimenDescription){ |
|
114 |
config.setDeleteFrom(((SpecimenDescription)imageGallery).getDescribedSpecimenOrObservation()); |
|
115 |
} else if (imageGallery instanceof TaxonDescription){ |
|
116 |
config.setDeleteFrom(((TaxonDescription)imageGallery).getTaxon()); |
|
117 |
}else if (imageGallery instanceof TaxonNameDescription){ |
|
118 |
config.setDeleteFrom(((TaxonNameDescription)imageGallery).getTaxonName()); |
|
119 |
} |
|
120 |
|
|
121 |
|
|
122 |
if (!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, shell, Messages.DeleteHandler_CONFIRM_DELETION, Messages.DeleteHandler_CONFIRM_DELETION_MESSAGE)){ |
|
123 |
return; |
|
124 |
} |
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
if (config.isOnlyRemoveFromGallery() || ((Media)selection).getId() == 0){ |
|
129 |
operations.add(new RemoveImageFromDescriptionElementOperation(label, undoContext, (Media) selection, imageGallery, factualDataPart)); |
|
130 |
}else{ |
|
131 |
operations.add(new DeleteMediaOperation(label, undoContext, imageGallery, (Media) selection, config, factualDataPart)); |
|
132 |
} |
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
} |
|
137 |
else{ |
|
138 |
MessagingUtils.error(getClass(), Messages.DeleteHandler_INVALID_SELECTION, null); |
|
139 |
} |
|
140 |
// } |
|
141 |
|
|
142 |
// execute all cumulated operations |
|
143 |
for(AbstractPostOperation<?> operation : operations){ |
|
144 |
AbstractUtility.executeOperation(operation); |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
@CanExecute |
|
149 |
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
|
150 |
MHandledMenuItem menuItem){ |
|
151 |
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject(); |
|
152 |
ISelection selection = factualDataPart.getViewer().getSelection(); |
|
153 |
boolean canExecute = selection !=null && !selection.isEmpty(); |
|
154 |
menuItem.setVisible(canExecute); |
|
155 |
return canExecute; |
|
156 |
} |
|
157 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DeleteHandlerE4.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.view.descriptive.e4.handler; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import javax.inject.Named; |
|
16 |
|
|
17 |
import org.eclipse.core.commands.operations.IUndoContext; |
|
18 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
|
19 |
import org.eclipse.e4.core.di.annotations.Execute; |
|
20 |
import org.eclipse.e4.core.di.annotations.Optional; |
|
21 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
22 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
23 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
|
24 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
25 |
import org.eclipse.jface.viewers.ISelection; |
|
26 |
import org.eclipse.jface.viewers.TreePath; |
|
27 |
import org.eclipse.jface.viewers.TreeSelection; |
|
28 |
import org.eclipse.swt.widgets.Shell; |
|
29 |
|
|
30 |
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator; |
|
31 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
32 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
33 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
|
34 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
35 |
import eu.etaxonomy.cdm.model.description.TaxonNameDescription; |
|
36 |
import eu.etaxonomy.cdm.model.media.Media; |
|
37 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
38 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
|
39 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4; |
|
40 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteDescriptionElementOperation; |
|
41 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteSpecimenDescriptionOperation; |
|
42 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteTaxonDescriptionOperation; |
|
43 |
import eu.etaxonomy.taxeditor.editor.view.media.operation.DeleteMediaOperation; |
|
44 |
import eu.etaxonomy.taxeditor.editor.view.media.operation.RemoveImageFromDescriptionElementOperation; |
|
45 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
46 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
47 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
48 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
49 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
|
50 |
import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog; |
|
51 |
|
|
52 |
/** |
|
53 |
* |
|
54 |
* @author pplitzner |
|
55 |
* @date 15.08.2017 |
|
56 |
* |
|
57 |
*/ |
|
58 |
public class DeleteHandlerE4 { |
|
59 |
|
|
60 |
@Execute |
|
61 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
|
62 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object selection, |
|
63 |
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell, MMenuItem menuItem) { |
|
64 |
|
|
65 |
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject(); |
|
66 |
|
|
67 |
Object selectionProvidingPart = factualDataPart.getSelectionProvidingPart(); |
|
68 |
ICdmEntitySessionEnabled cdmEntitySessionEnabled = null; |
|
69 |
if(selectionProvidingPart instanceof ICdmEntitySessionEnabled){ |
|
70 |
cdmEntitySessionEnabled = (ICdmEntitySessionEnabled) selectionProvidingPart; |
|
71 |
} |
|
72 |
|
|
73 |
String label = menuItem.getLocalizedLabel(); |
|
74 |
|
|
75 |
IUndoContext undoContext = EditorUtil.getUndoContext(); |
|
76 |
|
|
77 |
List<AbstractPostOperation<?>> operations = new ArrayList<AbstractPostOperation<?>>(); |
|
78 |
|
|
79 |
// for(Object object : selection.toArray()){ |
|
80 |
|
|
81 |
// TaxonDescription |
|
82 |
if(selection instanceof TaxonDescription){ |
|
83 |
operations.add(new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) selection, factualDataPart, cdmEntitySessionEnabled)); |
|
84 |
} |
|
85 |
else if(selection instanceof SpecimenDescription){ |
|
86 |
operations.add(new DeleteSpecimenDescriptionOperation(label, undoContext, (SpecimenDescription) selection, factualDataPart, cdmEntitySessionEnabled)) ; |
|
87 |
} |
|
88 |
// DescriptionElementBase |
|
89 |
else if(selection instanceof DescriptionElementBase){ |
|
90 |
operations.add(new DeleteDescriptionElementOperation(label, undoContext, (DescriptionElementBase) selection, factualDataPart, cdmEntitySessionEnabled)); |
|
91 |
} |
|
92 |
else if(selection instanceof FeatureNodeContainer){ |
|
93 |
List<DescriptionElementBase> descriptions = ((FeatureNodeContainer) selection).getDescriptionElementsForEntireBranch(); |
|
94 |
|
|
95 |
for(DescriptionElementBase description : descriptions){ |
|
96 |
operations.add(new DeleteDescriptionElementOperation(label, undoContext, description, factualDataPart, cdmEntitySessionEnabled)); |
|
97 |
} |
|
98 |
} |
|
99 |
// Media |
|
100 |
else if(selection instanceof Media){ |
|
101 |
|
|
102 |
TreeSelection treeSelection = (TreeSelection) factualDataPart.getViewer().getSelection(); |
|
103 |
|
|
104 |
TreePath[] path = treeSelection.getPathsFor(selection); |
|
105 |
|
|
106 |
DescriptionBase<?> imageGallery = (DescriptionBase<?>) path[0].getFirstSegment(); |
|
107 |
|
|
108 |
// TODO use undo context specific to editor |
|
109 |
MediaDeletionConfigurator config = new MediaDeletionConfigurator(); |
|
110 |
config.setDeleteFromDescription(true); |
|
111 |
config.setOnlyRemoveFromGallery(false); |
|
112 |
|
|
113 |
if (imageGallery instanceof SpecimenDescription){ |
|
114 |
config.setDeleteFrom(((SpecimenDescription)imageGallery).getDescribedSpecimenOrObservation()); |
|
115 |
} else if (imageGallery instanceof TaxonDescription){ |
|
116 |
config.setDeleteFrom(((TaxonDescription)imageGallery).getTaxon()); |
|
117 |
}else if (imageGallery instanceof TaxonNameDescription){ |
|
118 |
config.setDeleteFrom(((TaxonNameDescription)imageGallery).getTaxonName()); |
|
119 |
} |
|
120 |
|
|
121 |
|
|
122 |
if (!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, shell, Messages.DeleteHandler_CONFIRM_DELETION, Messages.DeleteHandler_CONFIRM_DELETION_MESSAGE)){ |
|
123 |
return; |
|
124 |
} |
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
if (config.isOnlyRemoveFromGallery() || ((Media)selection).getId() == 0){ |
|
129 |
operations.add(new RemoveImageFromDescriptionElementOperation(label, undoContext, (Media) selection, imageGallery, factualDataPart)); |
|
130 |
}else{ |
|
131 |
operations.add(new DeleteMediaOperation(label, undoContext, imageGallery, (Media) selection, config, factualDataPart)); |
|
132 |
} |
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
} |
|
137 |
else{ |
|
138 |
MessagingUtils.error(getClass(), Messages.DeleteHandler_INVALID_SELECTION, null); |
|
139 |
} |
|
140 |
// } |
|
141 |
|
|
142 |
// execute all cumulated operations |
|
143 |
for(AbstractPostOperation<?> operation : operations){ |
|
144 |
AbstractUtility.executeOperation(operation); |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
@CanExecute |
|
149 |
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
|
150 |
MHandledMenuItem menuItem){ |
|
151 |
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject(); |
|
152 |
ISelection selection = factualDataPart.getViewer().getSelection(); |
|
153 |
boolean canExecute = selection !=null && !selection.isEmpty(); |
|
154 |
menuItem.setVisible(canExecute); |
|
155 |
return canExecute; |
|
156 |
} |
|
157 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DescriptionsMenuPropertyTester.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler; |
|
5 |
|
|
6 |
import org.eclipse.core.expressions.PropertyTester; |
|
7 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
8 |
|
|
9 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
10 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
11 |
import eu.etaxonomy.cdm.model.description.IndividualsAssociation; |
|
12 |
import eu.etaxonomy.cdm.model.media.Media; |
|
13 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
|
14 |
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; |
|
15 |
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView; |
|
16 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
17 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
18 |
|
|
19 |
/** |
|
20 |
* Property tester used by the description tree menu. |
|
21 |
* |
|
22 |
* @author p.ciardelli |
|
23 |
* @author n.hoffmann |
|
24 |
* @version $Id: $ |
|
25 |
*/ |
|
26 |
public class DescriptionsMenuPropertyTester extends PropertyTester { |
|
27 |
|
|
28 |
private static final String MEDIA = "isMedia"; //$NON-NLS-1$ |
|
29 |
private static final String FEATURE_NODE_CONTAINER = "isFeatureNodeContainer"; //$NON-NLS-1$ |
|
30 |
private static final String DESCRIPTION = "isDescription"; //$NON-NLS-1$ |
|
31 |
private static final String INDIVIDUALS_ASSOCIATION = "isIndividualsAssociation"; //$NON-NLS-1$ |
|
32 |
private static final String DESCRIPTION_ELEMENT = "isDescriptionElement"; //$NON-NLS-1$ |
|
33 |
private static final String DELETABLE = "isDeletable"; //$NON-NLS-1$ |
|
34 |
private static final String IMAGE_GALLERY = "isImageGallery"; //$NON-NLS-1$ |
|
35 |
private static final String TAXON_EDITOR = "isTaxonEditor"; //$NON-NLS-1$ |
|
36 |
private static final String BULK_EDITOR = "isBulkEditor"; //$NON-NLS-1$ |
|
37 |
private static final String DERIVATE_EDITOR = "isDerivateEditor"; //$NON-NLS-1$ |
|
38 |
|
|
39 |
/* (non-Javadoc) |
|
40 |
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object) |
|
41 |
*/ |
|
42 |
/** {@inheritDoc} */ |
|
43 |
@Override |
|
44 |
public boolean test(Object receiver, String property, Object[] args, |
|
45 |
Object expectedValue) { |
|
46 |
|
|
47 |
if(TAXON_EDITOR.equals(property)){ |
|
48 |
return isTaxonEditor(); |
|
49 |
} |
|
50 |
else if(BULK_EDITOR.equals(property)){ |
|
51 |
return isBulkEditor(); |
|
52 |
} |
|
53 |
else if(DERIVATE_EDITOR.equals(property)){ |
|
54 |
return isDerivateEditor(); |
|
55 |
} |
|
56 |
|
|
57 |
Object[] selectedElements = ((IStructuredSelection) receiver).toArray(); |
|
58 |
|
|
59 |
if(selectedElements.length == 0){ |
|
60 |
// nothing selected so all tests should fail |
|
61 |
return false; |
|
62 |
} |
|
63 |
|
|
64 |
if(MEDIA.equals(property)){ |
|
65 |
return isMedia(selectedElements); |
|
66 |
} |
|
67 |
else if(FEATURE_NODE_CONTAINER.equals(property)){ |
|
68 |
return isFeatureNodeContainer(selectedElements); |
|
69 |
} |
|
70 |
else if(DESCRIPTION.equals(property)){ |
|
71 |
return isDescription(selectedElements); |
|
72 |
} |
|
73 |
else if(INDIVIDUALS_ASSOCIATION.equals(property)){ |
|
74 |
return isIndividualsAssociation(selectedElements); |
|
75 |
} |
|
76 |
else if(DESCRIPTION_ELEMENT.equals(property)){ |
|
77 |
return isDescriptionElement(selectedElements); |
|
78 |
} |
|
79 |
else if(DELETABLE.equals(property)){ |
|
80 |
return isDeletable(selectedElements); |
|
81 |
} |
|
82 |
else if(IMAGE_GALLERY.equals(property)){ |
|
83 |
return isImageGallery(selectedElements); |
|
84 |
} |
|
85 |
else{ |
|
86 |
return false; |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
private boolean isImageGallery(Object[] selectedElements) { |
|
91 |
for (Object object : selectedElements){ |
|
92 |
if(!(object instanceof DescriptionBase) || !((DescriptionBase<?>) object).isImageGallery()){ |
|
93 |
return false; |
|
94 |
} |
|
95 |
} |
|
96 |
return true; |
|
97 |
} |
|
98 |
|
|
99 |
private boolean isFeatureNodeContainer(Object[] selectedElements) { |
|
100 |
for (Object object : selectedElements){ |
|
101 |
if(!(object instanceof FeatureNodeContainer)){ |
|
102 |
return false; |
|
103 |
} |
|
104 |
} |
|
105 |
return true; |
|
106 |
} |
|
107 |
|
|
108 |
private boolean isDeletable(Object[] selectedElements) { |
|
109 |
boolean result = false; |
|
110 |
|
|
111 |
for (Object object : selectedElements) { |
|
112 |
|
|
113 |
if((object instanceof DescriptionBase) |
|
114 |
|| (object instanceof DescriptionElementBase) |
|
115 |
|| (object instanceof Media) |
|
116 |
|| (object instanceof FeatureNodeContainer)){ |
|
117 |
result = true; |
|
118 |
}else{ |
|
119 |
return false; |
|
120 |
} |
|
121 |
|
|
122 |
} |
|
123 |
return result; |
|
124 |
} |
|
125 |
|
|
126 |
private boolean isDescriptionElement(Object[] selectedElements) { |
|
127 |
for (Object object : selectedElements){ |
|
128 |
if(!(object instanceof DescriptionElementBase)){ |
|
129 |
return false; |
|
130 |
} |
|
131 |
} |
|
132 |
return true; |
|
133 |
} |
|
134 |
|
|
135 |
private boolean isDescription(Object[] selectedElements) { |
|
136 |
for (Object object : selectedElements){ |
|
137 |
if(!(object instanceof DescriptionBase)){ |
|
138 |
return false; |
|
139 |
} |
|
140 |
} |
|
141 |
return true; |
|
142 |
} |
|
143 |
|
|
144 |
private boolean isIndividualsAssociation(Object[] selectedElements) { |
|
145 |
for (Object object : selectedElements){ |
|
146 |
if(!(object instanceof IndividualsAssociation)){ |
|
147 |
return false; |
|
148 |
} |
|
149 |
} |
|
150 |
return true; |
|
151 |
} |
|
152 |
|
|
153 |
private boolean isMedia(Object[] selectedElements) { |
|
154 |
for (Object object : selectedElements){ |
|
155 |
if(!(object instanceof Media)){ |
|
156 |
return false; |
|
157 |
} |
|
158 |
} |
|
159 |
return true; |
|
160 |
} |
|
161 |
|
|
162 |
private boolean isTaxonEditor() { |
|
163 |
if(AbstractUtility.getActiveE4Editor() instanceof MultiPageTaxonEditor){ |
|
164 |
return true; |
|
165 |
} |
|
166 |
return false; |
|
167 |
} |
|
168 |
|
|
169 |
private boolean isBulkEditor() { |
|
170 |
if(AbstractUtility.getActiveE4Editor() instanceof BulkEditor){ |
|
171 |
return true; |
|
172 |
} |
|
173 |
return false; |
|
174 |
} |
|
175 |
|
|
176 |
private boolean isDerivateEditor() { |
|
177 |
if(AbstractUtility.getActiveE4Editor() instanceof DerivateView){ |
|
178 |
return true; |
|
179 |
} |
|
180 |
return false; |
|
181 |
} |
|
182 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DescriptionsMenuPropertyTesterE4.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler; |
|
5 |
|
|
6 |
import org.eclipse.core.expressions.PropertyTester; |
|
7 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
8 |
|
|
9 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
10 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
11 |
import eu.etaxonomy.cdm.model.description.IndividualsAssociation; |
|
12 |
import eu.etaxonomy.cdm.model.media.Media; |
|
13 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
|
14 |
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; |
|
15 |
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView; |
|
16 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
17 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
18 |
|
|
19 |
/** |
|
20 |
* Property tester used by the description tree menu. |
|
21 |
* |
|
22 |
* @author p.ciardelli |
|
23 |
* @author n.hoffmann |
|
24 |
* @version $Id: $ |
|
25 |
*/ |
|
26 |
public class DescriptionsMenuPropertyTesterE4 extends PropertyTester { |
|
27 |
|
|
28 |
private static final String MEDIA = "isMedia"; //$NON-NLS-1$ |
|
29 |
private static final String FEATURE_NODE_CONTAINER = "isFeatureNodeContainer"; //$NON-NLS-1$ |
|
30 |
private static final String DESCRIPTION = "isDescription"; //$NON-NLS-1$ |
|
31 |
private static final String INDIVIDUALS_ASSOCIATION = "isIndividualsAssociation"; //$NON-NLS-1$ |
|
32 |
private static final String DESCRIPTION_ELEMENT = "isDescriptionElement"; //$NON-NLS-1$ |
|
33 |
private static final String DELETABLE = "isDeletable"; //$NON-NLS-1$ |
|
34 |
private static final String IMAGE_GALLERY = "isImageGallery"; //$NON-NLS-1$ |
|
35 |
private static final String TAXON_EDITOR = "isTaxonEditor"; //$NON-NLS-1$ |
|
36 |
private static final String BULK_EDITOR = "isBulkEditor"; //$NON-NLS-1$ |
|
37 |
private static final String DERIVATE_EDITOR = "isDerivateEditor"; //$NON-NLS-1$ |
|
38 |
|
|
39 |
/* (non-Javadoc) |
|
40 |
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object) |
|
41 |
*/ |
|
42 |
/** {@inheritDoc} */ |
|
43 |
@Override |
|
44 |
public boolean test(Object receiver, String property, Object[] args, |
|
45 |
Object expectedValue) { |
|
46 |
|
|
47 |
if(TAXON_EDITOR.equals(property)){ |
|
48 |
return isTaxonEditor(); |
|
49 |
} |
|
50 |
else if(BULK_EDITOR.equals(property)){ |
|
51 |
return isBulkEditor(); |
|
52 |
} |
|
53 |
else if(DERIVATE_EDITOR.equals(property)){ |
|
54 |
return isDerivateEditor(); |
|
55 |
} |
|
56 |
|
|
57 |
Object[] selectedElements = ((IStructuredSelection) receiver).toArray(); |
|
58 |
|
|
59 |
if(selectedElements.length == 0){ |
|
60 |
// nothing selected so all tests should fail |
|
61 |
return false; |
|
62 |
} |
|
63 |
|
|
64 |
if(MEDIA.equals(property)){ |
|
65 |
return isMedia(selectedElements); |
|
66 |
} |
|
67 |
else if(FEATURE_NODE_CONTAINER.equals(property)){ |
|
68 |
return isFeatureNodeContainer(selectedElements); |
|
69 |
} |
|
70 |
else if(DESCRIPTION.equals(property)){ |
|
71 |
return isDescription(selectedElements); |
|
72 |
} |
|
73 |
else if(INDIVIDUALS_ASSOCIATION.equals(property)){ |
|
74 |
return isIndividualsAssociation(selectedElements); |
|
75 |
} |
|
76 |
else if(DESCRIPTION_ELEMENT.equals(property)){ |
|
77 |
return isDescriptionElement(selectedElements); |
|
78 |
} |
|
79 |
else if(DELETABLE.equals(property)){ |
|
80 |
return isDeletable(selectedElements); |
|
81 |
} |
|
82 |
else if(IMAGE_GALLERY.equals(property)){ |
|
83 |
return isImageGallery(selectedElements); |
|
84 |
} |
|
85 |
else{ |
|
86 |
return false; |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
private boolean isImageGallery(Object[] selectedElements) { |
|
91 |
for (Object object : selectedElements){ |
|
92 |
if(!(object instanceof DescriptionBase) || !((DescriptionBase<?>) object).isImageGallery()){ |
|
93 |
return false; |
|
94 |
} |
|
95 |
} |
|
96 |
return true; |
|
97 |
} |
|
98 |
|
|
99 |
private boolean isFeatureNodeContainer(Object[] selectedElements) { |
|
100 |
for (Object object : selectedElements){ |
|
101 |
if(!(object instanceof FeatureNodeContainer)){ |
|
102 |
return false; |
|
103 |
} |
|
104 |
} |
|
105 |
return true; |
|
106 |
} |
|
107 |
|
|
108 |
private boolean isDeletable(Object[] selectedElements) { |
|
109 |
boolean result = false; |
|
110 |
|
|
111 |
for (Object object : selectedElements) { |
|
112 |
|
|
113 |
if((object instanceof DescriptionBase) |
|
114 |
|| (object instanceof DescriptionElementBase) |
|
115 |
|| (object instanceof Media) |
|
116 |
|| (object instanceof FeatureNodeContainer)){ |
|
117 |
result = true; |
|
118 |
}else{ |
|
119 |
return false; |
|
120 |
} |
|
121 |
|
|
122 |
} |
|
123 |
return result; |
|
124 |
} |
|
125 |
|
|
126 |
private boolean isDescriptionElement(Object[] selectedElements) { |
|
127 |
for (Object object : selectedElements){ |
|
128 |
if(!(object instanceof DescriptionElementBase)){ |
|
129 |
return false; |
|
130 |
} |
|
131 |
} |
|
132 |
return true; |
|
133 |
} |
|
134 |
|
|
135 |
private boolean isDescription(Object[] selectedElements) { |
|
136 |
for (Object object : selectedElements){ |
|
137 |
if(!(object instanceof DescriptionBase)){ |
|
138 |
return false; |
|
139 |
} |
|
140 |
} |
|
141 |
return true; |
|
142 |
} |
|
143 |
|
|
144 |
private boolean isIndividualsAssociation(Object[] selectedElements) { |
|
145 |
for (Object object : selectedElements){ |
|
146 |
if(!(object instanceof IndividualsAssociation)){ |
|
147 |
return false; |
|
148 |
} |
|
149 |
} |
|
150 |
return true; |
|
151 |
} |
|
152 |
|
|
153 |
private boolean isMedia(Object[] selectedElements) { |
|
154 |
for (Object object : selectedElements){ |
|
155 |
if(!(object instanceof Media)){ |
|
156 |
return false; |
|
157 |
} |
|
158 |
} |
|
159 |
return true; |
|
160 |
} |
|
161 |
|
|
162 |
private boolean isTaxonEditor() { |
|
163 |
if(AbstractUtility.getActiveE4Editor() instanceof MultiPageTaxonEditor){ |
|
164 |
return true; |
|
165 |
} |
|
166 |
return false; |
|
167 |
} |
|
168 |
|
|
169 |
private boolean isBulkEditor() { |
|
170 |
if(AbstractUtility.getActiveE4Editor() instanceof BulkEditor){ |
|
171 |
return true; |
|
172 |
} |
|
173 |
return false; |
|
174 |
} |
|
175 |
|
|
176 |
private boolean isDerivateEditor() { |
|
177 |
if(AbstractUtility.getActiveE4Editor() instanceof DerivateView){ |
|
178 |
return true; |
|
179 |
} |
|
180 |
return false; |
|
181 |
} |
|
182 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenu.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.view.descriptive.e4.handler; |
|
11 |
|
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
import javax.inject.Inject; |
|
15 |
import javax.inject.Named; |
|
16 |
|
|
17 |
import org.eclipse.e4.core.commands.ECommandService; |
|
18 |
import org.eclipse.e4.core.commands.EHandlerService; |
|
19 |
import org.eclipse.e4.ui.di.AboutToShow; |
|
20 |
import org.eclipse.e4.ui.model.application.commands.MCommand; |
|
21 |
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory; |
|
22 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
23 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenu; |
|
24 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; |
|
25 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory; |
|
26 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
27 |
|
|
28 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
29 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
30 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
31 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
32 |
import eu.etaxonomy.cdm.model.description.FeatureNode; |
|
33 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
|
34 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation; |
|
35 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
36 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
37 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
38 |
|
|
39 |
/** |
|
40 |
* |
|
41 |
* @author pplitzner |
|
42 |
* @date 15.08.2017 |
|
43 |
* |
|
44 |
*/ |
|
45 |
public class DynamicFeatureMenu { |
|
46 |
|
|
47 |
@Inject |
|
48 |
private EHandlerService handlerService; |
|
49 |
|
|
50 |
@Inject |
|
51 |
private ECommandService commandService; |
|
52 |
|
|
53 |
/** {@inheritDoc} */ |
|
54 |
@AboutToShow |
|
55 |
public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) Object selection) { |
|
56 |
|
|
57 |
MMenu menu = MMenuFactory.INSTANCE.createMenu(); |
|
58 |
menu.setLabel("New"); |
|
59 |
items.add(menu); |
|
60 |
|
|
61 |
if (selection instanceof DescriptionBase<?>) { |
|
62 |
FeatureTree featureTree = getFeatureTree((DescriptionBase<?>) selection); |
|
63 |
|
|
64 |
for (FeatureNode childNode : featureTree.getRootChildren()) { |
|
65 |
createMenuItem(menu, childNode.getFeature()); |
|
66 |
|
|
67 |
} |
|
68 |
} else if (selection instanceof FeatureNodeContainer) { |
|
69 |
FeatureNode featureNode = ((FeatureNodeContainer) selection) |
|
70 |
.getFeatureNode(); |
|
71 |
|
|
72 |
// add the feature to the menu |
|
73 |
createMenuItem(menu, featureNode.getFeature()); |
|
74 |
|
|
75 |
// add possible children to the menu |
|
76 |
for (FeatureNode childNode : featureNode.getChildNodes()) { |
|
77 |
createMenuItem(menu, childNode.getFeature()); |
|
78 |
} |
|
79 |
} else if (selection instanceof DescriptionElementBase) { |
|
80 |
Feature feature = ((DescriptionElementBase) selection) |
|
81 |
.getFeature(); |
|
82 |
createMenuItem(menu, feature); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
private void createMenuItem(MMenu menu, final Feature feature) { |
|
87 |
final Feature deproxiedFeature = HibernateProxyHelper.deproxy(feature, Feature.class); |
|
88 |
|
|
89 |
String label = deproxiedFeature.getLabel(PreferencesUtil.getGlobalLanguage()); |
|
90 |
if (label == null){ |
|
91 |
label = deproxiedFeature.getLabel(); |
|
92 |
} |
|
93 |
if(label == null){ |
|
94 |
label = deproxiedFeature.generateTitle(); |
|
95 |
} |
|
96 |
if(label == null){ |
|
97 |
label = deproxiedFeature.toString(); |
|
98 |
} |
|
99 |
MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem(); |
|
100 |
menuItem.setLabel(label); |
|
101 |
MCommand mCommand = MCommandsFactory.INSTANCE.createCommand(); |
|
102 |
mCommand.setElementId(CreateDescriptionElementOperation.ID); |
|
103 |
mCommand.setCommandName(label); |
|
104 |
// try { |
|
105 |
// mCommand.setCommandName(command.getName()); |
|
106 |
// } catch (NotDefinedException e) { |
|
107 |
// e.printStackTrace(); |
|
108 |
// } |
|
109 |
//set params |
|
110 |
menuItem.getTransientData().put(CreateDescriptionElementOperation.ID+".feature.uuid", feature.getUuid()); |
|
111 |
|
|
112 |
menuItem.setCommand(mCommand); |
|
113 |
menu.getChildren().add(menuItem); |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Retrieves the feature tree associated with the given description |
|
118 |
* |
|
119 |
* TODO as of now this is always the same thing because feature trees may |
|
120 |
* not be associated to descriptions yet. |
|
121 |
* |
|
122 |
* @param description |
|
123 |
* @return |
|
124 |
*/ |
|
125 |
private FeatureTree getFeatureTree(DescriptionBase description) { |
|
126 |
FeatureTree featureTree = null; |
|
127 |
|
|
128 |
// TODO change this to the feature tree associated with this taxon |
|
129 |
// description |
|
130 |
if (description.hasStructuredData()) { |
|
131 |
featureTree = PreferencesUtil |
|
132 |
.getDefaultFeatureTreeForStructuredDescription(); |
|
133 |
} else { |
|
134 |
featureTree = PreferencesUtil |
|
135 |
.getDefaultFeatureTreeForTextualDescription(); |
|
136 |
} |
|
137 |
|
|
138 |
if (featureTree == null) { |
|
139 |
featureTree = FeatureTree.NewInstance(CdmStore.getTermManager() |
|
140 |
.getPreferredTerms(Feature.class)); |
|
141 |
} |
|
142 |
|
|
143 |
return featureTree; |
|
144 |
} |
|
145 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenuE4.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.view.descriptive.e4.handler; |
|
11 |
|
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
import javax.inject.Named; |
|
15 |
|
|
16 |
import org.eclipse.e4.ui.di.AboutToShow; |
|
17 |
import org.eclipse.e4.ui.model.application.commands.MCommand; |
|
18 |
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory; |
|
19 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
20 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenu; |
|
21 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; |
|
22 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory; |
|
23 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
26 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
27 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
28 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
29 |
import eu.etaxonomy.cdm.model.description.FeatureNode; |
|
30 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
|
31 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation; |
|
32 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
33 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
34 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
35 |
|
|
36 |
/** |
|
37 |
* |
|
38 |
* @author pplitzner |
|
39 |
* @date 15.08.2017 |
|
40 |
* |
|
41 |
*/ |
|
42 |
public class DynamicFeatureMenuE4 { |
|
43 |
|
|
44 |
/** {@inheritDoc} */ |
|
45 |
@AboutToShow |
|
46 |
public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) Object selection) { |
|
47 |
|
|
48 |
MMenu menu = MMenuFactory.INSTANCE.createMenu(); |
|
49 |
menu.setLabel("New"); |
|
50 |
items.add(menu); |
|
51 |
|
|
52 |
if (selection instanceof DescriptionBase<?>) { |
|
53 |
FeatureTree featureTree = getFeatureTree((DescriptionBase<?>) selection); |
|
54 |
|
|
55 |
for (FeatureNode childNode : featureTree.getRootChildren()) { |
|
56 |
createMenuItem(menu, childNode.getFeature()); |
|
57 |
|
|
58 |
} |
|
59 |
} else if (selection instanceof FeatureNodeContainer) { |
|
60 |
FeatureNode featureNode = ((FeatureNodeContainer) selection) |
|
61 |
.getFeatureNode(); |
|
62 |
|
|
63 |
// add the feature to the menu |
|
64 |
createMenuItem(menu, featureNode.getFeature()); |
|
65 |
|
|
66 |
// add possible children to the menu |
|
67 |
for (FeatureNode childNode : featureNode.getChildNodes()) { |
|
68 |
createMenuItem(menu, childNode.getFeature()); |
|
69 |
} |
|
70 |
} else if (selection instanceof DescriptionElementBase) { |
|
71 |
Feature feature = ((DescriptionElementBase) selection) |
|
72 |
.getFeature(); |
|
73 |
createMenuItem(menu, feature); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
private void createMenuItem(MMenu menu, final Feature feature) { |
|
78 |
final Feature deproxiedFeature = HibernateProxyHelper.deproxy(feature, Feature.class); |
|
79 |
|
|
80 |
String label = deproxiedFeature.getLabel(PreferencesUtil.getGlobalLanguage()); |
|
81 |
if (label == null){ |
|
82 |
label = deproxiedFeature.getLabel(); |
|
83 |
} |
|
84 |
if(label == null){ |
|
85 |
label = deproxiedFeature.generateTitle(); |
|
86 |
} |
|
87 |
if(label == null){ |
|
88 |
label = deproxiedFeature.toString(); |
|
89 |
} |
|
90 |
MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem(); |
|
91 |
menuItem.setLabel(label); |
|
92 |
MCommand mCommand = MCommandsFactory.INSTANCE.createCommand(); |
|
93 |
mCommand.setElementId(CreateDescriptionElementOperation.ID); |
|
94 |
mCommand.setCommandName(label); |
|
95 |
// try { |
|
96 |
// mCommand.setCommandName(command.getName()); |
|
97 |
// } catch (NotDefinedException e) { |
|
98 |
// e.printStackTrace(); |
|
99 |
// } |
|
100 |
//set params |
|
101 |
menuItem.getTransientData().put(CreateDescriptionElementOperation.ID+".feature.uuid", feature.getUuid()); |
|
102 |
|
|
103 |
menuItem.setCommand(mCommand); |
|
104 |
menu.getChildren().add(menuItem); |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* Retrieves the feature tree associated with the given description |
|
109 |
* |
|
110 |
* TODO as of now this is always the same thing because feature trees may |
|
111 |
* not be associated to descriptions yet. |
|
112 |
* |
|
113 |
* @param description |
|
114 |
* @return |
|
115 |
*/ |
|
116 |
private FeatureTree getFeatureTree(DescriptionBase description) { |
|
117 |
FeatureTree featureTree = null; |
|
118 |
|
|
119 |
// TODO change this to the feature tree associated with this taxon |
|
120 |
// description |
|
121 |
if (description.hasStructuredData()) { |
|
122 |
featureTree = PreferencesUtil |
|
123 |
.getDefaultFeatureTreeForStructuredDescription(); |
|
124 |
} else { |
|
125 |
featureTree = PreferencesUtil |
|
126 |
.getDefaultFeatureTreeForTextualDescription(); |
|
127 |
} |
|
128 |
|
|
129 |
if (featureTree == null) { |
|
130 |
featureTree = FeatureTree.NewInstance(CdmStore.getTermManager() |
|
131 |
.getPreferredTerms(Feature.class)); |
|
132 |
} |
|
133 |
|
|
134 |
return featureTree; |
|
135 |
} |
|
136 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionElementsHandler.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.view.descriptive.e4.handler; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
import java.util.UUID; |
|
15 |
|
|
16 |
import javax.inject.Named; |
|
17 |
|
|
18 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
|
19 |
import org.eclipse.e4.core.di.annotations.Execute; |
|
20 |
import org.eclipse.e4.core.di.annotations.Optional; |
|
21 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
22 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
23 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
|
24 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
25 |
import org.eclipse.jface.viewers.ISelection; |
|
26 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
27 |
import org.eclipse.swt.widgets.Display; |
|
28 |
import org.eclipse.swt.widgets.Shell; |
|
29 |
import org.eclipse.ui.PartInitException; |
|
30 |
|
|
31 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
|
32 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
33 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
34 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
35 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
36 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
37 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
38 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
39 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
40 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
41 |
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; |
|
42 |
import eu.etaxonomy.taxeditor.editor.Page; |
|
43 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
|
44 |
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor; |
|
45 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4; |
|
46 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation; |
|
47 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
48 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
49 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
50 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
51 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
52 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
53 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog; |
|
54 |
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility; |
|
55 |
|
|
56 |
|
|
57 |
/** |
|
58 |
* |
|
59 |
* @author pplitzner |
|
60 |
* @date 15.08.2017 |
|
61 |
* |
|
62 |
*/ |
|
63 |
public class MoveDescriptionElementsHandler implements IPostOperationEnabled{ |
|
64 |
private UUID newAcceptedTaxonNodeUuid; |
|
65 |
private TaxonNameEditor editor; |
|
66 |
|
|
67 |
@Execute |
|
68 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
|
69 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object selection, |
|
70 |
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell, MMenuItem menuItem) { |
|
71 |
|
|
72 |
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject(); |
|
73 |
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(factualDataPart.getSelectionProvidingPart()); |
|
74 |
if(e4WrappedPart instanceof MultiPageTaxonEditor){ |
|
75 |
editor = (TaxonNameEditor) ((MultiPageTaxonEditor) e4WrappedPart).getPage(Page.NAME); |
|
76 |
} |
|
77 |
Taxon actualTaxon= null; |
|
78 |
|
|
79 |
List<DescriptionElementBase> elements = new ArrayList<DescriptionElementBase>(); |
|
80 |
|
|
81 |
// for(Object element : structuredSelection.toArray()){ |
|
82 |
if(selection instanceof DescriptionElementBase){ |
|
83 |
UUID uuid = ((DescriptionElementBase) selection).getUuid(); |
|
84 |
|
|
85 |
elements.add(CdmStore.getService(IDescriptionService.class).loadDescriptionElement(uuid, null)); |
|
86 |
} else if(selection instanceof FeatureNodeContainer){ |
|
87 |
for(DescriptionElementBase de : ((FeatureNodeContainer)selection).getDescriptionElements()){ |
|
88 |
elements.add( |
|
89 |
CdmStore.getService(IDescriptionService.class).loadDescriptionElement(de.getUuid(), null) |
|
90 |
); |
|
91 |
} |
|
92 |
} |
|
93 |
// } |
|
94 |
|
|
95 |
if(elements.size() == 0){ |
|
96 |
return; |
|
97 |
} |
|
98 |
|
|
99 |
DescriptionBase description = elements.get(0).getInDescription(); |
|
100 |
List<UUID> excludeTaxa = new ArrayList<UUID>(); |
|
101 |
if (description!=null && description.isInstanceOf(TaxonDescription.class)){ |
|
102 |
TaxonDescription taxonDescription = HibernateProxyHelper.deproxy(description, TaxonDescription.class); |
|
103 |
actualTaxon = taxonDescription.getTaxon(); |
|
104 |
excludeTaxa.add(actualTaxon.getUuid()); |
|
105 |
} |
|
106 |
Classification classification = null; |
|
107 |
TaxonNode actualNode = null; |
|
108 |
if (actualTaxon != null){ |
|
109 |
if (!actualTaxon.getTaxonNodes().isEmpty() && actualTaxon.getTaxonNodes().size() ==1){ |
|
110 |
actualNode = actualTaxon.getTaxonNodes().iterator().next(); |
|
111 |
classification = actualNode.getClassification(); |
|
112 |
|
|
113 |
} |
|
114 |
} |
|
115 |
TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(shell, |
|
116 |
editor.getConversationHolder(), |
|
117 |
Messages.MoveDescriptionElementsHandler_CHOOSE_ACC_TAXON, |
|
118 |
excludeTaxa, |
|
119 |
null, classification |
|
120 |
); |
|
121 |
if (newAcceptedTaxonNode != null){ |
|
122 |
Taxon targetTaxon = newAcceptedTaxonNode.getTaxon(); |
|
123 |
|
Also available in: Unified diff
ref #6907 migrate remaining handlers