incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1415704 - in /sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin: ./ src/org/apache/sling/slingclipse/images/ src/org/apache/sling/slingclipse/ui/wizards/
Date Fri, 30 Nov 2012 15:43:49 GMT
Author: asanso
Date: Fri Nov 30 15:43:46 2012
New Revision: 1415704

URL: http://svn.apache.org/viewvc?rev=1415704&view=rev
Log:
SLING-2680 - [Tooling] Usability improvements for the Slingclipse import wizard. Applied patch
from Robert Munteanu. Thanks!!

Added:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/SharedImages.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/sling-logo.png
  (with props)
Modified:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml?rev=1415704&r1=1415703&r2=1415704&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml (original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml Fri Nov 30 15:43:46
2012
@@ -27,9 +27,9 @@
       <wizard
             category="org.apache.sling.slingclipse.ui.wizards.sampleCategory"
             class="org.apache.sling.slingclipse.ui.wizards.ImportWizard"
-            icon="icons/sample.gif"
+            icon="src/org/apache/sling/slingclipse/images/sling-logo.png"
             id="org.apache.sling.slingclipse.ui.wizards.ImportWizard"
-            name="Import from Repository">
+            name="Import from Sling Repository">
          <description>
             Import a file from the local file system into the workspace.
          </description>

Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/SharedImages.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/SharedImages.java?rev=1415704&view=auto
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/SharedImages.java
(added)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/SharedImages.java
Fri Nov 30 15:43:46 2012
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.slingclipse.images;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+
+/**
+ * The <tt>SharedImages</tt> class contains references to images
+ * 
+ */
+public final class SharedImages {
+    
+    public static final ImageDescriptor SLING_LOG = ImageDescriptor.createFromFile(SharedImages.class,
"sling-logo.png");
+
+    private SharedImages() {
+    }
+
+}

Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/sling-logo.png
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/sling-logo.png?rev=1415704&view=auto
==============================================================================
Binary file - no diff available.

Propchange: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/images/sling-logo.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java?rev=1415704&r1=1415703&r2=1415704&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
Fri Nov 30 15:43:46 2012
@@ -17,6 +17,7 @@
 package org.apache.sling.slingclipse.ui.wizards;
 
 import java.io.ByteArrayInputStream;
+import java.lang.reflect.InvocationTargetException;
 import java.nio.charset.Charset;
 import java.util.Iterator;
 
@@ -29,6 +30,7 @@ import org.apache.sling.slingclipse.api.
 import org.apache.sling.slingclipse.api.Result;
 import org.apache.sling.slingclipse.helper.SlingclipseHelper;
 import org.apache.sling.slingclipse.helper.Tracer;
+import org.apache.sling.slingclipse.images.SharedImages;
 import org.apache.sling.slingclipse.preferences.PreferencesMessages;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
@@ -37,9 +39,9 @@ import org.eclipse.core.resources.Resour
 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.Status;
-import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
@@ -56,73 +58,61 @@ import org.json.JSONObject;
 public class ImportWizard extends Wizard implements IImportWizard {
 	private ImportWizardPage mainPage;
 
-	/**
-	 * Construct a new Import Wizard container instance.
-	 */
-	public ImportWizard() {
-		super();
-	}
-
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
 	 */
 	public boolean performFinish() {
+	    
+	    if ( !mainPage.isPageComplete() )
+	        return false;
+		
+		final Repository repository = SlingclipsePlugin.getDefault().getRepository();
+		RepositoryInfo repositoryInfo = new RepositoryInfo(
+				mainPage.getUsername(),
+				mainPage.getPassword(),
+				mainPage.getRepositoryUrl());
+		repository.setRepositoryInfo(repositoryInfo);
+ 
+		IPath destinationPath = mainPage.getResourcePath();
 		
+		final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(destinationPath.segments()[0]);
+		final IPath projectRelativePath = destinationPath.removeFirstSegments(1);
+		final String repositoryPath = mainPage.getRepositoryPath();
 		
-		if (mainPage.isPageComplete()) {
+        try {
+            getContainer().run(false, true, new IRunnableWithProgress() {
+
+                @Override
+                public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
+                    Tracer tracer = SlingclipsePlugin.getDefault().getTracer();
 
-			final Repository repository = SlingclipsePlugin.getDefault().getRepository();
-			RepositoryInfo repositoryInfo = new RepositoryInfo(
-					mainPage.getUsername(),
-					mainPage.getPassword(),
-					mainPage.getRepositoryUrl());
-			repository.setRepositoryInfo(repositoryInfo);
-	 
-			IPath destinationPath = mainPage.getResourcePath();
-			
-			final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(destinationPath.segments()[0]);
-			final IPath projectRelativePath = destinationPath.removeFirstSegments(1);
-			final String repositoryPath = mainPage.getRepositoryPath();
-			
-			Job job = new Job("Import") {
-				
-
-				protected IStatus run(IProgressMonitor monitor) {
-					
-					Tracer tracer = SlingclipsePlugin.getDefault().getTracer();
-					
-					monitor.setTaskName("Loading configuration...");
-					monitor.worked(5);
-					
-					IPreferenceStore store = SlingclipsePlugin.getDefault().getPreferenceStore();
-					boolean autoSync=store.getBoolean(PreferencesMessages.REPOSITORY_AUTO_SYNC.getKey());
-					try {
-						store.setValue(PreferencesMessages.REPOSITORY_AUTO_SYNC.getKey(), false);
-
-						// TODO: We should try to make this give 'nice' progress feedback (aka here's what
I'm processing)
-						monitor.setTaskName("Importing...");
-						monitor.worked(10);
+                    monitor = SubMonitor.convert(monitor, "Importing from " + mainPage.getRepositoryUrl()
+ " ...",
+                            IProgressMonitor.UNKNOWN);
+
+                    IPreferenceStore store = SlingclipsePlugin.getDefault().getPreferenceStore();
+                    boolean autoSync = store.getBoolean(PreferencesMessages.REPOSITORY_AUTO_SYNC.getKey());
+                    try {
+                        store.setValue(PreferencesMessages.REPOSITORY_AUTO_SYNC.getKey(),
false);
+
+                        // TODO: We should try to make this give 'nice' progress feedback
(aka here's what I'm
+                        // processing)
+
+                        // TODO: check for cancellation
 
                         // we create the root node and assume this is a folder
                         createRoot(project, projectRelativePath, repositoryPath);
 
-				 		crawlChildrenAndImport(repository, repositoryPath, project, projectRelativePath, tracer);
-						
-						monitor.setTaskName("Import Complete");
-						monitor.worked(100);
-					} catch ( Exception e) {
-						Status status = new Status(Status.ERROR, SlingclipsePlugin.PLUGIN_ID, "Failed importing
repository ", e);
-						SlingclipsePlugin.getDefault().getLog().log(status);
-						return status;
-					}finally{
-						//restore to the original value
-						store.setValue(PreferencesMessages.REPOSITORY_AUTO_SYNC.getKey(), autoSync);
-					}
-					
-					return Status.OK_STATUS;
-				}
+                        crawlChildrenAndImport(repository, repositoryPath, project, projectRelativePath,
tracer);
+                    } catch (Exception e) {
+                        throw new InvocationTargetException(e);
+                    } finally {
+                        monitor.done();
+                        // restore to the original value
+                        store.setValue(PreferencesMessages.REPOSITORY_AUTO_SYNC.getKey(),
autoSync);
+                    }
+                }
 
                 private void createRoot(final IProject project, final IPath projectRelativePath,
                         final String repositoryPath) throws CoreException {
@@ -132,14 +122,18 @@ public class ImportWizard extends Wizard
                     for (int i = rootImportPath.segmentCount() - 1; i > 0; i--)
                         createFolder(project, rootImportPath.removeLastSegments(i));
                 }
-			};
-			job.setSystem(false);
-			job.setUser(true);
-			job.schedule();
-			return true;
-		} else {
-			return false;
-		}
+            });
+        } catch (InterruptedException e) {
+            return false;
+        } catch (InvocationTargetException e) {
+            Throwable cause = e.getCause();
+            mainPage.setErrorMessage("Import error : " + cause.getMessage()
+                    + " . Please see the error log for details.");
+            SlingclipsePlugin.getDefault().getLog()
+                    .log(new Status(Status.ERROR, SlingclipsePlugin.PLUGIN_ID, "Repository
import failed", cause));
+            return false;
+        }
+		return true;
 	}
 
 	/*
@@ -150,6 +144,7 @@ public class ImportWizard extends Wizard
 	 */
 	public void init(IWorkbench workbench, IStructuredSelection selection) {
 		setWindowTitle("Repositoy Import"); // NON-NLS-1
+        setDefaultPageImageDescriptor(SharedImages.SLING_LOG);
 		setNeedsProgressMonitor(true);
 		mainPage = new ImportWizardPage("Import from Repository", selection); // NON-NLS-1
 	}

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java?rev=1415704&r1=1415703&r2=1415704&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java
Fri Nov 30 15:43:46 2012
@@ -16,13 +16,14 @@
  */
 package org.apache.sling.slingclipse.ui.wizards;
 
-import java.util.List;
-
 import org.apache.sling.slingclipse.SlingclipsePlugin;
 import org.apache.sling.slingclipse.helper.SlingclipseHelper;
 import org.apache.sling.slingclipse.preferences.PreferencesMessages;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -55,7 +56,9 @@ public class ImportWizardPage extends Wi
 				determinePageCompletion();
 				updateWidgetEnablements();
 			}catch(Exception e){
-				//TODO: Log or just ignore?
+                setErrorMessage(e.getMessage());
+                SlingclipsePlugin.getDefault().getLog()
+                        .log(new Status(Status.ERROR, SlingclipsePlugin.PLUGIN_ID, e.getMessage(),
e));
 			}
 		}
 	};
@@ -165,12 +168,37 @@ public class ImportWizardPage extends Wi
 		path = new Text(container, SWT.BORDER);
 		path.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
 		path.addModifyListener(modifyListener);
-		
 
-		if (SlingclipseHelper.isValidSlingProjectPath(pathStr)) {
-			path.setText(SlingclipseHelper.getSlingProjectPath(pathStr));
-		}
-	}
+        if (SlingclipseHelper.isValidSlingProjectPath(pathStr)) {
+            path.setText(SlingclipseHelper.getSlingProjectPath(pathStr));
+        }
+
+        preselectJcrRootFolderForProject(resource);
+	}
+
+    private void preselectJcrRootFolderForProject(IResource resource) {
+        if (resource.getType() == IResource.PROJECT) {
+            try {
+                resource.accept(new IResourceVisitor() {
+                    public boolean visit(IResource resource) throws CoreException {
+
+                        if (resource.getType() == IResource.FILE)
+                            return false;
+
+                        if (SlingclipseHelper.JCR_ROOT.equals(resource.getName()) &&
resource.getType() == IResource.FOLDER) {
+                            setContainerFieldValue(resource.getFullPath().toString());
+                            return false;
+                        }
+
+                        return true;
+                    }
+                });
+            } catch (CoreException e) {
+                // best effort
+                SlingclipsePlugin.getDefault().getLog().log(e.getStatus());
+            }
+        }
+    }
 
 	/*
 	 * (non-Javadoc)
@@ -263,9 +291,14 @@ public class ImportWizardPage extends Wi
 			return false;
 		}
 		
+        if (getRepositoryPath().toString().endsWith("/")) {
+            setErrorMessage("The repository path must not have a trailing slash");
+            return false;
+        }
+
 		IPath containerNameField= super.getResourcePath();  
 		if (!containerNameField.toOSString().endsWith(SlingclipseHelper.JCR_ROOT)){
-			setErrorMessage("Please enter a valid Sling project folder (e.g. jcr_root)");
+            setErrorMessage("The folder name must be " + SlingclipseHelper.JCR_ROOT);
 			return false;
 		}
 		



Mime
View raw message