diff --git a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/META-INF/MANIFEST.MF b/common/plugins/org.polarsys.capella.common.platform.sirius.customization/META-INF/MANIFEST.MF index 04c9da4eac..011e4825a4 100644 --- a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/META-INF/MANIFEST.MF +++ b/common/plugins/org.polarsys.capella.common.platform.sirius.customization/META-INF/MANIFEST.MF @@ -14,10 +14,10 @@ Require-Bundle: org.eclipse.ui, org.eclipse.emf.common.ui, org.eclipse.sirius.common, org.eclipse.sirius.diagram.ui, - org.polarsys.capella.shared.id.handler + org.polarsys.capella.shared.id.handler, + org.eclipse.sirius.common.ui Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Export-Package: org.polarsys.capella.common.platform.sirius.customisation, - org.polarsys.capella.common.platform.sirius.customisation.resourcelocator, org.polarsys.capella.common.platform.sirius.customisation.uicallback Bundle-Localization: plugin diff --git a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/plugin.properties b/common/plugins/org.polarsys.capella.common.platform.sirius.customization/plugin.properties index be35ebf30d..2b92933653 100644 --- a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/plugin.properties +++ b/common/plugins/org.polarsys.capella.common.platform.sirius.customization/plugin.properties @@ -1,16 +1,13 @@ -# ==================================================================== -# Copyright (c) 2006, 2015 THALES GLOBAL SERVICES. -# 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: -# Thales - initial API and implementation -# ==================================================================== - -pluginName = Sirius Customization -providerName = Eclipse.org - -_Pref_ReloadOnLastEditorClose = false -_Pref_SaveWhenNoEditor = false +# ==================================================================== +# Copyright (c) 2006, 2018 THALES GLOBAL SERVICES. +# 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: +# Thales - initial API and implementation +# ==================================================================== + +pluginName = Sirius Customization +providerName = Eclipse.org diff --git a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/plugin.xml b/common/plugins/org.polarsys.capella.common.platform.sirius.customization/plugin.xml index 91231b1bea..6eccb6bd90 100644 --- a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/plugin.xml +++ b/common/plugins/org.polarsys.capella.common.platform.sirius.customization/plugin.xml @@ -12,11 +12,6 @@ Thales - initial API and implementation --> - - - - strings = new HashMap(); - - /** - * A cache of the untranslated strings. - */ - protected Map untranslatedStrings = new HashMap(); - - /** - * A cache of the image descriptions. - */ - protected Map images = new HashMap(); - - /** - * Whether to translate strings by default. - */ - protected boolean shouldTranslate = true; - - /** - * Creates an instance. - */ - public DelegatingResourceLocator() { - super(); - } - - /** - * Returns the primary resource locator. - * - * @return the primary resource locator. - */ - protected abstract ResourceLocator getPrimaryResourceLocator(); - - /** - * Returns the delegate resource locators. - * - * @return the delegate resource locators. - */ - protected abstract ResourceLocator[] getDelegateResourceLocators(); - - private static final URI DOT = URI.createURI("."); - - /* - * Javadoc copied from interface. - */ - public URL getBaseURL() { - if (baseURL == null) { - if (getPrimaryResourceLocator() == null) { - try { - // Determine the base URL by looking for the - // plugin.properties file in the standard way. - // - Class theClass = getClass(); - URL pluginPropertiesURL = theClass.getResource("plugin.properties"); - if (pluginPropertiesURL == null) { - // If that fails, determine the URL for the class - // itself. - // The URL will be of one of the following forms, - // so there are a few good places to consider looking - // for the plugin.properties. - // - // For a plugin.xml with runtime="common.jar": - // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/common.jar!/org/eclipse/common/CommonPlugin.class - // - // For a plugin.xml with runtime="runtime/common.jar": - // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/runtime/common.jar!/org/eclipse/common/CommonPlugin.class - // - // For a plugin.xml with runtime="." where the plugin is - // jarred: - // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common.jar!/org/eclipse/common/CommonPlugin.class - // - // For a plugin.xml with runtime="." where the plugin is - // not jarred. - // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/org/eclipse/emf/common/CommonPlugin.class - // - // Running in PDE with bin on classpath: - // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/bin/org/eclipse/emf/common/CommonPlugin.class - // - String className = theClass.getName(); - int index = className.lastIndexOf("."); - URL classURL = theClass.getResource((index == -1 ? className : className.substring(index + 1)) + ".class"); - URI uri = URI.createURI(classURL.toString()); - - // Trim off the segments corresponding to the package - // nesting. - // - int count = 1; - for (int i = 0; (i = className.indexOf('.', i)) != -1; ++i) { - ++count; - } - uri = uri.trimSegments(count); - - // For an archive URI, check for the plugin.properties - // in the archive. - // - if (URI.isArchiveScheme(uri.scheme())) { - try { - // If we can open an input stream, then the - // plugin.properties is there, and we have a - // good base URL. - // - InputStream inputStream = new URL(uri.appendSegment("plugin.properties").toString()).openStream(); - inputStream.close(); - baseURL = new URL(uri.toString()); - } catch (IOException exception) { - // If the plugin.properties isn't within the - // root of the archive, - // create a new URI for the folder location of - // the archive, - // so we can look in the folder that contains - // it. - // - uri = URI.createURI(uri.authority()).trimSegments(1); - } - } - - // If we didn't find the plugin.properties in the usual - // place nor in the archive... - // - if (baseURL == null) { - // Trim off the "bin" or "runtime" segment. - // - String lastSegment = uri.lastSegment(); - if ("bin".equals(lastSegment) || "runtime".equals(lastSegment)) { - uri = uri.trimSegments(1); - } - uri = uri.appendSegment("plugin.properties"); - try { - // If we can open an input stream, then the - // plugin.properties is in the folder, and we - // have a good base URL. - // - InputStream inputStream = new URL(uri.toString()).openStream(); - inputStream.close(); - baseURL = new URL(DOT.resolve(uri).toString()); - } catch (IOException exception) { - // Continue with the established base URL. - } - } - - // If we still don't have a good base URL, complain - // about it. - // - if (baseURL == null) { - String resourceName = index == -1 ? "plugin.properties" : className.substring(0, index + 1).replace('.', '/') + "plugin.properties"; - throw new MissingResourceException("Missing properties: " + resourceName, theClass.getName(), "plugin.properties"); - } - } else { - baseURL = new URL(DOT.resolve(URI.createURI(pluginPropertiesURL.toString())).toString()); - } - } catch (IOException exception) { - throw new WrappedException(exception); - } - } else { - baseURL = getPrimaryResourceLocator().getBaseURL(); - } - } - - return baseURL; - } - - /* - * Javadoc copied from interface. - */ - public Object getImage(String key) { - Object result = images.get(key); - if (result == null) { - ResourceLocator pluginResourceLocator = getPrimaryResourceLocator(); - if (pluginResourceLocator == null) { - try { - result = doGetImage(key); - } catch (MalformedURLException exception) { - throw new WrappedException(exception); - } catch (IOException exception) { - result = delegatedGetImage(key); - } - } else { - try { - result = pluginResourceLocator.getImage(key); - } catch (MissingResourceException exception) { - result = delegatedGetImage(key); - } - } - - images.put(key, result); - } - - return result; - } - - /** - * Does the work of fetching the image associated with the key. It ensures - * that the image exists. - * - * @param key - * the key of the image to fetch. - * @exception IOException - * if an image doesn't exist. - * @return the description of the image associated with the key. - */ - protected Object doGetImage(String key) throws IOException { - URL url = new URL(getBaseURL() + "icons/" + key + extensionFor(key)); - InputStream inputStream = url.openStream(); - inputStream.close(); - return url; - } - - /** - * Computes the file extension to be used with the key to specify an image - * resource. - * - * @param key - * the key for the imagine. - * @return the file extension to be used with the key to specify an image - * resource. - */ - protected static String extensionFor(String key) { - String result = ".gif"; - int index = key.lastIndexOf('.'); - if (index != -1) { - String extension = key.substring(index + 1); - if ("png".equalsIgnoreCase(extension) || "gif".equalsIgnoreCase(extension) || "bmp".equalsIgnoreCase(extension) || "ico".equalsIgnoreCase(extension) || "jpg".equalsIgnoreCase(extension) - || "jpeg".equalsIgnoreCase(extension) || "tif".equalsIgnoreCase(extension) || "tiff".equalsIgnoreCase(extension)) { - result = ""; - } - } - return result; - } - - /** - * Does the work of fetching the image associated with the key, when the - * image resource is not available locally. - * - * @param key - * the key of the image to fetch. - * @exception MissingResourceException - * if the image resource doesn't exist anywhere. - * @see #getDelegateResourceLocators() - */ - protected Object delegatedGetImage(String key) throws MissingResourceException { - ResourceLocator[] delegateResourceLocators = getDelegateResourceLocators(); - for (int i = 0; i < delegateResourceLocators.length; ++i) { - try { - return delegateResourceLocators[i].getImage(key); - } catch (MissingResourceException exception) { - // Ignore the exception since we will throw one when all else - // fails. - } - } - - throw new MissingResourceException(CommonPlugin.INSTANCE.getString("_UI_ImageResourceNotFound_exception", new Object[] { key }), getClass().getName(), key); - } - - /** - * Indicates whether strings should be translated by default. - * - * @return true if strings should be translated by default; - * false otherwise. - */ - public boolean shouldTranslate() { - return shouldTranslate; - } - - /** - * Sets whether strings should be translated by default. - * - * @param shouldTranslate - * whether strings should be translated by default. - */ - public void setShouldTranslate(boolean shouldTranslate) { - this.shouldTranslate = shouldTranslate; - } - - /* - * Javadoc copied from interface. - */ - public String getString(String key) { - return getString(key, shouldTranslate()); - } - - /* - * Javadoc copied from interface. - */ - public String getString(String key, boolean translate) { - Map stringMap = translate ? strings : untranslatedStrings; - String result = stringMap.get(key); - if (result == null) { - try { - ResourceLocator pluginResourceLocator = getPrimaryResourceLocator(); - if (pluginResourceLocator == null) { - result = doGetString(key, translate); - } else { - result = pluginResourceLocator.getString(key, translate); - } - } catch (MissingResourceException exception) { - result = delegatedGetString(key, translate); - } - - stringMap.put(key, result); - } - - return result; - } - - /** - * Does the work of fetching the string associated with the key. It ensures - * that the string exists. - * - * @param key - * the key of the string to fetch. - * @exception MissingResourceException - * if a string doesn't exist. - * @return the string associated with the key. - */ - protected String doGetString(String key, boolean translate) throws MissingResourceException { - ResourceBundle bundle = translate ? resourceBundle : untranslatedResourceBundle; - if (bundle == null) { - String packageName = getClass().getName(); - int index = packageName.lastIndexOf("."); - if (index != -1) { - packageName = packageName.substring(0, index); - } - if (translate) { - try { - bundle = resourceBundle = ResourceBundle.getBundle(packageName + ".plugin"); - } catch (MissingResourceException exception) { - // If the bundle can't be found the normal way, try to find - // it as the base URL. - // If that also doesn't work, rethrow the original - // exception. - // - try { - InputStream inputStream = new URL(getBaseURL().toString() + "plugin.properties").openStream(); - bundle = untranslatedResourceBundle = resourceBundle = new PropertyResourceBundle(inputStream); - inputStream.close(); - } catch (IOException ioException) { - // We'll rethrow the original exception, not this one. - } - if (bundle == null) { - throw exception; - } - } - } else { - String resourceName = getBaseURL().toString() + "plugin.properties"; - try { - InputStream inputStream = new URL(resourceName).openStream(); - bundle = untranslatedResourceBundle = new PropertyResourceBundle(inputStream); - inputStream.close(); - } catch (IOException ioException) { - throw new MissingResourceException("Missing properties: " + resourceName, getClass().getName(), "plugin.properties"); - } - } - } - return bundle.getString(key); - } - - /** - * Does the work of fetching the string associated with the key, when the - * string resource is not available locally. - * - * @param key - * the key of the string to fetch. - * @exception MissingResourceException - * if the string resource doesn't exist anywhere. - * @see #getDelegateResourceLocators() - */ - protected String delegatedGetString(String key, boolean translate) { - ResourceLocator[] delegateResourceLocators = getDelegateResourceLocators(); - for (int i = 0; i < delegateResourceLocators.length; ++i) { - try { - return delegateResourceLocators[i].getString(key, translate); - } catch (MissingResourceException exception) { - // Ignore this since we will throw an exception when all else - // fails. - } - } - - throw new MissingResourceException(MessageFormat.format("The string resource ''{0}'' could not be located", new Object[] { key }), getClass().getName(), key); - } - - /* - * Javadoc copied from interface. - */ - public String getString(String key, Object[] substitutions) { - return getString(key, substitutions, shouldTranslate()); - } - - /* - * Javadoc copied from interface. - */ - public String getString(String key, Object[] substitutions, boolean translate) { - return MessageFormat.format(getString(key, translate), substitutions); - } -} -// CHECKSTYLE:ON diff --git a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/src/org/polarsys/capella/common/platform/sirius/customisation/resourcelocator/DelegatingSiriusResourceLocator.java b/common/plugins/org.polarsys.capella.common.platform.sirius.customization/src/org/polarsys/capella/common/platform/sirius/customisation/resourcelocator/DelegatingSiriusResourceLocator.java deleted file mode 100644 index 1598e40051..0000000000 --- a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/src/org/polarsys/capella/common/platform/sirius/customisation/resourcelocator/DelegatingSiriusResourceLocator.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2014 THALES GLOBAL SERVICES. - * 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: - * Thales - initial API and implementation - *******************************************************************************/ -package org.polarsys.capella.common.platform.sirius.customisation.resourcelocator; - -import org.eclipse.emf.common.util.ResourceLocator; -import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; - -/** - * Specific resource locator for Sirius. - * - * - */ -public class DelegatingSiriusResourceLocator extends DelegatingResourceLocator { - - private static final ResourceLocator PRIMARY_RESOURCE_LOCATOR = new SiriusResourceLocator(); - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.common.util.DelegatingResourceLocator#getPrimaryResourceLocator() - */ - @Override - protected ResourceLocator getPrimaryResourceLocator() { - return PRIMARY_RESOURCE_LOCATOR; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.common.util.DelegatingResourceLocator#getDelegateResourceLocators() - */ - @Override - protected ResourceLocator[] getDelegateResourceLocators() { - return new ResourceLocator[] { SiriusEditPlugin.INSTANCE.getOriginalResourceLocator() }; - } - -} diff --git a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/src/org/polarsys/capella/common/platform/sirius/customisation/resourcelocator/SiriusResourceLocator.java b/common/plugins/org.polarsys.capella.common.platform.sirius.customization/src/org/polarsys/capella/common/platform/sirius/customisation/resourcelocator/SiriusResourceLocator.java deleted file mode 100644 index 6d678159a8..0000000000 --- a/common/plugins/org.polarsys.capella.common.platform.sirius.customization/src/org/polarsys/capella/common/platform/sirius/customisation/resourcelocator/SiriusResourceLocator.java +++ /dev/null @@ -1,313 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2014 THALES GLOBAL SERVICES. - * 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: - * Thales - initial API and implementation - *******************************************************************************/ -package org.polarsys.capella.common.platform.sirius.customisation.resourcelocator; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; -import java.util.MissingResourceException; -import java.util.PropertyResourceBundle; -import java.util.ResourceBundle; - -import org.eclipse.emf.common.CommonPlugin; -import org.eclipse.emf.common.util.ResourceLocator; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.common.util.WrappedException; - -/** - * A specific resource locator for Sirius to override some preferences. Some - * methods are copied from - * {@link org.eclipse.emf.common.util.DelegatingResourceLocator}. - * - * - */ -public class SiriusResourceLocator implements ResourceLocator { - - private static final String DOT = "."; - - private static final URI DOT_URI = URI.createURI(DOT); - - private static final String PLUGIN_PROPERTIES_FILE = "plugin.properties"; - - /** - * The cached base URL. - */ - protected URL baseURL; - - /** - * The resource bundle containing untranslated strings. - */ - protected ResourceBundle untranslatedResourceBundle; - - /** - * The resource bundle containing translated strings. - */ - protected ResourceBundle resourceBundle; - - /** - * Whether to translate strings by default. - */ - protected boolean shouldTranslate = true; - - /** - * A cache of the translated strings. - */ - protected Map strings = new HashMap(); - - /** - * A cache of the untranslated strings. - */ - protected Map untranslatedStrings = new HashMap(); - - /** - * Default constructor. - */ - public SiriusResourceLocator() { - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.common.util.ResourceLocator#getBaseURL() - */ - public URL getBaseURL() { - if (baseURL == null) { - try { - Class theClass = getClass(); - URL pluginPropertiesURL = theClass.getResource(PLUGIN_PROPERTIES_FILE); - if (pluginPropertiesURL == null) { - // If that fails, determine the URL for the class itself. - // The URL will be of one of the following forms, - // so there are a few good places to consider looking for - // the plugin.properties. - // - // - // * For a plugin.xml with runtime="common.jar": - // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/common.jar!/org/eclipse/common/CommonPlugin.class - // * For a plugin.xml with runtime="runtime/common.jar": - // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/runtime/common.jar!/org/eclipse/common/CommonPlugin.class - // * For a plugin.xml with runtime="." where the plugin is - // jarred: - // jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common.jar!/org/eclipse/common/CommonPlugin.class - // * For a plugin.xml with runtime="." where the plugin is - // not - // jarred. - // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/org/eclipse/emf/common/CommonPlugin.class - // * Running in PDE with bin on classpath: - // file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/bin/org/eclipse/emf/common/CommonPlugin.class - String className = theClass.getName(); - int index = className.lastIndexOf(DOT); - URL classURL = theClass.getResource((index == -1 ? className : className.substring(index + 1)) + ".class"); - URI uri = URI.createURI(classURL.toString()); - - // Trim off the segments corresponding to the package - // nesting. - int count = 1; - // CHECKSTYLE:OFF - for (int i = 0; (i = className.indexOf('.', i)) != -1; ++i) { - ++count; - } - // CHECKSTYLE:ON - uri = uri.trimSegments(count); - - // For an archive URI, check for the plugin.properties in - // the archive. - if (URI.isArchiveScheme(uri.scheme())) { - try { - // If we can open an input stream, then the - // plugin.properties is there, and we have a good - // base URL. - InputStream inputStream = new URL(uri.appendSegment(PLUGIN_PROPERTIES_FILE).toString()).openStream(); - inputStream.close(); - baseURL = new URL(uri.toString()); - } catch (IOException exception) { - // If the plugin.properties isn't within the root of - // the archive, - // create a new URI for the folder location of the - // archive, - // so we can look in the folder that contains it. - uri = URI.createURI(uri.authority()).trimSegments(1); - } - } - - // If we didn't find the plugin.properties in the usual - // place nor in the archive... - if (baseURL == null) { - // Trim off the "bin" or "runtime" segment. - String lastSegment = uri.lastSegment(); - if ("bin".equals(lastSegment) || "runtime".equals(lastSegment)) { - uri = uri.trimSegments(1); - } - uri = uri.appendSegment(PLUGIN_PROPERTIES_FILE); - try { - // If we can open an input stream, then the - // plugin.properties is in the folder, and we have a - // good base URL. - InputStream inputStream = new URL(uri.toString()).openStream(); - inputStream.close(); - baseURL = new URL(DOT_URI.resolve(uri).toString()); - } catch (IOException exception) { - // Continue with the established base URL. - } - } - - // If we still don't have a good base URL, complain about - // it. - if (baseURL == null) { - String resourceName = index == -1 ? PLUGIN_PROPERTIES_FILE : className.substring(0, index + 1).replace('.', '/') + PLUGIN_PROPERTIES_FILE; - throw new MissingResourceException("Missing properties: " + resourceName, theClass.getName(), PLUGIN_PROPERTIES_FILE); - } - } else { - baseURL = new URL(DOT_URI.resolve(URI.createURI(pluginPropertiesURL.toString())).toString()); - } - } catch (IOException exception) { - throw new WrappedException(exception); - } - } - return baseURL; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.common.util.ResourceLocator#getImage(java.lang.String) - */ - public Object getImage(String key) { - // We override no image - throw new MissingResourceException(CommonPlugin.INSTANCE.getString("_UI_ImageResourceNotFound_exception", new Object[] { key }), getClass().getName(), key); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.common.util.ResourceLocator#getString(java.lang.String) - */ - public String getString(String key) { - return getString(key, shouldTranslate()); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.common.util.ResourceLocator#getString(java.lang.String, - * boolean) - */ - public String getString(String key, boolean translate) { - Map stringMap = translate ? strings : untranslatedStrings; - String result = stringMap.get(key); - if (result == null) { - result = doGetString(key, translate); - stringMap.put(key, result); - } - return result; - } - - /** - * Does the work of fetching the string associated with the key. It ensures - * that the string exists. - * - * @param key - * the key of the string to fetch. - * @param translate - * whether the result is to be translated to the current locale. - * @exception MissingResourceException - * if a string doesn't exist. - * @return the string associated with the key. - */ - protected String doGetString(String key, boolean translate) throws MissingResourceException { - ResourceBundle bundle = translate ? resourceBundle : untranslatedResourceBundle; - if (bundle == null) { - String packageName = getClass().getName(); - int index = packageName.lastIndexOf(DOT); - if (index != -1) { - packageName = packageName.substring(0, index); - } - if (translate) { - try { - resourceBundle = ResourceBundle.getBundle(packageName + ".plugin"); - bundle = resourceBundle; - } catch (MissingResourceException exception) { - // If the bundle can't be found the normal way, try to find - // it as the base URL. - // If that also doesn't work, rethrow the original - // exception. - // - try { - InputStream inputStream = new URL(getBaseURL().toString() + PLUGIN_PROPERTIES_FILE).openStream(); - resourceBundle = new PropertyResourceBundle(inputStream); - untranslatedResourceBundle = resourceBundle; - bundle = untranslatedResourceBundle; - inputStream.close(); - } catch (IOException ioException) { - // We'll rethrow the original exception, not this one. - } - if (bundle == null) { - throw exception; - } - } - } else { - String resourceName = getBaseURL().toString() + PLUGIN_PROPERTIES_FILE; - try { - InputStream inputStream = new URL(resourceName).openStream(); - untranslatedResourceBundle = new PropertyResourceBundle(inputStream); - bundle = untranslatedResourceBundle; - inputStream.close(); - } catch (IOException ioException) { - throw new MissingResourceException("Missing properties: " + resourceName, getClass().getName(), PLUGIN_PROPERTIES_FILE); - } - } - } - return bundle.getString(key); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.common.util.ResourceLocator#getString(java.lang.String, - * java.lang.Object[]) - */ - public String getString(String key, Object[] substitutions) { - return getString(key, substitutions, shouldTranslate()); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.common.util.ResourceLocator#getString(java.lang.String, - * java.lang.Object[], boolean) - */ - public String getString(String key, Object[] substitutions, boolean translate) { - return MessageFormat.format(getString(key, translate), substitutions); - } - - /** - * Indicates whether strings should be translated by default. - * - * @return true if strings should be translated by default; - * false otherwise. - */ - public boolean shouldTranslate() { - return shouldTranslate; - } - - /** - * Sets whether strings should be translated by default. - * - * @param shouldTranslate - * whether strings should be translated by default. - */ - public void setShouldTranslate(boolean shouldTranslate) { - this.shouldTranslate = shouldTranslate; - } -} diff --git a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.perspective/META-INF/MANIFEST.MF b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.perspective/META-INF/MANIFEST.MF index b67f94dac4..06eb91ddf4 100644 --- a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.perspective/META-INF/MANIFEST.MF +++ b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.perspective/META-INF/MANIFEST.MF @@ -24,5 +24,6 @@ Require-Bundle: org.eclipse.ui, org.eclipse.sirius.common.ui, org.eclipse.ui.intro, org.polarsys.capella.core.preferences, - org.polarsys.capella.core.application + org.polarsys.capella.core.application, + org.polarsys.capella.common.platform.sirius.customization Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.perspective/src/org/polarsys/capella/core/platform/sirius/ui/app/CapellaWorkbenchAdvisor.java b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.perspective/src/org/polarsys/capella/core/platform/sirius/ui/app/CapellaWorkbenchAdvisor.java index deed979170..8260b6edfb 100644 --- a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.perspective/src/org/polarsys/capella/core/platform/sirius/ui/app/CapellaWorkbenchAdvisor.java +++ b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.perspective/src/org/polarsys/capella/core/platform/sirius/ui/app/CapellaWorkbenchAdvisor.java @@ -32,10 +32,6 @@ import org.eclipse.emf.validation.service.ModelValidationService; import org.eclipse.jface.viewers.ILabelDecorator; import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.sirius.business.api.preferences.SiriusPreferencesKeys; -import org.eclipse.sirius.common.tools.api.constant.CommonPreferencesConstants; -import org.eclipse.sirius.common.ui.SiriusTransPlugin; -import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; @@ -110,10 +106,9 @@ public String getInitialWindowPerspectiveId() { public void preStartup() { super.preStartup(); - // Load SiriusEdit - SiriusEditPlugin.getPlugin().getPreferenceStore().setValue(SiriusPreferencesKeys.PREF_EMPTY_AIRD_FRAGMENT_ON_CONTROL.name(), true); - // Disable Sirius Pre-commit listener behavior since Capella has the same one. - SiriusTransPlugin.getPlugin().getPreferenceStore().setValue(CommonPreferencesConstants.PREF_DEFENSIVE_EDIT_VALIDATION, false); + //Ensure that Sirius customization are properly overidden by loading customisation plugin + org.polarsys.capella.common.platform.sirius.customisation.SiriusPlugin.getDefault(); + // force all workspace operations to be undoable // That's the easiest way to avoid undo operation on a capella project creation from clipboard (copy/paste). IUndoContext workspaceUndoContext = WorkspaceUndoUtil.getWorkspaceUndoContext(); diff --git a/tests/plugins/org.polarsys.capella.test.platform.ju/META-INF/MANIFEST.MF b/tests/plugins/org.polarsys.capella.test.platform.ju/META-INF/MANIFEST.MF index 4bef08d874..e47db6200b 100644 --- a/tests/plugins/org.polarsys.capella.test.platform.ju/META-INF/MANIFEST.MF +++ b/tests/plugins/org.polarsys.capella.test.platform.ju/META-INF/MANIFEST.MF @@ -6,7 +6,8 @@ Bundle-Version: 1.3.0.qualifier Bundle-Activator: org.polarsys.capella.test.platform.ju.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, - org.polarsys.capella.test.framework;bundle-version="0.8.0" + org.polarsys.capella.test.framework;bundle-version="0.8.0", + org.eclipse.sirius.common.ui Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: org.polarsys.capella.test.platform.ju, diff --git a/tests/plugins/org.polarsys.capella.test.platform.ju/src/org/polarsys/capella/test/platform/ju/testcases/CapellaSiriusCustomisationEnabled.java b/tests/plugins/org.polarsys.capella.test.platform.ju/src/org/polarsys/capella/test/platform/ju/testcases/CapellaSiriusCustomisationEnabled.java new file mode 100644 index 0000000000..6271554ff7 --- /dev/null +++ b/tests/plugins/org.polarsys.capella.test.platform.ju/src/org/polarsys/capella/test/platform/ju/testcases/CapellaSiriusCustomisationEnabled.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2018 THALES GLOBAL SERVICES. + * 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: + * Thales - initial API and implementation + *******************************************************************************/ +package org.polarsys.capella.test.platform.ju.testcases; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.sirius.business.api.preferences.SiriusPreferencesKeys; +import org.eclipse.sirius.common.tools.api.constant.CommonPreferencesConstants; +import org.eclipse.sirius.common.ui.SiriusTransPlugin; +import org.eclipse.sirius.ui.business.api.preferences.SiriusUIPreferencesKeys; +import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; +import org.eclipse.ui.IWorkbenchPreferenceConstants; +import org.eclipse.ui.PlatformUI; +import org.polarsys.capella.test.framework.api.BasicTestCase; + +public class CapellaSiriusCustomisationEnabled extends BasicTestCase { + + @Override + public void test() throws Exception { + + // Ensure that Sirius overridden preference values are the intended ones. + // It can imply that loading plugin order is not the expected one or default values are re-overridden by Sirius + + IPreferenceStore store = SiriusEditPlugin.getPlugin().getPreferenceStore(); + + assertTrue("Preference value for 'Prompt when saveable still open' is not the intended one", PlatformUI.getPreferenceStore() + .getBoolean(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN) == false); + + assertTrue("Preference value for 'Defensive edit validation' is not the intended one", SiriusTransPlugin.getPlugin().getPreferenceStore() + .getBoolean(CommonPreferencesConstants.PREF_DEFENSIVE_EDIT_VALIDATION) == false); + + assertTrue("Preference value for 'Empty aird fragmentation' is not the intended one", + store.getBoolean(SiriusPreferencesKeys.PREF_EMPTY_AIRD_FRAGMENT_ON_CONTROL.name()) == true); + + assertTrue("Preference value for 'Save when no editor' is not the intended one", + store.getBoolean(SiriusUIPreferencesKeys.PREF_SAVE_WHEN_NO_EDITOR.name()) == false); + + assertTrue("Preference value for 'Reload on last editor close' is not the intended one", + store.getBoolean(SiriusUIPreferencesKeys.PREF_RELOAD_ON_LAST_EDITOR_CLOSE.name()) == false); + + assertTrue("Preference value for 'Scale level on diagram export' is not the intended one", + store.getInt(SiriusUIPreferencesKeys.PREF_SCALE_LEVEL_DIAGRAMS_ON_EXPORT.name()) == 2); + + assertTrue("Preference value for 'Use viewpoint colors' is not the intended one", + store.getBoolean(SiriusUIPreferencesKeys.PREF_DISPLAY_VSM_USER_FIXED_COLOR_IN_PALETTE.name()) == false); + + } + +} diff --git a/tests/plugins/org.polarsys.capella.test.platform.ju/src/org/polarsys/capella/test/platform/ju/testsuites/PlatformTestSuite.java b/tests/plugins/org.polarsys.capella.test.platform.ju/src/org/polarsys/capella/test/platform/ju/testsuites/PlatformTestSuite.java index b5246b37ab..2c23bf1be8 100644 --- a/tests/plugins/org.polarsys.capella.test.platform.ju/src/org/polarsys/capella/test/platform/ju/testsuites/PlatformTestSuite.java +++ b/tests/plugins/org.polarsys.capella.test.platform.ju/src/org/polarsys/capella/test/platform/ju/testsuites/PlatformTestSuite.java @@ -18,6 +18,7 @@ import org.polarsys.capella.test.platform.ju.testcases.CapellaCDOGenerationOfDerivedFeature; import org.polarsys.capella.test.platform.ju.testcases.CapellaDefaultEditorEnabled; import org.polarsys.capella.test.platform.ju.testcases.CapellaPlatformVersionNotNull; +import org.polarsys.capella.test.platform.ju.testcases.CapellaSiriusCustomisationEnabled; import junit.framework.Test; @@ -39,6 +40,7 @@ public static Test suite() { @Override protected List getTests() { List tests = new ArrayList(); + tests.add(new CapellaSiriusCustomisationEnabled()); tests.add(new CapellaPlatformVersionNotNull()); tests.add(new CapellaDefaultEditorEnabled()); tests.add(new CapellaCDOGenerationOfDerivedFeature());