Author: snjeza
Date: 2008-12-02 19:13:55 -0500 (Tue, 02 Dec 2008)
New Revision: 12226
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/ECFExamplesTransport.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java
Log:
JBIDE-3304 After download the project examples should be able to do a custom action (i.e.
show a downloaded readme.txt or cheatsheet)
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2008-12-02
23:46:57 UTC (rev 12225)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2008-12-03
00:13:55 UTC (rev 12226)
@@ -19,6 +19,7 @@
org.eclipse.equinox.p2.core,
org.eclipse.ui.ide,
org.eclipse.wst.validation,
- org.eclipse.ui.views
+ org.eclipse.ui.views,
+ org.eclipse.ui.cheatsheets
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2008-12-02
23:46:57 UTC (rev 12225)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2008-12-03
00:13:55 UTC (rev 12226)
@@ -16,7 +16,6 @@
private static final String BUNDLE_NAME =
"org.jboss.tools.project.examples.messages"; //$NON-NLS-1$
public static String Category_Other;
public static String ECFExamplesTransport_Downloading;
- public static String ECFExamplesTransport_Internal_error;
public static String ECFExamplesTransport_Internal_Error;
public static String ECFExamplesTransport_IO_error;
public static String ECFExamplesTransport_Loading;
@@ -33,6 +32,7 @@
public static String NewProjectExamplesWizard_Detail;
public static String NewProjectExamplesWizard_Downloading;
public static String NewProjectExamplesWizard_Error;
+ public static String NewProjectExamplesWizard_File_does_not_exist;
public static String NewProjectExamplesWizard_Importing;
public static String NewProjectExamplesWizard_New_Project_Example;
public static String NewProjectExamplesWizard_OverwriteProject;
@@ -47,6 +47,7 @@
public static String NewProjectExamplesWizardPage_URL;
public static String ProjectExamplesActivator_Waiting;
public static String ProjectUtil_Invalid_URL;
+ public static String ProjectUtil_Invalid_welcome_element;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/ECFExamplesTransport.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/ECFExamplesTransport.java 2008-12-02
23:46:57 UTC (rev 12225)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/ECFExamplesTransport.java 2008-12-03
00:13:55 UTC (rev 12226)
@@ -399,10 +399,10 @@
prefNode.put(IRepository.PROP_PASSWORD, loginDetails.getPassword(), true);
prefNode.flush();
} catch (StorageException e1) {
- String msg = Messages.ECFExamplesTransport_Internal_error;
+ String msg = Messages.ECFExamplesTransport_Internal_Error;
throw new CoreException(new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID,
msg, e1));
} catch (IOException e) {
- String msg = Messages.ECFExamplesTransport_Internal_error;
+ String msg = Messages.ECFExamplesTransport_Internal_Error;
throw new CoreException(new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID,
msg, e));
}
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2008-12-02
23:46:57 UTC (rev 12225)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2008-12-03
00:13:55 UTC (rev 12226)
@@ -1,6 +1,5 @@
Category_Other=Other
ECFExamplesTransport_Downloading=Downloading
-ECFExamplesTransport_Internal_error=Internal error
ECFExamplesTransport_Internal_Error=Internal Error
ECFExamplesTransport_IO_error=IO error
ECFExamplesTransport_Loading=Loading
@@ -17,6 +16,7 @@
NewProjectExamplesWizard_Detail=Detail
NewProjectExamplesWizard_Downloading=Downloading...
NewProjectExamplesWizard_Error=Error
+NewProjectExamplesWizard_File_does_not_exist=The {0} does not exist.
NewProjectExamplesWizard_Importing=Importing...
NewProjectExamplesWizard_New_Project_Example=New Project Example
NewProjectExamplesWizard_OverwriteProject=Overwrite project ''{0}''
@@ -31,3 +31,4 @@
NewProjectExamplesWizardPage_URL=URL:
ProjectExamplesActivator_Waiting=Waiting...
ProjectUtil_Invalid_URL=Invalid URL\: {0}
+ProjectUtil_Invalid_welcome_element=The welcome element has invalid the url attribute
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2008-12-02
23:46:57 UTC (rev 12225)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2008-12-03
00:13:55 UTC (rev 12226)
@@ -26,12 +26,16 @@
private long size;
private Category category;
private List<String> includedProjects;
-
+ private boolean welcome;
+ private String type;
+ private String welcomeURL;
+
public Project() {
name=""; //$NON-NLS-1$
shortDescription=""; //$NON-NLS-1$
description=""; //$NON-NLS-1$
url=""; //$NON-NLS-1$
+ welcome=false;
setCategory(Category.OTHER);
}
@@ -105,4 +109,28 @@
public void setIncludedProjects(List<String> includedProjects) {
this.includedProjects = includedProjects;
}
+
+ public boolean isWelcome() {
+ return welcome;
+ }
+
+ public void setWelcome(boolean welcome) {
+ this.welcome = welcome;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getWelcomeURL() {
+ return welcomeURL;
+ }
+
+ public void setWelcomeURL(String welcomeURL) {
+ this.welcomeURL = welcomeURL;
+ }
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2008-12-02
23:46:57 UTC (rev 12225)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2008-12-03
00:13:55 UTC (rev 12226)
@@ -47,6 +47,10 @@
*/
public class ProjectUtil {
+ private static final String EDITOR = "editor"; //$NON-NLS-1$
+
+ public static final String CHEATSHEETS = "cheatsheets"; //$NON-NLS-1$
+
private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$
private static final String PROJECT_EXAMPLES_XML_EXTENSION_ID =
"org.jboss.tools.project.examples.projectExamplesXml"; //$NON-NLS-1$
@@ -180,6 +184,22 @@
.setIncludedProjects(projectList);
}
}
+ if (nodeName.equals("welcome")) { //$NON-NLS-1$
+ project.setWelcome(true);
+ String attribute = child.getAttribute("type"); //$NON-NLS-1$
+ if (attribute != null && CHEATSHEETS.equals(attribute.trim())) {
+ project.setType(attribute.trim());
+ } else {
+ project.setType(EDITOR);
+ }
+ attribute = child.getAttribute("url"); //$NON-NLS-1$
+ if (attribute == null || attribute.trim().length() <= 0) {
+ project.setWelcome(false);
+ ProjectExamplesActivator.log(Messages.ProjectUtil_Invalid_welcome_element);
+ } else {
+ project.setWelcomeURL(attribute.trim());
+ }
+ }
}
}
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2008-12-02
23:46:57 UTC (rev 12225)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2008-12-03
00:13:55 UTC (rev 12226)
@@ -27,14 +27,19 @@
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
@@ -49,9 +54,14 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.browser.IWebBrowser;
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.dialogs.IOverwriteQuery;
-import org.eclipse.ui.internal.services.SourceProviderService;
+import org.eclipse.ui.internal.cheatsheets.state.DefaultStateManager;
+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetView;
+import org.eclipse.ui.internal.cheatsheets.views.ViewUtilities;
import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
@@ -178,7 +188,6 @@
.schedule();
ProjectExamplesActivator.waitForBuildAndValidation
.join();
-
} catch (InterruptedException e) {
return;
}
@@ -189,6 +198,7 @@
showQuickFix();
}
}
+ openWelcome();
}
public void running(IJobChangeEvent event) {
@@ -204,10 +214,70 @@
}
});
+ } else {
+ openWelcome();
}
return true;
}
+ private void openWelcome() {
+ for(final Project project:projects) {
+ if (project.isWelcome()) {
+ String urlString = project.getWelcomeURL();
+ URL url = null;
+ if (urlString.startsWith("/")) { //$NON-NLS-1$
+ IPath path = new Path(urlString);
+ IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if (resource instanceof IFile && resource.isAccessible()) {
+ try {
+ url = resource.getRawLocationURI().toURL();
+ } catch (MalformedURLException e) {
+ ProjectExamplesActivator.log(e);
+ }
+ } else {
+ ProjectExamplesActivator.log(NLS.bind(Messages.NewProjectExamplesWizard_File_does_not_exist,urlString));
+ }
+ } else {
+ try {
+ url = new URL(urlString);
+ } catch (MalformedURLException e) {
+ ProjectExamplesActivator.log(e);
+ }
+ }
+ if (url!=null) {
+ final URL finalURL = url;
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ if (ProjectUtil.CHEATSHEETS.equals(project.getType())) {
+ CheatSheetView view = ViewUtilities.showCheatSheetView();
+ if (view == null) {
+ return;
+ }
+ IPath filePath = new Path(finalURL.getPath());
+ String id = filePath.lastSegment();
+ if (id == null) {
+ id = ""; //$NON-NLS-1$
+ }
+ view.getCheatSheetViewer().setInput(id, id, finalURL, new DefaultStateManager(),
true);
+ } else {
+ try {
+ IWorkbenchBrowserSupport browserSupport =
ProjectExamplesActivator.getDefault().getWorkbench().getBrowserSupport();
+ IWebBrowser browser =
browserSupport.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR |
IWorkbenchBrowserSupport.NAVIGATION_BAR, null, null, null);
+ browser.openURL(finalURL);
+ } catch (PartInitException e) {
+ ProjectExamplesActivator.log(e);
+ }
+ }
+ }
+
+ });
+
+ }
+ }
+ }
+ }
+
private void showQuickFix() {
Display.getDefault().asyncExec(new Runnable() {