[dna-commits] DNA SVN: r1063 - in branches/eclipse: org.jboss.dna.publish/META-INF and 5 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Jun 24 14:31:41 EDT 2009


Author: elvisisking
Date: 2009-06-24 14:31:40 -0400 (Wed, 24 Jun 2009)
New Revision: 1063

Added:
   branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/EclipseStatus.java
   branches/eclipse/org.jboss.dna.publish/slf4j-api-1.5.8-sources.jar
   branches/eclipse/org.jboss.dna.publish/slf4j-api-1.5.8.jar
   branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Logger.java
Modified:
   branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/Activator.java
   branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/actions/PublishAction.java
   branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/wizards/PublishPage.java
   branches/eclipse/org.jboss.dna.publish/.classpath
   branches/eclipse/org.jboss.dna.publish/META-INF/MANIFEST.MF
   branches/eclipse/org.jboss.dna.publish/build.properties
   branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/IConstants.java
   branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Messages.properties
   branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Publisher.java
   branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/ServerManager.java
   branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Status.java
   branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/domain/Repository.java
   branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/domain/Workspace.java
Log:
Added logging and more UI implementation.

Modified: branches/eclipse/org.jboss.dna.publish/.classpath
===================================================================
--- branches/eclipse/org.jboss.dna.publish/.classpath	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/.classpath	2009-06-24 18:31:40 UTC (rev 1063)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+	<classpathentry exported="true" kind="lib" path="slf4j-api-1.5.8.jar"/>
 	<classpathentry exported="true" kind="lib" path="jettison-1.1.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>

Modified: branches/eclipse/org.jboss.dna.publish/META-INF/MANIFEST.MF
===================================================================
--- branches/eclipse/org.jboss.dna.publish/META-INF/MANIFEST.MF	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/META-INF/MANIFEST.MF	2009-06-24 18:31:40 UTC (rev 1063)
@@ -8,7 +8,8 @@
 Bundle-ActivationPolicy: lazy
 Bundle-Localization: plugin
 Bundle-ClassPath: dnaPublish.jar,
- jettison-1.1.jar
+ jettison-1.1.jar,
+ slf4j-api-1.5.8.jar
 Export-Package: org.jboss.dna.publish,
  org.jboss.dna.publish.domain,
  org.jboss.dna.publish.domain.validation

Modified: branches/eclipse/org.jboss.dna.publish/build.properties
===================================================================
--- branches/eclipse/org.jboss.dna.publish/build.properties	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/build.properties	2009-06-24 18:31:40 UTC (rev 1063)
@@ -1,7 +1,8 @@
 bin.includes = META-INF/,\
                plugin.properties,\
                jettison-1.1.jar,\
-               dnaPublish.jar
+               dnaPublish.jar,\
+               slf4j-api-1.5.8.jar
 jars.compile.order = dnaPublish.jar
 src.includes = src/
 source.dnaPublish.jar = src/

Added: branches/eclipse/org.jboss.dna.publish/slf4j-api-1.5.8-sources.jar
===================================================================
(Binary files differ)


Property changes on: branches/eclipse/org.jboss.dna.publish/slf4j-api-1.5.8-sources.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: branches/eclipse/org.jboss.dna.publish/slf4j-api-1.5.8.jar
===================================================================
(Binary files differ)


Property changes on: branches/eclipse/org.jboss.dna.publish/slf4j-api-1.5.8.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/IConstants.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/IConstants.java	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/IConstants.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -33,6 +33,12 @@
     
     ResourceBundle MESSAGES = ResourceBundle.getBundle(IConstants.class.getPackage().getName() + ".Messages"); //$NON-NLS-1$
     
+    String ErrorDeletingServerRegistryFile = "ErrorDeletingServerRegistryFile"; //$NON-NLS-1$
+    
+    String ErrorRestoringServerRegistry = "ErrorRestoringServerRegistry"; //$NON-NLS-1$
+    
+    String ErrorSavingServerRegistry = "ErrorSavingServerRegistry"; //$NON-NLS-1$
+    
     String RemovingServerProblemMsg = "RemovingServerProblemMsg"; //$NON-NLS-1$
     
     String RepositoryEmptyNameMsg = "RepositoryEmptyNameMsg"; //$NON-NLS-1$

Added: branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Logger.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Logger.java	                        (rev 0)
+++ branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Logger.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -0,0 +1,84 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.publish;
+
+import java.text.MessageFormat;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Dan Florian
+ */
+public final class Logger {
+
+    // ===========================================================================================================================
+    // Class Methods
+    // ===========================================================================================================================
+
+    /**
+     * @param clazz the class whose logger will be used
+     * @param error the error being logged
+     * @param message the message being logged
+     * @since 0.6
+     */
+    public static void error( Class<?> clazz,
+                              Throwable error,
+                              String message ) {
+        org.slf4j.Logger delegate = LoggerFactory.getLogger(clazz);
+
+        if (delegate.isErrorEnabled()) {
+            delegate.error(message, error);
+        }
+    }
+
+    /**
+     * @param clazz the class whose logger will be used
+     * @param error the error being logged
+     * @param pattern the message format pattern
+     * @param arguments the arguments to be inserted into the pattern
+     * @since 0.6
+     */
+    public static void error( Class<?> clazz,
+                              Throwable error,
+                              String pattern,
+                              Object... arguments ) {
+        org.slf4j.Logger delegate = LoggerFactory.getLogger(clazz);
+
+        if (delegate.isErrorEnabled()) {
+            delegate.error(MessageFormat.format(pattern, arguments), error);
+        }
+    }
+
+    // ===========================================================================================================================
+    // Constructors
+    // ===========================================================================================================================
+
+    /**
+     * Don't allow construction.
+     * 
+     * @since 0.6
+     */
+    private Logger() {
+        // nothing to do
+    }
+}


Property changes on: branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Logger.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Messages.properties
===================================================================
--- branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Messages.properties	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Messages.properties	2009-06-24 18:31:40 UTC (rev 1063)
@@ -1,3 +1,7 @@
+ErrorDeletingServerRegistryFile = There was a problem deleting server registry file "{0}"
+ErrorRestoringServerRegistry = Error trying to restore the server registry from file "{0}"
+ErrorSavingServerRegistry = Error trying to save the server registry to "{0}"
+
 RemovingServerProblemMsg = {0} cannot be removed as it has not been registered
 
 RepositoryEmptyNameMsg = A repository name cannot be empty

Modified: branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Publisher.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Publisher.java	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Publisher.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -24,8 +24,11 @@
 package org.jboss.dna.publish;
 
 import java.io.File;
+import java.net.Authenticator;
+import java.net.PasswordAuthentication;
 import java.util.Collection;
 import org.jboss.dna.publish.domain.Server;
+import org.jboss.dna.publish.domain.Workspace;
 
 /**
  * @author Dan Florian
@@ -33,13 +36,39 @@
  */
 public class Publisher {
 
-    public Status publish( Server server,
+    // ===========================================================================================================================
+    // Constants
+    // ===========================================================================================================================
+
+//    private static final String SERVER_CONTEXT = "/resources"; //$NON-NLS-1$
+
+    // ===========================================================================================================================
+    // Class Methods
+    // ===========================================================================================================================
+
+    private static void setAuthenticator(final Server server) {
+        Authenticator.setDefault(new Authenticator() {
+            @Override
+            protected PasswordAuthentication getPasswordAuthentication() {
+                return new PasswordAuthentication(server.getUser(), server.getPassword().toCharArray());
+            }
+        });        
+    }
+
+    // ===========================================================================================================================
+    // Methods
+    // ===========================================================================================================================
+
+    public Status publish( Workspace workspace,
                            Collection<File> files ) {
         // TODO implement
+        Server server = workspace.getServer();
+        setAuthenticator(server);
+
         return null;
     }
 
-    public Status unpublish( Server server,
+    public Status unpublish( Workspace workspace,
                              Collection<File> files ) {
         // TODO implement
         return null;

Modified: branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/ServerManager.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/ServerManager.java	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/ServerManager.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -125,7 +125,6 @@
     public ServerManager( String stateLocationPath ) {
         this.servers = Collections.synchronizedList(new ArrayList<Server>());
         this.stateLocationPath = stateLocationPath;
-        restoreState();
     }
 
     // ===========================================================================================================================
@@ -159,13 +158,19 @@
     public Collection<Server> getServers() {
         return Collections.unmodifiableCollection(this.servers);
     }
-    
+
     /**
-     * @return the name of the state file that the server registry is persisted to
+     * @return the name of the state file that the server registry is persisted to or <code>null</code>
      * @since 0.6
      */
     private String getStateFileName() {
-        return this.stateLocationPath + File.separatorChar + REGISTRY_FILE;
+        String name = this.stateLocationPath;
+
+        if (this.stateLocationPath != null) {
+            name += File.separatorChar + REGISTRY_FILE;
+        }
+
+        return name;
     }
 
     /**
@@ -195,10 +200,10 @@
     }
 
     /**
-     * @return a status indicating if the previous session state was restored
+     * @return a status indicating if the previous session state was restored successfully
      * @since 0.6
      */
-    private Status restoreState() {
+    public Status restoreState() {
         if (this.stateLocationPath != null) {
             if (stateFileExists()) {
                 try {
@@ -207,15 +212,15 @@
                     Document doc = docBuilder.parse(new File(getStateFileName()));
                     Node root = doc.getDocumentElement();
                     NodeList servers = root.getChildNodes();
-                    
+
                     for (int size = servers.getLength(), i = 0; i < size; ++i) {
                         Node server = servers.item(i);
-                        
+
                         if (server.getNodeType() != Node.TEXT_NODE) {
                             NamedNodeMap attributeMap = server.getAttributes();
-                            
+
                             if (attributeMap == null) continue;
-                            
+
                             for (int numAttrs = attributeMap.getLength(), j = 0; j < numAttrs; ++j) {
                                 Node urlNode = attributeMap.getNamedItem(URL_TAG);
                                 Node userNode = attributeMap.getNamedItem(USER_TAG);
@@ -225,12 +230,13 @@
                         }
                     }
                 } catch (Exception e) {
-                    // TODO log
+                    String pattern = MESSAGES.getString(ErrorRestoringServerRegistry);
+                    return new Status(Severity.ERROR, MessageFormat.format(pattern, getStateFileName()), e);
                 }
             }
         }
 
-        // do nothing of there is no save location
+        // do nothing of there is no save location or state file does not exist
         return Status.OK_STATUS;
     }
 
@@ -241,8 +247,8 @@
      * @since 0.6
      */
     public Status saveState() {
-        try {
-            if ((this.stateLocationPath != null) && !getServers().isEmpty()) {
+        if ((this.stateLocationPath != null) && !getServers().isEmpty()) {
+            try {
                 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                 DocumentBuilder docBuilder = factory.newDocumentBuilder();
                 Document doc = docBuilder.newDocument();
@@ -259,7 +265,7 @@
                     serverElement.setAttribute(USER_TAG, server.getUser());
                     serverElement.setAttribute(PASSWORD_TAG, server.getPassword());
                 }
-                
+
                 DOMSource source = new DOMSource(doc);
                 StreamResult resultXML = new StreamResult(new FileOutputStream(getStateFileName()));
                 TransformerFactory transFactory = TransformerFactory.newInstance();
@@ -267,12 +273,18 @@
                 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
                 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); //$NON-NLS-1$ //$NON-NLS-2$
                 transformer.transform(source, resultXML);
-            } else if ((this.stateLocationPath != null) && stateFileExists()) {
-                // delete current registry file is all servers have been deleted
+            } catch (Exception e) {
+                String pattern = MESSAGES.getString(ErrorSavingServerRegistry);
+                return new Status(Severity.ERROR, MessageFormat.format(pattern, getStateFileName()), e);
+            }
+        } else if ((this.stateLocationPath != null) && stateFileExists()) {
+            // delete current registry file since all servers have been deleted
+            try {
                 new File(getStateFileName()).delete();
+            } catch (Exception e) {
+                String pattern = MESSAGES.getString(ErrorDeletingServerRegistryFile);
+                return new Status(Severity.ERROR, MessageFormat.format(pattern, getStateFileName()), e);
             }
-        } catch (Exception e) {
-            // TODO log
         }
 
         return Status.OK_STATUS;
@@ -299,7 +311,7 @@
                 mgr.addServer(new Server("http://server" + i + ".com", "user" + i, "password" + i)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
             }
         }
-        
+
         mgr.saveState();
     }
 

Modified: branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Status.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Status.java	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/Status.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -92,27 +92,34 @@
      * 
      * @since 0.6
      */
-    private final Throwable exception;
+    protected Throwable exception;
 
     /**
      * The localized message of this status (never <code>null</code>).
      * 
      * @since 0.6
      */
-    private final String message;
+    protected String message;
 
     /**
      * The severity level of this status.
      * 
      * @since 0.6
      */
-    private final Severity severity;
+    protected Severity severity;
 
     // ===========================================================================================================================
     // Constructors
     // ===========================================================================================================================
 
     /**
+     * @since 0.6
+     */
+    protected Status() {
+        // nothing to do
+    }
+
+    /**
      * @param severity the status severity (<code>null</code> will be converted to {@link Severity#UNKNOWN}.
      * @param message the status message or <code>null</code>
      * @param exception the status exception or <code>null</code>
@@ -147,6 +154,14 @@
     }
 
     /**
+     * @return severity the status severity
+     * @since 0.6
+     */
+    public Severity getSeverity() {
+        return severity;
+    }
+
+    /**
      * @return <code>true</code> if the status is an error
      * @see Severity#ERROR
      * @since 0.6

Modified: branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/domain/Repository.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/domain/Repository.java	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/domain/Repository.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -144,7 +144,7 @@
     }
 
     /**
-     * @return the server where this repository is located
+     * @return the server where this repository is located (never <code>null</code>)
      * @since 0.6
      */
     public Server getServer() {

Modified: branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/domain/Workspace.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/domain/Workspace.java	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish/src/org/jboss/dna/publish/domain/Workspace.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -134,9 +134,24 @@
      */
     @Override
     public IDnaObject getParent() {
-        // a workspace's parent is a repository
+        return getRepository();
+    }
+    
+    /**
+     * @return the repository where this workspace is located (never <code>null</code>)
+     * @since 0.6
+     */
+    public Repository getRepository() {
         return this.repository;
     }
+    
+    /**
+     * @return the server where this workspace is located (never <code>null</code>)
+     * @since 0.6
+     */
+    public Server getServer() {
+        return this.repository.getServer();
+    }
 
     /**
      * {@inheritDoc}

Modified: branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/Activator.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/Activator.java	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/Activator.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -23,10 +23,14 @@
  */
 package org.jboss.dna.publish.ui.swt;
 
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.jboss.dna.publish.Logger;
 import org.jboss.dna.publish.ServerManager;
+import org.jboss.dna.publish.Status;
 import org.jboss.dna.publish.domain.IDnaObject;
 import org.jboss.dna.publish.domain.Repository;
 import org.jboss.dna.publish.domain.Server;
@@ -166,13 +170,44 @@
      * Note: This should <strong>ONLY</strong> be called when the OSGi framework is not running (i.e., {@link BundleContext bundle
      * context} is <code>null</code>) and should be called instead of calling {@link #start(BundleContext)}.
      * 
-     * @param stateLocationPath
+     * @param stateLocationPath the file system directory where state files can be stored or <code>null</code> if saving state is
+     *        not desired
      * @since 0.6
      */
     public void initialize( String stateLocationPath ) {
         this.serverMgr = new ServerManager(stateLocationPath);
+        Status status = this.serverMgr.restoreState();
+
+        // problem restoring server registry
+        if (status.isError()) {
+            log(getClass(), status);
+        }
     }
 
+    public void log( Class<?> sourceClass,
+                     Status status ) {
+        if (Platform.isRunning()) {
+            IStatus eclipseStatus;
+
+            if (status instanceof EclipseStatus) {
+                eclipseStatus = ((EclipseStatus)status).getDelegate();
+            } else {
+                eclipseStatus = new org.eclipse.core.runtime.Status(EclipseStatus.convertSeverity(status.getSeverity()),
+                                                                    IUiConstants.PLUGIN_ID, status.getMessage(),
+                                                                    status.getException());
+            }
+
+            getLog().log(eclipseStatus);
+        } else {
+            Logger.error(getClass(), status.getException(), status.getMessage());
+        }
+    }
+
+    public void log( Class<?> sourceClass,
+                     IStatus status ) {
+        log(sourceClass, new EclipseStatus(status));
+    }
+
     /**
      * {@inheritDoc}
      * <p>
@@ -199,8 +234,10 @@
     @Override
     public void stop( BundleContext context ) throws Exception {
         if (this.serverMgr != null) {
-            if (this.serverMgr.saveState().isError()) {
-                // TODO log this
+            Status status = this.serverMgr.saveState();
+            
+            if (status.isError()) {
+                log(getClass(), status);
             }
 
             this.serverMgr = null;

Added: branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/EclipseStatus.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/EclipseStatus.java	                        (rev 0)
+++ branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/EclipseStatus.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -0,0 +1,112 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.publish.ui.swt;
+
+import org.eclipse.core.runtime.IStatus;
+import org.jboss.dna.publish.Status;
+
+/**
+ * Converts an Eclipse status into an non-Eclipse status.
+ * 
+ * @author Dan Florian
+ * @since 0.6
+ */
+public class EclipseStatus extends Status {
+
+    // ===========================================================================================================================
+    // Class Methods
+    // ===========================================================================================================================
+
+    /**
+     * Converts the non-Eclipse status severity to an Eclipse severity level. An {@link Status.Severity#UNKNOWN unknown status} is
+     * converted to {@link IStatus#CANCEL cancel}. A {@link Status.Severity} is
+     * 
+     * @param severity the eclipse status severity level
+     * @return the converted severity level
+     * @see IStatus
+     * @since 0.6
+     */
+    public static int convertSeverity( Severity severity ) {
+        if (severity == Severity.OK) return IStatus.OK;
+        if (severity == Severity.ERROR) return IStatus.ERROR;
+        if (severity == Severity.WARNING) return IStatus.WARNING;
+        if (severity == Severity.INFO) return IStatus.INFO;
+        return IStatus.CANCEL;
+    }
+
+    /**
+     * Converts the Eclipse status severity level to a non-Eclipse severity.
+     * 
+     * @param severity the eclipse status severity level
+     * @return the converted severity level
+     * @see IStatus
+     * @since 0.6
+     */
+    public static Severity convertSeverity( int severity ) {
+        if (severity == IStatus.OK) return Severity.OK;
+        if (severity == IStatus.ERROR) return Severity.ERROR;
+        if (severity == IStatus.WARNING) return Severity.WARNING;
+        if (severity == IStatus.INFO) return Severity.INFO;
+        return Severity.UNKNOWN;
+    }
+
+    // ===========================================================================================================================
+    // Fields
+    // ===========================================================================================================================
+
+    /**
+     * The Eclipse status.
+     * 
+     * @since 0.6
+     */
+    private final IStatus delegate;
+
+    // ===========================================================================================================================
+    // Constructors
+    // ===========================================================================================================================
+
+    /**
+     * @param delegate the eclipse status delegate
+     * @since 0.6
+     */
+    public EclipseStatus( IStatus delegate ) {
+        this.delegate = delegate;
+        this.severity = convertSeverity(delegate.getSeverity());
+        this.message = delegate.getMessage();
+        this.exception = delegate.getException();
+    }
+
+    // ===========================================================================================================================
+    // Methods
+    // ===========================================================================================================================
+
+    /**
+     * @return the Eclipse status object
+     * @since 0.6
+     */
+    public IStatus getDelegate() {
+        return this.delegate;
+    }
+
+}


Property changes on: branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/EclipseStatus.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/actions/PublishAction.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/actions/PublishAction.java	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/actions/PublishAction.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -23,13 +23,20 @@
  */
 package org.jboss.dna.publish.ui.swt.actions;
 
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.List;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
+import org.jboss.dna.publish.ui.swt.Activator;
+import org.jboss.dna.publish.ui.swt.wizards.PublishWizard;
+import org.jboss.dna.publish.ui.swt.wizards.PublishWizard.Type;
 
 /**
  * The PublishAction controls the publishing of one or more {@link org.eclipse.core.resources.IResource}s to a DNA repository.
@@ -50,7 +57,7 @@
      * 
      * @since 0.6
      */
-//    private Shell shell;
+    private Shell shell;
 
     // ===========================================================================================================================
     // Constants
@@ -58,24 +65,37 @@
 
     /**
      * {@inheritDoc}
-     *
+     * 
      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
      * @since 0.6
      */
     @Override
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     public void run( IAction action ) {
-        for (Iterator itr = this.selection.iterator(); itr.hasNext();) {
-            // TODO implement run(IAction) - display publish wizard
-            IResource resource = (IResource)itr.next();
-            resource.getFullPath().toFile();
+        assert (this.selection != null);
+        assert (!this.selection.isEmpty());
+
+        List<IResource> resources;
+
+        if (this.selection.size() == 1) {
+            resources = Collections.singletonList((IResource)this.selection.getFirstElement());
+        } else {
+            resources = this.selection.toList();
         }
+
+        WizardDialog dialog = new WizardDialog(shell, new PublishWizard(Type.PUBLISH, resources,
+                                                                        Activator.getDefault().getServerManager()));
+
+        if (dialog.getReturnCode() == Window.OK) {
+            // TODO implement run publish
+        }
     }
-    
+
     /**
      * {@inheritDoc}
-     *
-     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+     * 
+     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
+     *      org.eclipse.jface.viewers.ISelection)
      * @since 0.6
      */
     @Override
@@ -87,7 +107,7 @@
             this.selection = null;
         }
     }
-    
+
     /**
      * {@inheritDoc}
      * 
@@ -97,7 +117,7 @@
     @Override
     public void setActivePart( IAction action,
                                IWorkbenchPart targetPart ) {
-//        this.shell = targetPart.getSite().getShell();
+        this.shell = targetPart.getSite().getShell();
     }
 
 }

Modified: branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/wizards/PublishPage.java
===================================================================
--- branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/wizards/PublishPage.java	2009-06-23 18:44:56 UTC (rev 1062)
+++ branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/publish/ui/swt/wizards/PublishPage.java	2009-06-24 18:31:40 UTC (rev 1063)
@@ -23,6 +23,8 @@
  */
 package org.jboss.dna.publish.ui.swt.wizards;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.jface.dialogs.IMessageProvider;
@@ -36,8 +38,12 @@
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
+import org.jboss.dna.publish.ServerManager;
 import org.jboss.dna.publish.Status;
 import org.jboss.dna.publish.Status.Severity;
+import org.jboss.dna.publish.domain.Repository;
+import org.jboss.dna.publish.domain.Server;
+import org.jboss.dna.publish.domain.Workspace;
 import org.jboss.dna.publish.ui.swt.I18n;
 import org.jboss.dna.publish.ui.swt.wizards.PublishWizard.Type;
 
@@ -84,22 +90,28 @@
      * 
      * @since 0.6
      */
-    private String repository;
+    private Repository repository;
 
+    private List<Repository> repositories;
+
     /**
      * The server where the repository is located.
      * 
      * @since 0.6
      */
-    private String server;
+    private Server server;
 
+    private List<Server> servers;
+
     /**
      * The workspace where the resources are being published/unpublished.
      * 
      * @since 0.6
      */
-    private String workspace;
+    private Workspace workspace;
 
+    private List<Workspace> workspaces;
+
     /**
      * The collection of resources being published/unpublished.
      * 
@@ -198,8 +210,9 @@
 
         // set initial value
         // TODO implement load resources
-        String[]  data = new String[20];
-        for (int i = 0; i < 20; ++i) data[i] = "my/resource" + i + ".xmi"; //$NON-NLS-1$ //$NON-NLS-2$
+        String[] data = new String[20];
+        for (int i = 0; i < 20; ++i)
+            data[i] = "my/resource" + i + ".xmi"; //$NON-NLS-1$ //$NON-NLS-2$
         lstResources.setItems(data);
     }
 
@@ -217,25 +230,40 @@
         constructResourcesPanel(pnlMain);
         setControl(pnlMain);
 
-        loadServers();
+        resetServers();
         installLocationListeners();
     }
 
     /**
+     * @return the server manager obtained from the wizard
+     * @since 0.6
+     */
+    private ServerManager getServerManager() {
+        return ((ServerWizard)getWizard()).getServerManager();
+    }
+
+    /**
+     * @return thw workspace to use when publishing or unpublishing
+     * @since 0.6
+     */
+    public Workspace getWorkspace() {
+        assert isPageComplete();
+        return this.workspace;
+    }
+
+    /**
      * Handler for when the repository control value is modified
      * 
      * @since 0.6
      */
     void handleRepositoryModified() {
-        this.repository = this.cbxRepository.getText();
-        this.workspace = null;
+        int index = this.cbxRepository.getSelectionIndex();
+        this.repository = this.repositories.get(index);
 
         // clear loaded workspaces
-        uninstallLocationListeners();
-        this.cbxWorkspace.removeAll();
-        reloadWorkspaces();
-        installLocationListeners();
+        resetWorkspaces();
 
+        // update page state
         updateState();
     }
 
@@ -245,17 +273,12 @@
      * @since 0.6
      */
     void handleServerModified() {
-        this.server = this.cbxServer.getText();
-        this.repository = null;
-        this.workspace = null;
+        this.server = this.servers.get(this.cbxServer.getSelectionIndex());
 
-        // clear loaded repositories and workspaces
-        uninstallLocationListeners();
-        this.cbxRepository.removeAll();
-        this.cbxWorkspace.removeAll();
-        reloadRepositories();
-        installLocationListeners();
+        // need to reload repositories since server changed
+        resetRepositories();
 
+        // update page state
         updateState();
     }
 
@@ -265,7 +288,7 @@
      * @since 0.6
      */
     void handleWorkspaceModified() {
-        this.workspace = this.cbxWorkspace.getText();
+        this.workspace = this.workspaces.get(this.cbxWorkspace.getSelectionIndex());
         updateState();
     }
 
@@ -280,13 +303,6 @@
         this.cbxWorkspace.addModifyListener(this);
     }
 
-    private void loadServers() {
-        // TODO implement loadServers()
-        String[]  data = new String[20];
-        for (int i = 0; i < 20; ++i) data[i] = "server" + i; //$NON-NLS-1$
-        this.cbxServer.setItems(data);
-    }
-
     /**
      * {@inheritDoc}
      * 
@@ -301,34 +317,155 @@
         } else if (e.widget == this.cbxRepository) {
             handleWorkspaceModified();
         } else {
-            // should not happen
-            // TODO log
+            assert false; // should not happen
         }
     }
 
     /**
-     * Reloads the repository combobox based on the newly selected server.
+     * Resets the repository-related fields and controls.
      * 
      * @since 0.6
      */
-    private void reloadRepositories() {
-        // TODO implement reloadRepositories()
-        // if only one repository set it on the combobox
-        // if no repositories ???
+    private void resetRepositories() {
+        this.repository = null;
+
+        if (this.server == null) {
+            this.repositories = Collections.emptyList();
+        } else {
+            this.repositories = new ArrayList<Repository>(this.server.getRepositories());
+        }
+
+        // uninstall listeners to prevent handling events
+        uninstallLocationListeners();
+
+        // clear items
+        this.cbxRepository.removeAll();
+
+        // reload
+        if (this.repositories.isEmpty()) {
+            // disable control if necessary
+            if (this.cbxRepository.getEnabled()) {
+                this.cbxRepository.setEnabled(false);
+            }
+        } else if (this.repositories.size() == 1) {
+            this.repository = this.repositories.get(0);
+            this.cbxRepository.add(this.repository.getName());
+            this.cbxRepository.select(0);
+
+            // enable control if necessary
+            if (!this.cbxRepository.getEnabled()) {
+                this.cbxRepository.setEnabled(true);
+            }
+        } else {
+            // add an item for each repository
+            for (Repository repository : this.repositories) {
+                this.cbxRepository.add(repository.getName());
+            }
+
+            // enable control if necessary
+            if (!this.cbxRepository.getEnabled()) {
+                this.cbxRepository.setEnabled(true);
+            }
+        }
+
+        // must reload workspaces
+        resetWorkspaces();
+
+        // reinstall listening
+        installLocationListeners();
     }
 
     /**
-     * Reloads the repository combobox based on the newly selected server.
+     * Resets the server-related fields and controls.
      * 
      * @since 0.6
      */
-    private void reloadWorkspaces() {
-        // TODO implement reloadRepositories()
-        // if only one workspace set it on the combobox
-        // if no workspaces ???
+    private void resetServers() {
+        this.server = null;
+        this.servers = new ArrayList<Server>(getServerManager().getServers());
+
+        if (this.servers.size() == 0) {
+            // disable control if necessary
+            if (this.cbxServer.getEnabled()) {
+                this.cbxServer.setEnabled(false);
+            }
+        } else if (this.servers.size() == 1) {
+            this.server = this.servers.get(0);
+            this.cbxServer.add(this.server.getName());
+            this.cbxServer.select(0);
+
+            // enable control if necessary
+            if (!this.cbxServer.getEnabled()) {
+                this.cbxServer.setEnabled(true);
+            }
+        } else {
+            // add an item for each server
+            for (Server server : this.servers) {
+                this.cbxServer.add(server.getName());
+            }
+
+            // enable control if necessary
+            if (!this.cbxServer.getEnabled()) {
+                this.cbxServer.setEnabled(true);
+            }
+        }
+
+        // must reload repositories
+        resetRepositories();
     }
 
     /**
+     * Resets the workspace-related fields and controls.
+     * 
+     * @since 0.6
+     */
+    private void resetWorkspaces() {
+        this.workspace = null;
+
+        if (this.repository == null) {
+            this.workspaces = Collections.emptyList();
+        } else {
+            this.workspaces = new ArrayList<Workspace>(this.repository.getWorkspaces());
+        }
+
+        // uninstall listeners to prevent handling events
+        uninstallLocationListeners();
+
+        // clear items
+        this.cbxWorkspace.removeAll();
+
+        // reload
+        if (this.workspaces.isEmpty()) {
+            // disable control if necessary
+            if (this.cbxWorkspace.getEnabled()) {
+                this.cbxWorkspace.setEnabled(false);
+            }
+        } else if (this.workspaces.size() == 1) {
+            this.workspace = this.workspaces.get(0);
+            this.cbxWorkspace.add(this.workspace.getName());
+            this.cbxWorkspace.select(0);
+
+            // enable control if necessary
+            if (!this.cbxWorkspace.getEnabled()) {
+                this.cbxWorkspace.setEnabled(true);
+            }
+        } else {
+            // add an item for each workspace
+            for (Workspace workspace : this.workspaces) {
+                this.cbxWorkspace.add(workspace.getName());
+            }
+
+            // enable control if necessary
+            if (!this.cbxWorkspace.getEnabled()) {
+                this.cbxWorkspace.setEnabled(true);
+            }
+        }
+
+        // reinstall listening
+        installLocationListeners();
+    }
+
+    /**
      * {@inheritDoc}
      * 
      * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
@@ -403,7 +540,7 @@
             int count = this.cbxRepository.getItemCount();
             msg = ((count == 0) ? I18n.PublishPageNoAvailableRepositoriesStatusMsg : I18n.PublishPageMissingRepositoryStatusMsg);
         } else if (this.workspace == null) {
-            int count = this.cbxServer.getItemCount();
+            int count = this.cbxWorkspace.getItemCount();
             msg = ((count == 0) ? I18n.PublishPageNoAvailableWorkspacesStatusMsg : I18n.PublishPageMissingWorkspaceStatusMsg);
         } else {
             severity = Severity.OK;
@@ -412,4 +549,5 @@
 
         this.status = new Status(severity, msg, null);
     }
+
 }




More information about the dna-commits mailing list