Author: snjeza
Date: 2008-10-08 11:39:37 -0400 (Wed, 08 Oct 2008)
New Revision: 10749
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/.classpath
trunk/examples/plugins/org.jboss.tools.project.examples/.project
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
trunk/examples/plugins/org.jboss.tools.project.examples/about.html
trunk/examples/plugins/org.jboss.tools.project.examples/about.ini
trunk/examples/plugins/org.jboss.tools.project.examples/about.mappings
trunk/examples/plugins/org.jboss.tools.project.examples/about.properties
trunk/examples/plugins/org.jboss.tools.project.examples/build.properties
trunk/examples/plugins/org.jboss.tools.project.examples/icons/
trunk/examples/plugins/org.jboss.tools.project.examples/icons/examples_wiz.gif
trunk/examples/plugins/org.jboss.tools.project.examples/icons/new_wiz.gif
trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml
trunk/examples/plugins/org.jboss.tools.project.examples/projectExamples.xml
trunk/examples/plugins/org.jboss.tools.project.examples/rhds_wiz.png
trunk/examples/plugins/org.jboss.tools.project.examples/src/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/
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/model/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java
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/
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/NewProjectExamplesWizardPage.java
Log:
Initial import.
Added: trunk/examples/plugins/org.jboss.tools.project.examples/.classpath
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/.classpath
(rev 0)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/.classpath 2008-10-08 15:39:37
UTC (rev 10749)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/examples/plugins/org.jboss.tools.project.examples/.project
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/.project
(rev 0)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/.project 2008-10-08 15:39:37
UTC (rev 10749)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.project.examples</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Project Examples
+Bundle-SymbolicName: org.jboss.tools.project.examples;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.jboss.tools.project.examples.ProjectExamplesActivator
+Bundle-Vendor: Red Hat, inc
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.jface,
+ org.eclipse.osgi,
+ org.eclipse.ecf,
+ org.eclipse.ecf.filetransfer,
+ org.eclipse.equinox.common,
+ org.eclipse.ecf.provider.filetransfer,
+ org.eclipse.equinox.security,
+ org.eclipse.equinox.p2.engine,
+ org.eclipse.equinox.p2.core,
+ org.eclipse.ui.ide
+Bundle-ActivationPolicy: lazy
Added: trunk/examples/plugins/org.jboss.tools.project.examples/about.html
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/about.html
(rev 0)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/about.html 2008-10-08 15:39:37
UTC (rev 10749)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1" />
+<title>Project Examples</title>
+<style type="text/css" media="screen">
+<!--
+ body {
+ font-family: Sans-serif, Arial, Helvetica;
+ }
+
+-->
+</style>
+</head>
+<body>
+<h1>JBoss Portlet</h1>
+
+<p>
+This plugin is part of the JBoss Tools developed by the <a
href="http://www.jboss.com">JBoss Inc.</a>
+</p>
+
+<p>Information about this plugin is available at <a
href="http://www.jboss.org/tools">JBoss Tools project
page</a></p>
+
+<p>
+This software is distributed under the terms of the Eclipse Public License - v 1.0
+(see <a
href="www.eclipse.org/legal/epl-v10.html">Eclipse Public License
- Version 1.0</a>).
+</p>
+</body>
+</html>
\ No newline at end of file
Added: trunk/examples/plugins/org.jboss.tools.project.examples/about.ini
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/about.ini
(rev 0)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/about.ini 2008-10-08 15:39:37
UTC (rev 10749)
@@ -0,0 +1,27 @@
+# about.ini
+# contains information about a feature
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# "%key" are externalized strings defined in about.properties
+# This file does not need to be translated.
+# test
+# Property "aboutText" contains blurb for "About" dialog
(translated)
+aboutText=%blurb
+
+# Property "windowImage" contains path to window icon (16x16)
+# needed for primary features only
+
+# Property "featureImage" contains path to feature image (32x32)
+featureImage=rhds_wiz.png
+
+# Property "aboutImage" contains path to product image (500x330 or 115x164)
+# needed for primary features only
+
+# Property "appName" contains name of the application (not translated)
+# needed for primary features only
+
+# Property "welcomePerspective" contains the id of the perspective in which
the
+# welcome page is to be opened.
+# optional
+
+
+
Added: trunk/examples/plugins/org.jboss.tools.project.examples/about.mappings
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/about.mappings
(rev 0)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/about.mappings 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,5 @@
+# about.mappings
+# contains fill-ins for about.properties
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# This file does not need to be translated.
+
Added: trunk/examples/plugins/org.jboss.tools.project.examples/about.properties
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/about.properties
(rev 0)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/about.properties 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,2 @@
+blurb=JBoss Project Examples\n\nVersion\: {featureVersion}\n\n(c) Copyright JBoss Inc.
contributors and others 2004 - 2008. All rights reserved.\nVisit http\://jboss.org/tools
+
Added: trunk/examples/plugins/org.jboss.tools.project.examples/build.properties
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/build.properties
(rev 0)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/build.properties 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,7 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ icons/,\
+ projectExamples.xml
Added: trunk/examples/plugins/org.jboss.tools.project.examples/icons/examples_wiz.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/examples/plugins/org.jboss.tools.project.examples/icons/examples_wiz.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/examples/plugins/org.jboss.tools.project.examples/icons/new_wiz.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/examples/plugins/org.jboss.tools.project.examples/icons/new_wiz.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml
(rev 0)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml 2008-10-08 15:39:37
UTC (rev 10749)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+ <extension point="org.eclipse.ui.newWizards">
+ <category
+ name="JBoss Tools"
+ id="org.jboss.ide.eclipse.ui.wizards">
+ </category>
+ <wizard
+ id="org.jboss.tools.project.examples.wizard.NewProjectExamplesWizard"
+ name="Project Examples"
+ class="org.jboss.tools.project.examples.wizard.NewProjectExamplesWizard"
+ category="org.jboss.ide.eclipse.ui.wizards"
+ icon="icons/examples_wiz.gif">
+ </wizard>
+ </extension>
+</plugin>
Added: trunk/examples/plugins/org.jboss.tools.project.examples/projectExamples.xml
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/projectExamples.xml
(rev 0)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/projectExamples.xml 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,46 @@
+<projects>
+ <project>
+ <category>Seam</category>
+ <name>dvdstore</name>
+ <shortDescription>Seam DVD Store Example</shortDescription>
+ <description>This example demonstrates the use of Seam with jBPM pageflow and
business process management. It runs on JBoss AS and Tomcat.</description>
+ <size>10000000</size>
+ <url>
+
http://anonsvn.jboss.org/repos/jbosstools/workspace/snjeza/seam-examples/...
+ </url>
+ </project>
+
+ <project>
+ <category>Portlet</category>
+ <name>TestJavaPortlet</name>
+ <shortDescription>JBoss Java Portlet Example</shortDescription>
+ <description>This example demonstrates the use of JBoss Java Portlet. It runs on
JBoss Portal 2.7.0.</description>
+ <size>10000</size>
+ <url>
+
http://anonsvn.jboss.org/repos/jbosstools/workspace/snjeza/portlet-exampl...
+ </url>
+ </project>
+
+ <project>
+ <category>Portlet</category>
+ <name>TestJSFPortlet</name>
+ <shortDescription>JBoss JSF Portlet Example</shortDescription>
+ <description>This example demonstrates the use of JBoss JSF Portlet. It runs on
JBoss Portal 2.7.0.</description>
+ <size>4000000</size>
+ <url>
+
http://anonsvn.jboss.org/repos/jbosstools/workspace/snjeza/portlet-exampl...
+ </url>
+ </project>
+
+ <project>
+ <category>Portlet</category>
+ <name>TestSeamPortlet</name>
+ <shortDescription>JBoss Seam Portlet Example</shortDescription>
+ <description>This example demonstrates the use of JBoss Seam Portlet. It runs on
JBoss Portal 2.7.0.</description>
+ <size>10000000</size>
+ <url>
+
http://anonsvn.jboss.org/repos/jbosstools/workspace/snjeza/portlet-exampl...
+ </url>
+ </project>
+
+</projects>
\ No newline at end of file
Added: trunk/examples/plugins/org.jboss.tools.project.examples/rhds_wiz.png
===================================================================
(Binary files differ)
Property changes on: trunk/examples/plugins/org.jboss.tools.project.examples/rhds_wiz.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,72 @@
+package org.jboss.tools.project.examples;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ProjectExamplesActivator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.tools.project.examples";
+
+ // The shared instance
+ private static ProjectExamplesActivator plugin;
+
+ private static BundleContext context;
+
+ /**
+ * The constructor
+ */
+ public ProjectExamplesActivator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ this.context = context;
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ plugin = null;
+ context = null;
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static ProjectExamplesActivator getDefault() {
+ return plugin;
+ }
+
+ public static void log(Throwable e) {
+ IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e
+ .getLocalizedMessage(), e);
+ ProjectExamplesActivator.getDefault().getLog().log(status);
+ }
+
+ public static BundleContext getBundleContext() {
+ return context;
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/ECFExamplesTransport.java 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,435 @@
+package org.jboss.tools.project.examples.filetransfer;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.ProtocolException;
+import java.net.URL;
+import java.net.URLEncoder;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.ecf.core.ContainerCreateException;
+import org.eclipse.ecf.core.ContainerFactory;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.security.ConnectContextFactory;
+import org.eclipse.ecf.core.security.IConnectContext;
+import org.eclipse.ecf.filetransfer.IFileTransferListener;
+import org.eclipse.ecf.filetransfer.IIncomingFileTransfer;
+import org.eclipse.ecf.filetransfer.IRemoteFile;
+import org.eclipse.ecf.filetransfer.IRemoteFileSystemBrowserContainerAdapter;
+import org.eclipse.ecf.filetransfer.IRemoteFileSystemListener;
+import org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter;
+import org.eclipse.ecf.filetransfer.IncomingFileTransferException;
+import org.eclipse.ecf.filetransfer.RemoteFileSystemException;
+import org.eclipse.ecf.filetransfer.UserCancelledException;
+import org.eclipse.ecf.filetransfer.events.IFileTransferEvent;
+import org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDataEvent;
+import org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent;
+import org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent;
+import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemBrowseEvent;
+import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemEvent;
+import org.eclipse.ecf.filetransfer.identity.FileCreateException;
+import org.eclipse.ecf.filetransfer.identity.FileIDFactory;
+import org.eclipse.ecf.filetransfer.service.IRetrieveFileTransferFactory;
+import org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer;
+import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
+import org.eclipse.equinox.internal.provisional.p2.core.IServiceUI;
+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
+import org.eclipse.equinox.internal.provisional.p2.core.IServiceUI.AuthenticationInfo;
+import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.StorageException;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * @author snjeza
+ * based on org.eclipse.equinox.internal.p2.updatesite.ECFTransport
+ *
+ */
+public class ECFExamplesTransport {
+
+ /**
+ * The number of password retry attempts allowed before failing.
+ */
+ private static final int LOGIN_RETRIES = 3;
+ private static final ProtocolException ERROR_401 = new ProtocolException();
+ private static final String SERVER_REDIRECT = "Server redirected too many
times";
+
+ private static ECFExamplesTransport INSTANCE;
+ private ServiceTracker retrievalFactoryTracker;
+
+ /**
+ * A job that waits on a barrier.
+ */
+ static class WaitJob extends Job {
+ private final Object[] barrier;
+
+ /**
+ * Creates a wait job.
+ * @param location A location string that is used in the job name
+ * @param barrier The job will wait until the first entry in the barrier is non-null
+ */
+ WaitJob(String location, Object[] barrier) {
+ super("Loading");
+ this.barrier = barrier;
+ setSystem(true);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected IStatus run(IProgressMonitor monitor) {
+ synchronized (barrier) {
+ while (barrier[0] == null) {
+ try {
+ barrier.wait();
+ } catch (InterruptedException e) {
+ //ignore
+ }
+ }
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ /**
+ * Private to avoid client instantiation.
+ */
+ private ECFExamplesTransport() {
+ retrievalFactoryTracker = new
ServiceTracker(ProjectExamplesActivator.getBundleContext(),
IRetrieveFileTransferFactory.class.getName(), null);
+ retrievalFactoryTracker.open();
+ }
+
+ /**
+ * Returns an initialized instance of ECFExamplesTransport
+ */
+ public static synchronized ECFExamplesTransport getInstance() {
+ if (INSTANCE == null) {
+ INSTANCE = new ECFExamplesTransport();
+ }
+ return INSTANCE;
+ }
+
+ /**
+ * Gets the last modified date for the specified file.
+ * @param location - The URL location of the file.
+ * @return A <code>long</code> representing the date. Returns
<code>0</code> if the file is not found or an error occurred.
+ * @exception OperationCanceledException if the request was canceled.
+ */
+ public long getLastModified(URL location) throws CoreException {
+ String locationString = location.toExternalForm();
+ try {
+ IConnectContext context = getConnectionContext(locationString, false);
+ for (int i = 0; i < LOGIN_RETRIES; i++) {
+ try {
+ return doGetLastModified(locationString, context);
+ } catch (ProtocolException e) {
+ if (ERROR_401 == e)
+ context = getConnectionContext(locationString, true);
+ } catch (Exception e) {
+ e.getMessage();
+ }
+ }
+ } catch (UserCancelledException e) {
+ throw new OperationCanceledException();
+ }
+ //too many retries, so report as failure
+ throw new CoreException(new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID,
"IO error", null));
+ }
+
+ /**
+ * Perform the ECF call to get the last modified time, failing if there is any
+ * protocol failure such as an authentication failure.
+ */
+ private long doGetLastModified(String location, IConnectContext context) throws
ProtocolException {
+ IContainer container;
+ try {
+ container = ContainerFactory.getDefault().createContainer();
+ } catch (ContainerCreateException e) {
+ return 0;
+ }
+ IRemoteFileSystemBrowserContainerAdapter adapter =
(IRemoteFileSystemBrowserContainerAdapter)
container.getAdapter(IRemoteFileSystemBrowserContainerAdapter.class);
+ if (adapter == null) {
+ return 0;
+ }
+ IRemoteFile remoteFile = checkFile(adapter, location, context);
+ if (remoteFile == null) {
+ return 0;
+ }
+ return remoteFile.getInfo().getLastModified();
+ }
+
+ /**
+ * Downloads the contents of the given URL to the given output stream. The
+ * destination stream will be closed by this method whether it succeeds
+ * to download or not.
+ */
+ public IStatus download(String name,String url, OutputStream destination,
IProgressMonitor monitor) {
+ try {
+ IConnectContext context = getConnectionContext(url, false);
+ for (int i = 0; i < LOGIN_RETRIES; i++) {
+ try {
+ return performDownload(name,url, destination, context, monitor);
+ } catch (ProtocolException e) {
+ if (e == ERROR_401)
+ context = getConnectionContext(url, true);
+ }
+ }
+ } catch (UserCancelledException e) {
+ return Status.CANCEL_STATUS;
+ } catch (CoreException e) {
+ return e.getStatus();
+ } finally {
+ try {
+ destination.close();
+ } catch (IOException e) {
+ //ignore secondary failure
+ }
+ }
+ //reached maximum number of retries without success
+ return new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID, "IO
error", null);
+ }
+
+ public IStatus performDownload(String name,String toDownload, OutputStream target,
IConnectContext context, IProgressMonitor monitor) throws ProtocolException {
+ IRetrieveFileTransferFactory factory = (IRetrieveFileTransferFactory)
retrievalFactoryTracker.getService();
+ if (factory == null)
+ return new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID, "IO
error");
+
+ return transfer(name,factory.newInstance(), toDownload, target, context, monitor);
+ }
+
+ private IStatus transfer(final String name,final IRetrieveFileTransferContainerAdapter
retrievalContainer, final String toDownload, final OutputStream target, IConnectContext
context, final IProgressMonitor monitor) throws ProtocolException {
+ final IStatus[] result = new IStatus[1];
+ IFileTransferListener listener = new IFileTransferListener() {
+ private long transferStartTime;
+ protected int oldWorked;
+
+ public void handleTransferEvent(IFileTransferEvent event) {
+ if (event instanceof IIncomingFileTransferReceiveStartEvent) {
+ IIncomingFileTransferReceiveStartEvent rse =
(IIncomingFileTransferReceiveStartEvent) event;
+ try {
+ if (target != null) {
+ rse.receive(target);
+ transferStartTime = System.currentTimeMillis();
+ }
+ if (monitor != null) {
+ long fileLength = rse.getSource().getFileLength();
+ final long totalWork = ((fileLength == -1) ? 100 : fileLength);
+ int work = (totalWork > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)
totalWork;
+ monitor.beginTask("Downloading " + name,work);
+ oldWorked=0;
+ }
+ } catch (IOException e) {
+ IStatus status = convertToStatus(e);
+ synchronized (result) {
+ result[0] = status;
+ result.notify();
+ }
+ }
+ }
+ if (event instanceof IIncomingFileTransferReceiveDataEvent) {
+ IIncomingFileTransfer source = ((IIncomingFileTransferReceiveDataEvent)
event).getSource();
+ if (monitor != null) {
+ if (monitor.isCanceled()) {
+ source.cancel();
+ return;
+ }
+ long fileLength = source.getFileLength();
+ final long totalWork = ((fileLength == -1) ? 100 : fileLength);
+ double factor = (totalWork > Integer.MAX_VALUE) ? (((double) Integer.MAX_VALUE)
/ ((double) totalWork)) : 1.0;
+ long received = source.getBytesReceived();
+ int worked = (int) Math.round(factor * received);
+ double downloadRateBytesPerSecond = (received / ((System.currentTimeMillis() + 1 -
transferStartTime) / 1000.0));
+
+ String rates = String.format(" (at %s/s)",
AbstractRetrieveFileTransfer.toHumanReadableBytes(downloadRateBytesPerSecond));
+ String receivedString =
AbstractRetrieveFileTransfer.toHumanReadableBytes(received);
+ String fileLengthString =
AbstractRetrieveFileTransfer.toHumanReadableBytes(fileLength);
+ monitor.subTask(receivedString + " of " + fileLengthString + rates);
+ monitor.worked(worked-oldWorked);
+ oldWorked=worked;
+ }
+ }
+ if (event instanceof IIncomingFileTransferReceiveDoneEvent) {
+ Exception exception = ((IIncomingFileTransferReceiveDoneEvent)
event).getException();
+ IStatus status = convertToStatus(exception);
+ synchronized (result) {
+ result[0] = status;
+ result.notify();
+ }
+ }
+ }
+ };
+
+ try {
+ retrievalContainer.setConnectContextForAuthentication(context);
+ retrievalContainer.sendRetrieveRequest(FileIDFactory.getDefault().createFileID(retrievalContainer.getRetrieveNamespace(),
toDownload), listener, null);
+ } catch (IncomingFileTransferException e) {
+ IStatus status = e.getStatus();
+ Throwable exception = status.getException();
+ if (exception instanceof IOException) {
+ if (exception.getMessage() != null &&
(exception.getMessage().indexOf("401") != -1 ||
exception.getMessage().indexOf(SERVER_REDIRECT) != -1)) //$NON-NLS-1$
+ throw ERROR_401;
+ }
+ return status;
+ } catch (FileCreateException e) {
+ return e.getStatus();
+ }
+ waitFor(toDownload, result);
+ return result[0];
+ }
+
+ private IRemoteFile checkFile(final IRemoteFileSystemBrowserContainerAdapter
retrievalContainer, final String location, IConnectContext context) throws
ProtocolException {
+ final Object[] result = new Object[2];
+ final Object FAIL = new Object();
+ IRemoteFileSystemListener listener = new IRemoteFileSystemListener() {
+ public void handleRemoteFileEvent(IRemoteFileSystemEvent event) {
+ Exception exception = event.getException();
+ if (exception != null) {
+ synchronized (result) {
+ result[0] = FAIL;
+ result[1] = exception;
+ result.notify();
+ }
+ } else if (event instanceof IRemoteFileSystemBrowseEvent) {
+ IRemoteFileSystemBrowseEvent fsbe = (IRemoteFileSystemBrowseEvent) event;
+ IRemoteFile[] remoteFiles = fsbe.getRemoteFiles();
+ if (remoteFiles != null && remoteFiles.length > 0 &&
remoteFiles[0] != null) {
+ synchronized (result) {
+ result[0] = remoteFiles[0];
+ result.notify();
+ }
+ } else {
+ synchronized (result) {
+ result[0] = FAIL;
+ result.notify();
+ }
+ }
+ }
+ }
+ };
+ try {
+ retrievalContainer.setConnectContextForAuthentication(context);
+ retrievalContainer.sendBrowseRequest(FileIDFactory.getDefault().createFileID(retrievalContainer.getBrowseNamespace(),
location), listener);
+ } catch (RemoteFileSystemException e) {
+ return null;
+ } catch (FileCreateException e) {
+ return null;
+ }
+ waitFor(location, result);
+ if (result[0] == FAIL && result[1] instanceof IOException) {
+ IOException ioException = (IOException) result[1];
+ //throw a special exception for authentication failure so we know to prompt for
username/password
+ String message = ioException.getMessage();
+ if (message != null && (message.indexOf(" 401 ") != -1 ||
message.indexOf(SERVER_REDIRECT) != -1)) //$NON-NLS-1$
+ throw ERROR_401;
+ }
+ if (result[0] instanceof IRemoteFile)
+ return (IRemoteFile) result[0];
+ return null;
+ }
+
+
+ /**
+ * Returns the connection context for the given URL. This may prompt the
+ * user for user name and password as required.
+ *
+ * @param xmlLocation - the file location requiring login details
+ * @param prompt - use <code>true</code> to prompt the user instead of
+ * looking at the secure preference store for login, use <code>false</code>
+ * to only try the secure preference store
+ * @throws UserCancelledException when the user cancels the login prompt
+ * @throws CoreException if the password cannot be read or saved
+ * @return The connection context
+ */
+ public IConnectContext getConnectionContext(String xmlLocation, boolean prompt) throws
UserCancelledException, CoreException {
+ ISecurePreferences securePreferences = SecurePreferencesFactory.getDefault();
+ IPath hostLocation = new Path(xmlLocation).removeLastSegments(1);
+ String nodeKey;
+ try {
+ nodeKey = URLEncoder.encode(hostLocation.toString(), "UTF-8");
//$NON-NLS-1$
+ } catch (UnsupportedEncodingException e2) {
+ //fall back to default platform encoding
+ nodeKey = URLEncoder.encode(hostLocation.toString());
+ }
+ String nodeName = IRepository.PREFERENCE_NODE + '/' + nodeKey;
+ ISecurePreferences prefNode = null;
+ if (securePreferences.nodeExists(nodeName))
+ prefNode = securePreferences.node(nodeName);
+ if (!prompt) {
+ if (prefNode == null)
+ return null;
+ try {
+ String username = prefNode.get(IRepository.PROP_USERNAME, null);
+ String password = prefNode.get(IRepository.PROP_PASSWORD, null);
+ //if we don't have stored connection data just return a null connection context
+ if (username == null || password == null)
+ return null;
+ return ConnectContextFactory.createUsernamePasswordConnectContext(username,
password);
+ } catch (StorageException e) {
+ String msg = "Internal Error";
+ throw new CoreException(new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID,
msg, e));
+ }
+ }
+ //need to prompt user for user name and password
+ ServiceTracker adminUITracker = new
ServiceTracker(ProjectExamplesActivator.getBundleContext(), IServiceUI.class.getName(),
null);
+ adminUITracker.open();
+ IServiceUI adminUIService = (IServiceUI) adminUITracker.getService();
+ AuthenticationInfo loginDetails = null;
+ if (adminUIService != null)
+ loginDetails = adminUIService.getUsernamePassword(hostLocation.toString());
+ //null result means user canceled password dialog
+ if (loginDetails == null)
+ throw new UserCancelledException();
+ //save user name and password if requested by user
+ if (loginDetails.saveResult()) {
+ if (prefNode == null)
+ prefNode = securePreferences.node(nodeName);
+ try {
+ prefNode.put(IRepository.PROP_USERNAME, loginDetails.getUserName(), true);
+ prefNode.put(IRepository.PROP_PASSWORD, loginDetails.getPassword(), true);
+ prefNode.flush();
+ } catch (StorageException e1) {
+ String msg = "Internal error";
+ throw new CoreException(new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID,
msg, e1));
+ } catch (IOException e) {
+ String msg = "Internal error";
+ throw new CoreException(new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID,
msg, e));
+ }
+ }
+ return
ConnectContextFactory.createUsernamePasswordConnectContext(loginDetails.getUserName(),
loginDetails.getPassword());
+ }
+
+ private IStatus convertToStatus(Exception e) {
+ if (e == null)
+ return Status.OK_STATUS;
+ if (e instanceof UserCancelledException)
+ return new Status(IStatus.CANCEL, ProjectExamplesActivator.PLUGIN_ID, e.getMessage(),
e);
+ return new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID, e.getMessage(),
e);
+ }
+
+ /**
+ * Waits until the first entry in the given array is non-null.
+ */
+ private void waitFor(String location, Object[] barrier) {
+ WaitJob wait = new WaitJob(location, barrier);
+ wait.schedule();
+ while (barrier[0] == null) {
+ boolean logged = false;
+ try {
+ wait.join();
+ } catch (InterruptedException e) {
+ if (!logged)
+ LogHelper.log(new Status(IStatus.WARNING, ProjectExamplesActivator.PLUGIN_ID,
"Unexpected interrupt while waiting on ECF transfer", e));
+ }
+ }
+ }
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,72 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat 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:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.project.examples.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author snjeza
+ *
+ */
+public class Category {
+
+ private String name;
+ private List<Project> projects = new ArrayList<Project>();
+ public static Category OTHER = new Category("Other");
+
+ public Category(String name) {
+ super();
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<Project> getProjects() {
+ return projects;
+ }
+
+ public void setProjects(List<Project> projects) {
+ this.projects = projects;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Category other = (Category) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,98 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat 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:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.project.examples.model;
+
+import java.math.BigDecimal;
+
+/**
+ * @author snjeza
+ *
+ */
+public class Project {
+
+ private String name;
+ private String shortDescription;
+ private String description;
+ private String url;
+ private long size;
+ private Category category;
+
+ public Project() {
+ name="";
+ shortDescription="";
+ description="";
+ url="";
+ setCategory(Category.OTHER);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getShortDescription() {
+ return shortDescription;
+ }
+
+ public void setShortDescription(String shortDescription) {
+ this.shortDescription = shortDescription;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public long getSize() {
+ return size;
+ }
+
+ public void setSize(long size) {
+ this.size = size;
+ }
+
+ public Category getCategory() {
+ return category;
+ }
+
+ public void setCategory(Category category) {
+ this.category = category;
+ }
+
+ public String getSizeAsText() {
+ String sizeString = "";
+ BigDecimal sizeDecimal = new BigDecimal(size);
+ BigDecimal MB = new BigDecimal(1024*1024);
+ BigDecimal KB = new BigDecimal(1024);
+ if (sizeDecimal.compareTo(MB) > 0) {
+ sizeString = String.format("%5.2fM", sizeDecimal.divide(MB));
+ } else if (sizeDecimal.compareTo(KB) > 0) {
+ sizeString = String.format("%5.2fK", sizeDecimal.divide(KB));
+ } else {
+ sizeString = String.format("%d", size);
+ }
+ return sizeString;
+ }
+}
Added:
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
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,242 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat 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:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.project.examples.model;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.filetransfer.ECFExamplesTransport;
+import org.osgi.framework.Bundle;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author snjeza
+ *
+ */
+public class ProjectUtil {
+
+ private final static String PROJECT_EXAMPLES_XML =
"http://anonsvn.jboss.org/repos/jbosstools/workspace/examples/projectExamples.xml";
+ private static final String PROTOCOL_FILE = "file";
+
+ private ProjectUtil() {
+
+ }
+
+ public static List<Category> getTestProjects() {
+ Category seamCategory = new Category("Seam");
+ Project project = new Project();
+ project.setName("dvdstore");
+ project.setShortDescription("Seam DVD Store Example");
+ project
+ .setDescription("This example demonstrates the use of Seam with jBPM pageflow
and business process management. It runs on JBoss AS and Tomcat.");
+ project.setSize(10000);
+ project
+ .setUrl("http://anonsvn.jboss.org/repos/jbosstools/workspace/snjeza/portlet-examples/dvdstore.zip");
+ project.setCategory(seamCategory);
+ seamCategory.getProjects().add(project);
+
+ Category portletCategory = new Category("Portlet");
+
+ project = new Project();
+ project.setName("TestJavaPortlet");
+ project.setShortDescription("JBoss Java Portlet Example");
+ project
+ .setDescription("This example demonstrates the use of JBoss Java Portlet. It
runs on JBoss Portal 2.7.0");
+ project.setSize(10000);
+ project
+ .setUrl("http://anonsvn.jboss.org/repos/jbosstools/workspace/snjeza/portlet-examples/TestJavaPortlet.zip");
+ project.setCategory(portletCategory);
+ portletCategory.getProjects().add(project);
+
+ project = new Project();
+ project.setName("TestJSFPortlet");
+ project.setShortDescription("JBoss JSF Portlet Example");
+ project
+ .setDescription("This example demonstrates the use of JBoss JSF Portlet. It runs
on JBoss Portal 2.7.0");
+ project.setSize(4000000);
+ project
+ .setUrl("http://anonsvn.jboss.org/repos/jbosstools/workspace/snjeza/portlet-examples/TestJSFPortlet.zip");
+ project.setCategory(portletCategory);
+ portletCategory.getProjects().add(project);
+
+ project = new Project();
+ project.setName("TestSeamPortlet");
+ project.setShortDescription("JBoss Seam Portlet Example");
+ project
+ .setDescription("This example demonstrates the use of JBoss Seam Portlet. It
runs on JBoss Portal 2.7.0");
+ project.setSize(10000000);
+ project
+ .setUrl("http://anonsvn.jboss.org/repos/jbosstools/workspace/snjeza/portlet-examples/TestSeamPortlet.zip");
+ project.setCategory(portletCategory);
+ portletCategory.getProjects().add(project);
+
+ Category otherCategory = new Category("Other");
+
+ List<Category> list = new ArrayList<Category>();
+ list.add(seamCategory);
+ list.add(portletCategory);
+ list.add(otherCategory);
+
+ return list;
+ }
+
+ public static List<Category> getProjects() {
+ List<Category> list = new ArrayList<Category>();
+ Category other = Category.OTHER;
+ try {
+ // TODO add a progress monitor
+ File file = getProjectExamplesFile(PROJECT_EXAMPLES_XML,"projectExamples",
".xml",null);
+ if (file.exists() && file.isFile()) {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(file);
+ NodeList projects = doc.getElementsByTagName("project");
+ int len = projects.getLength();
+ for (int i = 0; i < len; i++) {
+ Node node = projects.item(i);
+ Project project = new Project();
+ Category category = other;
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ Element element = (Element) node;
+ NodeList children = element.getChildNodes();
+ int cLen = children.getLength();
+ for (int j = 0; j < cLen; j++) {
+ Node cNode = children.item(j);
+ if (cNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element child = (Element) cNode;
+ String nodeName = child.getNodeName();
+ if (nodeName.equals("category")) {
+ String value = getContent(child);
+ boolean found = false;
+ for (Category cat:list) {
+ if (cat.getName().equals(value)) {
+ category=cat;
+ found=true;
+ break;
+ }
+ }
+ if (!found) {
+ category = new Category(value);
+ list.add(category);
+ }
+ project.setCategory(category);
+ }
+ if (nodeName.equals("name")) {
+ project.setName(getContent(child));
+ }
+ if (nodeName.equals("shortDescription")) {
+ project.setShortDescription(getContent(child));
+ }
+ if (nodeName.equals("description")) {
+ project.setDescription(getContent(child));
+ }
+ if (nodeName.equals("url")) {
+ project.setUrl(getContent(child));
+ }
+ if (nodeName.equals("size")) {
+ long size = 0;
+ try {
+ size = new Long(getContent(child));
+ } catch (Exception ignored) {
+ }
+ project.setSize(size);
+ }
+ }
+ }
+ }
+ category.getProjects().add(project);
+ }
+ }
+ } catch (Exception e) {
+ ProjectExamplesActivator.log(e);
+ }
+ list.add(other);
+ return list;
+ }
+
+ private static String getContent(Element child) {
+ String value = child.getTextContent();
+ if (value == null) {
+ value="";
+ }
+ return value.trim();
+ }
+
+ private static File getProjectExamplesXmlTest() throws Exception {
+ Bundle bundle = Platform.getBundle(ProjectExamplesActivator.PLUGIN_ID);
+ URL examplesURL = bundle.getEntry("/projectExamples.xml");
+ URL url = FileLocator.resolve(examplesURL);
+ File file = new File(FileLocator.toFileURL(url).getFile());
+ return file;
+ }
+
+ public static File getProjectExamplesFile(String urlString,String prefix, String suffix,
IProgressMonitor monitor) {
+ URL url;
+ try {
+ url = new URL(urlString);
+ } catch (MalformedURLException e) {
+ ProjectExamplesActivator.log(e);
+ return null;
+ }
+ File file = null;
+ if (PROTOCOL_FILE.equals(url.getProtocol())) {
+ try {
+ //assume all illegal characters have been properly encoded, so use URI class to
unencode
+ file = new File(new URI(url.toExternalForm()));
+ } catch (Exception e) {
+ //URL contains unencoded characters
+ file = new File(url.getFile());
+ }
+ if (!file.exists())
+ return null;
+ } else {
+ try {
+ file = File.createTempFile(prefix,suffix);
+ file.deleteOnExit();
+ BufferedOutputStream destination = new BufferedOutputStream(new
FileOutputStream(file));
+ IStatus result = getTransport().download(prefix,url.toExternalForm(), destination,
monitor);
+ if (!result.isOK())
+ return null;
+ } catch (FileNotFoundException e) {
+ ProjectExamplesActivator.log(e);
+ return null;
+ } catch (IOException e) {
+ ProjectExamplesActivator.log(e);
+ return null;
+ }
+ }
+ return file;
+ }
+
+ private static ECFExamplesTransport getTransport() {
+ return ECFExamplesTransport.getInstance();
+ }
+}
Added:
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
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,173 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat 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:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.project.examples.wizard;
+
+/**
+ * @author snjeza
+ *
+ */
+import java.io.File;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.resources.IProject;
+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.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
+import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectUtil;
+
+public class NewProjectExamplesWizard extends Wizard implements INewWizard {
+
+ private static final IOverwriteQuery OVERWRITE_ALL_QUERY = new IOverwriteQuery() {
+ public String queryOverwrite(String pathString) {
+ return IOverwriteQuery.ALL;
+ }
+ };
+
+ /**
+ * The workbench.
+ */
+ private IWorkbench workbench;
+
+ /**
+ * The current selection.
+ */
+ private IStructuredSelection selection;
+
+ private NewProjectExamplesWizardPage page;
+
+ protected boolean overwrite;
+
+ public NewProjectExamplesWizard() {
+ super();
+ setWindowTitle("New Project Example");
+
+ }
+
+ /**
+ * Creates an empty wizard for creating a new resource in the workspace.
+ */
+
+ @Override
+ public boolean performFinish() {
+ final Project project = page.getSelectedProject();
+ if (project == null) {
+ return false;
+ }
+ WorkspaceJob job = new WorkspaceJob("Downloading...") {
+
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor)
+ throws CoreException {
+ String url = project.getUrl();
+ String name = project.getName();
+ final File file = ProjectUtil.getProjectExamplesFile(url, name,
+ ".zip",monitor);
+ if (file == null) {
+ return Status.CANCEL_STATUS;
+ }
+ try {
+ importProject(project, file, monitor);
+ } catch (final Exception e) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ MessageDialogWithToggle.openError(getShell(), "Error", e
+ .getMessage(), "Detail", false,
+ ProjectExamplesActivator.getDefault()
+ .getPreferenceStore(), "errorDialog");
+ }
+
+ });
+ ProjectExamplesActivator.log(e);
+ }
+ return Status.OK_STATUS;
+ }
+
+ };
+ job.setUser(true);
+ job.schedule();
+ //try {
+ // job.join();
+ //} catch (InterruptedException e) {
+ // return false;
+ //}
+ return true;
+ }
+
+ private void importProject(Project projectDescription, File file, IProgressMonitor
monitor) throws Exception {
+ final String projectName = projectDescription.getName();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IProject project = workspace.getRoot().getProject(projectName);
+ if (project.exists()) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ overwrite = MessageDialog.openQuestion(getShell(), "Question",
"Overwrite project '" + projectName + "'");
+ }
+
+ });
+ if (!overwrite) {
+ return;
+ }
+ project.delete(true, true, monitor);
+ }
+ project.create(monitor);
+ project.open(monitor);
+ ZipFile sourceFile = new ZipFile(file);
+ ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(
+ sourceFile);
+
+ ImportOperation operation = new ImportOperation(workspace.getRoot().getFullPath(),
+ structureProvider.getRoot(), structureProvider,
+ OVERWRITE_ALL_QUERY);
+ operation.setContext(getShell());
+ operation.run(monitor);
+
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.workbench = workbench;
+ this.selection = selection;
+ initializeDefaultPageImageDescriptor();
+ }
+
+ protected void initializeDefaultPageImageDescriptor() {
+ ImageDescriptor desc = ProjectExamplesActivator
+ .imageDescriptorFromPlugin(ProjectExamplesActivator.PLUGIN_ID,
+ "icons/new_wiz.gif");
+ setDefaultPageImageDescriptor(desc);
+ }
+
+ @Override
+ public void addPages() {
+ super.addPages();
+ page = new NewProjectExamplesWizardPage();
+ addPage(page);
+ }
+
+}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2008-10-08
15:39:37 UTC (rev 10749)
@@ -0,0 +1,186 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat 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:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.project.examples.wizard;
+
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.Category;
+import org.jboss.tools.project.examples.model.Project;
+import org.jboss.tools.project.examples.model.ProjectUtil;
+
+/**
+ * @author snjeza
+ *
+ */
+public class NewProjectExamplesWizardPage extends WizardPage {
+
+ private Project selectedProject;
+
+ public NewProjectExamplesWizardPage() {
+ super("org.jboss.tools.project.examples");
+ setTitle( "Project Example" );
+ setDescription( "Import Project Example" );
+ setImageDescriptor(
ProjectExamplesActivator.imageDescriptorFromPlugin(ProjectExamplesActivator.PLUGIN_ID,
"icons/new_wiz.gif"));
+
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent,SWT.NULL);
+ composite.setLayout(new GridLayout(1,false));
+
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.widthHint= 225;
+ composite.setLayoutData(gd);
+
+ TreeViewer viewer = new TreeViewer(composite,SWT.SINGLE);
+ Tree tree = viewer.getTree();
+ tree.setLayoutData(new GridData(GridData.FILL_BOTH));
+ tree.setFont(parent.getFont());
+
+ viewer.setLabelProvider(new ProjectLabelProvider());
+ viewer.setContentProvider(new ProjectContentProvider());
+ viewer.setInput(ProjectUtil.getProjects());
+
+ Label descriptionLabel = new Label(composite,SWT.NULL);
+ descriptionLabel.setText("Description:");
+ final Text text = new Text(composite,SWT.BORDER | SWT.MULTI | SWT.WRAP |
SWT.READ_ONLY);
+ gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL |
GridData.GRAB_VERTICAL);
+ gd.heightHint=75;
+ text.setLayoutData(gd);
+
+ Composite internal = new Composite(composite, SWT.NULL);
+ internal.setLayout(new GridLayout(2,false));
+ gd = new GridData(GridData.FILL_BOTH);
+ internal.setLayoutData(gd);
+
+ Label projectNameLabel = new Label(internal,SWT.NULL);
+ projectNameLabel.setText("Project name:");
+ final Text projectName = new Text(internal,SWT.BORDER | SWT.READ_ONLY);
+ projectName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Label projectSizeLabel = new Label(internal,SWT.NULL);
+ projectSizeLabel.setText("Project size:");
+ final Text projectSize = new Text(internal,SWT.BORDER | SWT.READ_ONLY);
+ projectSize.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Label projectURLLabel = new Label(internal,SWT.NULL);
+ projectURLLabel.setText("URL:");
+ final Text projectURL = new Text(internal,SWT.BORDER | SWT.READ_ONLY);
+ projectURL.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ Object selected = selection.getFirstElement();
+ if (selected instanceof Project) {
+ selectedProject = (Project) selected;
+ text.setText(selectedProject.getDescription());
+ setPageComplete(true);
+ projectName.setText(selectedProject.getName());
+ projectURL.setText(selectedProject.getUrl());
+ projectSize.setText(selectedProject.getSizeAsText());
+ } else {
+ selectedProject=null;
+ text.setText("");
+ projectName.setText("");
+ projectURL.setText("");
+ projectSize.setText("");
+ setPageComplete(false);
+ }
+ }
+
+ });
+ setPageComplete(false);
+
+ setControl(composite);
+ }
+
+ private class ProjectLabelProvider extends LabelProvider {
+
+ @Override
+ public Image getImage(Object element) {
+ return super.getImage(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof Category) {
+ Category category = (Category) element;
+ return category.getName();
+ }
+ if (element instanceof Project) {
+ Project project = (Project) element;
+ return project.getShortDescription();
+ }
+ return super.getText(element);
+ }
+ }
+
+ private class ProjectContentProvider implements ITreeContentProvider {
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof List) {
+ List children = (List) parentElement;
+ return children.toArray();
+ }
+ if (parentElement instanceof Category) {
+ Category category = (Category) parentElement;
+ return category.getProjects().toArray();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ if (element instanceof Project) {
+ return ((Project)element).getCategory();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return element instanceof Category;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ }
+
+ public Project getSelectedProject() {
+ return selectedProject;
+ }
+}