Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Fluegge2011-09-25 19:03:50 +0000
committerMartin Fluegge2011-09-25 19:03:50 +0000
commit69b5c9ecaf1edc80e4270892ee76a83e185d446e (patch)
tree07acbec2349a3127242c67967fa8771b6e7f213e /plugins/org.eclipse.emf.cdo.dawn.ui
parent9eec85bb8884ca82791f1f8bc4bb00f2f0d4af34 (diff)
downloadcdo-69b5c9ecaf1edc80e4270892ee76a83e185d446e.tar.gz
cdo-69b5c9ecaf1edc80e4270892ee76a83e185d446e.tar.xz
cdo-69b5c9ecaf1edc80e4270892ee76a83e185d446e.zip
[319486] [Dawn] Implement locking mechanism for extended editors
https://bugs.eclipse.org/bugs/show_bug.cgi?id=319486
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.dawn.ui')
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.ui/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.ui/icons/dawn_locked_16x16.gifbin0 -> 901 bytes
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/DawnLabelProvider.java54
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/icons/DawnIconRegistry.java103
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/stylizer/DawnDefaultElementStylizer.java84
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/stylizer/DawnElementStylizerRegistry.java162
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/views/DawnItemProvider.java1
7 files changed, 403 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.dawn.ui/META-INF/MANIFEST.MF
index 8b8249a8c7..052779fb0a 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.dawn.ui/META-INF/MANIFEST.MF
@@ -14,12 +14,14 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: %providerName
Bundle-Localization: plugin
-Export-Package: org.eclipse.emf.cdo.dawn.internal.ui.bundle;version="2.0.0",
+Export-Package: org.eclipse.emf.cdo.dawn.internal.ui.bundle;version="2.0.0";x-internal:=true,
org.eclipse.emf.cdo.dawn.ui;version="2.0.0",
org.eclipse.emf.cdo.dawn.ui.composites;version="2.0.0",
org.eclipse.emf.cdo.dawn.ui.handlers;version="2.0.0";x-internal:=true,
org.eclipse.emf.cdo.dawn.ui.helper;version="2.0.0",
+ org.eclipse.emf.cdo.dawn.ui.icons;version="2.0.0",
org.eclipse.emf.cdo.dawn.ui.messages;version="2.0.0",
+ org.eclipse.emf.cdo.dawn.ui.stylizer;version="2.0.0",
org.eclipse.emf.cdo.dawn.ui.views;version="2.0.0",
org.eclipse.emf.cdo.dawn.ui.wizards;version="2.0.0",
org.eclipse.emf.cdo.dawn.ui.wizards.dialogs;version="2.0.0"
diff --git a/plugins/org.eclipse.emf.cdo.dawn.ui/icons/dawn_locked_16x16.gif b/plugins/org.eclipse.emf.cdo.dawn.ui/icons/dawn_locked_16x16.gif
new file mode 100644
index 0000000000..e87e04a0e2
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.ui/icons/dawn_locked_16x16.gif
Binary files differ
diff --git a/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/DawnLabelProvider.java b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/DawnLabelProvider.java
index 228c56c8ca..56a86a7082 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/DawnLabelProvider.java
+++ b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/DawnLabelProvider.java
@@ -10,6 +10,10 @@
*/
package org.eclipse.emf.cdo.dawn.ui;
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer;
+import org.eclipse.emf.cdo.dawn.spi.DawnState;
+import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnElementStylizerRegistry;
import org.eclipse.emf.cdo.ui.CDOLabelProvider;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOView;
@@ -19,6 +23,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
/**
* @author Martin Fluegge
@@ -36,15 +41,58 @@ public class DawnLabelProvider extends CDOLabelProvider
{
// makes sure that the object is adapted
Color foreground = super.getForeground(object);
- if (CDOUtil.getCDOObject((EObject)object).cdoWriteLock().isLocked())
+
+ DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(object);
+
+ CDOObject cdoObject = CDOUtil.getCDOObject((EObject)object);
+ if (cdoObject.cdoWriteLock().isLocked())
{
- return DawnColorConstants.COLOR_LOCKED_LOCALLY;
+ return stylizer.getForegroundColor(cdoObject, DawnState.LOCKED_LOCALLY);
}
else if (CDOUtil.getCDOObject((EObject)object).cdoWriteLock().isLockedByOthers())
{
- return DawnColorConstants.COLOR_LOCKED_REMOTELY;
+ return stylizer.getForegroundColor(cdoObject, DawnState.LOCKED_REMOTELY);
}
// Use default
return foreground;
}
+
+ @Override
+ public Color getBackground(Object object)
+ {
+ // makes sure that the object is adapted
+ Color background = super.getBackground(object);
+
+ DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(object);
+
+ CDOObject cdoObject = CDOUtil.getCDOObject((EObject)object);
+ if (cdoObject.cdoWriteLock().isLocked())
+ {
+ return stylizer.getBackgroundColor(cdoObject, DawnState.LOCKED_LOCALLY);
+ }
+ else if (CDOUtil.getCDOObject((EObject)object).cdoWriteLock().isLockedByOthers())
+ {
+ return stylizer.getBackgroundColor(cdoObject, DawnState.LOCKED_REMOTELY);
+ }
+ // Use default
+ return background;
+ }
+
+ @Override
+ public Image getImage(Object object)
+ {
+ DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(object);
+
+ CDOObject cdoObject = CDOUtil.getCDOObject((EObject)object);
+ if (cdoObject.cdoWriteLock().isLocked())
+ {
+ return stylizer.getImage(cdoObject, DawnState.LOCKED_LOCALLY);
+ }
+ else if (CDOUtil.getCDOObject((EObject)object).cdoWriteLock().isLockedByOthers())
+ {
+ return stylizer.getImage(cdoObject, DawnState.LOCKED_REMOTELY);
+ }
+
+ return super.getImage(object);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/icons/DawnIconRegistry.java b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/icons/DawnIconRegistry.java
new file mode 100644
index 0000000000..535c83ecbe
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/icons/DawnIconRegistry.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - maintenance
+ */
+package org.eclipse.emf.cdo.dawn.ui.icons;
+
+import org.eclipse.emf.cdo.dawn.internal.ui.bundle.OM;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * Based on the implementation from org.eclipse.emf.cdo.ui.shared.SharedIcons. TODO clarify with Eike whether we could
+ * provide a better extensibility.
+ *
+ * @author Martin Fluegge
+ * @since 2.0
+ */
+public class DawnIconRegistry
+{
+ private static final String GIF = ".gif"; //$NON-NLS-1$
+
+ private static final String PNG = ".png"; //$NON-NLS-1$
+
+ private static final ImageRegistry REGISTRY = new ImageRegistry(getDisplay());
+
+ private static final String ICONS_FOLDER = "icons/"; //$NON-NLS-1$
+
+ public static final String LOCKED = ICONS_FOLDER + "dawn_locked_16x16" + GIF; //$NON-NLS-1$
+
+ public static final String DAWN_LIGHT = ICONS_FOLDER + "dawn_16x16" + PNG; //$NON-NLS-1$
+
+ public static final String DAWN_DARK = ICONS_FOLDER + "dawn_16x16" + GIF; //$NON-NLS-1$
+
+ public static Image getImage(String key)
+ {
+ Image image = REGISTRY.get(key);
+ if (image == null)
+ {
+ createDescriptor(key);
+ image = REGISTRY.get(key);
+ }
+
+ // For some reason, sometimes images get disposed.
+ // In that case, create and put in registry again.
+ if (image.isDisposed())
+ {
+ REGISTRY.remove(key);
+ createDescriptor(key);
+ image = REGISTRY.get(key);
+ }
+
+ return image;
+ }
+
+ public static ImageDescriptor getDescriptor(String key)
+ {
+ ImageDescriptor descriptor = REGISTRY.getDescriptor(key);
+ if (descriptor == null)
+ {
+ descriptor = createDescriptor(key);
+ }
+
+ return descriptor;
+ }
+
+ private static ImageDescriptor createDescriptor(String key)
+ {
+ ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(OM.BUNDLE_ID, key);
+ if (descriptor != null)
+ {
+ REGISTRY.put(key, descriptor);
+ }
+
+ return descriptor;
+ }
+
+ private static Display getDisplay()
+ {
+ Display display = Display.getCurrent();
+ if (display == null)
+ {
+ display = Display.getDefault();
+ }
+
+ if (display == null)
+ {
+ throw new IllegalStateException("display == null"); //$NON-NLS-1$
+ }
+
+ return display;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/stylizer/DawnDefaultElementStylizer.java b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/stylizer/DawnDefaultElementStylizer.java
new file mode 100644
index 0000000000..20cbcd3e07
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/stylizer/DawnDefaultElementStylizer.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.ui.stylizer;
+
+import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer;
+import org.eclipse.emf.cdo.dawn.spi.DawnState;
+import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants;
+import org.eclipse.emf.cdo.dawn.ui.icons.DawnIconRegistry;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Martin Fluegge
+ * @since 2.0
+ */
+public class DawnDefaultElementStylizer implements DawnElementStylizer
+{
+ public void setDefault(Object element)
+ {
+ }
+
+ public void setConflicted(Object element, int type)
+ {
+ }
+
+ public void setLocked(Object element, int type)
+ {
+ }
+
+ public Image getImage(Object element, DawnState state)
+ {
+ switch (state)
+ {
+ case LOCKED_LOCALLY:
+ {
+ return DawnIconRegistry.getImage(DawnIconRegistry.LOCKED);
+ }
+ case LOCKED_REMOTELY:
+ {
+ return DawnIconRegistry.getImage(DawnIconRegistry.LOCKED);
+ }
+ }
+ return null;
+ }
+
+ public Color getForegroundColor(Object element, DawnState state)
+ {
+ switch (state)
+ {
+ case CONFLICT:
+ {
+ return DawnColorConstants.COLOR_DELETE_CONFLICT;
+ }
+ }
+
+ return null;
+ }
+
+ public Color getBackgroundColor(Object element, DawnState state)
+ {
+ switch (state)
+ {
+ case LOCKED_LOCALLY:
+ {
+ return DawnColorConstants.COLOR_LOCKED_LOCALLY;
+ }
+ case LOCKED_REMOTELY:
+ {
+ return DawnColorConstants.COLOR_LOCKED_REMOTELY;
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/stylizer/DawnElementStylizerRegistry.java b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/stylizer/DawnElementStylizerRegistry.java
new file mode 100644
index 0000000000..81c93b4bb2
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/stylizer/DawnElementStylizerRegistry.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.ui.stylizer;
+
+import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer;
+import org.eclipse.emf.cdo.dawn.appearance.IDawnElementStylizerFactory;
+import org.eclipse.emf.cdo.dawn.internal.ui.bundle.OM;
+
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.Platform;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This registry provides the DawnElementStylizer implementation for a given object.
+ *
+ * @see org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer
+ * @author Martin Fluegge
+ * @since 2.0
+ */
+public class DawnElementStylizerRegistry
+{
+ private static final String ATTRIBUTE_PRIORITY = "priority";
+
+ private static final String ATTRIIBUTE_FACTORY = "factory";
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnElementStylizerRegistry.class);
+
+ private static final String DAWN_STYLIZER_FACTORY_EXTENSION_POINT_ID = "org.eclipse.emf.cdo.dawn.elementstylizerfactory";
+
+ public static DawnElementStylizerRegistry instance = new DawnElementStylizerRegistry();
+
+ private Map<String, DawnElementStylizer> registeredStylizers = new HashMap<String, DawnElementStylizer>();
+
+ private Map<String, FactoryContainer> stylizerFactories = new HashMap<String, FactoryContainer>();
+
+ private DawnDefaultElementStylizer dawnDefaultElementStylizer;
+
+ /**
+ * @since 2.0
+ */
+ public DawnElementStylizer getStylizer(Object object)
+ {
+ DawnElementStylizer stylizer = registeredStylizers.get(object.getClass().getCanonicalName());
+
+ if (stylizer == null)
+ {
+ stylizer = getStylizerFromExtensionPoint(object);
+ registeredStylizers.put(object.getClass().getCanonicalName(), stylizer);
+ }
+
+ if (stylizer == null)
+ {
+ stylizer = getDefaultStylizer(object);
+ }
+
+ return stylizer;
+ }
+
+ private DawnElementStylizer getDefaultStylizer(Object object)
+ {
+ dawnDefaultElementStylizer = new DawnDefaultElementStylizer();
+ return dawnDefaultElementStylizer;
+ }
+
+ private DawnElementStylizer getStylizerFromExtensionPoint(Object object)
+ {
+ Map<String, FactoryContainer> factories = getFactories();
+ DawnElementStylizer elementStylizer = null;
+ int lastPriority = -1;
+
+ for (FactoryContainer factoryContainer : factories.values())
+ {
+ DawnElementStylizer currentElementStylizer = factoryContainer.getFactory().getElementStylizer(object);
+ if (currentElementStylizer != null)
+ {
+ int priority = factoryContainer.getPriority();
+ if (priority > lastPriority)
+ {
+ elementStylizer = currentElementStylizer;
+ lastPriority = priority;
+ }
+ }
+ }
+
+ return elementStylizer;
+ }
+
+ private Map<String, FactoryContainer> getFactories()
+ {
+ try
+ {
+ IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(
+ DAWN_STYLIZER_FACTORY_EXTENSION_POINT_ID);
+ for (IConfigurationElement e : config)
+ {
+ String factoryClassName = e.getAttribute(ATTRIIBUTE_FACTORY);
+ if (!stylizerFactories.containsKey(factoryClassName))
+ {
+ IDawnElementStylizerFactory stylizer = (IDawnElementStylizerFactory)e
+ .createExecutableExtension(ATTRIIBUTE_FACTORY);
+
+ int priority = Integer.parseInt(e.getAttribute(ATTRIBUTE_PRIORITY).substring(0, 1));
+
+ FactoryContainer container = new FactoryContainer(priority, stylizer);
+
+ stylizerFactories.put(factoryClassName, container);
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Registered IDawnElementStylizerFactory {0} ", stylizer); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ catch (InvalidRegistryObjectException e)
+ {
+ e.printStackTrace();
+ }
+ catch (CoreException e)
+ {
+ e.printStackTrace();
+ }
+
+ return stylizerFactories;
+ }
+
+ private class FactoryContainer
+ {
+ private int priority;
+
+ private IDawnElementStylizerFactory factory;
+
+ public FactoryContainer(int priority, IDawnElementStylizerFactory factory)
+ {
+ this.priority = priority;
+ this.factory = factory;
+ }
+
+ public IDawnElementStylizerFactory getFactory()
+ {
+ return factory;
+ }
+
+ public int getPriority()
+ {
+ return priority;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/views/DawnItemProvider.java b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/views/DawnItemProvider.java
index 2bd1fd1a68..86b384711f 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/views/DawnItemProvider.java
+++ b/plugins/org.eclipse.emf.cdo.dawn.ui/src/org/eclipse/emf/cdo/dawn/ui/views/DawnItemProvider.java
@@ -26,7 +26,6 @@ import org.eclipse.ui.IWorkbenchPage;
*/
public class DawnItemProvider extends CDOItemProvider
{
-
private final DawnExplorer dawnExplorer;
public DawnItemProvider(IWorkbenchPage page, DawnExplorer dawnExplorer, IElementFilter rootElementFilter)

Back to the top