From: Patrick Plitzner Date: Tue, 20 Oct 2015 14:41:30 +0000 (+0200) Subject: Disable term menu when disconnected (#4901) X-Git-Tag: 3.12.0^2~83^2 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/75dd69275ea327a31c55db6524c9e83cab9d8b8c Disable term menu when disconnected (#4901) --- diff --git a/eu.etaxonomy.taxeditor.store/plugin.xml b/eu.etaxonomy.taxeditor.store/plugin.xml index a09f26a7c..21885b855 100644 --- a/eu.etaxonomy.taxeditor.store/plugin.xml +++ b/eu.etaxonomy.taxeditor.store/plugin.xml @@ -415,9 +415,19 @@ - + + + + + + + diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenuFactory.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenu.java similarity index 57% rename from eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenuFactory.java rename to eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenu.java index 9bd7ccbda..4f3e7770f 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenuFactory.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenu.java @@ -1,9 +1,9 @@ // $Id$ /** * Copyright (C) 2009 EDIT -* European Distributed Institute of Taxonomy +* European Distributed Institute of Taxonomy * http://www.e-taxonomy.eu -* +* * The contents of this file are subject to the Mozilla Public License Version 1.1 * See LICENSE.TXT at the top of this package for the full license terms. */ @@ -11,6 +11,7 @@ package eu.etaxonomy.taxeditor.editor.definedterm; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.EnumSet; @@ -23,89 +24,89 @@ import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.swt.SWT; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.CompoundContributionItem; import org.eclipse.ui.menus.CommandContributionItem; import org.eclipse.ui.menus.CommandContributionItemParameter; -import org.eclipse.ui.menus.ExtensionContributionFactory; -import org.eclipse.ui.menus.IContributionRoot; -import org.eclipse.ui.services.IServiceLocator; import eu.etaxonomy.cdm.model.common.TermType; /** - * Menu factory used in the store plugin xml to dynamically generate menu (sub-menu) contribution items + * Menu used in the store plugin xml to dynamically generate menu (sub-menu) contribution items * for term types which when clicked open the defined term editor for the chosen term type - * - * @author c.mathew - * @date 18 Jul 2013 + * + * @author pplitzner + * @date 21 Jul 2015 * */ -public class DefinedTermMenuFactory extends ExtensionContributionFactory { - - @Override - public void createContributionItems(IServiceLocator serviceLocator, - IContributionRoot additions) { - - MenuManager dtMenuManager = - new MenuManager("Term Editor","eu.etaxonomy.taxeditor.store.definedTermEditorMenu"); - - dtMenuManager.setVisible(true); - - additions.addContributionItem(dtMenuManager, null); - List ttList = new ArrayList(EnumSet.allOf(TermType.class)); - Collections.sort(ttList,new SortByTermTypeMessage()); - for (TermType tt : ttList) - { - // if term type has a parent, do not add it - // it will be added in the recursive call - if(tt.getKindOf() == null) { - IContributionItem ici = addChildTermsToMenuManager(tt, serviceLocator); - if(ici != null) { - dtMenuManager.add(ici); - } - } - } +public class DefinedTermMenu extends CompoundContributionItem { + + + @Override + protected IContributionItem[] getContributionItems() { + Collection items = new ArrayList(); + MenuManager dtMenuManager = + new MenuManager("Term Editor","eu.etaxonomy.taxeditor.store.definedTermEditorMenu"); + + dtMenuManager.setVisible(true); + + items.add(dtMenuManager); + List ttList = new ArrayList(EnumSet.allOf(TermType.class)); + Collections.sort(ttList,new SortByTermTypeMessage()); + for (TermType tt : ttList) + { + // if term type has a parent, do not add it + // it will be added in the recursive call + if(tt.getKindOf() == null) { + IContributionItem ici = addChildTermsToMenuManager(tt); + if(ici != null) { + dtMenuManager.add(ici); + } + } + } + return items.toArray(new IContributionItem[]{}); } - - private IContributionItem addChildTermsToMenuManager(TermType termType, IServiceLocator serviceLocator) { - + + private IContributionItem addChildTermsToMenuManager(TermType termType) { + //FIXME : need a better way to find out if a term type can be editable (ticket 3853) if(termType.getEmptyDefinedTermBase() != null) { Set children = termType.getGeneralizationOf(); // term type has no children, so create menu item - if(children.isEmpty()) { - return createMenuItem(termType, serviceLocator); + if(children.isEmpty()) { + return createMenuItem(termType); } - // term type has children, so create sub menu - MenuManager dtMenuManager = - new MenuManager(termType.getMessage(),"eu.etaxonomy.taxeditor.store." + termType.getKey() + "Menu"); + // term type has children, so create sub menu + MenuManager dtMenuManager = + new MenuManager(termType.getMessage(),"eu.etaxonomy.taxeditor.store." + termType.getKey() + "Menu"); dtMenuManager.setVisible(true); - dtMenuManager.add(createDefaultMenuItem(termType, serviceLocator)); + dtMenuManager.add(createDefaultMenuItem(termType)); Separator sep = new Separator(); dtMenuManager.add(sep); // add child items to the sub menu - for(TermType tt : children) { - IContributionItem item = addChildTermsToMenuManager(tt,serviceLocator); - if(item != null) { + for(TermType tt : children) { + IContributionItem item = addChildTermsToMenuManager(tt); + if(item != null) { dtMenuManager.add(item); - } - } + } + } return dtMenuManager; } else { return null; } - + } - - private CommandContributionItem createMenuItem(TermType termType, IServiceLocator serviceLocator) { - + + private CommandContributionItem createMenuItem(TermType termType) { + Map params = new HashMap(); params.put("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid", - termType.getUuid().toString()); - + termType.getUuid().toString()); + CommandContributionItemParameter p = new CommandContributionItemParameter( - serviceLocator, + PlatformUI.getWorkbench(), "", "eu.etaxonomy.taxeditor.store.openDefinedTermEditor", params, @@ -114,24 +115,24 @@ public class DefinedTermMenuFactory extends ExtensionContributionFactory { null, termType.getMessage(), "", - "", + "", SWT.PUSH, "", true); - - CommandContributionItem item = new CommandContributionItem(p); + + CommandContributionItem item = new CommandContributionItem(p); return item; - + } - - private CommandContributionItem createDefaultMenuItem(TermType termType, IServiceLocator serviceLocator) { - + + private CommandContributionItem createDefaultMenuItem(TermType termType) { + Map params = new HashMap(); params.put("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid", - termType.getUuid().toString()); - + termType.getUuid().toString()); + CommandContributionItemParameter p = new CommandContributionItemParameter( - serviceLocator, + PlatformUI.getWorkbench(), "", "eu.etaxonomy.taxeditor.store.openDefinedTermEditor", params, @@ -140,23 +141,24 @@ public class DefinedTermMenuFactory extends ExtensionContributionFactory { null, "Other " + termType.getMessage() + "s", "", - "", + "", SWT.PUSH, "", true); - - - - CommandContributionItem item = new CommandContributionItem(p); + + + + CommandContributionItem item = new CommandContributionItem(p); return item; - + } - + private class SortByTermTypeMessage implements Comparator { - public int compare(TermType t1, TermType t2) { + @Override + public int compare(TermType t1, TermType t2) { return t1.getMessage().compareTo(t2.getMessage()); } } - + }