Revision deb3ab1f
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermEditorE4.java | ||
---|---|---|
44 | 44 |
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput; |
45 | 45 |
import eu.etaxonomy.taxeditor.event.EventUtility; |
46 | 46 |
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants; |
47 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
48 | 47 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
49 | 48 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
50 | 49 |
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; |
... | ... | |
105 | 104 |
layout.type = SWT.VERTICAL; |
106 | 105 |
|
107 | 106 |
parent.setLayout(layout); |
108 |
viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION)); |
|
107 |
viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
|
|
109 | 108 |
viewer.getControl().setLayoutData(LayoutConstants.FILL()); |
110 | 109 |
viewer.setContentProvider(new TermContentProvider()); |
111 | 110 |
viewer.setLabelProvider(new TermLabelProvider()); |
... | ... | |
118 | 117 |
viewer.addDropSupport(dndOperations, transfers, dropListener); |
119 | 118 |
|
120 | 119 |
//propagate selection |
121 |
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
|
120 |
selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
|
|
122 | 121 |
viewer.addSelectionChangedListener(selectionChangedListener); |
123 | 122 |
|
124 | 123 |
//create context menu |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermMenuE4.java | ||
---|---|---|
16 | 16 |
import java.util.List; |
17 | 17 |
import java.util.Set; |
18 | 18 |
|
19 |
import javax.inject.Named; |
|
20 |
|
|
21 | 19 |
import org.eclipse.e4.ui.di.AboutToShow; |
22 | 20 |
import org.eclipse.e4.ui.model.application.commands.MCommand; |
23 | 21 |
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory; |
... | ... | |
25 | 23 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenu; |
26 | 24 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; |
27 | 25 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory; |
28 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
29 | 26 |
|
30 | 27 |
import eu.etaxonomy.cdm.model.common.TermType; |
31 | 28 |
import eu.etaxonomy.taxeditor.l10n.Messages; |
... | ... | |
47 | 44 |
|
48 | 45 |
/** {@inheritDoc} */ |
49 | 46 |
@AboutToShow |
50 |
public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) Object selection) {
|
|
47 |
public void aboutToShow(List<MMenuElement> items) { |
|
51 | 48 |
|
52 | 49 |
if(CdmStore.isActive()){ |
53 | 50 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/CreateDefinedTermHandlerE4.java | ||
---|---|---|
13 | 13 |
import org.eclipse.core.commands.operations.IUndoContext; |
14 | 14 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
15 | 15 |
import org.eclipse.e4.core.di.annotations.Execute; |
16 |
import org.eclipse.e4.core.di.annotations.Optional; |
|
17 | 16 |
import org.eclipse.e4.ui.di.UISynchronize; |
18 | 17 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
19 | 18 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
20 | 19 |
import org.eclipse.e4.ui.services.IServiceConstants; |
20 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
21 | 21 |
|
22 | 22 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
23 |
import eu.etaxonomy.cdm.model.common.Marker; |
|
24 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
25 | 23 |
import eu.etaxonomy.cdm.model.common.TermBase; |
26 | 24 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
27 | 25 |
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4; |
... | ... | |
40 | 38 |
|
41 | 39 |
@Execute |
42 | 40 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
43 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase, MHandledMenuItem menuItem,
|
|
41 |
@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MHandledMenuItem menuItem,
|
|
44 | 42 |
UISynchronize sync) { |
45 | 43 |
|
46 | 44 |
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject(); |
... | ... | |
54 | 52 |
AbstractPostOperation operation = |
55 | 53 |
new CreateDefinedTermOperation(label, |
56 | 54 |
undoContext, |
57 |
termBase,
|
|
55 |
(TermBase) selection.getFirstElement(),
|
|
58 | 56 |
termEditor.getDefinedTermEditorInput(), |
59 | 57 |
termEditor, addTermAsKindOf); |
60 | 58 |
AbstractUtility.executeOperation(operation, sync); |
... | ... | |
62 | 60 |
} |
63 | 61 |
|
64 | 62 |
@CanExecute |
65 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase){ |
|
66 |
if (termBase == null){ |
|
67 |
return true; |
|
68 |
} |
|
69 |
|
|
63 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, |
|
64 |
MHandledMenuItem menuItem){ |
|
65 |
boolean canExecute = false; |
|
66 |
Object firstElement = selection.getFirstElement(); |
|
67 |
canExecute = selection.size()==1 |
|
68 |
&& |
|
69 |
(firstElement instanceof DefinedTermBase |
|
70 |
|| firstElement instanceof TermVocabulary); |
|
70 | 71 |
TermVocabulary vocabulary = null; |
71 | 72 |
|
72 |
if(termBase instanceof DefinedTermBase){ |
|
73 |
vocabulary = ((DefinedTermBase) termBase).getVocabulary(); |
|
74 |
}else if(termBase instanceof TermVocabulary){ |
|
75 |
vocabulary = (TermVocabulary) termBase; |
|
76 |
} |
|
77 |
|
|
78 |
if(vocabulary == null){ |
|
79 |
return true; |
|
73 |
if(firstElement instanceof DefinedTermBase){ |
|
74 |
vocabulary = ((DefinedTermBase) firstElement).getVocabulary(); |
|
75 |
}else if(firstElement instanceof TermVocabulary){ |
|
76 |
vocabulary = (TermVocabulary) firstElement; |
|
80 | 77 |
} |
81 |
|
|
82 |
for(Marker vocabularyMarker : vocabulary.getMarkers()){ |
|
83 |
if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){ |
|
84 |
return vocabularyMarker.getValue(); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
return true; |
|
78 |
canExecute &= vocabulary!=null; |
|
79 |
menuItem.setVisible(canExecute); |
|
80 |
return canExecute; |
|
89 | 81 |
} |
90 | 82 |
|
91 | 83 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/DeleteTermBaseHandlerE4.java | ||
---|---|---|
13 | 13 |
import org.eclipse.core.commands.operations.IUndoContext; |
14 | 14 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
15 | 15 |
import org.eclipse.e4.core.di.annotations.Execute; |
16 |
import org.eclipse.e4.core.di.annotations.Optional; |
|
17 | 16 |
import org.eclipse.e4.ui.di.UISynchronize; |
18 | 17 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
18 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
19 | 19 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
20 | 20 |
import org.eclipse.e4.ui.services.IServiceConstants; |
21 | 21 |
import org.eclipse.jface.dialogs.MessageDialog; |
22 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
22 | 23 |
|
23 | 24 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
24 |
import eu.etaxonomy.cdm.model.common.Marker; |
|
25 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
26 | 25 |
import eu.etaxonomy.cdm.model.common.TermBase; |
27 | 26 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
28 | 27 |
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4; |
... | ... | |
41 | 40 |
|
42 | 41 |
@Execute |
43 | 42 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
44 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase, MMenuItem menuItem,
|
|
43 |
@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MMenuItem menuItem,
|
|
45 | 44 |
UISynchronize sync) { |
46 | 45 |
|
47 | 46 |
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject(); |
... | ... | |
60 | 59 |
AbstractPostOperation operation = |
61 | 60 |
new DeleteTermBaseOperation(label, |
62 | 61 |
undoContext, |
63 |
termBase,
|
|
62 |
(TermBase) selection.getFirstElement(),
|
|
64 | 63 |
termEditor.getDefinedTermEditorInput(), |
65 | 64 |
termEditor); |
66 | 65 |
AbstractUtility.executeOperation(operation, sync); |
67 | 66 |
} |
68 | 67 |
|
69 | 68 |
@CanExecute |
70 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase){ |
|
71 |
if (termBase == null){ |
|
72 |
return true; |
|
73 |
} |
|
74 |
|
|
69 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, |
|
70 |
MHandledMenuItem menuItem){ |
|
71 |
boolean canExecute = false; |
|
72 |
Object firstElement = selection.getFirstElement(); |
|
73 |
canExecute = selection.size()==1 |
|
74 |
&& |
|
75 |
(firstElement instanceof DefinedTermBase |
|
76 |
|| firstElement instanceof TermVocabulary); |
|
75 | 77 |
TermVocabulary vocabulary = null; |
76 |
|
|
77 |
if(termBase instanceof DefinedTermBase){ |
|
78 |
vocabulary = ((DefinedTermBase) termBase).getVocabulary(); |
|
79 |
}else if(termBase instanceof TermVocabulary){ |
|
80 |
vocabulary = (TermVocabulary) termBase; |
|
81 |
} |
|
82 |
|
|
83 |
if(vocabulary == null){ |
|
84 |
return true; |
|
78 |
if(firstElement instanceof DefinedTermBase){ |
|
79 |
vocabulary = ((DefinedTermBase) firstElement).getVocabulary(); |
|
80 |
}else if(firstElement instanceof TermVocabulary){ |
|
81 |
vocabulary = (TermVocabulary) firstElement; |
|
85 | 82 |
} |
86 |
|
|
87 |
for(Marker vocabularyMarker : vocabulary.getMarkers()){ |
|
88 |
if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){ |
|
89 |
return vocabularyMarker.getValue(); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
return true; |
|
83 |
canExecute &= vocabulary!=null; |
|
84 |
menuItem.setVisible(canExecute); |
|
85 |
return canExecute; |
|
94 | 86 |
} |
95 | 87 |
} |
Also available in: Unified diff
ref #7010 Adapt term editor handlers for multiple selection