diff options
author | nitind | 2010-03-01 18:33:27 +0000 |
---|---|---|
committer | nitind | 2010-03-01 18:33:27 +0000 |
commit | 61decee16d6165d05d73c7732d8604b527d5a0b1 (patch) | |
tree | 9135de4486ce2069254b69c720a0b0503446cb97 | |
parent | e4d0b002d06b28cec83cf93b6684cc27dcf6e83f (diff) | |
download | webtools.jsdt.core-61decee16d6165d05d73c7732d8604b527d5a0b1.tar.gz webtools.jsdt.core-61decee16d6165d05d73c7732d8604b527d5a0b1.tar.xz webtools.jsdt.core-61decee16d6165d05d73c7732d8604b527d5a0b1.zip |
[274550] [explorer] Clean up and streamline explorer UI
7 files changed, 241 insertions, 73 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.core/plugin.properties b/bundles/org.eclipse.wst.jsdt.core/plugin.properties index d691f096..c4f8cb56 100644 --- a/bundles/org.eclipse.wst.jsdt.core/plugin.properties +++ b/bundles/org.eclipse.wst.jsdt.core/plugin.properties @@ -25,4 +25,5 @@ jsSourceName=JavaScript Source File jsonSourceName=JS Object Notation File -extension-point.name.0 = Support for Inferrencing +extension-point.name.0 = Support for Inferencing +extension-point.name.1 = Default source path provider diff --git a/bundles/org.eclipse.wst.jsdt.core/plugin.xml b/bundles/org.eclipse.wst.jsdt.core/plugin.xml index c6ba6d7e..d123f955 100644 --- a/bundles/org.eclipse.wst.jsdt.core/plugin.xml +++ b/bundles/org.eclipse.wst.jsdt.core/plugin.xml @@ -52,6 +52,7 @@ <!-- =================================================================================== --> <extension-point id="inferrenceSupport" name="%extension-point.name.0" schema="schema/inferrenceSupport.exsd"/> +<extension-point id="sourcePathProvider" name="%extension-point.name.1" schema="schema/sourcePathProvider.exsd"/> <!-- =================================================================================== --> <!-- Extension: JavaScript Nature --> diff --git a/bundles/org.eclipse.wst.jsdt.core/schema/sourcePathProvider.exsd b/bundles/org.eclipse.wst.jsdt.core/schema/sourcePathProvider.exsd new file mode 100644 index 00000000..59053da5 --- /dev/null +++ b/bundles/org.eclipse.wst.jsdt.core/schema/sourcePathProvider.exsd @@ -0,0 +1,102 @@ +<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.wst.jsdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.wst.jsdt.core" id="sourcePathProvider" name="s"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element internal="true" />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <choice>
+ <element ref="provider"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="provider">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.wst.jsdt.internal.core.util.DefaultSourcePathProvider:"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/util/ConvertUtility.java b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/util/ConvertUtility.java index 638f7fe4..7060293a 100644 --- a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/util/ConvertUtility.java +++ b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/util/ConvertUtility.java @@ -17,11 +17,15 @@ import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.wst.jsdt.core.IAccessRule; import org.eclipse.wst.jsdt.core.IIncludePathAttribute; @@ -31,7 +35,7 @@ import org.eclipse.wst.jsdt.core.LibrarySuperType; import org.eclipse.wst.jsdt.internal.core.JavaProject; public class ConvertUtility { - private static final String NATURE_IDS[] = { JavaScriptCore.NATURE_ID }; + private static final String NATURE_IDS[] = {JavaScriptCore.NATURE_ID}; private static final String SYSTEM_LIBRARY = org.eclipse.wst.jsdt.launching.JavaRuntime.JRE_CONTAINER; //$NON-NLS-1$ private static final String SYSTEM_SUPER_TYPE_NAME = "Global"; //$NON-NLS-1$ @@ -39,11 +43,11 @@ public class ConvertUtility { private static final String BROWSER_LIBRARY = org.eclipse.wst.jsdt.launching.JavaRuntime.BASE_BROWSER_LIB; //$NON-NLS-1$ public static final IPath BROWSER_LIBRARY_PATH = new Path(BROWSER_LIBRARY); private static final String BROWSER_SUPER_TYPE_NAME = "Window"; //$NON-NLS-1$ - + public static final String VIRTUAL_CONTAINER = "org.eclipse.wst.jsdt.launching.WebProject"; //$NON-NLS-1$ - public static final IIncludePathEntry VIRTUAL_SCOPE_ENTRY = JavaScriptCore.newContainerEntry(new Path(VIRTUAL_CONTAINER), new IAccessRule[0], new IIncludePathAttribute[] {IIncludePathAttribute.HIDE}, false); - - + public static final IIncludePathEntry VIRTUAL_SCOPE_ENTRY = JavaScriptCore.newContainerEntry(new Path(VIRTUAL_CONTAINER), new IAccessRule[0], new IIncludePathAttribute[]{IIncludePathAttribute.HIDE}, false); + + static void addJsNature(IProject project, IProgressMonitor monitor) throws CoreException { if (monitor != null && monitor.isCanceled()) { throw new OperationCanceledException(); @@ -59,13 +63,14 @@ public class ConvertUtility { } description.setNatureIds(newNatures); project.setDescription(description, monitor); - } else { + } + else { if (monitor != null) { monitor.worked(1); } } } - + public static boolean hasNature(IProject project) { try { for (int i = 0; i < NATURE_IDS.length; i++) { @@ -73,12 +78,13 @@ public class ConvertUtility { return false; } } - } catch (CoreException ex) { + } + catch (CoreException ex) { return false; } return true; } - + static void removeJsNature(IProject project, IProgressMonitor monitor) throws CoreException { if (monitor != null && monitor.isCanceled()) { throw new OperationCanceledException(); @@ -88,7 +94,7 @@ public class ConvertUtility { String[] prevNatures = description.getNatureIds(); String[] newNatures = new String[prevNatures.length - NATURE_IDS.length]; int k = 0; - head: for (int i = 0; i < prevNatures.length; i++) { + head : for (int i = 0; i < prevNatures.length; i++) { for (int j = 0; j < NATURE_IDS.length; j++) { if (prevNatures[i].equals(NATURE_IDS[j])) { continue head; @@ -98,28 +104,30 @@ public class ConvertUtility { } description.setNatureIds(newNatures); project.setDescription(description, monitor); - } else { + } + else { if (monitor != null) { monitor.worked(1); } } } + private boolean DEBUG = false; private IProject fCurrProject; private JavaProject fJavaProject; private IPath fOutputLocation; - + public ConvertUtility(IProject project) { fCurrProject = project; fOutputLocation = fCurrProject.getFullPath(); } - + private IProgressMonitor monitorFor(IProgressMonitor monitor) { if (monitor != null) return monitor; return new NullProgressMonitor(); } - + public void addBrowserSupport(boolean changeSuperType, IProgressMonitor monitor) throws CoreException { IProgressMonitor progressMonitor = monitorFor(monitor); progressMonitor.beginTask(Messages.converter_ConfiguringForBrowser, 2); @@ -131,8 +139,8 @@ public class ConvertUtility { IIncludePathEntry[] includePath = getRawClassPath(); includePath = addEntry(includePath, VIRTUAL_SCOPE_ENTRY, false); - includePath = addEntry(includePath, JavaScriptCore.newContainerEntry( BROWSER_LIBRARY_PATH), false); - + includePath = addEntry(includePath, JavaScriptCore.newContainerEntry(BROWSER_LIBRARY_PATH), false); + try { if (!hasProjectClassPathFile()) { fJavaProject.setRawIncludepath(includePath, fOutputLocation, new SubProgressMonitor(progressMonitor, 1)); @@ -144,17 +152,17 @@ public class ConvertUtility { catch (Exception e) { System.out.println(e); } - + if (changeSuperType) { LibrarySuperType superType = new LibrarySuperType(BROWSER_LIBRARY_PATH, getJavaScriptProject(), BROWSER_SUPER_TYPE_NAME); getJavaScriptProject().setCommonSuperType(superType); } - + // getJavaProject().addToBuildSpec(BUILDER_ID); // fCurrProject.refreshLocal(IResource.DEPTH_INFINITE, monitor); progressMonitor.done(); } - + private IIncludePathEntry[] addEntry(IIncludePathEntry[] entries, IIncludePathEntry newEntry, boolean first) { for (int i = 0; i < entries.length; i++) { // avoid duplicate IIncludePathEntry-s @@ -162,72 +170,76 @@ public class ConvertUtility { return entries; } } - - List entriesList = new ArrayList(Arrays.asList(entries)); + + List entriesList = new ArrayList(Arrays.asList(entries)); if (first && !entriesList.isEmpty()) entriesList.add(0, newEntry); else entriesList.add(newEntry); return (IIncludePathEntry[]) entriesList.toArray(new IIncludePathEntry[entriesList.size()]); } - -// private void createSourceClassPath() { -// if (hasAValidSourcePath()) { -// return; -// } -// // IPath projectPath = fCurrProject.getFullPath(); -// // classPathEntries.add(JavaScriptCore.newSourceEntry(projectPath)); -// } - -// public void deconfigure() throws CoreException { -// Vector badEntries = new Vector(); -// IIncludePathEntry defaultJRELibrary = createRuntimeEntry(); -// IIncludePathEntry[] localEntries = initLocalClassPath(); -// badEntries.add(defaultJRELibrary); -// badEntries.addAll(Arrays.asList(localEntries)); -// IIncludePathEntry[] entries = getRawClassPath(); -// List goodEntries = new ArrayList(); -// for (int i = 0; i < entries.length; i++) { -// if (!badEntries.contains(entries[i])) { -// goodEntries.add(entries[i]); -// } -// } -// IPath outputLocation = getJavaScriptProject().getOutputLocation(); -// getJavaScriptProject().setRawIncludepath((IIncludePathEntry[]) goodEntries.toArray(new IIncludePathEntry[] {}), outputLocation, monitor); -// -// // getJavaProject().removeFromBuildSpec(BUILDER_ID); -// getJavaScriptProject().deconfigure(); -// -// removeJsNature(fCurrProject, monitor); -// fCurrProject.refreshLocal(IResource.DEPTH_INFINITE, monitor); -// } - + + // private void createSourceClassPath() { + // if (hasAValidSourcePath()) { + // return; + // } + // // IPath projectPath = fCurrProject.getFullPath(); + // // classPathEntries.add(JavaScriptCore.newSourceEntry(projectPath)); + // } + + // public void deconfigure() throws CoreException { + // Vector badEntries = new Vector(); + // IIncludePathEntry defaultJRELibrary = createRuntimeEntry(); + // IIncludePathEntry[] localEntries = initLocalClassPath(); + // badEntries.add(defaultJRELibrary); + // badEntries.addAll(Arrays.asList(localEntries)); + // IIncludePathEntry[] entries = getRawClassPath(); + // List goodEntries = new ArrayList(); + // for (int i = 0; i < entries.length; i++) { + // if (!badEntries.contains(entries[i])) { + // goodEntries.add(entries[i]); + // } + // } + // IPath outputLocation = getJavaScriptProject().getOutputLocation(); + // getJavaScriptProject().setRawIncludepath((IIncludePathEntry[]) + // goodEntries.toArray(new IIncludePathEntry[] {}), outputLocation, + // monitor); + // + // // getJavaProject().removeFromBuildSpec(BUILDER_ID); + // getJavaScriptProject().deconfigure(); + // + // removeJsNature(fCurrProject, monitor); + // fCurrProject.refreshLocal(IResource.DEPTH_INFINITE, monitor); + // } + private IIncludePathEntry[] addSystemEntry(IIncludePathEntry[] entries) { - IIncludePathEntry defaultJRELibrary = createRuntimeEntry(); + IIncludePathEntry defaultJRELibrary = createRuntimeEntry(); try { for (int i = 0; i < entries.length; i++) { if (defaultJRELibrary.equals(entries[i])) { return entries; } } - } catch (Exception e) { + } + catch (Exception e) { if (DEBUG) { System.out.println("Error checking system library in include path:" + e); //$NON-NLS-1$ } } return addEntry(entries, defaultJRELibrary, false); } - + public void configure(IProgressMonitor monitor) throws CoreException { IProgressMonitor progressMonitor = monitorFor(monitor); progressMonitor.beginTask("", 2);//$NON-NLS-1$ addJsNature(fCurrProject, new SubProgressMonitor(progressMonitor, 1)); + fJavaProject = (JavaProject) JavaScriptCore.create(fCurrProject); fJavaProject.setProject(fCurrProject); IIncludePathEntry[] includePath = getRawClassPath(); includePath = addSystemEntry(includePath); - + try { if (!hasProjectClassPathFile()) { fJavaProject.setRawIncludepath(includePath, fOutputLocation, new SubProgressMonitor(progressMonitor, 1)); @@ -239,19 +251,19 @@ public class ConvertUtility { catch (Exception e) { System.out.println(e); } - + LibrarySuperType superType = new LibrarySuperType(new Path(SYSTEM_LIBRARY), getJavaScriptProject(), SYSTEM_SUPER_TYPE_NAME); getJavaScriptProject().setCommonSuperType(superType); progressMonitor.done(); - + // getJavaProject().addToBuildSpec(BUILDER_ID); // fCurrProject.refreshLocal(IResource.DEPTH_INFINITE, monitor); } - + private IIncludePathEntry createRuntimeEntry() { return JavaScriptCore.newContainerEntry(new Path(SYSTEM_LIBRARY)); } - + private JavaProject getJavaScriptProject() { if (fJavaProject == null) { fJavaProject = (JavaProject) JavaScriptCore.create(fCurrProject); @@ -259,17 +271,36 @@ public class ConvertUtility { } return fJavaProject; } - + public IProject getProject() { return this.fCurrProject; } - + + public IIncludePathEntry[] getDefaultSourcePaths(IProject p) { + IIncludePathEntry[] defaults = new IIncludePathEntry[]{JavaScriptCore.newSourceEntry(p.getFullPath())}; + try { + IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.wst.jsdt.core.sourcePathProvider"); + for (int i = 0; i < configurationElements.length; i++) { + DefaultSourcePathProvider provider = (DefaultSourcePathProvider) configurationElements[i].createExecutableExtension("class"); + if (provider != null) { + return provider.getDefaultSourcePaths(p); + } + } + } + catch (Exception e) { + if (Platform.inDebugMode()) { + Platform.getLog(JavaScriptCore.getPlugin().getBundle()).log(new Status(IStatus.ERROR, JavaScriptCore.PLUGIN_ID, "Problem getting source paths", e)); + } + } + return defaults; + } + private IIncludePathEntry[] getRawClassPath() { JavaProject proj = new JavaProject(); proj.setProject(fCurrProject); return proj.readRawIncludepath(); } - + private boolean hasAValidSourcePath() { if (hasProjectClassPathFile()) { try { @@ -279,7 +310,8 @@ public class ConvertUtility { return true; } } - } catch (Exception e) { + } + catch (Exception e) { if (DEBUG) { System.out.println("Error checking sourcepath:" + e); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/util/DefaultSourcePathProvider.java b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/util/DefaultSourcePathProvider.java new file mode 100644 index 00000000..a148ea62 --- /dev/null +++ b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/util/DefaultSourcePathProvider.java @@ -0,0 +1,24 @@ +/*******************************************************************************
+ * Copyright (c) 2010 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
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.internal.core.util;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.wst.jsdt.core.IIncludePathEntry;
+import org.eclipse.wst.jsdt.core.JavaScriptCore;
+
+public abstract class DefaultSourcePathProvider {
+ public DefaultSourcePathProvider() {
+ }
+
+ public IIncludePathEntry[] getDefaultSourcePaths(IProject p) {
+ return new IIncludePathEntry[]{JavaScriptCore.newSourceEntry(p.getFullPath())};
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.ui/plugin.properties b/bundles/org.eclipse.wst.jsdt.ui/plugin.properties index bb1bb12a..406f6570 100644 --- a/bundles/org.eclipse.wst.jsdt.ui/plugin.properties +++ b/bundles/org.eclipse.wst.jsdt.ui/plugin.properties @@ -1020,4 +1020,4 @@ wizard.description.0 = Create a new JavaScript file extension-point.name.0 = JsGlobalScopeUIInitializer extension-point.name.1 = JsGlobalScopeUIInitializer -action.label.projectConvert=Convert to JavaScript Project +action.label.projectConvert=Convert to JavaScript Project... diff --git a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/util/ConvertAction.java b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/util/ConvertAction.java index 80129147..f49fc8d5 100644 --- a/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/util/ConvertAction.java +++ b/bundles/org.eclipse.wst.jsdt.ui/src/org/eclipse/wst/jsdt/internal/ui/util/ConvertAction.java @@ -22,7 +22,6 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; @@ -42,6 +41,7 @@ import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.ui.progress.IProgressService; import org.eclipse.wst.jsdt.core.IIncludePathEntry; import org.eclipse.wst.jsdt.core.IJavaScriptProject; +import org.eclipse.wst.jsdt.core.IPackageFragmentRoot; import org.eclipse.wst.jsdt.core.JavaScriptCore; import org.eclipse.wst.jsdt.core.JavaScriptModelException; import org.eclipse.wst.jsdt.internal.core.JavaProject; @@ -79,15 +79,23 @@ public class ConvertAction implements IObjectActionDelegate, IActionDelegate { IIncludePathEntry[] oldEntries = null; try { oldEntries = jp.getRawIncludepath(); + List entries = new ArrayList(); + for (int i = 0; i < oldEntries.length; i++) { + if (oldEntries[i].getContentKind() != IPackageFragmentRoot.K_SOURCE || oldEntries[i].getEntryKind() != IIncludePathEntry.CPE_SOURCE) { + entries.add(oldEntries[i]); + } + } + oldEntries = (IIncludePathEntry[]) entries.toArray(new IIncludePathEntry[entries.size()]); } catch (JavaScriptModelException ex1) { Logger.log(Logger.ERROR_DEBUG, null, ex1); oldEntries = new IIncludePathEntry[0]; } - IIncludePathEntry[] newEntries = new IIncludePathEntry[oldEntries.length + 1]; - System.arraycopy(oldEntries, 0, newEntries, 1, oldEntries.length); - IPath projectPath = project.getFullPath(); - newEntries[0] = JavaScriptCore.newSourceEntry(projectPath); + IIncludePathEntry[] sourcePaths = convertor.getDefaultSourcePaths(project); + IIncludePathEntry[] newEntries = new IIncludePathEntry[oldEntries.length + sourcePaths.length]; + System.arraycopy(sourcePaths, 0, newEntries, 0, sourcePaths.length); + System.arraycopy(oldEntries, 0, newEntries, sourcePaths.length, oldEntries.length); + try { jp.setRawIncludepath(newEntries, project.getFullPath(), new SubProgressMonitor(monitor, 1)); @@ -107,7 +115,7 @@ public class ConvertAction implements IObjectActionDelegate, IActionDelegate { } monitor.done(); } - + private void doUninstall(IProject project, IProgressMonitor monitor) { // ConvertUtility nature = new ConvertUtility(project); // try { |