--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.utils.ui.jface;\r
+\r
+import org.eclipse.jface.action.IContributionItem;\r
+import org.eclipse.jface.action.IMenuManager;\r
+import org.eclipse.jface.action.MenuManager;\r
+import org.eclipse.jface.action.SubContributionManager;\r
+\r
+/**\r
+ * \r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public class MenuTools {\r
+\r
+ /**\r
+ * Searches for existing menu, or creates a new menu.\r
+ * @param uniqueID unique id of the contributor (editor's ID + input)\r
+ * @param name name of the menu\r
+ * @param manager\r
+ * @return the menu (created or existing)\r
+ */\r
+ public static IMenuManager getOrCreate(String uniqueID,String name, IMenuManager manager) {\r
+ IContributionItem menu = manager.find(uniqueID+name);\r
+ if (menu == null) {\r
+ MenuManager m = new MenuManager(name,uniqueID+name);\r
+ manager.add(m);\r
+ m.setVisible(true);\r
+ return m;\r
+ }\r
+ if (menu instanceof SubContributionManager) {\r
+ // without this recreated menus would show only the first item.\r
+ SubContributionManager emenu = (SubContributionManager)menu;\r
+ return (IMenuManager)emenu.getParent();\r
+ }\r
+ return (IMenuManager)menu;\r
+ }\r
+}\r