Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael ADAM2016-04-25 05:00:08 -0400
committerMickael ADAM2016-05-03 11:37:09 -0400
commit5fd08f0df30ff6ead65ff15898839ab8ec9d29a3 (patch)
treea1b6fe8955128cb4d5d69aff395ee3ce88dabfd9 /plugins/infra/newchild
parentad36682d1ea37d37b4189b3dec6e989c4de3e967 (diff)
downloadorg.eclipse.papyrus-5fd08f0df30ff6ead65ff15898839ab8ec9d29a3.tar.gz
org.eclipse.papyrus-5fd08f0df30ff6ead65ff15898839ab8ec9d29a3.tar.xz
org.eclipse.papyrus-5fd08f0df30ff6ead65ff15898839ab8ec9d29a3.zip
Bug 492194 - [NewChild] it should be possible to hide NewChild
contribution https://bugs.eclipse.org/bugs/show_bug.cgi?id=492194 Conflicts: features/papyrus-main-features/org.eclipse.papyrus.infra.ui.feature/feature.xml Change-Id: I8ff8a6324a1d3cd92b774e0cca3c3d21f52591fb Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
Diffstat (limited to 'plugins/infra/newchild')
-rw-r--r--plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF4
-rw-r--r--plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/plugin.xml126
-rw-r--r--plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/CreationMenuRegistry.java630
-rw-r--r--plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/handler/DeployCreationMenuModelHandler.java137
-rw-r--r--plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/handler/UndeployCreationMenuModelHandler.java145
5 files changed, 460 insertions, 582 deletions
diff --git a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF b/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF
index 2216298957b..90bb571a913 100644
--- a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF
+++ b/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF
@@ -3,8 +3,8 @@ Export-Package: org.eclipse.papyrus.infra.newchild,
org.eclipse.papyrus.infra.newchild.elementcreationmenumodel,
org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.impl,
org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.util,
- org.eclipse.papyrus.infra.newchild.handler,
- org.eclipse.papyrus.infra.newchild.ui
+ org.eclipse.papyrus.infra.newchild.messages,
+ org.eclipse.papyrus.infra.newchild.ui;x-friends:="org.eclipse.papyrus.infra.newchild.ui"
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)",
org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)";visibility:=reexport,
org.eclipse.emf.ecore.xmi;bundle-version="[2.12.0,3.0.0)";visibility:=reexport,
diff --git a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/plugin.xml b/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/plugin.xml
index c7141b2685f..78808c787f5 100644
--- a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/plugin.xml
+++ b/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/plugin.xml
@@ -1,96 +1,30 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
- <extension-point id="org.eclipse.papyrus.infra.newchild" name="ElementCreationMenuModel" schema="schema/org.eclipse.papyrus.infra.newchild.exsd"/>
- <extension
- point="org.eclipse.ui.menus">
- <menuContribution
- allPopups="false"
- locationURI="popup:org.eclipse.ui.popup.any?after=additions">
- <command
- commandId="org.eclipse.papyrus.infra.newchild.deploy"
- style="push">
- <visibleWhen
- checkEnabled="false">
- <with
- variable="selection">
- <iterate
- ifEmpty="false"
- operator="and">
- <adapt
- type="org.eclipse.core.resources.IFile">
- <or>
- <test
- property="org.eclipse.core.resources.extension"
- value="creationmenumodel">
- </test>
- </or>
- </adapt>
- </iterate>
- </with>
- </visibleWhen>
- </command>
- <command
- commandId="org.eclipse.papyrus.infra.newchild.undeploy"
- style="push">
- <visibleWhen
- checkEnabled="false">
- <with
- variable="selection">
- <iterate
- ifEmpty="false"
- operator="and">
- <adapt
- type="org.eclipse.core.resources.IFile">
- <or>
- <test
- property="org.eclipse.core.resources.extension"
- value="creationmenumodel">
- </test>
- </or>
- </adapt>
- </iterate>
- </with>
- </visibleWhen>
- </command>
- </menuContribution>
- </extension>
- <extension
- point="org.eclipse.ui.commands">
- <command
- defaultHandler="org.eclipse.papyrus.infra.newchild.handler.DeployCreationMenuModelHandler"
- id="org.eclipse.papyrus.infra.newchild.deploy"
- name="Deploy Creation Menu Model">
- </command>
- <command
- defaultHandler="org.eclipse.papyrus.infra.newchild.handler.UndeployCreationMenuModelHandler"
- id="org.eclipse.papyrus.infra.newchild.undeploy"
- name="Undeploy Creation Menu Model">
- </command>
- </extension>
-
- <extension point="org.eclipse.emf.ecore.generated_package">
- <!-- @generated elementCreationMenuModel -->
- <package
- uri="http://www.eclipse.org/papyrus/infra/newchild/elementcreationmenumodel"
- class="org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.ElementCreationMenuModelPackage"
- genModel="resource/elementCreationMenuModel.genmodel"/>
- </extension>
-
- <extension point="org.eclipse.emf.ecore.extension_parser">
- <!-- @generated elementCreationMenuModel -->
- <parser
- type="creationmenumodel"
- class="org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.util.ElementCreationMenuModelResourceFactoryImpl"/>
- </extension>
-
- <!-- COMPATIBILITY -->
- <extension point="org.eclipse.emf.ecore.generated_package">
- <package
- uri="http://ElementCreationMenuModel"
- class="org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.ElementCreationMenuModelPackage"
- genModel="resource/elementCreationMenuModel.genmodel"/>
- </extension>
-</plugin>
-
-
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="org.eclipse.papyrus.infra.newchild" name="ElementCreationMenuModel" schema="schema/org.eclipse.papyrus.infra.newchild.exsd"/>
+
+ <extension point="org.eclipse.emf.ecore.generated_package">
+ <!-- @generated elementCreationMenuModel -->
+ <package
+ uri="http://www.eclipse.org/papyrus/infra/newchild/elementcreationmenumodel"
+ class="org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.ElementCreationMenuModelPackage"
+ genModel="resource/elementCreationMenuModel.genmodel"/>
+ </extension>
+
+ <extension point="org.eclipse.emf.ecore.extension_parser">
+ <!-- @generated elementCreationMenuModel -->
+ <parser
+ type="creationmenumodel"
+ class="org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.util.ElementCreationMenuModelResourceFactoryImpl"/>
+ </extension>
+
+ <!-- COMPATIBILITY -->
+ <extension point="org.eclipse.emf.ecore.generated_package">
+ <package
+ uri="http://ElementCreationMenuModel"
+ class="org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.ElementCreationMenuModelPackage"
+ genModel="resource/elementCreationMenuModel.genmodel"/>
+ </extension>
+</plugin>
+
+
diff --git a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/CreationMenuRegistry.java b/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/CreationMenuRegistry.java
index db994af8cf3..0a01b07449d 100644
--- a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/CreationMenuRegistry.java
+++ b/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/CreationMenuRegistry.java
@@ -1,203 +1,429 @@
-/*****************************************************************************
- * Copyright (c) 2011, 2016 CEA LIST and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *
- * CEA LIST - Initial API and implementation
- * Christian W. Damus (CEA) - bug 422257
- * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - bug 487199
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.newchild;
-
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
-import org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.ElementCreationMenuModelPackage;
-import org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.Folder;
-import org.eclipse.papyrus.infra.newchild.messages.Messages;
-import org.osgi.framework.Bundle;
-
-/**
- * This class is used to load all extension point call org.eclipse.papyrus.infra.newchild
- * It gives the set of all Folder that has to be displayed
- */
-public class CreationMenuRegistry {
-
- /** The registry. */
- protected static CreationMenuRegistry creationMenuRegistry;
-
- /** The extension id. */
- private final String MENU_CREATION_MODEL_EXTENSION_ID = "org.eclipse.papyrus.infra.newchild"; //$NON-NLS-1$
-
- /** The model id. */
- private final String MODEL_ID = "model"; //$NON-NLS-1$
-
- /** the folders collection. */
- private List<Folder> rootFolders = new ArrayList<Folder>();
-
- /** the resource set. */
- private static ResourceSetImpl resourceSet;
-
- /**
- * returns the singleton instance of this registry
- *
- * @return the singleton instance of this registry
- */
- public static synchronized CreationMenuRegistry getInstance() {
- if (null == creationMenuRegistry) {
- creationMenuRegistry = new CreationMenuRegistry();
- creationMenuRegistry.init();
- }
- return creationMenuRegistry;
- }
-
- /**
- * Constructor.
- */
- public CreationMenuRegistry() {
- }
-
- /**
- * this method load the extension points and initialize resource set.
- */
- public void init() {
- // Obtain a new resource set
- resourceSet = new ResourceSetImpl();
- resourceSet.getPackageRegistry().put(ElementCreationMenuModelPackage.eINSTANCE.getNsURI(), ElementCreationMenuModelPackage.eINSTANCE);
-
- // Reading data from plugins
- IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(MENU_CREATION_MODEL_EXTENSION_ID);
- for (int i = 0; i < configElements.length; i++) {
- rootFolders.add(initializeOneModel(configElements[i]));
- }
-
- }
-
- /**
- * @return the set of root folders
- */
- public List<Folder> getRootFolder() {
- return rootFolders;
- }
-
- /**
- * Load one model
- *
- * @param element
- * the extension point
- * @return the Folder
- */
- private Folder initializeOneModel(final IConfigurationElement element) {
- try {
- return createExtension(element, element.getAttribute(MODEL_ID));
-
- } catch (Exception e) {
- Activator.log.error(Messages.CreationMenuRegistry_Error_ModelCanBeLoaded, e);
- }
- return null;
- }
-
- /**
- * Load the {@link Folder} of the CreationMenuModel from the {@link URI}.
- *
- * @param uri
- * the uri of the model file to load
- * @throws Exception
- */
- public void loadCreationMenuModel(final URI uri) throws Exception {
- // unload before add it;
- unloadCreationMenuModel(uri);
- try {
- rootFolders.add(getCreationMenuModel(uri));
- } catch (URISyntaxException e) {
- throw new Exception(Messages.CreationMenuRegistry_Error_UnableToLoadCreationMenu + e);
- }
- }
-
- /**
- * Unload the {@link Folder} of the CreationMenuModel from the {@link URI}.
- * This is done by removing all {@link Folder} with the same Label.
- *
- * @param uri
- * the uri of the model file to unload
- * @throws Exception
- */
- public void unloadCreationMenuModel(final URI uri) throws Exception {
- try {
- Folder creationMenuModel = getCreationMenuModel(uri);
-
- // get all folders with the same Label
- Object[] array = rootFolders.stream().filter(f -> f.getLabel().equals(creationMenuModel.getLabel())).toArray();
-
- // Remove them from registry
- rootFolders.removeAll(Arrays.asList(array));
-
- } catch (URISyntaxException e) {
- throw new Exception(Messages.CreationMenuRegistry_Error_UnableToUnloadCreationMenu + e);
- }
- }
-
- /**
- * Load a resource instanceof ElementCreationMenuModel
- *
- * @param resourceSet
- * the resource set in which to load the menu model
- * @param element
- * the extension point
- * @param classAttribute
- * the name of the resource to load
- * @return the loaded Folder
- * @throws Exception
- * if the resource is not loaded
- */
- private static Folder createExtension(final IConfigurationElement element, final String classAttribute) throws Exception {
- Folder folder = null;
- try {
- Bundle extensionBundle = Platform.getBundle(element.getDeclaringExtension().getNamespaceIdentifier());
- URL url = extensionBundle.getResource(classAttribute);
- if (url != null) {
- URI uri = URI.createURI(url.toURI().toASCIIString());
- folder = getCreationMenuModel(uri);
- }
-
- } catch (URISyntaxException e) {
- throw new Exception(Messages.CreationMenuRegistry_Error_UnableToCreateExtension + e);
- }
- return folder;
- }
-
- /**
- *
- * @param uri
- * The uri of the fle of the model.
- * @return the root {@link Folder} from the model CreationMenuModel
- * @throws URISyntaxException
- */
- private static Folder getCreationMenuModel(final URI uri) throws URISyntaxException {
- Folder folder = null;
- Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
-
- // Get the resource
- Resource resource = resourceSet.getResource(uri, true);
- if (null != resource.getContents() && 0 < resource.getContents().size() && resource.getContents().get(0) instanceof Folder) {
- folder = (Folder) resource.getContents().get(0);
- }
-
- return folder;
- }
+/*****************************************************************************
+ * Copyright (c) 2011, 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *
+ * CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 422257
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - bug 487199
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.newchild;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.ElementCreationMenuModelPackage;
+import org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.Folder;
+import org.eclipse.papyrus.infra.newchild.messages.Messages;
+import org.osgi.framework.Bundle;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * This class is used to load all extension point call org.eclipse.papyrus.infra.newchild
+ * It gives the set of all Folder that has to be displayed
+ */
+public class CreationMenuRegistry {
+
+ /** The default visibility of folders */
+ private static final boolean DEFAULT_VISIBILITY = true;
+
+ /** The registry. */
+ protected static CreationMenuRegistry creationMenuRegistry;
+
+ /** The extension id. */
+ private final String MENU_CREATION_MODEL_EXTENSION_ID = "org.eclipse.papyrus.infra.newchild"; //$NON-NLS-1$
+
+ /** The model id. */
+ private final String MODEL_ID = "model"; //$NON-NLS-1$
+
+ /** The tool id. */
+ private final String ID = "id"; //$NON-NLS-1$
+
+ /** preferences which contain visible folder */
+ private Preferences preferences;
+
+ /** the folders collection. */
+ private Map<String, Folder> rootFolders = new HashMap<>();
+
+ /** Default values of folder visibilities */
+ private Map<String, Boolean> defaultValues = new HashMap<>();
+
+ /** the resource set. */
+ private static ResourceSetImpl resourceSet;
+
+ /**
+ * returns the singleton instance of this registry
+ *
+ * @return the singleton instance of this registry
+ */
+ public static synchronized CreationMenuRegistry getInstance() {
+ if (null == creationMenuRegistry) {
+ creationMenuRegistry = new CreationMenuRegistry();
+ creationMenuRegistry.init();
+ }
+ return creationMenuRegistry;
+ }
+
+ /**
+ * Constructor.
+ */
+ public CreationMenuRegistry() {
+ }
+
+ /**
+ * this method load the extension points and initialize resource set.
+ */
+ public void init() {
+ // Obtain a new resource set
+ resourceSet = new ResourceSetImpl();
+ resourceSet.getPackageRegistry().put(ElementCreationMenuModelPackage.eINSTANCE.getNsURI(), ElementCreationMenuModelPackage.eINSTANCE);
+
+ // Preference init
+ preferences = ConfigurationScope.INSTANCE.getNode(Activator.PLUGIN_ID);
+
+ // Reading data from plugins
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(MENU_CREATION_MODEL_EXTENSION_ID);
+ for (int i = 0; i < configElements.length; i++) {
+ initializeOneModel(configElements[i]);
+ }
+
+ }
+
+ /**
+ * @return the set of root folders
+ */
+ public List<Folder> getRootFolder() {
+ return new ArrayList<>(rootFolders.values());
+ }
+
+ /**
+ * Return the id of the folder if is loaded.
+ */
+ public String getFolderId(Folder folder) {
+ String id = "";//$NON-NLS-1$
+
+ Iterator<Entry<String, Folder>> entrySet = rootFolders.entrySet().iterator();
+ while (entrySet.hasNext()) {
+ Entry<String, Folder> entry = entrySet.next();
+ if (folder.equals(entry.getValue())) {
+ id = entry.getKey();
+ }
+ }
+
+ return id;
+ }
+
+ /**
+ * Load one model.
+ *
+ * @param element
+ * the extension point
+ * @return the Folder
+ */
+ private Folder initializeOneModel(final IConfigurationElement element) {
+ Folder folder = null;
+ try {
+ folder = createExtension(element, element.getAttribute(MODEL_ID));
+ } catch (Exception e) {
+ Activator.log.error(Messages.CreationMenuRegistry_Error_ModelCanBeLoaded, e);
+ }
+ return folder;
+ }
+
+ /**
+ * Load the {@link Folder} of the CreationMenuModel from the {@link URI}.
+ *
+ * @param uri
+ * the uri of the model file to load
+ * @throws Exception
+ */
+ public void loadCreationMenuModel(final URI uri) throws Exception {
+ // unload before add it;
+ unloadCreationMenuModel(uri);
+ try {
+ Folder folder = getCreationMenuModel(uri);
+ String creationMenuId = getCreationMenuId(uri);
+ rootFolders.put(creationMenuId, folder);
+ defaultValues.put(creationMenuId, folder.isVisible());
+
+ folder.setVisible(getPreferedVisibility(uri, DEFAULT_VISIBILITY));
+
+ } catch (URISyntaxException e) {
+ throw new Exception(Messages.CreationMenuRegistry_Error_UnableToLoadCreationMenu + e);
+ }
+ }
+
+ /**
+ * Unload the {@link Folder} of the CreationMenuModel from the {@link URI}.
+ * This is done by removing all {@link Folder} with the same Label.
+ *
+ * @param uri
+ * the uri of the model file to unload
+ * @throws Exception
+ */
+ public void unloadCreationMenuModel(final URI uri) throws Exception {
+ String creationMenuModelId = getCreationMenuId(uri);
+
+ rootFolders.remove(creationMenuModelId);
+ defaultValues.remove(creationMenuModelId);
+ preferences.remove(creationMenuModelId);
+ }
+
+ /**
+ * Load a resource instanceof ElementCreationMenuModel
+ *
+ * @param resourceSet
+ * the resource set in which to load the menu model
+ * @param element
+ * the extension point
+ * @param classAttribute
+ * the name of the resource to load
+ * @return the loaded Folder
+ * @throws Exception
+ * if the resource is not loaded
+ */
+ private Folder createExtension(final IConfigurationElement element, final String classAttribute) throws Exception {
+ Folder folder = null;
+ try {
+ Bundle extensionBundle = Platform.getBundle(element.getDeclaringExtension().getNamespaceIdentifier());
+ URL url = extensionBundle.getResource(classAttribute);
+ if (null != url) {
+ URI uri = URI.createURI(url.toURI().toASCIIString());
+
+ String creationMenuId = getCreationMenuId(uri);
+ folder = getCreationMenuModel(uri);
+ defaultValues.put(creationMenuId, folder.isVisible());
+
+ String visible = preferences.get(creationMenuId, "true"); //$NON-NLS-1$
+ folder.setVisible(Boolean.valueOf(visible));
+
+ rootFolders.put(creationMenuId, folder);
+ }
+
+ } catch (URISyntaxException e) {
+ throw new Exception(Messages.CreationMenuRegistry_Error_UnableToCreateExtension + e);
+ }
+ return folder;
+ }
+
+ /**
+ * Get the creation menu id from a {@link URI}.
+ */
+ public String getCreationMenuId(URI uri) {
+
+ // FileLocator.resolve(url)(url).getPath();
+
+ String bundleId = "";//$NON-NLS-1$
+ String relativePath = "";//$NON-NLS-1$
+ String fileName = uri.lastSegment();
+
+ try {
+ // Bundle id
+ URL url = new URL(uri.toString());
+ String absolutePath = FileLocator.resolve(url).getPath();
+ String replace = absolutePath.replace(url.getPath(), "");//$NON-NLS-1$
+ int lastIndexOf = replace.lastIndexOf("/");//$NON-NLS-1$
+ bundleId = replace.substring(lastIndexOf + 1, replace.length());
+ // relative path
+ relativePath = url.getPath().replace(fileName, "");//$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ Activator.log.error(e);
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(fileName);
+ stringBuilder.append(" - ");//$NON-NLS-1$
+ stringBuilder.append(bundleId);
+ stringBuilder.append(relativePath);
+
+ return stringBuilder.toString();
+ }
+
+ /**
+ * @param uri
+ * The uri of the file of the model.
+ * @return the root {@link Folder} from the model CreationMenuModel.
+ * @throws URISyntaxException
+ */
+ private Folder getCreationMenuModel(final URI uri) throws URISyntaxException {
+ Folder folder = null;
+ Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
+
+ // Get the resource
+ Resource resource = resourceSet.getResource(uri, true);
+ if (null != resource.getContents() && 0 < resource.getContents().size() && resource.getContents().get(0) instanceof Folder) {
+ folder = (Folder) resource.getContents().get(0);
+ }
+
+ return folder;
+ }
+
+ /**
+ * Set the visibility of a menu by its id.
+ *
+ * @param id
+ * The id.
+ * @param visibility
+ * The visibility to set.
+ */
+ public void setCreationMenuVisibility(final String id, final Boolean visibility) {
+ preferences.put(id, String.valueOf(visibility));
+ rootFolders.get(id).setVisible(visibility);
+ try {
+ // forces the application to save the preferences
+ preferences.flush();
+ } catch (BackingStoreException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ /**
+ * Set the creation menu visibility by its folder model.
+ *
+ * @param folder
+ * The folder.
+ * @param visibility
+ * The visibility to set.
+ */
+ public void setCreationMenuVisibility(final Folder folder, final Boolean visibility) {
+ Set<Entry<String, Folder>> entrySet = rootFolders.entrySet();
+
+ for (Entry<String, Folder> entry : entrySet) {
+ if (folder.equals(entry.getValue())) {
+ setCreationMenuVisibility(entry.getKey(), visibility);
+ }
+ }
+ }
+
+ /**
+ * Gets the visibility of a {@link Folder}.
+ *
+ * @param folder
+ * The folder.
+ * @return The current visibility of the folder.
+ */
+ public boolean getCreationMenuVisibility(final Folder folder) {
+ String visible = preferences.get(getFolderId(folder), "");//$NON-NLS-1$
+ return "" == visible ? folder.isVisible() : Boolean.valueOf(visible);//$NON-NLS-1$
+ }
+
+ /**
+ * Gets the visibility of a {@link Folder} refereed by its URI.
+ *
+ * @param folder
+ * The folder.
+ * @return The current visibility of the folder.
+ */
+ public boolean getCreationMenuVisibility(final URI uri) {
+ Folder folder = null;
+ try {
+ folder = getCreationMenuModel(uri);
+ } catch (URISyntaxException e) {
+ Activator.log.error(e);
+ }
+ String visible = preferences.get(getCreationMenuId(uri), "");//$NON-NLS-1$
+ return "" == visible ? folder.isVisible() : Boolean.valueOf(visible);//$NON-NLS-1$
+ }
+
+ /**
+ * Gets the default value of a {@link Folder}.
+ *
+ * @param folder
+ * The folder
+ * @return The default visibility of the folder.
+ */
+ public boolean getDefaultCreationMenuVisibility(final Folder folder) {
+ Boolean defaultVisibility = defaultValues.get(getFolderId(folder));
+ return null != defaultVisibility ? defaultVisibility : folder.isVisible();
+ }
+
+ /**
+ * Gets the default value of a {@link Folder} refereed by its URI.
+ *
+ * @param folder
+ * The folder
+ * @return The default visibility of the folder.
+ */
+ public boolean getDefaultCreationMenuVisibility(final URI uri) {
+ Folder folder = null;
+ try {
+ folder = getCreationMenuModel(uri);
+ } catch (URISyntaxException e) {
+ Activator.log.error(e);
+ }
+ return getDefaultCreationMenuVisibility(folder);
+ }
+
+ /**
+ * Gets the visibility of the {@link Folder} set in preferences.
+ *
+ * @param folder
+ * The folder.
+ * @param defautVisibility
+ * The default visibility if it is not set in preferences.
+ * @return
+ * The preferred visibility.
+ */
+ public boolean getPreferedVisibility(final Folder folder, final boolean defautVisibility) {
+ String visible = preferences.get(getFolderId(folder), String.valueOf(defautVisibility));
+ return Boolean.valueOf(visible);
+ }
+
+ /**
+ * Gets the visibility of the {@link Folder} refereed by its URI set in preferences.
+ *
+ * @param folder
+ * The folder.
+ * @param defautVisibility
+ * The default visibility if it is not set in preferences.
+ * @return
+ * The preferred visibility.
+ */
+ public boolean getPreferedVisibility(final URI uri, final boolean defautVisibility) {
+ String visible = preferences.get(getCreationMenuId(uri), String.valueOf(defautVisibility));
+ return Boolean.valueOf(visible);
+ }
+
+ /**
+ * Restore the default visibility value of folders.
+ */
+ public void restoreDefault() {
+ try {
+ preferences.clear();
+ } catch (BackingStoreException e) {
+ Activator.log.error(e);
+ }
+ Set<Entry<String, Folder>> entrySet = rootFolders.entrySet();
+ for (Entry<String, Folder> entry : entrySet) {
+ Folder folder = entry.getValue();
+ folder.setVisible(getDefaultCreationMenuVisibility(folder));
+ }
+ }
+
} \ No newline at end of file
diff --git a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/handler/DeployCreationMenuModelHandler.java b/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/handler/DeployCreationMenuModelHandler.java
deleted file mode 100644
index c52a652b66e..00000000000
--- a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/handler/DeployCreationMenuModelHandler.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2016 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation - bug 487199
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.newchild.handler;
-
-import java.util.Iterator;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.newchild.Activator;
-import org.eclipse.papyrus.infra.newchild.CreationMenuRegistry;
-import org.eclipse.papyrus.infra.newchild.messages.Messages;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.statushandlers.StatusManager;
-
-/**
- * Handler to deploy new creation menu model
- */
-public class DeployCreationMenuModelHandler extends AbstractHandler implements IHandler {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object execute(final ExecutionEvent event) throws ExecutionException {
- ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
- if (currentSelection instanceof IStructuredSelection && !currentSelection.isEmpty()) {
- final IStructuredSelection selection = (IStructuredSelection) currentSelection;
- final Shell activeShell = HandlerUtil.getActiveShell(event);
-
- Job job = new Job(Messages.DeployCreationMenuModelHandler_DeployMenuJobTitle) {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask(Messages.DeployCreationMenuModelHandler_DoployingMonitorTasksLabel, selection.size());
- return doExecute(selection, monitor);
- }
- };
-
- job.addJobChangeListener(new JobChangeAdapter() {
-
- @Override
- public void done(final IJobChangeEvent event) {
- activeShell.getDisplay().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- if (event.getResult().isOK()) {
- MessageDialog.openInformation(activeShell, Messages.DeployCreationMenuModelHandler_SuccesLabel, event.getResult().getMessage());
- } else if (IStatus.ERROR != event.getResult().getSeverity()) { // Errors are already logged
- StatusManager.getManager().handle(event.getResult(), StatusManager.SHOW);
- }
- }
- });
- }
- });
- job.setUser(true);
- job.schedule();
- }
- return null;
- }
-
- /**
- * do the execution of deployment on the selection
- *
- * @param selection
- * selected files
- * @param monitor
- * the monitor
- * @return the return status of the execution
- */
- protected IStatus doExecute(final IStructuredSelection selection, final IProgressMonitor monitor) {
- Iterator<?> selectionIterator = selection.iterator();
- MultiStatus result = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, Messages.DeployCreationMenuModelHandler_DeploymentSuccess, null);
- while (selectionIterator.hasNext()) {
- Object selectedElement = selectionIterator.next();
- if (selectedElement instanceof IAdaptable) {
- IFile selectedFile = ((IAdaptable) selectedElement).getAdapter(IFile.class);
- if (null == selectedFile) {
- monitor.worked(1);
- result.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.DeployCreationMenuModelHandler_ElementNotAFile + selectedElement.toString()));
- } else {
- String fileName = selectedFile.getFullPath().removeFileExtension().lastSegment();
- monitor.subTask(Messages.DeployCreationMenuModelHandler_Deploy + fileName);
-
- try {
- CreationMenuRegistry.getInstance().loadCreationMenuModel(URI.createURI(selectedFile.getLocationURI().toASCIIString()));
- monitor.worked(1);
- result.add(new Status(IStatus.OK, Activator.PLUGIN_ID, Messages.DeployCreationMenuModelHandler_Status_deployed + fileName));
- } catch (Exception e) {
- monitor.worked(1);
- result.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.DeployCreationMenuModelHandler_ErrorDeployFile + e));
- }
- }
- }
- }
-
- // The returned status
- IStatus returnedStatus = null;
-
- if (1 == result.getChildren().length) {
- returnedStatus = result.getChildren()[0];
- } else { // Merge the result and specify an appropriate message based on the result
- if (!result.isOK()) {
- returnedStatus = new MultiStatus(Activator.PLUGIN_ID, result.getCode(), Messages.DeployCreationMenuModelHandler_SomeErorsOccured, result.getException());
- ((MultiStatus) returnedStatus).merge(result);
- }
- }
- return returnedStatus;
- }
-
-}
diff --git a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/handler/UndeployCreationMenuModelHandler.java b/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/handler/UndeployCreationMenuModelHandler.java
deleted file mode 100644
index a91e7cb382a..00000000000
--- a/plugins/infra/newchild/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/handler/UndeployCreationMenuModelHandler.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation - bug 487199
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.newchild.handler;
-
-import java.util.Iterator;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.newchild.Activator;
-import org.eclipse.papyrus.infra.newchild.CreationMenuRegistry;
-import org.eclipse.papyrus.infra.newchild.messages.Messages;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.statushandlers.StatusManager;
-
-/**
- * Handler to undeploy a creation menu model
- */
-public class UndeployCreationMenuModelHandler extends AbstractHandler {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object execute(final ExecutionEvent event) throws ExecutionException {
- ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
- if (currentSelection instanceof IStructuredSelection && !currentSelection.isEmpty()) {
- final IStructuredSelection selection = (IStructuredSelection) currentSelection;
- final Shell activeShell = HandlerUtil.getActiveShell(event);
-
- Job job = new Job(Messages.UndeployCreationMenuModelHandler_UndeployMenuJobTitle) {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask(Messages.UndeployCreationMenuModelHandler_UndeploySectionTasksTitle, selection.size());
- return doExecute(selection, monitor, activeShell);
- }
- };
- job.addJobChangeListener(new JobChangeAdapter() {
-
- @Override
- public void done(final IJobChangeEvent event) {
- activeShell.getDisplay().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- if (event.getResult().isOK()) {
- MessageDialog.openInformation(activeShell, Messages.UndeployCreationMenuModelHandler_SuccessLabel, event.getResult().getMessage());
- } else if (IStatus.ERROR != event.getResult().getSeverity()) { // Errors are already logged
- StatusManager.getManager().handle(event.getResult(), StatusManager.SHOW);
- }
- }
- });
- }
- });
- job.setUser(true);
- job.schedule();
- }
- return null;
- }
-
- /**
- * do the execution of undeployment on the selection
- *
- * @param selection
- * selected files
- * @param monitor
- * the monitor
- * @return the return status of the execution
- */
- protected IStatus doExecute(final IStructuredSelection selection, final IProgressMonitor monitor, Shell shell) {
- Iterator<?> selectionIterator = selection.iterator();
- MultiStatus result = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, Messages.UndeployCreationMenuModelHandler_Success_UndeployMenu, null);
- while (selectionIterator.hasNext()) {
- Object selectedElement = selectionIterator.next();
- if (selectedElement instanceof IAdaptable) {
- IFile selectedFile = ((IAdaptable) selectedElement).getAdapter(IFile.class);
- if (null == selectedFile) {
- monitor.worked(1);
- result.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.UndeployCreationMenuModelHandler_Error_NotAFile + selectedElement.toString()));
- } else {
- String fileName = selectedFile.getFullPath().removeFileExtension().lastSegment();
- monitor.subTask(Messages.UndeployCreationMenuModelHandler_Undeploy + fileName);
- URI emfURI = null;
- if (null != selectedFile.getFullPath()) {
- emfURI = URI.createPlatformResourceURI(selectedFile.getFullPath().toString(), true);
- } else if (selectedFile.getRawLocation() != null) {
- emfURI = URI.createFileURI(selectedFile.getRawLocation().toString());
- }
- if (null == emfURI) {
- monitor.worked(1);
- result.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.UndeployCreationMenuModelHandler_Error_NotAValidFile));
- continue;
- }
- monitor.subTask(Messages.UndeployCreationMenuModelHandler_SubTaskTitle_ResetRegistry);
-
- try {
- CreationMenuRegistry.getInstance().unloadCreationMenuModel(emfURI);
- monitor.worked(1);
- result.add(new Status(IStatus.OK, Activator.PLUGIN_ID, Messages.UndeployCreationMenuModelHandler_SuccessfullyUndeployed + fileName));
- } catch (Exception e) {
- result.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.UndeployCreationMenuModelHandler_Error_UndeployFile + e));
- }
- }
- }
- }
-
- // The returned status
- IStatus returnedStatus = null;
-
- if (1 == result.getChildren().length) {
- returnedStatus = result.getChildren()[0];
- } else { // Merge the result and specify an appropriate message based on the result
- if (!result.isOK()) {
- returnedStatus = new MultiStatus(Activator.PLUGIN_ID, result.getCode(), Messages.UndeployCreationMenuModelHandler_Erro_SomeErrorsOccurred, result.getException());
- ((MultiStatus) returnedStatus).merge(result);
- }
- }
- return returnedStatus;
- }
-}

Back to the top