You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2014/05/14 23:38:31 UTC

svn commit: r1594736 - in /sling/trunk/tooling/ide/eclipse-ui: ./ src/org/apache/sling/ide/eclipse/ui/internal/

Author: rombert
Date: Wed May 14 21:38:30 2014
New Revision: 1594736

URL: http://svn.apache.org/r1594736
Log:
SLING-2651 - Manually trigger sync on files/directories

Add a basic export wizard, registered for project nodes only for now.

Added:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportContentAction.java   (with props)
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java   (with props)
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizardPage.java   (with props)
Modified:
    sling/trunk/tooling/ide/eclipse-ui/plugin.xml
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java

Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1594736&r1=1594735&r2=1594736&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Wed May 14 21:38:30 2014
@@ -105,6 +105,32 @@
 		    </or>         
          </enablement>
 		</objectContribution>
+		<!-- Export -->
+		<objectContribution id="org.apache.sling.ide.menu.export"
+         	objectClass="org.eclipse.core.resources.IProject">
+         	
+         <action
+               class="org.apache.sling.ide.eclipse.ui.internal.ExportContentAction"
+               id="org.apache.sling.ide.menu.exportContentAction"
+               definitionId="org.apache.sling.ide.commands.exportContent"
+               label="Export Content..."
+               menubarPath="org.apache.sling.ide.menu/sling"
+               style="push">
+         </action>
+         <visibility>
+               <objectState
+                     name="open"
+                     value="true">
+               </objectState>
+         </visibility>
+         <enablement>
+			<or>
+			    <test 
+		            property="org.eclipse.wst.common.project.facet.core.projectFacet" 
+		            value="sling.content"/>
+		    </or>         
+         </enablement>
+		</objectContribution>		
   </extension>
    <extension
          point="org.eclipse.ui.importWizards">
@@ -132,6 +158,12 @@
                categoryId="org.eclipse.ui.category.window"
                defaultHandler="org.apache.sling.ide.eclipse.ui.internal.ImportContentAction">
          </command>
+         <command
+               id="org.apache.sling.ide.commands.exportContent"
+               name="Export content to a Sling Repository"
+               categoryId="org.eclipse.ui.category.window"
+               defaultHandler="org.apache.sling.ide.eclipse.ui.internal.ExportContentAction">
+         </command>         
    </extension>
 
    <!-- Property page for project to select directory to sync -->
@@ -511,6 +543,12 @@
             schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
             sequence="M1+M2+I">
       </key>
+      <key
+            commandId="org.apache.sling.ide.commands.exportContent"
+            contextId="org.eclipse.ui.contexts.window"
+            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+            sequence="M1+M2+P">
+      </key>      
    </extension>
 
     <extension

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportContentAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportContentAction.java?rev=1594736&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportContentAction.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportContentAction.java Wed May 14 21:38:30 2014
@@ -0,0 +1,98 @@
+package org.apache.sling.ide.eclipse.ui.internal;
+
+import java.util.Iterator;
+
+import org.apache.sling.ide.eclipse.core.ProjectUtil;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class ExportContentAction extends AbstractHandler implements IObjectActionDelegate, IExecutableExtension {
+
+    private ISelection selection;
+
+    @Override
+    public void run(IAction action) {
+        run(selection);
+    }
+
+    private void run(ISelection selection) {
+
+        if (!(selection instanceof IStructuredSelection)) {
+            return;
+        }
+
+        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+
+        for (Iterator<?> it = structuredSelection.iterator(); it.hasNext();) {
+            Object selected = it.next();
+            if (selected instanceof IProject) {
+                IProject project = (IProject) selected;
+
+                IFolder syncDir = ProjectUtil.getSyncDirectory(project);
+
+                Shell activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+
+                ExportWizard wiz = new ExportWizard();
+                wiz.init(PlatformUI.getWorkbench(), syncDir);
+
+                WizardDialog dialog = new WizardDialog(activeShell, wiz);
+                dialog.open();
+            }
+        }
+
+    }
+
+    @Override
+    public void selectionChanged(IAction action, ISelection selection) {
+        this.selection = selection;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+     */
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        run(HandlerUtil.getCurrentSelection(event));
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement
+     * , java.lang.String, java.lang.Object)
+     */
+    @Override
+    public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
+            throws CoreException {
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
+     * org.eclipse.ui.IWorkbenchPart)
+     */
+    @Override
+    public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+    }
+
+}

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportContentAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportContentAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java?rev=1594736&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java Wed May 14 21:38:30 2014
@@ -0,0 +1,116 @@
+/*
+ * 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.ide.eclipse.ui.internal;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.sling.ide.eclipse.core.ServerUtil;
+import org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory;
+import org.apache.sling.ide.transport.Command;
+import org.apache.sling.ide.transport.Repository;
+import org.apache.sling.ide.transport.Result;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbench;
+
+public class ExportWizard extends Wizard {
+
+    private IResource syncStartPoint;
+    private ExportWizardPage exportPage;
+
+    public void init(IWorkbench workbench, IResource syncStartPoint) {
+        setWindowTitle("Repositoy Export"); // NON-NLS-1
+        setNeedsProgressMonitor(true);
+        setDefaultPageImageDescriptor(SharedImages.SLING_LOG);
+
+        this.syncStartPoint = syncStartPoint;
+        this.exportPage = new ExportWizardPage(syncStartPoint);
+    }
+
+    @Override
+    public void addPages() {
+        addPage(exportPage);
+    }
+
+    @Override
+    public boolean performFinish() {
+
+        try {
+            getContainer().run(true, false, new IRunnableWithProgress() {
+
+                @Override
+                public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+                    final ResourceChangeCommandFactory factory = new ResourceChangeCommandFactory(Activator
+                            .getDefault().getSerializationManager());
+
+                    final Repository[] selectedServer = new Repository[1];
+                    Display.getDefault().syncExec(new Runnable() {
+                        @Override
+                        public void run() {
+                            try {
+                                selectedServer[0] = ServerUtil.getRepository(exportPage.getServer(), monitor);
+                            } catch (CoreException e) {
+                                throw new RuntimeException(e);
+                            }
+                        }
+                    });
+
+                    try {
+
+                        syncStartPoint.accept(new IResourceVisitor() {
+
+                            @Override
+                            public boolean visit(IResource resource) throws CoreException {
+                                Command<?> command = factory.newCommandForAddedOrUpdated(selectedServer[0], resource);
+                                if (command == null) {
+                                    return true;
+                                }
+                                Result<?> result = command.execute();
+                                if (!result.isSuccess()) {
+                                    throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID,
+                                            "Failed exporting: " + result.toString()));
+                                }
+
+                                return true;
+                            }
+                        });
+                    } catch (CoreException e) {
+                        throw new InvocationTargetException(e);
+                    } catch (Throwable t) {
+                        t.printStackTrace();
+                        throw new InvocationTargetException(t);
+                    }
+                }
+            });
+
+            return true;
+        } catch (InvocationTargetException e) {
+            exportPage.setErrorMessage(e.getMessage());
+            return false;
+        } catch (InterruptedException e) {
+            exportPage.setErrorMessage(e.getMessage());
+            return false;
+        }
+
+    }
+}

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizardPage.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizardPage.java?rev=1594736&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizardPage.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizardPage.java Wed May 14 21:38:30 2014
@@ -0,0 +1,113 @@
+/*
+ * 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.ide.eclipse.ui.internal;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+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.Label;
+import org.eclipse.ui.dialogs.WizardDataTransferPage;
+import org.eclipse.wst.server.core.IServer;
+
+public class ExportWizardPage extends WizardDataTransferPage {
+
+    private SlingLaunchpadCombo repositoryCombo;
+    private IResource syncStartPoint;
+
+    public ExportWizardPage(IResource syncStartPoint) {
+        super("Repository selection");
+        setTitle("Repository selection");
+        setDescription("Select a repository to export content to");
+        this.syncStartPoint = syncStartPoint;
+    }
+
+    @Override
+    public void handleEvent(Event event) {
+        determinePageCompletion();
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        Composite composite = new Composite(parent, SWT.NULL);
+        composite.setLayout(new GridLayout());
+        composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
+        composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+
+        Composite container = new Composite(composite, SWT.NONE);
+        container.setLayout(new GridLayout(2, false));
+        GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+        gridData.minimumWidth = 450;
+        container.setLayoutData(gridData);
+
+        new Label(container, SWT.NONE).setText("Repository: ");
+
+        repositoryCombo = new SlingLaunchpadCombo(container, syncStartPoint.getProject());
+        repositoryCombo.getWidget().addSelectionListener(new SelectionListener() {
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                determinePageCompletion();
+                updateWidgetEnablements();
+            }
+
+            @Override
+            public void widgetDefaultSelected(SelectionEvent e) {
+                determinePageCompletion();
+                updateWidgetEnablements();
+            }
+        });
+        repositoryCombo.refreshRepositoryList(new NullProgressMonitor());
+
+        createOptionsGroup(composite);
+
+        setControl(composite);
+
+        updateWidgetEnablements();
+        determinePageCompletion();
+    }
+
+    public IServer getServer() {
+        return repositoryCombo.getServer();
+    }
+
+    @Override
+    protected boolean allowNewContainerName() {
+        return false;
+    }
+
+    @Override
+    protected void createOptionsGroup(Composite parent) {
+
+    }
+
+    @Override
+    protected boolean validateDestinationGroup() {
+        String repositoryError = repositoryCombo.getErrorMessage();
+        if (repositoryError != null) {
+            setErrorMessage(repositoryError);
+            return false;
+        }
+
+        return true;
+    }
+}

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizardPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizardPage.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java?rev=1594736&r1=1594735&r2=1594736&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java Wed May 14 21:38:30 2014
@@ -17,7 +17,6 @@
 package org.apache.sling.ide.eclipse.ui.internal;
 
 import java.io.File;
-import java.util.List;
 
 import org.apache.sling.ide.eclipse.core.ProjectUtil;
 import org.apache.sling.ide.filter.FilterLocator;
@@ -41,7 +40,6 @@ import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.layout.RowLayout;
 import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Label;
@@ -52,7 +50,6 @@ import org.eclipse.ui.dialogs.ISelection
 import org.eclipse.ui.dialogs.PreferencesUtil;
 import org.eclipse.ui.dialogs.WizardDataTransferPage;
 import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.ServerCore;
 
 /**
  * Wizard page for importing content from Sling Repositories.