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 2016/02/22 17:06:58 UTC

svn commit: r1731673 - in /sling/trunk/tooling/ide/eclipse-sightly-ui: ./ META-INF/ src/org/apache/sling/ide/eclipse/sightly/ui/internal/

Author: rombert
Date: Mon Feb 22 16:06:57 2016
New Revision: 1731673

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

Add a new Sightly Java use-script wizard

Added:
    sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptHandler.java
    sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptWizard.java
Modified:
    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/AbstractNewSightlyFileWizard.java

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=1731673&r1=1731672&r2=1731673&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:57 2016
@@ -8,7 +8,8 @@ Require-Bundle: org.eclipse.core.runtime
  org.eclipse.core.resources,
  org.eclipse.jface,
  org.eclipse.swt
-Import-Package: org.apache.sling.ide.eclipse.sightly,
+Import-Package: org.apache.sling.ide.eclipse.core,
+ org.apache.sling.ide.eclipse.sightly,
  org.apache.sling.ide.eclipse.sightly.model,
  org.apache.sling.ide.eclipse.sightly.validation,
  org.eclipse.core.commands,

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=1731673&r1=1731672&r2=1731673&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:57 2016
@@ -83,6 +83,13 @@
             id="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyJsUseWizard"
             name="Sightly JS Use-Script">
       </wizard>
+      <wizard
+            category="org.apache.sling.ide.eclipse.sightly.ui"
+            class="org.apache.sling.ide.eclipse.sightly.ui.internal.NewSightlyJavaUseScriptWizard"
+            icon="icons/obj16/sightly.gif"
+            id="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyJavaUseWizard"
+            name="Sightly Java Use-Script">
+      </wizard>
    </extension>
    
    <!-- Menu contributions -->
@@ -117,6 +124,19 @@
                    </iterate>
                  </visibleWhen>
               </command>              
+              <command
+              	commandId="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyJavaUseScriptHandler"
+              	icon="icons/obj16/sightly.gif"
+              	label="&amp;Sightly Java Use-Script">
+                 <visibleWhen
+                       checkEnabled="false">
+                   <iterate ifEmpty="false">
+                        <test
+                            property="org.apache.sling.ide.eclipse.sightly.sightlyNature">
+                        </test>
+                   </iterate>
+                 </visibleWhen>
+              </command>              
         </menuContribution>         
    </extension>
    
@@ -133,5 +153,10 @@
    	      		defaultHandler="org.apache.sling.ide.eclipse.sightly.ui.internal.NewSightlyJsUseScriptHandler"
    	      		name="New Sightly Javascript Use-Object...">
          </command>
+ 	     <command
+   	      		id="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyJavaUseScriptHandler"
+   	      		defaultHandler="org.apache.sling.ide.eclipse.sightly.ui.internal.NewSightlyJavaUseScriptHandler"
+   	      		name="New Sightly Java Use-Object...">
+         </command>
    </extension>
 </plugin>

Modified: sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/AbstractNewSightlyFileWizard.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/AbstractNewSightlyFileWizard.java?rev=1731673&r1=1731672&r2=1731673&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/AbstractNewSightlyFileWizard.java (original)
+++ sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/AbstractNewSightlyFileWizard.java Mon Feb 22 16:06:57 2016
@@ -36,7 +36,7 @@ import org.eclipse.ui.statushandlers.Sta
 public abstract class AbstractNewSightlyFileWizard extends Wizard implements INewWizard {
 
     private IWorkbench workbench;
-    private WizardNewFileCreationPage fileCreationPage;
+    protected WizardNewFileCreationPage fileCreationPage;
 
     private String pageTitle;
     private String wizardDescription;

Added: sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptHandler.java?rev=1731673&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptHandler.java (added)
+++ sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptHandler.java Mon Feb 22 16:06:57 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 NewSightlyJavaUseScriptHandler extends AbstractHandler {
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        
+        ISelection selection = HandlerUtil.getCurrentSelection(event);
+        
+        NewSightlyJavaUseScriptWizard wiz = new NewSightlyJavaUseScriptWizard();
+        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/NewSightlyJavaUseScriptWizard.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptWizard.java?rev=1731673&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptWizard.java (added)
+++ sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptWizard.java Mon Feb 22 16:06:57 2016
@@ -0,0 +1,59 @@
+/*
+ * 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.apache.sling.ide.eclipse.core.ProjectUtil;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+
+public class NewSightlyJavaUseScriptWizard extends AbstractNewSightlyFileWizard {
+
+    public NewSightlyJavaUseScriptWizard() {
+        super("New Sightly Java Use-Script", "Create a new Sightly Java Use-Script");
+    }
+    
+    @Override
+    protected String getInitialContents() {
+        
+        IPath fullPath = fileCreationPage.getContainerFullPath();
+        
+        String className = fileCreationPage.getFileName().replace(".java", "");
+        
+        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(fullPath.segment(0));
+        
+        // we could make this dependency optional if needed, but I don't see a great need right now 
+        IFolder contentSyncRoot = ProjectUtil.getSyncDirectory(project);
+        String inferredPackage = "unknown // TODO - replace with actual path";
+        if ( contentSyncRoot != null ) {
+            inferredPackage = fullPath.makeRelativeTo(contentSyncRoot.getFullPath()).toPortableString().replace('/', '.');
+        }
+        
+        return "" +
+               "package " + inferredPackage + ";\n" + 
+               "\n" +
+               "import java.util.Date;\n" +
+               "\n" +
+               "public class " + className + " {\n" +
+               "    public String getDate() {\n" +
+               "        return new Date().toString();\n" +
+               "    }\n" +
+               "}";
+    }
+
+}