Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2017-12-08 17:27:11 +0000
committerChristian W. Damus2017-12-20 19:08:43 +0000
commitd4b80d9f68cba0e9637c64c87adafe095e8f566a (patch)
tree9eaa186e6acfbfb6245849a7e898125f9ed7b2f0 /plugins/infra
parentf2e8c0e8156eadce40d9ab26df610b1cabcb1e6e (diff)
downloadorg.eclipse.papyrus-d4b80d9f68cba0e9637c64c87adafe095e8f566a.tar.gz
org.eclipse.papyrus-d4b80d9f68cba0e9637c64c87adafe095e8f566a.tar.xz
org.eclipse.papyrus-d4b80d9f68cba0e9637c64c87adafe095e8f566a.zip
Bug 528343: [I18N] Preference checking overhead for models that don't use i18n
Rework the InternationalizationUMLItemProviderAdapterFactory to provide standard UML item-providers for resource sets that don’t enabled i18n support, until such time as it is needed. At that point, dispose the standard item-providers and let the i18n-enabled ones replace them. An new event-listener protocol lets the item-provider detect this change in i18n status. Also improve performance of the i18n utility's tracking of preference stores and fix the hash code calculation of the PapyrusProjectScope (as it matters now that it is used as the key in a map). (cherry-picked from streams/3.0-maintenance) https://bugs.eclipse.org/bugs/show_bug.cgi?id=528343 Change-Id: Ifb415da65d6af26e5bfaac0ea3f1b9718b758227
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/pom.xml2
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/PapyrusProjectScope.java28
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/pom.xml2
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/Activator.java51
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferenceChangeEvent.java117
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferenceListener.java35
-rw-r--r--plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesUtils.java54
9 files changed, 250 insertions, 43 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
index f6d621c2349..1c870582133 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
@@ -31,7 +31,7 @@ Require-Bundle: org.eclipse.emf.workspace;bundle-version="[1.5.0,2.0.0)",
org.eclipse.papyrus.infra.core.architecture;bundle-version="[1.0.0,2.0.0)";visibility:=reexport
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.0.100.qualifier
Bundle-Name: %pluginName
Bundle-Localization: plugin
Bundle-Activator: org.eclipse.papyrus.infra.core.Activator
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/pom.xml b/plugins/infra/core/org.eclipse.papyrus.infra.core/pom.xml
index 0907a49f8c4..dcb0047c077 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/pom.xml
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/pom.xml
@@ -6,6 +6,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.core</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/PapyrusProjectScope.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/PapyrusProjectScope.java
index c792d8c1de0..5efef5e01e3 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/PapyrusProjectScope.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/PapyrusProjectScope.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
+ * Copyright (c) 2016, 2017 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,11 +8,14 @@
*
* Contributors:
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
+ * Christian W. Damus - bug 528343
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource;
+import java.util.Objects;
+
import org.eclipse.core.internal.preferences.AbstractScope;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
@@ -36,14 +39,19 @@ public class PapyrusProjectScope extends AbstractScope {
/**
* The papyrus project name.
*/
- private String papyrusProjectName;
+ private final String papyrusProjectName;
/**
* The context project.
*/
- private IProject context;
+ private final IProject context;
/**
+ * Cached hash code.
+ */
+ private int hash = 0;
+
+ /**
* Constructor.
*
* @param project
@@ -105,10 +113,10 @@ public class PapyrusProjectScope extends AbstractScope {
public boolean equals(final Object obj) {
if (this == obj)
return true;
- if (!super.equals(obj))
- return false;
if (!(obj instanceof PapyrusProjectScope))
return false;
+ if (!super.equals(obj))
+ return false;
PapyrusProjectScope other = (PapyrusProjectScope) obj;
return context.equals(other.context) && papyrusProjectName.equals(other.papyrusProjectName);
}
@@ -120,7 +128,15 @@ public class PapyrusProjectScope extends AbstractScope {
*/
@Override
public int hashCode() {
- return super.hashCode() + context.getFullPath().hashCode() + "/".hashCode() + papyrusProjectName.hashCode(); //$NON-NLS-1$
+ if (hash == 0) {
+ int h = super.hashCode();
+ h = 37 * h + Objects.hashCode(context);
+ h = 37 * h + Objects.hashCode(papyrusProjectName);
+
+ hash = h;
+ }
+
+ return hash;
}
}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/META-INF/MANIFEST.MF b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/META-INF/MANIFEST.MF
index 206039bfccc..1f78da869c6 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/META-INF/MANIFEST.MF
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.papyrus.infra.internationalization.common;singleton:=true
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.100.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/pom.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/pom.xml
index f3af17149ec..4308de57e70 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/pom.xml
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/pom.xml
@@ -8,6 +8,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.internationalization.common</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.100.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/Activator.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/Activator.java
index ae1975d5007..40a3d627b31 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/Activator.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/Activator.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
+ * Copyright (c) 2016, 2017 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,17 +8,16 @@
*
* Contributors:
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
+ * Christian W. Damus - bug 528343
*
*****************************************************************************/
package org.eclipse.papyrus.infra.internationalization.common;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -55,16 +54,15 @@ public class Activator extends AbstractUIPlugin {
public static LogHelper log;
/**
- * Storage for preferences. Use a list of preference store (one preference
- * store by internationalization of a project).
+ * Storage for preferences, per scope.
*/
- private List<IPreferenceStore> preferencesStore;
+ private Map<IScopeContext, IPreferenceStore> preferencesStore;
/**
* The constructor
*/
public Activator() {
- preferencesStore = new ArrayList<IPreferenceStore>(0);
+ preferencesStore = new HashMap<>();
}
/**
@@ -101,28 +99,12 @@ public class Activator extends AbstractUIPlugin {
*/
public IPreferenceStore getInternationalizationPreferenceStore(final IProject project,
final String papyrusProjectName) {
- IPreferenceStore result = null;
+
final IScopeContext scope = new PapyrusProjectScope(project, papyrusProjectName);
- if (!preferencesStore.isEmpty()) {
- final IEclipsePreferences scopePreferenceNode = scope.getNode(INTERNATIONALIZATION_NODE_LABEL);
- final Iterator<IPreferenceStore> preferenceStoreIterator = preferencesStore.iterator();
- while (preferenceStoreIterator.hasNext() && null == result) {
- final IPreferenceStore preferenceStore = preferenceStoreIterator.next();
- if (preferenceStore instanceof PapyrusScopedPreferenceStore) {
- final IEclipsePreferences[] preferenceNodes = ((PapyrusScopedPreferenceStore) preferenceStore)
- .getPreferenceNodes(false);
- for (int index = 0; index < preferenceNodes.length && null == result; index++) {
- if (preferenceNodes[index].equals(scopePreferenceNode)) {
- result = preferenceStore;
- }
- }
- }
- }
- }
-
+ IPreferenceStore result = preferencesStore.get(scope);
if (null == result) {
result = new PapyrusScopedPreferenceStore(scope, INTERNATIONALIZATION_NODE_LABEL);
- preferencesStore.add(result); // $NON-NLS-1$
+ preferencesStore.put(scope, result);
}
return result;
@@ -135,11 +117,16 @@ public class Activator extends AbstractUIPlugin {
* @return The preference store.
*/
public IPreferenceStore getInternationalizationPreferenceStore() {
- // Create the preference store lazily.
- if (preferencesStore.isEmpty()) {
- preferencesStore.add(new ScopedPreferenceStore(InstanceScope.INSTANCE, getBundle().getSymbolicName()));
+ IScopeContext scope = InstanceScope.INSTANCE;
+ IPreferenceStore result = preferencesStore.get(scope);
+
+ if (result == null) {
+ // Create the preference store lazily.
+ result = new ScopedPreferenceStore(scope, getBundle().getSymbolicName());
+ preferencesStore.put(scope, result);
}
- return preferencesStore.get(0);
+
+ return result;
}
/**
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferenceChangeEvent.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferenceChangeEvent.java
new file mode 100644
index 00000000000..ae9331d481f
--- /dev/null
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferenceChangeEvent.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Christian W. Damus 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:
+ * Christian W. Damus - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.internationalization.common.utils;
+
+import java.util.EventObject;
+import java.util.Locale;
+
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * Event indicating some change in the internationalization preferences
+ * for a resource, by URI.
+ *
+ * @author Christian W. Damus
+ *
+ * @since 1.1
+ */
+public final class InternationalizationPreferenceChangeEvent extends EventObject {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Event type indicating change in enablement of internationalization. */
+ public static final int ENABLED = 0;
+
+ /** Event type indicating change in locale of internationalization. */
+ public static final int LOCALE = 1;
+
+ private final int eventType;
+ private final URI resourceURI;
+
+ private final boolean enabled;
+ private final Locale locale;
+
+ /**
+ * Initializes me with my source, resource URI, and enablement change.
+ *
+ * @param source my source, which is opaque to clients
+ * @param resourceURI my resource URI
+ * @param enabled whether enablement changed to {@code true} or {@code false}
+ */
+ public InternationalizationPreferenceChangeEvent(Object source, URI resourceURI, boolean enabled) {
+ this(source, resourceURI, ENABLED, enabled, null);
+ }
+
+ /**
+ * Initializes me with my source, resource URI, and locale change.
+ *
+ * @param source my source, which is opaque to clients
+ * @param resourceURI my resource URI
+ * @param locale the new locale for the resource
+ */
+ public InternationalizationPreferenceChangeEvent(Object source, URI resourceURI, Locale locale) {
+ this(source, resourceURI, LOCALE, false, locale);
+ }
+
+ /**
+ * Initializes me.
+ */
+ private InternationalizationPreferenceChangeEvent(Object source, URI resourceURI, int eventType, boolean enabled, Locale locale) {
+ super(source);
+
+ this.resourceURI = resourceURI;
+ this.eventType = eventType;
+ this.enabled = enabled;
+ this.locale = locale;
+ }
+
+ /**
+ * Queries the {@linkplain #ENABLED type} of event that I am.
+ *
+ * @return my type
+ */
+ public int getEventType() {
+ return eventType;
+ }
+
+ /**
+ * Queries the resource URI to which I pertain.
+ *
+ * @return the resource URI for which a preference changed
+ */
+ public URI getResourceURI() {
+ return resourceURI;
+ }
+
+ /**
+ * Queries whether the internationalization was enabled or disabled for
+ * the resource. Only makes sense for the {@link #ENABLED} event type.
+ *
+ * @return {@code true} if I am an {@linkplain #ENABLED enablement} event and my
+ * resource enabled internationalization; {@code false} if either I am
+ * not an enablement event or I am but my resource disabled internationalization
+ */
+ public boolean isInternationalizationEnabled() {
+ return enabled;
+ }
+
+ /**
+ * Queries the locale that was set for the internationalization of
+ * the resource. Only makes sense for the {@link #LOCALE} event type.
+ *
+ * @return the new locale if I am a {@linkplain #LOCALE locale} event;
+ * {@code null} if either I am not a locale event
+ */
+ public Locale getLocale() {
+ return locale;
+ }
+}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferenceListener.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferenceListener.java
new file mode 100644
index 00000000000..0149dff7ab4
--- /dev/null
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferenceListener.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Christian W. Damus 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:
+ * Christian W. Damus - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.internationalization.common.utils;
+
+import java.util.EventListener;
+import java.util.EventObject;
+
+/**
+ * Protocol for a listener to be notified of changes in the internationalization
+ * preferences for resources.
+ *
+ * @author Christian W. Damus
+ *
+ * @since 1.1
+ */
+public interface InternationalizationPreferenceListener extends EventListener {
+
+ /**
+ * Handles the change of internationalization for some resource.
+ * The {@code event} object's {@link EventObject#getSource() source} is
+ * to be treated as opaque, not interpreted by the receiver.
+ *
+ * @param event the internationalization change event
+ */
+ void internationalizationChanged(InternationalizationPreferenceChangeEvent event);
+}
diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesUtils.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesUtils.java
index 14bbe347097..be71c53b0f6 100644
--- a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesUtils.java
+++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesUtils.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
+ * Copyright (c) 2016, 2017 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,12 +8,14 @@
*
* Contributors:
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
+ * Christian W. Damus - bug 528343
*
*****************************************************************************/
package org.eclipse.papyrus.infra.internationalization.common.utils;
import java.util.Locale;
+import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -35,6 +37,8 @@ import org.eclipse.papyrus.infra.internationalization.common.Activator;
*/
public class InternationalizationPreferencesUtils {
+ private static final CopyOnWriteArrayList<InternationalizationPreferenceListener> listeners = new CopyOnWriteArrayList<>();
+
/**
* This allows to get the load of internationalization preference value.
*
@@ -183,6 +187,10 @@ public class InternationalizationPreferencesUtils {
if (null != preferenceStore) {
preferenceStore.setValue(InternationalizationPreferencesConstants.USE_INTERNATIONALIZATION_PREFERENCE,
value);
+
+ if (hasListeners()) {
+ fire(new InternationalizationPreferenceChangeEvent(preferenceStore, resourceURI, value));
+ }
}
}
@@ -344,6 +352,50 @@ public class InternationalizationPreferencesUtils {
if (null != preferenceStore) {
preferenceStore.setValue(InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE, language);
+
+ if (hasListeners()) {
+ Locale locale = (language == null) ? Locale.getDefault()
+ : LocaleNameResolver.getLocaleFromString(language);
+ fire(new InternationalizationPreferenceChangeEvent(preferenceStore, resourceURI, locale));
+ }
+ }
+ }
+
+ private static boolean hasListeners() {
+ return !listeners.isEmpty();
+ }
+
+ private static void fire(InternationalizationPreferenceChangeEvent event) {
+ for (InternationalizationPreferenceListener next : listeners) {
+ try {
+ next.internationalizationChanged(event);
+ } catch (Exception e) {
+ Activator.log.error("Uncaught exception in listener call-back.", e); //$NON-NLS-1$
+ }
}
}
+
+ /**
+ * Adds a {@code listener} for changes in the internationalization preferences of resources.
+ * Has no effect if the {@code listener} is already attached.
+ *
+ * @param listener a listener to add
+ *
+ * @since 1.1
+ */
+ public static void addPreferenceListener(InternationalizationPreferenceListener listener) {
+ listeners.addIfAbsent(listener);
+ }
+
+ /**
+ * Removes a {@code listener} for changes in the internationalization preferences of resources.
+ * Has no effect if the {@code listener} is not currently attached.
+ *
+ * @param listener a listener to remove
+ *
+ * @since 1.1
+ */
+ public static void removePreferenceListener(InternationalizationPreferenceListener listener) {
+ listeners.remove(listener);
+ }
}

Back to the top