Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2013-09-04 19:58:36 +0000
committerChristian W. Damus2013-09-06 18:39:02 +0000
commit08ad54d115a32e64c69fa578a67653acfb565907 (patch)
tree54e92c59a4592c9ad7cce1b47d507cccfd10ce20 /extraplugins
parent5fbf74b32bca5ac1980b170c34abe0afc2c55cd5 (diff)
downloadorg.eclipse.papyrus-08ad54d115a32e64c69fa578a67653acfb565907.tar.gz
org.eclipse.papyrus-08ad54d115a32e64c69fa578a67653acfb565907.tar.xz
org.eclipse.papyrus-08ad54d115a32e64c69fa578a67653acfb565907.zip
415371: User-friendly labels for CDO resources in search results
https://bugs.eclipse.org/bugs/show_bug.cgi?id=415371
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/cdo/org.eclipse.papyrus.cdo.ui/META-INF/MANIFEST.MF3
-rw-r--r--extraplugins/cdo/org.eclipse.papyrus.cdo.ui/plugin.xml7
-rw-r--r--extraplugins/cdo/org.eclipse.papyrus.cdo.ui/src/org/eclipse/papyrus/cdo/internal/ui/providers/CDOResourceLabelProvider.java118
3 files changed, 127 insertions, 1 deletions
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/META-INF/MANIFEST.MF b/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/META-INF/MANIFEST.MF
index b6340fc3d61..5ab654329e3 100644
--- a/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/META-INF/MANIFEST.MF
+++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/META-INF/MANIFEST.MF
@@ -18,7 +18,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.papyrus.cdo.validation.problems.edit;bundle-version="0.10.1",
org.eclipse.papyrus.editor;bundle-version="0.10.1",
org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="0.10.1",
- com.google.guava;bundle-version="[11.0.0,12.0.0)"
+ com.google.guava;bundle-version="[11.0.0,12.0.0)",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="0.10.1"
Export-Package: org.eclipse.papyrus.cdo.internal.ui;x-friends:="org.eclipse.papyrus.cdo.ui.tests,org.eclipse.papyrus.cdo.uml.ui",
org.eclipse.papyrus.cdo.internal.ui.actions;x-friends:="org.eclipse.papyrus.cdo.ui.tests",
org.eclipse.papyrus.cdo.internal.ui.adapters;x-friends:="org.eclipse.papyrus.cdo.ui.tests",
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/plugin.xml b/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/plugin.xml
index 95960890212..e58fbcbc747 100644
--- a/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/plugin.xml
+++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/plugin.xml
@@ -321,4 +321,11 @@
id="org.eclipse.papyrus.cdo.ui.modelDropAction">
</action>
</extension>
+ <extension
+ point="org.eclipse.papyrus.infra.services.labelprovider.labelProvider">
+ <labelProvider
+ priority="255"
+ provider="org.eclipse.papyrus.cdo.internal.ui.providers.CDOResourceLabelProvider">
+ </labelProvider>
+ </extension>
</plugin>
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/src/org/eclipse/papyrus/cdo/internal/ui/providers/CDOResourceLabelProvider.java b/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/src/org/eclipse/papyrus/cdo/internal/ui/providers/CDOResourceLabelProvider.java
new file mode 100644
index 00000000000..cc17023136b
--- /dev/null
+++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/src/org/eclipse/papyrus/cdo/internal/ui/providers/CDOResourceLabelProvider.java
@@ -0,0 +1,118 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.cdo.internal.ui.providers;
+
+import org.eclipse.emf.cdo.eresource.CDOBinaryResource;
+import org.eclipse.emf.cdo.eresource.CDOFileResource;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
+import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.eresource.CDOTextResource;
+import org.eclipse.emf.cdo.eresource.util.EresourceSwitch;
+import org.eclipse.emf.cdo.util.CDOURIUtil;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.cdo.core.IPapyrusRepository;
+import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
+import org.eclipse.papyrus.cdo.internal.core.PapyrusRepositoryManager;
+import org.eclipse.papyrus.cdo.internal.ui.Activator;
+import org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * A provider of labels for CDO resources and URIs for CDO resources in the Papyrus label-provider service.
+ */
+public class CDOResourceLabelProvider extends LabelProvider implements IFilteredLabelProvider {
+
+ private final ResourceManager images = new LocalResourceManager(JFaceResources.getResources());
+
+ private final EresourceSwitch<String> nodeTypeSwitch = createNodeTypeSwitch();
+
+ public CDOResourceLabelProvider() {
+ super();
+ }
+
+ public boolean accept(Object element) {
+ return (element instanceof CDOResourceNode) || (element instanceof URI) && CDOUtils.isCDOURI((URI)element);
+ }
+
+ @Override
+ public void dispose() {
+ images.dispose();
+
+ super.dispose();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ return images.createImage(Activator.getIcon(Activator.ICON_OPEN_REPOSITORY));
+ }
+
+ @Override
+ public String getText(Object element) {
+ String result = null;
+
+ URI uri = (element instanceof URI) ? (URI)element : ((CDOResourceNode)element).getURI();
+
+ if(uri != null) {
+ String nodeType = element instanceof CDOResourceNode ? nodeTypeSwitch.doSwitch((CDOResource)element) : "Node";
+ String path = CDOURIUtil.extractResourcePath(uri);
+ IPapyrusRepository repo = PapyrusRepositoryManager.INSTANCE.getRepositoryForURI(uri);
+ String repoName = (repo == null) ? "(unknown)" : repo.getName();
+
+ result = NLS.bind("{0} {1} in repository \"{2}\"", new Object[]{ nodeType, path, repoName });
+ }
+
+ return result;
+ }
+
+ private EresourceSwitch<String> createNodeTypeSwitch() {
+ return new EresourceSwitch<String>() {
+
+ @Override
+ public String defaultCase(EObject object) {
+ return "Node";
+ }
+
+ @Override
+ public String caseCDOResource(CDOResource object) {
+ return "Model";
+ }
+
+ @Override
+ public String caseCDOResourceFolder(CDOResourceFolder object) {
+ return "Folder";
+ }
+
+ @Override
+ public String caseCDOBinaryResource(CDOBinaryResource object) {
+ return "Binary file";
+ }
+
+ @Override
+ public String caseCDOTextResource(CDOTextResource object) {
+ return "Text file";
+ }
+
+ @Override
+ public String caseCDOFileResource(CDOFileResource<?> object) {
+ return "File";
+ }
+ };
+ }
+}

Back to the top