Author: rombert
Date: Mon Feb 22 16:06:47 2016
New Revision: 1731671

URL: http://svn.apache.org/viewvc?rev=1731671&view=rev
Log:
SLING-5538 - Create new Sightly file wizards

Add a new Sightly file wizard

Added:
    sling/trunk/tooling/ide/eclipse-sightly-ui/icons/wizban/
    sling/trunk/tooling/ide/eclipse-sightly-ui/icons/wizban/sightly.gif
    
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/Constants.java
      - copied, changed from r1731670, 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/SharedImages.java
    
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileHandler.java
    
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.java
Modified:
    sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF
    sling/trunk/tooling/ide/eclipse-sightly-ui/META-INF/MANIFEST.MF
    sling/trunk/tooling/ide/eclipse-sightly-ui/plugin.xml
    
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/SharedImages.java

Modified: sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF?rev=1731671&r1=1731670&r2=1731671&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF Mon Feb 
22 16:06:47 2016
@@ -9,10 +9,11 @@ Require-Bundle: org.eclipse.core.runtime
  org.eclipse.core.resources,
  org.eclipse.swt,
  org.eclipse.osgi
-Import-Package: org.apache.sling.ide.eclipse.core.debug,
- org.apache.sling.ide.eclipse.core,
+Import-Package: org.apache.sling.ide.eclipse.core,
+ org.apache.sling.ide.eclipse.core.debug,
  org.apache.sling.ide.eclipse.core.facet,
  org.apache.sling.ide.log,
+ org.eclipse.core.expressions,
  org.eclipse.jface.resource,
  org.eclipse.jface.text,
  org.eclipse.jface.text.contentassist,

Modified: sling/trunk/tooling/ide/eclipse-sightly-ui/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/META-INF/MANIFEST.MF?rev=1731671&r1=1731670&r2=1731671&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-sightly-ui/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-sightly-ui/META-INF/MANIFEST.MF Mon Feb 22 
16:06:47 2016
@@ -6,13 +6,19 @@ Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.core.resources,
+ org.eclipse.jface,
  org.eclipse.swt
 Import-Package: org.apache.sling.ide.eclipse.sightly,
  org.apache.sling.ide.eclipse.sightly.model,
  org.apache.sling.ide.eclipse.sightly.validation,
- org.eclipse.jface.resource,
+ org.eclipse.core.commands,
  org.eclipse.jface.text,
  org.eclipse.jface.text.contentassist,
+ org.eclipse.ui,
+ org.eclipse.ui.dialogs,
+ org.eclipse.ui.handlers,
+ org.eclipse.ui.ide,
+ org.eclipse.ui.statushandlers,
  org.eclipse.wst.html.core.internal.validation,
  org.eclipse.wst.html.internal.validation,
  org.eclipse.wst.sse.core,

Added: sling/trunk/tooling/ide/eclipse-sightly-ui/icons/wizban/sightly.gif
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/icons/wizban/sightly.gif?rev=1731671&view=auto
==============================================================================
Binary files 
sling/trunk/tooling/ide/eclipse-sightly-ui/icons/wizban/sightly.gif (added) and 
sling/trunk/tooling/ide/eclipse-sightly-ui/icons/wizban/sightly.gif Mon Feb 22 
16:06:47 2016 differ

Modified: sling/trunk/tooling/ide/eclipse-sightly-ui/plugin.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/plugin.xml?rev=1731671&r1=1731670&r2=1731671&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-sightly-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-sightly-ui/plugin.xml Mon Feb 22 16:06:47 
2016
@@ -60,5 +60,53 @@
        <!-- Facet images  --> 
     <extension point="org.eclipse.wst.common.project.facet.ui.images">
         <image facet="sightly" path="icons/obj16/sightly.gif" />
-  </extension> 
-</plugin>
\ No newline at end of file
+  </extension>
+  
+   <!-- Wizards -->
+   <extension
+         point="org.eclipse.ui.newWizards">
+      <category
+            id="org.apache.sling.ide.eclipse.sightly.ui"
+            name="Sightly">
+      </category>
+      <wizard
+            category="org.apache.sling.ide.eclipse.sightly.ui"
+            
class="org.apache.sling.ide.eclipse.sightly.ui.internal.NewSightlyFileWizard"
+            icon="icons/obj16/sightly.gif"
+            
id="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyFileWizard"
+            name="Sightly File">
+      </wizard>
+   </extension>
+   
+   <!-- Menu contributions -->
+   <extension
+         point="org.eclipse.ui.menus">
+        <menuContribution
+              locationURI="popup:common.new.menu?after=new">
+              <!-- enabled for all resources part of a Sightly Project -->
+              <command
+               
commandId="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyFileHandler"
+               icon="icons/obj16/sightly.gif"
+               label="&amp;Sightly File">
+                 <visibleWhen
+                       checkEnabled="false">
+                   <iterate ifEmpty="false">
+                        <test
+                            
property="org.apache.sling.ide.eclipse.sightly.sightlyNature">
+                        </test>
+                   </iterate>
+                 </visibleWhen>
+              </command>              
+        </menuContribution>         
+   </extension>
+   
+   <!-- commands -->
+   <extension
+         point="org.eclipse.ui.commands">
+             <command
+                       
id="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyFileHandler"
+                       
defaultHandler="org.apache.sling.ide.eclipse.sightly.ui.internal.NewSightlyFileHandler"
+                       name="New Sightly File...">
+         </command>
+   </extension>
+</plugin>

Copied: 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/Constants.java
 (from r1731670, 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/SharedImages.java)
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/Constants.java?p2=sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/Constants.java&p1=sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/SharedImages.java&r1=1731670&r2=1731671&rev=1731671&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/SharedImages.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/Constants.java
 Mon Feb 22 16:06:47 2016
@@ -16,14 +16,7 @@
  */
 package org.apache.sling.ide.eclipse.sightly.ui.internal;
 
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.osgi.framework.FrameworkUtil;
-
-public class SharedImages {
-
-    public static final ImageDescriptor SIGHTLY_ICON = 
ImageDescriptor.createFromURL(
-            FileLocator.find(FrameworkUtil.getBundle(SharedImages.class), 
Path.fromPortableString("icons/obj16/sightly.gif"), null));
-
+public class Constants {
+    public static final String PLUGIN_ID = 
"org.apache.sling.ide.eclipse-sightly-ui";
+    
 }

Added: 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileHandler.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileHandler.java?rev=1731671&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileHandler.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileHandler.java
 Mon Feb 22 16:06:47 2016
@@ -0,0 +1,43 @@
+/*
+ * 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.sightly.ui.internal;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class NewSightlyFileHandler extends AbstractHandler {
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        
+        ISelection selection = HandlerUtil.getCurrentSelection(event);
+        
+        NewSightlyFileWizard wiz = new NewSightlyFileWizard();
+        wiz.init(HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench(), 
(IStructuredSelection) selection);
+        
+        WizardDialog dialog = new 
WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wiz);
+        dialog.open();
+        
+        return null;
+    }
+}

Added: 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.java?rev=1731671&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.java
 (added)
+++ 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.java
 Mon Feb 22 16:06:47 2016
@@ -0,0 +1,102 @@
+/*
+ * 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.sightly.ui.internal;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.statushandlers.StatusManager;
+
+public class NewSightlyFileWizard extends Wizard implements INewWizard {
+
+    private IWorkbench workbench;
+    private WizardNewFileCreationPage fileCreationPage;
+
+    @Override
+    public void init(IWorkbench workbench, IStructuredSelection selection) {
+        
+        this.workbench = workbench;
+        
+        fileCreationPage = new WizardNewFileCreationPage("New Sightly File", 
selection) {
+            
+            @Override
+            protected InputStream getInitialContents() {
+                String contents = ""
+                        + "<!DOCTYPE html!>\n"
+                        + "<!--/* A simple sightly script */-->\n"
+                        + "<html>\n"
+                        + " <head>\n"
+                        + "   <title>${properties.jcr:title}</title>\n"
+                        + "  </head>\n"
+                        + "  <body>\n"
+                        + "    <h1 
data-sly-test=\"${properties.jcr:title}\">${properties.jcr:title}</h1>\n"
+                        + "  </body>\n"
+                        + "</html>"
+                        + "";
+                
+                return new ByteArrayInputStream(contents.getBytes());
+            }
+        };
+        fileCreationPage.setTitle("Sighty");
+        fileCreationPage.setDescription("Create a new Sightly file");
+        
fileCreationPage.setImageDescriptor(SharedImages.SIGHTLY_WIZARD_BANNER);
+        
+        
+        setWindowTitle("New Sightly File");
+        addPage(fileCreationPage);
+    }
+
+    @Override
+    public boolean performFinish() {
+        
+        if ( !fileCreationPage.isPageComplete() ) {
+            return false;
+        }
+        
+        IFile file = fileCreationPage.createNewFile();
+        
+        // copied from BasicNewFileResourceWizard
+        // Open editor on new file.
+        IWorkbenchWindow dw = workbench.getActiveWorkbenchWindow();
+        try {
+            if (dw != null) {
+                IWorkbenchPage page = dw.getActivePage();
+                if (page != null) {
+                    IDE.openEditor(page, file, true);
+                }
+            }
+        } catch (PartInitException e) {
+            StatusManager.getManager().handle(new Status(IStatus.WARNING, 
Constants.PLUGIN_ID, "Failed opening " + file + " in an editor", e), 
+                    StatusManager.SHOW | StatusManager.LOG);
+        }
+        
+        return true;
+    }
+
+}

Modified: 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/SharedImages.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/SharedImages.java?rev=1731671&r1=1731670&r2=1731671&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/SharedImages.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/SharedImages.java
 Mon Feb 22 16:06:47 2016
@@ -26,4 +26,7 @@ public class SharedImages {
     public static final ImageDescriptor SIGHTLY_ICON = 
ImageDescriptor.createFromURL(
             FileLocator.find(FrameworkUtil.getBundle(SharedImages.class), 
Path.fromPortableString("icons/obj16/sightly.gif"), null));
 
+    public static final ImageDescriptor SIGHTLY_WIZARD_BANNER = 
ImageDescriptor.createFromURL(
+            FileLocator.find(FrameworkUtil.getBundle(SharedImages.class), 
Path.fromPortableString("icons/wizban/sightly.gif"), null));
+
 }


Reply via email to