Project

General

Profile

Revision 90cf660a

ID90cf660a0f8827f0a66011c6df51950744bc5652
Parent a7d1d751
Child b692de70

Added by Patrick Plitzner almost 3 years ago

ref #6595 Set visibility of context menu items in name editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/ChangeSynonymToAcceptedTaxonHandlerE4.java
14 14
import javax.inject.Named;
15 15

  
16 16
import org.apache.log4j.Logger;
17
import org.eclipse.e4.core.di.annotations.CanExecute;
17 18
import org.eclipse.e4.core.di.annotations.Execute;
18 19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19 21
import org.eclipse.e4.ui.services.IServiceConstants;
20 22
import org.eclipse.jface.viewers.IStructuredSelection;
21 23
import org.eclipse.swt.widgets.Shell;
22 24
import org.eclipse.ui.IEditorInput;
23
import org.eclipse.ui.PartInitException;
24 25

  
25 26
import eu.etaxonomy.cdm.model.common.CdmBase;
26 27
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
......
29 30
import eu.etaxonomy.cdm.model.taxon.Taxon;
30 31
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
31 32
import eu.etaxonomy.taxeditor.editor.EditorUtil;
32
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
33
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
33 34
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
34 35
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
36
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
35 37
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToAcceptedTaxonOperation;
36 38
import eu.etaxonomy.taxeditor.model.AbstractUtility;
37
import eu.etaxonomy.taxeditor.model.MessagingUtils;
38 39
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
39 40
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
40 41

  
......
59 60

  
60 61
		IEditorInput input = editor.getEditorInput();
61 62

  
62
		if (!(input instanceof TaxonEditorInput)) {
63
		if (!(input instanceof TaxonEditorInputE4)) {
63 64
			logger.error("Editor input is not TaxonEditorInput"); //$NON-NLS-1$
64 65
			return;
65 66
		}
......
78 79
		}
79 80

  
80 81
		// Get taxon
81
		Taxon taxon = ((TaxonEditorInput) input).getTaxon();
82
		Taxon taxon = ((TaxonEditorInputE4) input).getTaxon();
82 83

  
83
		TaxonNode newParentNode = TaxonNodeSelectionDialog.select(shell, editor.getConversationHolder(), Messages.ChangeSynonymToAcceptedTaxonHandler_SELECT_PARENT, null, null, ((TaxonEditorInput) input).getTaxonNode().getClassification());
84
		TaxonNode newParentNode = TaxonNodeSelectionDialog.select(shell, editor.getConversationHolder(), Messages.ChangeSynonymToAcceptedTaxonHandler_SELECT_PARENT, null, null, ((TaxonEditorInputE4) input).getTaxonNode().getClassification());
84 85

  
85 86

  
86 87
		if(newParentNode != null){
......
113 114
			TaxonNode newNode = (TaxonNode) objectAffectedByOperation;
114 115
//			TaxonNode newNode = parentNode.addChild(newTaxon);
115 116

  
116
			try {
117
				// TODO
118
				/*
119
				 * This doesn't work b/c newNode hasn't been committed yet, and therefore
120
				 *  CdmStore.getTaxonService().getTaxonNodeByUuid(taxonNodeUuid);
121
				 *  doesn't work yet.
122
				 */
123
				EditorUtil.openTaxonNode(newNode.getUuid());
124

  
125
			} catch (PartInitException e) {
126
				// TODO Auto-generated catch block
127
				e.printStackTrace();
128
			} catch (Exception e) {
129
				MessagingUtils.warningDialog(Messages.ChangeSynonymToAcceptedTaxonHandler_CREATE_FAILURE, this, e.getMessage());
130
			}
117
//			try {
118
				// FIXME E4 this throws an exception
119
//				EditorUtil.openTaxonNodeE4(newNode.getUuid());
120
//
121
//			} catch (PartInitException e) {
122
//				e.printStackTrace();
123
//			} catch (Exception e) {
124
//				MessagingUtils.warningDialog(Messages.ChangeSynonymToAcceptedTaxonHandler_CREATE_FAILURE, this, e.getMessage());
125
//			}
131 126
		}
132 127
		return true;
133 128
	}
......
136 131
    public boolean onComplete() {
137 132
		return false;
138 133
	}
134

  
135

  
136
    @CanExecute
137
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
138
            MHandledMenuItem menuItem){
139
        boolean canExecute = false;
140
        Object selectedElement = selection.getFirstElement();
141
        canExecute =
142
                NameEditorMenuPropertyTester.isNotHomotypicSynonymOfAcceptedTaxon(selectedElement)
143
                && !NameEditorMenuPropertyTester.isAccepted(selectedElement)
144
                && !NameEditorMenuPropertyTester.isMisapplication(selectedElement);
145
        menuItem.setVisible(canExecute);
146
        return canExecute;
147
    }
148

  
139 149
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/ChangeToMisapplicationHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
14 15
import org.eclipse.e4.core.di.annotations.Execute;
15 16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16 17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
......
23 24
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24 25
import eu.etaxonomy.taxeditor.editor.EditorUtil;
25 26
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
27
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
26 28
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptRelationshipTypeOperation;
27 29
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation;
28 30
import eu.etaxonomy.taxeditor.model.AbstractUtility;
......
64 66

  
65 67
        AbstractUtility.executeOperation(operation);
66 68
	}
69

  
70
    @CanExecute
71
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
72
            MHandledMenuItem menuItem){
73
        boolean canExecute = false;
74
        Object selectedElement = selection.getFirstElement();
75
        canExecute =
76
                !NameEditorMenuPropertyTester.isAccepted(selectedElement)
77
                && !NameEditorMenuPropertyTester.isMisapplication(selectedElement);
78
        menuItem.setVisible(canExecute);
79
        return canExecute;
80
    }
81

  
67 82
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/ChangeToSynonymHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
14 15
import org.eclipse.e4.core.di.annotations.Execute;
15 16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16 17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
......
19 20

  
20 21
import eu.etaxonomy.cdm.model.taxon.Taxon;
21 22
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
23
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
22 24
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation;
23 25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
24 26
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
......
48 50
        AbstractUtility.executeOperation(operation);
49 51

  
50 52
	}
53

  
54
    @CanExecute
55
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
56
            MHandledMenuItem menuItem){
57
        boolean canExecute = false;
58
        Object selectedElement = selection.getFirstElement();
59
        canExecute =
60
                !NameEditorMenuPropertyTester.isAccepted(selectedElement)
61
                && !NameEditorMenuPropertyTester.isSynonym(selectedElement);
62
        menuItem.setVisible(canExecute);
63
        return canExecute;
64
    }
65

  
51 66
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/CreateHeterotypicSynonymHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

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

  
19 21
import eu.etaxonomy.cdm.model.name.TaxonName;
20 22
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
23
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
21 24
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInNewGroupOperation;
22 25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
23 26
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
......
45 48
        		editor.getUndoContext(), editor.getTaxon(), newSynonymName, editor);
46 49
        AbstractUtility.executeOperation(operation);
47 50
	}
51

  
52
    @CanExecute
53
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
54
            MHandledMenuItem menuItem){
55
        Object selectedElement = selection.getFirstElement();
56
        boolean canExecute = NameEditorMenuPropertyTester.isAccepted(selectedElement);
57
        menuItem.setVisible(canExecute);
58
        return canExecute;
59
    }
48 60
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/CreateHomotypicSynonymHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

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

  
19 21
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
20 22
import eu.etaxonomy.cdm.model.name.TaxonName;
21 23
import eu.etaxonomy.cdm.model.taxon.Taxon;
22 24
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
25
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
23 26
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
24 27
import eu.etaxonomy.taxeditor.model.AbstractUtility;
25 28
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
......
48 51
        		editor.getUndoContext(), taxon, group, newSynonymName, editor);
49 52
        AbstractUtility.executeOperation(operation);
50 53
	}
54

  
55
    @CanExecute
56
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
57
            MHandledMenuItem menuItem){
58
        Object selectedElement = selection.getFirstElement();
59
        boolean canExecute = NameEditorMenuPropertyTester.isAccepted(selectedElement);
60
        menuItem.setVisible(canExecute);
61
        return canExecute;
62
    }
51 63
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/CreateMisapplicationHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

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

  
19 21
import eu.etaxonomy.cdm.model.name.TaxonName;
20 22
import eu.etaxonomy.cdm.model.taxon.Taxon;
21 23
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
22 24
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
25
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
23 26
import eu.etaxonomy.taxeditor.editor.view.concept.operation.CreateConceptRelationOperation;
24 27
import eu.etaxonomy.taxeditor.model.AbstractUtility;
25 28
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
......
49 52
        		editor.getUndoContext(), editor.getTaxon(), concept, type, editor);
50 53
        AbstractUtility.executeOperation(operation);
51 54
	}
55

  
56

  
57
    @CanExecute
58
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
59
            MHandledMenuItem menuItem){
60
        boolean canExecute = false;
61
        Object selectedElement = selection.getFirstElement();
62
        canExecute = NameEditorMenuPropertyTester.isAccepted(selectedElement)
63
                && NameEditorMenuPropertyTester.isMisapplication(selectedElement);
64
        menuItem.setVisible(canExecute);
65
        return canExecute;
66
    }
52 67
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/CreateSynonymInHomotypicalGroupHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
14 15
import org.eclipse.e4.core.di.annotations.Execute;
15 16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16 17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
......
21 22
import eu.etaxonomy.cdm.model.name.TaxonName;
22 23
import eu.etaxonomy.cdm.model.taxon.Synonym;
23 24
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
25
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
24 26
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
25 27
import eu.etaxonomy.taxeditor.model.AbstractUtility;
26 28
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
......
60 62
        AbstractUtility.executeOperation(operation);
61 63

  
62 64
	}
65

  
66

  
67
    @CanExecute
68
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
69
            MHandledMenuItem menuItem){
70
        boolean canExecute = false;
71
        Object selectedElement = selection.getFirstElement();
72
        canExecute = NameEditorMenuPropertyTester.isSynonym(selectedElement);
73
        menuItem.setVisible(canExecute);
74
        return canExecute;
75
    }
63 76
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/DeleteAllEmptyNamesHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
14 15
import org.eclipse.e4.core.di.annotations.Execute;
15 16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16 17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
......
45 46

  
46 47
	}
47 48

  
49
    @Override
50
    @CanExecute
51
    public boolean canExecute(
52
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
53
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
54
            MHandledMenuItem menuItem){
55

  
56
        editor = (TaxonNameEditorE4) activePart.getObject();
57

  
58
        boolean canExecute = false;
59
        Object selectedElement = selection.getFirstElement();
60
        canExecute = editor.checkForEmptyNames();
61
        menuItem.setVisible(canExecute);
62
        return canExecute;
63
    }
64

  
48 65
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/DeleteTaxonBaseHandlerE4.java
10 10
package eu.etaxonomy.taxeditor.editor.name.e4.handler;
11 11
import javax.inject.Named;
12 12

  
13
import org.eclipse.e4.core.di.annotations.CanExecute;
13 14
import org.eclipse.e4.core.di.annotations.Execute;
14 15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
15 16
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
......
28 29
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
29 30
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
30 31
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
32
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
31 33
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteMisapplicationOperation;
32 34
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteSynonymOperation;
33 35
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteTaxonBaseOperation;
......
112 114
                DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
113 115
    		}
114 116
		}
115

  
116

  
117 117
	}
118 118

  
119
    @CanExecute
120
    public boolean canExecute(
121
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
122
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
123
            MHandledMenuItem menuItem){
124
        boolean canExecute = false;
125
        Object selectedElement = selection.getFirstElement();
126
        canExecute =
127
                NameEditorMenuPropertyTester.isSynonym(selectedElement)
128
                || NameEditorMenuPropertyTester.isMisapplication(selectedElement)
129
                || NameEditorMenuPropertyTester.isRelatedConcept(selectedElement);
130
        menuItem.setVisible(canExecute);
131
        return canExecute;
132
    }
133

  
119 134
	@Override
120 135
	public boolean postOperation(CdmBase objectAffectedByOperation) {
121 136

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/MoveSynonymToAnotherAcceptedTaxonHandlerE4.java
7 7
import javax.inject.Named;
8 8

  
9 9
import org.apache.log4j.Logger;
10
import org.eclipse.e4.core.di.annotations.CanExecute;
10 11
import org.eclipse.e4.core.di.annotations.Execute;
11 12
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
13
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
12 14
import org.eclipse.e4.ui.services.IServiceConstants;
13 15
import org.eclipse.jface.viewers.IStructuredSelection;
14 16
import org.eclipse.swt.widgets.Shell;
......
22 24
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
23 25
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
24 26
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
27
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
25 28
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;
26 29
import eu.etaxonomy.taxeditor.model.AbstractUtility;
27 30
import eu.etaxonomy.taxeditor.model.MessagingUtils;
......
69 72
		            oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor);
70 73

  
71 74
		    AbstractUtility.executeOperation(operation);
72

  
73 75
		}
74 76
	}
75 77

  
78
    @CanExecute
79
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
80
            MHandledMenuItem menuItem){
81
        boolean canExecute = false;
82
        Object selectedElement = selection.getFirstElement();
83
        canExecute =
84
                NameEditorMenuPropertyTester.isSynonym(selectedElement)
85
                        && NameEditorMenuPropertyTester.isNotHomotypicSynonymOfAcceptedTaxon(selectedElement);
86

  
87
        menuItem.setVisible(canExecute);
88
        return canExecute;
89
    }
90

  
76 91
	@Override
77 92
	public boolean postOperation(CdmBase objectAffectedByOperation) {
78
		// TODO Auto-generated method stub
79 93
		return false;
80 94
	}
81 95

  
82 96
	@Override
83 97
	public boolean onComplete() {
84
		// TODO Auto-generated method stub
85 98
		return false;
86 99
	}
87 100

  
88

  
89

  
90 101
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/SetBasionymHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
14 15
import org.eclipse.e4.core.di.annotations.Execute;
15 16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16 17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
......
19 20

  
20 21
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
21 22
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
23
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
22 24
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicalGroupBasionymOperation;
23 25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
24 26
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
......
46 48
        					editor.getTaxon(), selectedTaxonBase, editor);
47 49
        AbstractUtility.executeOperation(operation);
48 50
	}
51

  
52
    @CanExecute
53
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
54
            MHandledMenuItem menuItem){
55
        boolean canExecute = false;
56
        Object selectedElement = selection.getFirstElement();
57
        canExecute =
58
                NameEditorMenuPropertyTester.isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement);
59
        menuItem.setVisible(canExecute);
60
        return canExecute;
61
    }
49 62
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/SwapSynonymAndAcceptedHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
14 15
import org.eclipse.e4.core.di.annotations.Execute;
15 16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16 17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
......
26 27
import eu.etaxonomy.taxeditor.editor.EditorUtil;
27 28
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
28 29
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
30
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
29 31
import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
30 32
import eu.etaxonomy.taxeditor.model.AbstractUtility;
31 33
import eu.etaxonomy.taxeditor.model.MessagingUtils;
......
68 70

  
69 71
    }
70 72

  
73
    @CanExecute
74
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
75
            MHandledMenuItem menuItem){
76
        boolean canExecute = false;
77
        Object selectedElement = selection.getFirstElement();
78
        canExecute =
79
                NameEditorMenuPropertyTester.isSynonym(selectedElement);
80
        menuItem.setVisible(canExecute);
81
        return canExecute;
82
    }
83

  
71 84
    @Override
72 85
    public boolean postOperation(CdmBase objectAffectedByOperation) {
73 86
        // Redraw existing editor
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/NameEditorMenuPropertyTester.java
19 19
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
20 20
import eu.etaxonomy.taxeditor.editor.EditorUtil;
21 21
import eu.etaxonomy.taxeditor.editor.Page;
22
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
22
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
23 23
import eu.etaxonomy.taxeditor.store.CdmStore;
24 24

  
25 25
/**
......
101 101

  
102 102
	}
103 103

  
104
	private boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
104
	public static boolean isAcceptedAndHasNoHomotypicSynonyms(Object selectedElement) {
105 105
		if (isAccepted(selectedElement)){
106 106
			Taxon taxon = (Taxon) selectedElement;
107 107
			return taxon.getSynonymsInGroup(taxon.getHomotypicGroup()).isEmpty();
......
109 109
		return false;
110 110
	}
111 111

  
112
	private boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement) {
112
	public static boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement) {
113 113
		if (isSynonym(selectedElement)){
114 114
			Synonym synonym = (Synonym) selectedElement;
115 115
			return synonym.getHomotypicGroup().getTypifiedNames().size()>1;
......
118 118
	}
119 119

  
120 120

  
121
	private boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement) {
121
	public static boolean isNotHomotypicSynonymOfAcceptedTaxon(Object selectedElement) {
122 122
		if (isSynonym(selectedElement)){
123 123
			Synonym synonym = (Synonym) selectedElement;
124 124
			Taxon taxon = synonym.getAcceptedTaxon();
125
			if (taxon != null && 
125
			if (taxon != null &&
126 126
					taxon.getHomotypicGroup().equals(synonym.getHomotypicGroup())){
127 127
				return false;
128 128
			}
......
135 135
	 * @param receiver
136 136
	 * @return
137 137
	 */
138
	private boolean hasEmptyNames(Object receiver) {
139
		TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
138
	public static boolean hasEmptyNames(Object receiver) {
139
		TaxonNameEditorE4 editor = (TaxonNameEditorE4) EditorUtil.getActiveEditorPage(Page.NAME);
140 140
		return editor == null ? false : editor.checkForEmptyNames();
141 141
	}
142 142

  
143
	private boolean isRelatedConcept(Object selectedElement) {
143
	public static boolean isRelatedConcept(Object selectedElement) {
144 144
		if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
145 145
			return true;
146 146
		}
147 147
		return false;
148 148
	}
149 149

  
150
	private boolean isTaxonBase(Object selectedElement) {
150
	public static boolean isTaxonBase(Object selectedElement) {
151 151
		return (selectedElement instanceof TaxonBase) ? true : false;
152 152
	}
153 153

  
154
	private boolean isMisapplication(Object selectedElement) {
154
	public static boolean isMisapplication(Object selectedElement) {
155 155
		if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
156 156
			return true;
157 157
		}
158 158
		return false;
159 159
	}
160 160

  
161
	private boolean isSynonym(Object selectedElement) {
161
	public static boolean isSynonym(Object selectedElement) {
162 162
		return (selectedElement instanceof Synonym) ? true : false;
163 163
	}
164 164

  
165
	private boolean isAccepted(Object selectedElement) {
165
	public static boolean isAccepted(Object selectedElement) {
166 166
		return (selectedElement instanceof Taxon  && ! ((Taxon) selectedElement).isMisapplication()) ? true : false;
167 167
	}
168 168

  
169
	private boolean isOrphaned(Object selectedElement) {
169
	public static boolean isOrphaned(Object selectedElement) {
170 170
	    if(selectedElement instanceof Taxon){
171 171
	        return ((Taxon) selectedElement).isOrphaned();
172 172
	    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)