import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
import eu.etaxonomy.taxeditor.event.EventUtility;
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.IContextListener;
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
layout.type = SWT.VERTICAL;
parent.setLayout(layout);
- viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
+ viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
viewer.getControl().setLayoutData(LayoutConstants.FILL());
viewer.setContentProvider(new TermContentProvider());
viewer.setLabelProvider(new TermLabelProvider());
viewer.addDropSupport(dndOperations, transfers, dropListener);
//propagate selection
- selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
+ selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
viewer.addSelectionChangedListener(selectionChangedListener);
//create context menu
import java.util.List;
import java.util.Set;
-import javax.inject.Named;
-
import org.eclipse.e4.ui.di.AboutToShow;
import org.eclipse.e4.ui.model.application.commands.MCommand;
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
-import org.eclipse.e4.ui.services.IServiceConstants;
import eu.etaxonomy.cdm.model.common.TermType;
import eu.etaxonomy.taxeditor.l10n.Messages;
/** {@inheritDoc} */
@AboutToShow
- public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) Object selection) {
+ public void aboutToShow(List<MMenuElement> items) {
if(CdmStore.isActive()){
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
-import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.IStructuredSelection;
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
-import eu.etaxonomy.cdm.model.common.Marker;
-import eu.etaxonomy.cdm.model.common.MarkerType;
import eu.etaxonomy.cdm.model.common.TermBase;
import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
- @Optional@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase, MHandledMenuItem menuItem,
+ @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MHandledMenuItem menuItem,
UISynchronize sync) {
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
AbstractPostOperation operation =
new CreateDefinedTermOperation(label,
undoContext,
- termBase,
+ (TermBase) selection.getFirstElement(),
termEditor.getDefinedTermEditorInput(),
termEditor, addTermAsKindOf);
AbstractUtility.executeOperation(operation, sync);
}
@CanExecute
- public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase){
- if (termBase == null){
- return true;
- }
-
+ public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
+ MHandledMenuItem menuItem){
+ boolean canExecute = false;
+ Object firstElement = selection.getFirstElement();
+ canExecute = selection.size()==1
+ &&
+ (firstElement instanceof DefinedTermBase
+ || firstElement instanceof TermVocabulary);
TermVocabulary vocabulary = null;
- if(termBase instanceof DefinedTermBase){
- vocabulary = ((DefinedTermBase) termBase).getVocabulary();
- }else if(termBase instanceof TermVocabulary){
- vocabulary = (TermVocabulary) termBase;
- }
-
- if(vocabulary == null){
- return true;
+ if(firstElement instanceof DefinedTermBase){
+ vocabulary = ((DefinedTermBase) firstElement).getVocabulary();
+ }else if(firstElement instanceof TermVocabulary){
+ vocabulary = (TermVocabulary) firstElement;
}
-
- for(Marker vocabularyMarker : vocabulary.getMarkers()){
- if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
- return vocabularyMarker.getValue();
- }
- }
-
- return true;
+ canExecute &= vocabulary!=null;
+ menuItem.setVisible(canExecute);
+ return canExecute;
}
}
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
-import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
-import eu.etaxonomy.cdm.model.common.Marker;
-import eu.etaxonomy.cdm.model.common.MarkerType;
import eu.etaxonomy.cdm.model.common.TermBase;
import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
- @Optional@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase, MMenuItem menuItem,
+ @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MMenuItem menuItem,
UISynchronize sync) {
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
AbstractPostOperation operation =
new DeleteTermBaseOperation(label,
undoContext,
- termBase,
+ (TermBase) selection.getFirstElement(),
termEditor.getDefinedTermEditorInput(),
termEditor);
AbstractUtility.executeOperation(operation, sync);
}
@CanExecute
- public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase){
- if (termBase == null){
- return true;
- }
-
+ public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
+ MHandledMenuItem menuItem){
+ boolean canExecute = false;
+ Object firstElement = selection.getFirstElement();
+ canExecute = selection.size()==1
+ &&
+ (firstElement instanceof DefinedTermBase
+ || firstElement instanceof TermVocabulary);
TermVocabulary vocabulary = null;
-
- if(termBase instanceof DefinedTermBase){
- vocabulary = ((DefinedTermBase) termBase).getVocabulary();
- }else if(termBase instanceof TermVocabulary){
- vocabulary = (TermVocabulary) termBase;
- }
-
- if(vocabulary == null){
- return true;
+ if(firstElement instanceof DefinedTermBase){
+ vocabulary = ((DefinedTermBase) firstElement).getVocabulary();
+ }else if(firstElement instanceof TermVocabulary){
+ vocabulary = (TermVocabulary) firstElement;
}
-
- for(Marker vocabularyMarker : vocabulary.getMarkers()){
- if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
- return vocabularyMarker.getValue();
- }
- }
-
- return true;
+ canExecute &= vocabulary!=null;
+ menuItem.setVisible(canExecute);
+ return canExecute;
}
}