incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1403719 - in /sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin: ./ META-INF/ src/org/apache/sling/slingclipse/ui/ src/org/apache/sling/slingclipse/ui/wizards/
Date Tue, 30 Oct 2012 14:35:46 GMT
Author: asanso
Date: Tue Oct 30 14:35:46 2012
New Revision: 1403719

URL: http://svn.apache.org/viewvc?rev=1403719&view=rev
Log:
SLING-2636 - [Tooling] Add ability to Import from Sling Repository. Applying patch from Dan
Kico!

Added:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/
    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/META-INF/MANIFEST.MF
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/META-INF/MANIFEST.MF?rev=1403719&r1=1403718&r2=1403719&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/META-INF/MANIFEST.MF (original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/META-INF/MANIFEST.MF Tue Oct
30 14:35:46 2012
@@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.ui,
  org.apache.commons.httpclient;bundle-version="3.1.0",
  org.apache.sling.slingclipse.api;bundle-version="0.0.1",
  org.eclipse.equinox.ds;bundle-version="1.2.1",
- org.eclipse.osgi.services;bundle-version="3.2.100"
+ org.eclipse.osgi.services;bundle-version="3.2.100",
+ org.eclipse.ui.ide
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ClassPath: .

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=1403719&r1=1403718&r2=1403719&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml (original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml Tue Oct 30 14:35:46
2012
@@ -24,5 +24,22 @@
             class="org.apache.sling.slingclipse.SlingclipseStrartup">
       </startup>
    </extension>
+   <extension
+         point="org.eclipse.ui.importWizards">
+      <category
+            id="org.apache.sling.slingclipse.ui.wizards.sampleCategory"
+            name="Sling">
+      </category>
+      <wizard
+            category="org.apache.sling.slingclipse.ui.wizards.sampleCategory"
+            class="org.apache.sling.slingclipse.ui.wizards.ImportWizard"
+            icon="icons/sample.gif"
+            id="org.apache.sling.slingclipse.ui.wizards.ImportWizard"
+            name="Import from Repository">
+         <description>
+            Import a file from the local file system into the workspace.
+         </description>
+      </wizard>
+   </extension>
 
 </plugin>

Added: 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=1403719&view=auto
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
(added)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
Tue Oct 30 14:35:46 2012
@@ -0,0 +1,105 @@
+/*
+ * 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.ui.wizards;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ * Renders the import wizard container page for the Slingclipse repository
+ * import.
+ */
+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()) {
+			Job job = new Job("Import") {
+
+				protected IStatus run(IProgressMonitor monitor) {
+					monitor.setTaskName("Starting import...");
+					monitor.worked(10);
+					// TODO: Actually run the job here
+					try {
+						long numMillisecondsToSleep = 5000; // 5 seconds
+						Thread.sleep(numMillisecondsToSleep);
+					} catch (InterruptedException e) {
+					}
+					return Status.OK_STATUS;
+				}
+			};
+			job.addJobChangeListener(new JobChangeAdapter() {
+				public void done(IJobChangeEvent event) {
+					if (event.getResult().isOK()) {
+						System.out.println("Job Succeeded!");
+					} else {
+						System.err.println("Job Failed!");
+					}
+				}
+			});
+			job.setSystem(false);
+			job.setUser(true);
+			job.schedule();
+			return true;
+		} else {
+			return false;
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
+	 * org.eclipse.jface.viewers.IStructuredSelection)
+	 */
+	public void init(IWorkbench workbench, IStructuredSelection selection) {
+		setWindowTitle("Repositoy Import"); // NON-NLS-1
+		setNeedsProgressMonitor(true);
+		mainPage = new ImportWizardPage("Import from Repository", selection); // NON-NLS-1
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.jface.wizard.IWizard#addPages()
+	 */
+	public void addPages() {
+		super.addPages();
+		addPage(mainPage);
+	}
+
+}

Added: 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=1403719&view=auto
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java
(added)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java
Tue Oct 30 14:35:46 2012
@@ -0,0 +1,268 @@
+/*
+ * 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.ui.wizards;
+
+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.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.WizardResourceImportPage;
+
+/**
+ * Wizard page for importing content from Sling Repositories.
+ */
+public class ImportWizardPage extends WizardResourceImportPage {
+
+	private IStructuredSelection selection;
+	private Text password;
+	private Text user;
+	private Text repo;
+	private Text path;
+	private ModifyListener modifyListener = new ModifyListener() {
+		@Override
+		public void modifyText(ModifyEvent event) {
+			try{
+				determinePageCompletion();
+				updateWidgetEnablements();
+			}catch(Exception e){
+				//TODO: Log or just ignore?
+			}
+		}
+	};
+
+	/**
+	 * Creates an import wizard page for importing from a Sling Repository. If
+	 * the initial resource selection contains exactly one container resource
+	 * then it will be used as the default import destination. Multiple
+	 * selections are not supported, but are not disallowed.
+	 * 
+	 * @param pageName
+	 *            the name of the page
+	 * @param selection
+	 *            the current resource selection
+	 */
+	public ImportWizardPage(String pageName, IStructuredSelection selection) {
+		super(pageName, selection);
+		this.selection = selection;
+		setTitle(pageName); // NON-NLS-1
+		setDescription("Import content from a Sling Repository into the workspace"); // NON-NLS-1
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.eclipse.ui.dialogs.WizardResourceImportPage#allowNewContainerName()
+	 */
+	@Override
+	protected boolean allowNewContainerName() {
+		return false;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.eclipse.ui.dialogs.WizardDataTransferPage#createOptionsGroup(org.
+	 * eclipse.swt.widgets.Composite)
+	 */
+	@Override
+	protected void createOptionsGroup(Composite parent) {
+		Group optionsGroup = new Group(parent, SWT.NONE);
+		GridLayout layout = new GridLayout();
+		optionsGroup.setLayout(layout);
+		optionsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+		optionsGroup.setText("Options");
+		optionsGroup.setFont(parent.getFont());
+
+		Composite container = new Composite(optionsGroup, SWT.NONE);
+		container.setLayout(new GridLayout(2, false));
+		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+		gridData.minimumWidth = 450;
+		container.setLayoutData(gridData);
+		
+		IPreferenceStore store = SlingclipsePlugin.getDefault()
+				.getPreferenceStore();
+
+		Label repoLabel = new Label(container, SWT.NONE);
+		repoLabel.setText("Repository URL:");
+		repo = new Text(container, SWT.BORDER);
+		repo.setText(store.getString(PreferencesMessages.REPOSITORY_URL
+				.getKey()));
+		repo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+		repo.addModifyListener(modifyListener);
+
+		Label userLabel = new Label(container, SWT.NONE);
+		userLabel.setText("Username:");
+		user = new Text(container, SWT.BORDER);
+		user.setText(store.getString(PreferencesMessages.USERNAME.getKey()));
+		user.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+		user.addModifyListener(modifyListener);
+
+		Label passwordLabel = new Label(container, SWT.NONE);
+		passwordLabel.setText("Password:");
+		password = new Text(container, SWT.BORDER);
+		password.setText(store.getString(PreferencesMessages.PASSWORD.getKey()));
+		password.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+		password.addModifyListener(modifyListener);
+
+		createOptionsGroupButtons(optionsGroup);
+
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.eclipse.ui.dialogs.WizardResourceImportPage#createSourceGroup(org
+	 * .eclipse.swt.widgets.Composite)
+	 */
+	@Override
+	protected void createSourceGroup(Composite parent) {
+
+		// TODO: Currently only supports first selection
+		IResource resource = ((IResource) selection.getFirstElement());
+		String pathStr = resource.getFullPath().toPortableString();
+
+		Composite container = new Composite(parent, SWT.NONE);
+		container.setLayout(new GridLayout(2, false));
+		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+		gridData.minimumWidth = 450;
+		container.setLayoutData(gridData);
+		
+		Label pathLabel = new Label(container, SWT.NONE);
+		pathLabel.setText("Repository Path:");
+		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));
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.ui.dialogs.WizardResourceImportPage#getFileProvider()
+	 */
+	@Override
+	protected ITreeContentProvider getFileProvider() {
+		// TODO Not sure if I need to return anything here...
+		return null;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.ui.dialogs.WizardResourceImportPage#getFolderProvider()
+	 */
+	@Override
+	protected ITreeContentProvider getFolderProvider() {
+		// TODO Not sure if I need to return anything here...
+		return null;
+	}
+
+	/**
+	 * Get the password with which to connect to the Sling Repository.
+	 * 
+	 * @return the username
+	 */
+	public String getPassword() {
+		return password != null ? password.getText() : null;
+	}
+
+	/**
+	 * Returns the Sling Repository URL to connect to.
+	 * 
+	 * @return the Sling Repository URL
+	 */
+	public String getRepositoryUrl() {
+		return repo != null ? repo.getText() : null;
+	}
+
+	/**
+	 * Returns the path from which to import from the Sling Repository.
+	 * 
+	 * @return the repository path
+	 */
+	public String getRepositoryPath() {
+		return path != null ? path.getText() : null;
+	}
+
+	/**
+	 * Get the username with which to connect to the Sling Repository.
+	 * 
+	 * @return the username
+	 */
+	public String getUsername() {
+		return user != null ? user.getText() : null;
+	}
+
+	public void handleEvent(Event event) {
+		super.handleEvent(event);
+		determinePageCompletion();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.ui.dialogs.WizardDataTransferPage#validateOptionsGroup()
+	 */
+	@Override
+	protected boolean validateOptionsGroup() {
+		if (this.getRepositoryUrl() == null
+				|| this.getRepositoryUrl().trim().length() == 0
+				|| this.getUsername() == null
+				|| this.getUsername().trim().length() == 0
+				|| this.getPassword() == null
+				|| this.getPassword().trim().length() == 0) {
+			setErrorMessage("Please enter valid server information");
+			return false;
+		}
+		return true;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.ui.dialogs.WizardDataTransferPage#validateSourceGroup()
+	 */
+	@Override
+	protected boolean validateSourceGroup() {
+		if (getRepositoryPath() == null
+				|| getRepositoryPath().trim().length() == 0) {
+			setErrorMessage("Please enter a valid Sling Repository path");
+			return false;
+		}
+		return true;
+	}
+}



Mime
View raw message