]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.selectionview/src/org/simantics/selectionview/SelectionProcessorExtensionManager.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / SelectionProcessorExtensionManager.java
index 64710d76e50f8c604f4c187e82c1eafc7afba6e7..ab4fef8e91d6ddbc2ddfbbf5ecc1e1b79a8b1204 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.selectionview;\r
-\r
-import java.util.Arrays;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.core.runtime.IConfigurationElement;\r
-import org.eclipse.core.runtime.IExtension;\r
-import org.eclipse.core.runtime.IExtensionPoint;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;\r
-import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;\r
-import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;\r
-import org.eclipse.core.runtime.dynamichelpers.IFilter;\r
-import org.simantics.browsing.ui.common.Activator;\r
-import org.simantics.browsing.ui.common.ErrorLogger;\r
-import org.simantics.utils.strings.StringUtils;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class SelectionProcessorExtensionManager implements IExtensionChangeHandler {\r
-\r
-    private final static String   NAMESPACE  = Activator.PLUGIN_ID;\r
-\r
-    private final static String   EP_NAME    = "selectionProcessor";\r
-\r
-    private ExtensionTracker      tracker;\r
-\r
-    SelectionProcessorExtension[] extensions = new SelectionProcessorExtension[0];\r
-\r
-    SelectionProcessorExtensionManager() {\r
-        tracker = new ExtensionTracker();\r
-\r
-        // Cache defined actions\r
-        IExtensionPoint expt = Platform.getExtensionRegistry().getExtensionPoint(NAMESPACE, EP_NAME);\r
-        loadExtensions(expt.getConfigurationElements());\r
-\r
-        // Start tracking for new and removed extensions\r
-        IFilter filter = ExtensionTracker.createExtensionPointFilter(expt);\r
-        tracker.registerHandler(this, filter);\r
-    }\r
-\r
-    void close() {\r
-        tracker.close();\r
-        tracker = null;\r
-        extensions = new SelectionProcessorExtension[0];\r
-    }\r
-\r
-    public SelectionProcessorExtension[] getExtensions() {\r
-        return extensions;\r
-    }\r
-\r
-    private void loadExtensions(IConfigurationElement[] elements) {\r
-\r
-        Set<SelectionProcessorExtension> newExtensions = new HashSet<SelectionProcessorExtension>(Arrays.asList(extensions));\r
-\r
-        for (IConfigurationElement el : elements) {\r
-            try {\r
-\r
-                String id = StringUtils.safeString(el.getAttribute("id"));\r
-                SelectionProcessor<?, ?> factory = (SelectionProcessor<?, ?>) el.createExecutableExtension("class");\r
-                SelectionProcessorExtension ext = new SelectionProcessorExtensionImpl(id, factory);\r
-\r
-                // Start tracking the new extension object, its removal will be notified of\r
-                // with removeExtension(extension, Object[]).\r
-                tracker.registerObject(el.getDeclaringExtension(), ext, IExtensionTracker.REF_STRONG);\r
-\r
-                newExtensions.add(ext);\r
-            } catch (CoreException e) {\r
-                ErrorLogger.defaultLogError("Failed to initialize " + EP_NAME + " extension \"" + el.getName()\r
-                        + "\" with name \"" + el.getAttribute("name") + "\": "\r
-                        + e.getMessage(), e);\r
-            }\r
-        }\r
-\r
-        // Atomic assignment\r
-        this.extensions = newExtensions.toArray(new SelectionProcessorExtension[newExtensions.size()]);\r
-    }\r
-\r
-    @Override\r
-    public void addExtension(IExtensionTracker tracker, IExtension extension) {\r
-        loadExtensions(extension.getConfigurationElements());\r
-    }\r
-\r
-    @Override\r
-    public void removeExtension(IExtension extension, Object[] objects) {\r
-        Set<SelectionProcessorExtension> newExtensions = new HashSet<SelectionProcessorExtension>(Arrays.asList(extensions));\r
-\r
-        for (Object o : objects) {\r
-            tracker.unregisterObject(extension, o);\r
-            newExtensions.remove(o);\r
-        }\r
-\r
-        // Atomic assignment\r
-        this.extensions = newExtensions.toArray(new SelectionProcessorExtension[newExtensions.size()]);\r
-    }\r
-\r
-    private static SelectionProcessorExtensionManager INSTANCE;\r
-\r
-    public static synchronized SelectionProcessorExtensionManager getInstance() {\r
-        if (INSTANCE == null)\r
-            INSTANCE = new SelectionProcessorExtensionManager();\r
-        return INSTANCE;\r
-    }\r
-\r
-\r
-    public static synchronized void dispose() {\r
-        if (INSTANCE != null) {\r
-            INSTANCE.close();\r
-            INSTANCE = null;\r
-        }\r
-    }\r
-\r
-    public static SelectionProcessor<?, ?> getProcessor(String id) {\r
-        for (SelectionProcessorExtension ext : getInstance().extensions) {\r
-            if (ext.getProcessor().getClass().getCanonicalName().equals(id))\r
-                return ext.getProcessor();\r
-        }\r
-        return null;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.selectionview;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
+import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
+import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
+import org.eclipse.core.runtime.dynamichelpers.IFilter;
+import org.simantics.browsing.ui.common.Activator;
+import org.simantics.browsing.ui.common.ErrorLogger;
+import org.simantics.utils.strings.StringUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class SelectionProcessorExtensionManager implements IExtensionChangeHandler {
+
+    private final static String   NAMESPACE  = Activator.PLUGIN_ID;
+
+    private final static String   EP_NAME    = "selectionProcessor";
+
+    private ExtensionTracker      tracker;
+
+    SelectionProcessorExtension[] extensions = new SelectionProcessorExtension[0];
+
+    SelectionProcessorExtensionManager() {
+        tracker = new ExtensionTracker();
+
+        // Cache defined actions
+        IExtensionPoint expt = Platform.getExtensionRegistry().getExtensionPoint(NAMESPACE, EP_NAME);
+        loadExtensions(expt.getConfigurationElements());
+
+        // Start tracking for new and removed extensions
+        IFilter filter = ExtensionTracker.createExtensionPointFilter(expt);
+        tracker.registerHandler(this, filter);
+    }
+
+    void close() {
+        tracker.close();
+        tracker = null;
+        extensions = new SelectionProcessorExtension[0];
+    }
+
+    public SelectionProcessorExtension[] getExtensions() {
+        return extensions;
+    }
+
+    private void loadExtensions(IConfigurationElement[] elements) {
+
+        Set<SelectionProcessorExtension> newExtensions = new HashSet<SelectionProcessorExtension>(Arrays.asList(extensions));
+
+        for (IConfigurationElement el : elements) {
+            try {
+
+                String id = StringUtils.safeString(el.getAttribute("id"));
+                SelectionProcessor<?, ?> factory = (SelectionProcessor<?, ?>) el.createExecutableExtension("class");
+                SelectionProcessorExtension ext = new SelectionProcessorExtensionImpl(id, factory);
+
+                // Start tracking the new extension object, its removal will be notified of
+                // with removeExtension(extension, Object[]).
+                tracker.registerObject(el.getDeclaringExtension(), ext, IExtensionTracker.REF_STRONG);
+
+                newExtensions.add(ext);
+            } catch (CoreException e) {
+                ErrorLogger.defaultLogError("Failed to initialize " + EP_NAME + " extension \"" + el.getName()
+                        + "\" with name \"" + el.getAttribute("name") + "\": "
+                        + e.getMessage(), e);
+            }
+        }
+
+        // Atomic assignment
+        this.extensions = newExtensions.toArray(new SelectionProcessorExtension[newExtensions.size()]);
+    }
+
+    @Override
+    public void addExtension(IExtensionTracker tracker, IExtension extension) {
+        loadExtensions(extension.getConfigurationElements());
+    }
+
+    @Override
+    public void removeExtension(IExtension extension, Object[] objects) {
+        Set<SelectionProcessorExtension> newExtensions = new HashSet<SelectionProcessorExtension>(Arrays.asList(extensions));
+
+        for (Object o : objects) {
+            tracker.unregisterObject(extension, o);
+            newExtensions.remove(o);
+        }
+
+        // Atomic assignment
+        this.extensions = newExtensions.toArray(new SelectionProcessorExtension[newExtensions.size()]);
+    }
+
+    private static SelectionProcessorExtensionManager INSTANCE;
+
+    public static synchronized SelectionProcessorExtensionManager getInstance() {
+        if (INSTANCE == null)
+            INSTANCE = new SelectionProcessorExtensionManager();
+        return INSTANCE;
+    }
+
+
+    public static synchronized void dispose() {
+        if (INSTANCE != null) {
+            INSTANCE.close();
+            INSTANCE = null;
+        }
+    }
+
+    public static SelectionProcessor<?, ?> getProcessor(String id) {
+        for (SelectionProcessorExtension ext : getInstance().extensions) {
+            if (ext.getProcessor().getClass().getCanonicalName().equals(id))
+                return ext.getProcessor();
+        }
+        return null;
+    }
+
+}