Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Roldan Betancort2008-12-30 14:58:57 -0500
committerVictor Roldan Betancort2008-12-30 14:58:57 -0500
commite28e0f3492b5a8895bb683d31255b4305ed2ad12 (patch)
tree766eeb7a09d99434ef24704809fb688b77e0d2ce /plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util
parentf3f2c372b54a1f0c4a2fc723841a3909ac8c3953 (diff)
downloadcdo-e28e0f3492b5a8895bb683d31255b4305ed2ad12.tar.gz
cdo-e28e0f3492b5a8895bb683d31255b4305ed2ad12.tar.xz
cdo-e28e0f3492b5a8895bb683d31255b4305ed2ad12.zip
[259518] Create a Container based CDOViewProvider
https://bugs.eclipse.org/bugs/show_bug.cgi?id=259518
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderImpl.java48
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderRegistryImpl.java96
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PluginContainerViewProvider.java79
3 files changed, 165 insertions, 58 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderImpl.java
deleted file mode 100644
index ece60dd4fa..0000000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderImpl.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * 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:
- * Victor Roldan Betancort - initial API and implementation
- **************************************************************************/
-package org.eclipse.emf.internal.cdo.util;
-
-import org.eclipse.emf.cdo.CDOView;
-import org.eclipse.emf.cdo.CDOViewSet;
-import org.eclipse.emf.cdo.util.AbstractCDOViewProvider;
-import org.eclipse.emf.cdo.util.CDOURIUtil;
-
-import org.eclipse.emf.common.util.URI;
-
-/**
- * Emulates the same behaviour as before the CDOViewProvider concept was introduced. Will provide a view from an already
- * populated <code>CDOViewSet</code>
- *
- * @author Victor Roldan Betancort
- * @since 2.0
- */
-public class CDOViewProviderImpl extends AbstractCDOViewProvider
-{
- public CDOViewProviderImpl()
- {
- super("cdo:.*");
- }
-
- public CDOView getView(URI uri, CDOViewSet viewSet)
- {
- if (viewSet == null)
- {
- throw new IllegalArgumentException("viewSet == null");
- }
- if (uri == null)
- {
- throw new IllegalArgumentException("uri == null");
- }
-
- String repositoryUUID = CDOURIUtil.extractRepositoryUUID(uri);
- return viewSet.resolveView(repositoryUUID);
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderRegistryImpl.java
index c5dd643f8e..ce5d2464cf 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderRegistryImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOViewProviderRegistryImpl.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.internal.cdo.util;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.CDOViewSet;
import org.eclipse.emf.cdo.util.AbstractCDOViewProvider;
+import org.eclipse.emf.cdo.util.CDOURIUtil;
import org.eclipse.emf.cdo.util.CDOViewProvider;
import org.eclipse.emf.cdo.util.CDOViewProviderRegistry;
@@ -31,6 +32,8 @@ import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
/**
@@ -51,26 +54,95 @@ public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider> impl
public CDOViewProviderRegistryImpl()
{
- addViewProvider(new CDOViewProviderImpl());
+ addViewProvider(new PluginContainerViewProvider());
}
- public CDOViewProvider getViewProvider(URI uri)
+ public CDOView provideView(URI uri, CDOViewSet viewSet)
{
- CDOViewProvider result = null;
- for (CDOViewProvider viewProvider : viewProviders)
+ if (uri == null)
{
- if (viewProvider.matchesRegex(uri))
+ return null;
+ }
+
+ if (viewSet != null)
+ {
+ try
{
- if (result == null || result.getPriority() < viewProvider.getPriority())
+ String uuid = CDOURIUtil.extractRepositoryUUID(uri);
+ CDOView view = viewSet.resolveView(uuid);
+ if (view != null)
{
- result = viewProvider;
+ return view;
}
}
+ catch (Exception ignore)
+ {
+ // Do nothing
+ }
}
- return result;
+ for (CDOViewProvider viewProvider : getViewProviders(uri))
+ {
+ CDOView view = viewProvider.getView(uri, viewSet);
+ if (view != null)
+ {
+ return view;
+ }
+ }
+
+ return null;
}
+ public CDOViewProvider[] getViewProviders(URI uri)
+ {
+ List<CDOViewProvider> result = new ArrayList<CDOViewProvider>();
+ for (CDOViewProvider viewProvider : viewProviders)
+ {
+ if (viewProvider.matchesRegex(uri))
+ {
+ result.add(viewProvider);
+ }
+ }
+
+ // Sort highest priority first
+ Collections.sort(result, new Comparator<CDOViewProvider>()
+ {
+ public int compare(CDOViewProvider o1, CDOViewProvider o2)
+ {
+ return -new Integer(o1.getPriority()).compareTo(o2.getPriority());
+ }
+ });
+
+ return result.toArray(new CDOViewProvider[result.size()]);
+ }
+
+ // public CDOViewProvider[] getViewProviders(URI uri, CDOViewSet viewSet)
+ // {
+ // List<CDOViewProvider> orderedProviders = new ArrayList<CDOViewProvider>();
+ // for (CDOViewProvider viewProvider : viewProviders)
+ // {
+ // if (viewProvider.matchesRegex(uri))
+ // {
+ // for (int i = orderedProviders.size() - 1; i >= 0; i--)
+ // {
+ // if (viewProvider.getPriority() <= orderedProviders.get(i).getPriority())
+ // {
+ // orderedProviders.add(i + 1, viewProvider);
+ // break;
+ // }
+ // }
+ //
+ // // if not inserted, it has highest priority
+ // if (!orderedProviders.contains(viewProvider))
+ // {
+ // orderedProviders.add(0, viewProvider);
+ // }
+ // }
+ // }
+ //
+ // return orderedProviders.toArray(new CDOViewProvider[orderedProviders.size()]);
+ // }
+
public void addViewProvider(CDOViewProvider viewProvider)
{
boolean added;
@@ -186,10 +258,14 @@ public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider> impl
public CDOView getView(URI uri, CDOViewSet viewSet)
{
+ return getViewProvider().getView(uri, viewSet);
+ }
+
+ private CDOViewProvider getViewProvider()
+ {
try
{
- CDOViewProvider viewProvider = (CDOViewProvider)element.createExecutableExtension("class");
- return viewProvider.getView(uri, viewSet);
+ return (CDOViewProvider)element.createExecutableExtension("class");
}
catch (CoreException ex)
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PluginContainerViewProvider.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PluginContainerViewProvider.java
new file mode 100644
index 0000000000..19762a77bc
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PluginContainerViewProvider.java
@@ -0,0 +1,79 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Victor Roldan Betancort - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.util;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.CDOViewSet;
+import org.eclipse.emf.cdo.util.CDOURIUtil;
+import org.eclipse.emf.cdo.util.CDOViewProvider;
+import org.eclipse.emf.cdo.util.ManagedContainerViewProvider;
+
+import org.eclipse.emf.internal.cdo.CDOSessionFactory;
+
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.IPluginContainer;
+
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * Provides <code>CDOView</code> from <code>CDOSession</code> registered in IPluginContainer
+ *
+ * @author Victor Roldan Betancort
+ */
+public class PluginContainerViewProvider extends ManagedContainerViewProvider implements CDOViewProvider
+{
+ private final static String REGEX = "cdo:.*";
+
+ private final static int PRIORITY = 400;
+
+ public PluginContainerViewProvider()
+ {
+ super(IPluginContainer.INSTANCE, REGEX, PRIORITY);
+ }
+
+ public CDOView getView(URI uri, CDOViewSet viewSet)
+ {
+ IManagedContainer container = getContainer();
+ if (container == null)
+ {
+ return null;
+ }
+
+ String repoUUID = CDOURIUtil.extractRepositoryUUID(uri);
+ for (Object element : container.getElements(CDOSessionFactory.PRODUCT_GROUP, CDOSessionFactory.TYPE))
+ {
+ CDOSession session = (CDOSession)element;
+ String uuid = session.repository().getUUID();
+ if (repoUUID.equals(uuid))
+ {
+ CDOView view = openView(session, uri);
+ if (view != null)
+ {
+ return view;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ protected IManagedContainer getContainer()
+ {
+ return IPluginContainer.INSTANCE;
+ }
+
+ protected CDOView openView(CDOSession session, URI uri)
+ {
+ return session.openTransaction();
+ }
+}

Back to the top