aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek Pospychala2012-10-09 08:11:08 (EDT)
committerJacek Pospychala2012-10-09 08:11:08 (EDT)
commita31d347ee34126b11f427724d6c2daaa6e319193 (patch)
tree44874f0c416311d90155f4415cfbb7937a5111c0
parentca80dbce11103a4d99da22e4f1736f75ac3f1bfb (diff)
downloadorg.eclipse.pdt-a31d347ee34126b11f427724d6c2daaa6e319193.zip
org.eclipse.pdt-a31d347ee34126b11f427724d6c2daaa6e319193.tar.gz
org.eclipse.pdt-a31d347ee34126b11f427724d6c2daaa6e319193.tar.bz2
Bug 391432 - Implement phpTreeContentProvider extension point
-rw-r--r--plugins/org.eclipse.php.ui/schema/phpTreeContentProviders.exsd57
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerContentProvider.java50
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerLabelProvider.java25
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/TreeContentProviderRegistry.java93
4 files changed, 184 insertions, 41 deletions
diff --git a/plugins/org.eclipse.php.ui/schema/phpTreeContentProviders.exsd b/plugins/org.eclipse.php.ui/schema/phpTreeContentProviders.exsd
index 3798ae7..852f584 100644
--- a/plugins/org.eclipse.php.ui/schema/phpTreeContentProviders.exsd
+++ b/plugins/org.eclipse.php.ui/schema/phpTreeContentProviders.exsd
@@ -1,16 +1,21 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.php.ui">
+<schema targetNamespace="org.eclipse.php.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.php.ui" id="phpTreeContentProviders" name="PHP Tree Content Provider"/>
</appInfo>
<documentation>
- This extension points allows to provide content providers for a Tree Viewer used for displaying PHP elements (PHP Explorer, Outline, Project Outline, etc&apos;). Standard PHP Element Content Provider (the default one) collects all content providers contributed via extension point, and concatenates their contents.
+ This extension points allows to provide content providers for a Tree Viewer used for displaying PHP elements in the PHP Explorer. Standard PHP Explorer Content Provider (the default one) collects all content providers contributed via extension point, and concatenates their contents.
</documentation>
</annotation>
<element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="provider" minOccurs="1" maxOccurs="unbounded"/>
@@ -44,21 +49,24 @@
<element name="provider">
<complexType>
- <attribute name="class" type="string" use="required">
+ <attribute name="labelProvider" type="string" use="required">
<annotation>
<documentation>
- PHP tree content provider&apos;s class
+ PHP tree label provider&apos;s class
</documentation>
<appInfo>
- <meta.attribute kind="java" basedOn="org.eclipse.php.ui.treecontent.IPHPTreeContentProvider"/>
+ <meta.attribute kind="java" basedOn=":org.eclipse.jface.viewers.ILabelProvider"/>
</appInfo>
</annotation>
</attribute>
- <attribute name="targetId" type="string">
+ <attribute name="contentProvider" type="string" use="required">
<annotation>
<documentation>
- A comma-separated list of tree viewers, this content provider is applicable to.
+ PHP tree content provider&apos;s class
</documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.jface.viewers.ITreeContentProvider"/>
+ </appInfo>
</annotation>
</attribute>
</complexType>
@@ -66,47 +74,38 @@
<annotation>
<appInfo>
- <meta.section type="since"/>
+ <meta.section type="apiInfo"/>
</appInfo>
<documentation>
- 0.7
+ PHP tree content provider class must implement &lt;code&gt;org.eclipse.php.ui.treecontent.IPHPTreeContentProvider&lt;/code&gt;.
</documentation>
</annotation>
<annotation>
<appInfo>
- <meta.section type="examples"/>
+ <meta.section type="since"/>
</appInfo>
<documentation>
- &lt;p&gt;
-&lt;pre&gt;
- &lt;extension point=&quot;org.eclipse.php.ui.phpTreeContentProviders&quot;&gt;
- &lt;provider
- class=&quot;org.eclipse.php.ui.treecontent.IncludePathTreeContent&quot;
- targetId=&quot;org.eclipse.php.ui.explorer&quot; /&gt;
- &lt;/extension&gt;
-&lt;/pre&gt;
-&lt;/p&gt;
+ 3.1.2
</documentation>
</annotation>
<annotation>
<appInfo>
- <meta.section type="apiInfo"/>
+ <meta.section type="examples"/>
</appInfo>
<documentation>
- PHP tree content provider class must implement &lt;code&gt;org.eclipse.php.ui.treecontent.IPHPTreeContentProvider&lt;/code&gt;.
+ &lt;p&gt;
+&lt;pre&gt;
+ &lt;extension point=&quot;org.eclipse.php.ui.phpTreeContentProviders&quot;&gt;
+ &lt;provider
+ class=&quot;org.eclipse.php.ui.treecontent.IncludePathTreeContent&quot;/&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+&lt;/p&gt;
</documentation>
</annotation>
- <annotation>
- <appInfo>
- <meta.section type="implementation"/>
- </appInfo>
- <documentation>
- Look at &lt;code&gt;org.eclipse.php.ui.treecontent.IncludePathTreeContent&lt;/code&gt;, which is contributed to PHP Explorer.
- </documentation>
- </annotation>
<annotation>
<appInfo>
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerContentProvider.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerContentProvider.java
index 170ac74..dfe1d5a 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerContentProvider.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerContentProvider.java
@@ -28,6 +28,7 @@ import org.eclipse.dltk.internal.core.*;
import org.eclipse.dltk.internal.ui.StandardModelElementContentProvider;
import org.eclipse.dltk.internal.ui.navigator.ScriptExplorerContentProvider;
import org.eclipse.dltk.internal.ui.scriptview.BuildPathContainer;
+import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.php.internal.core.PHPVersion;
import org.eclipse.php.internal.core.includepath.IIncludepathListener;
@@ -58,7 +59,7 @@ import org.eclipse.wst.jsdt.ui.project.JsNature;
public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
implements IIncludepathListener /* , IResourceChangeListener */,
IElementChangedListener {
- public final static ArrayList EMPTY_LIST = new ArrayList();
+ public final static ArrayList<Object> EMPTY_LIST = new ArrayList<Object>();
StandardJavaScriptElementContentProvider jsContentProvider;
public PHPExplorerContentProvider(boolean provideMembers) {
@@ -161,6 +162,17 @@ public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
return (Object[]) returnChlidren
.toArray(new Object[returnChlidren.size()]);
}
+
+ for (ITreeContentProvider provider : TreeContentProviderRegistry
+ .getInstance().getTreeProviders()) {
+
+ Object[] providerChildren = provider
+ .getChildren(parentElement);
+ if (providerChildren != null) {
+ return providerChildren;
+ }
+ }
+
return super.getChildren(parentElement);
}
@@ -177,7 +189,7 @@ public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
return NO_CHILDREN;
}
- ArrayList<Object> returnChlidren = new ArrayList<Object>();
+ ArrayList<Object> returnChildren = new ArrayList<Object>();
boolean groupByNamespace = PHPUiPlugin
.getDefault()
@@ -187,9 +199,9 @@ public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
if (groupByNamespace
&& parentElement instanceof IScriptProject
&& supportsNamespaces((IScriptProject) parentElement)) {
- returnChlidren.add(new GlobalNamespace(
+ returnChildren.add(new GlobalNamespace(
(IScriptProject) parentElement));
- returnChlidren
+ returnChildren
.addAll(Arrays
.asList(getAllNamespaces((IScriptProject) parentElement)));
@@ -200,7 +212,7 @@ public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
.create(resource2);
if (modelElement == null
|| !isInSourceFolder(modelElement)) {
- returnChlidren.add(resource2);
+ returnChildren.add(resource2);
}
}
} else {
@@ -211,9 +223,9 @@ public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
.create(resource2);
if (modelElement != null
&& isInSourceFolder(modelElement)) {
- returnChlidren.add(modelElement);
+ returnChildren.add(modelElement);
} else {
- returnChlidren.add(resource2);
+ returnChildren.add(resource2);
}
}
}
@@ -228,7 +240,7 @@ public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
.getInstance().getIncludePaths(project);
IncludePathContainer incPathContainer = new IncludePathContainer(
scriptProject, includePaths);
- returnChlidren.add(incPathContainer);
+ returnChildren.add(incPathContainer);
// Add the language library
Object[] projectChildren = getProjectFragments(scriptProject);
@@ -238,7 +250,7 @@ public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
.getBuildpathEntry()
.getPath()
.equals(LanguageModelInitializer.LANGUAGE_CONTAINER_PATH)) {
- returnChlidren.add(modelElement);
+ returnChildren.add(modelElement);
}
}
@@ -246,19 +258,33 @@ public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
if (hasJsNature) {
ProjectLibraryRoot projectLibs = new ProjectLibraryRoot(
JavaScriptCore.create(project));
- returnChlidren.add(projectLibs);
+ returnChildren.add(projectLibs);
+ }
+
+ // let extensions contribute explorer root elements
+ for (ITreeContentProvider provider : TreeContentProviderRegistry
+ .getInstance().getTreeProviders()) {
+
+ Object[] providerChildren = provider
+ .getChildren(parentElement);
+ if (providerChildren != null) {
+ returnChildren.addAll(new ArrayList<Object>(
+ Arrays.asList(providerChildren)));
+ }
}
}
- return returnChlidren.toArray();
+ return returnChildren.toArray();
}
}
} catch (CoreException e) {
Logger.logException(e);
}
+
if (parentElement instanceof ArchiveProjectFragment
|| parentElement instanceof ArchiveFolder) {
return super.getChildren(parentElement);
}
+
return NO_CHILDREN;
}
@@ -361,7 +387,7 @@ public class PHPExplorerContentProvider extends ScriptExplorerContentProvider
return new Object[0];
ArrayList<IJavaScriptElement> allChildren = new ArrayList<IJavaScriptElement>();
- ArrayList expanded = new ArrayList();
+ ArrayList<Object> expanded = new ArrayList<Object>();
expanded.addAll(Arrays.asList(children));
if (expanded == null || expanded.size() < 1)
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerLabelProvider.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerLabelProvider.java
index e7b86fd..566205e 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerLabelProvider.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/PHPExplorerLabelProvider.java
@@ -21,6 +21,7 @@ import org.eclipse.dltk.internal.core.ExternalProjectFragment;
import org.eclipse.dltk.internal.ui.navigator.ScriptExplorerContentProvider;
import org.eclipse.dltk.internal.ui.navigator.ScriptExplorerLabelProvider;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.php.core.compiler.PHPFlags;
import org.eclipse.php.internal.core.includepath.IncludePath;
import org.eclipse.php.internal.core.language.LanguageModelInitializer;
@@ -124,6 +125,18 @@ public class PHPExplorerLabelProvider extends ScriptExplorerLabelProvider {
}
} catch (ModelException e) {
}
+
+ if (element != null) {
+ for (ILabelProvider provider : TreeContentProviderRegistry
+ .getInstance().getLabelProviders()) {
+ Image image = provider.getImage(element);
+
+ if (image != null) {
+ return image;
+ }
+ }
+ }
+
return super.getImage(element);
}
@@ -190,6 +203,18 @@ public class PHPExplorerLabelProvider extends ScriptExplorerLabelProvider {
return null;
}
+
+ if (element != null) {
+ for (ILabelProvider provider : TreeContentProviderRegistry
+ .getInstance().getLabelProviders()) {
+ String label = provider.getText(element);
+
+ if (label != null) {
+ return label;
+ }
+ }
+ }
+
return super.getText(element);
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/TreeContentProviderRegistry.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/TreeContentProviderRegistry.java
new file mode 100644
index 0000000..220f0d5
--- /dev/null
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/explorer/TreeContentProviderRegistry.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ * Zend Technologies
+ *******************************************************************************/
+package org.eclipse.php.internal.ui.explorer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.*;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.php.internal.ui.Logger;
+import org.eclipse.php.internal.ui.PHPUiPlugin;
+
+/**
+ *
+ * Registry for phpTreeContentProviders extension point contributions.
+ *
+ * @since 3.1.2
+ * @author Robert Gruendler <r.gruendler@gmail.com>
+ */
+public class TreeContentProviderRegistry {
+
+ private static final String EXTENSION_POINT = "phpTreeContentProviders"; //$NON-NLS-1$
+ private static final String LABEL_PROVIDER = "labelProvider"; //$NON-NLS-1$
+ private static final String CONTENT_PROVIDER = "contentProvider"; //$NON-NLS-1$
+
+ private static TreeContentProviderRegistry instance;
+ private List<ITreeContentProvider> contentProviders = new ArrayList<ITreeContentProvider>();
+ private List<ILabelProvider> labelProviders = new ArrayList<ILabelProvider>();
+
+ private TreeContentProviderRegistry() {
+
+ IExtensionPoint extension = Platform.getExtensionRegistry()
+ .getExtensionPoint(PHPUiPlugin.ID, EXTENSION_POINT);
+ if (extension != null) {
+ IExtension[] extensions = extension.getExtensions();
+ for (int i = 0; i < extensions.length; i++) {
+ IConfigurationElement[] configElements = extensions[i]
+ .getConfigurationElements();
+ for (int j = 0; j < configElements.length; j++) {
+ IConfigurationElement configElement = configElements[j];
+ try {
+
+ Object execExt = configElement
+ .createExecutableExtension(CONTENT_PROVIDER); //$NON-NLS-1$
+ if (execExt instanceof ITreeContentProvider) {
+ contentProviders
+ .add((ITreeContentProvider) execExt);
+ }
+
+ Object labelProvider = configElement
+ .createExecutableExtension(LABEL_PROVIDER); //$NON-NLS-1$
+ if (labelProvider instanceof ILabelProvider) {
+ labelProviders.add((ILabelProvider) labelProvider);
+ }
+
+ } catch (CoreException e) {
+ // executable extension could not be
+ // created: ignore
+ // this initializer
+ Logger.logException(e);
+ }
+ }
+ }
+ }
+ }
+
+ public synchronized static TreeContentProviderRegistry getInstance() {
+
+ if (instance == null) {
+ instance = new TreeContentProviderRegistry();
+ }
+
+ return instance;
+ }
+
+ public List<ITreeContentProvider> getTreeProviders() {
+ return contentProviders;
+ }
+
+ public List<ILabelProvider> getLabelProviders() {
+ return labelProviders;
+ }
+}