Author: rombert
Date: Mon Feb 22 16:06:52 2016
New Revision: 1731672
URL: http://svn.apache.org/viewvc?rev=1731672&view=rev
Log:
SLING-5538 - Create new Sightly file wizards
Add a new Sightly JS use-script wizard
Added:
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/AbstractNewSightlyFileWizard.java
- copied, changed from r1731671,
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.java
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJsUseScriptHandler.java
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJsUseScriptWizard.java
Modified:
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/NewSightlyFileWizard.java
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=1731672&r1=1731671&r2=1731672&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:52
2016
@@ -76,6 +76,13 @@
id="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyFileWizard"
name="Sightly File">
</wizard>
+ <wizard
+ category="org.apache.sling.ide.eclipse.sightly.ui"
+
class="org.apache.sling.ide.eclipse.sightly.ui.internal.NewSightlyJsUseScriptWizard"
+ icon="icons/obj16/sightly.gif"
+
id="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyJsUseWizard"
+ name="Sightly JS Use-Script">
+ </wizard>
</extension>
<!-- Menu contributions -->
@@ -97,6 +104,19 @@
</iterate>
</visibleWhen>
</command>
+ <command
+
commandId="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyJsUseScriptHandler"
+ icon="icons/obj16/sightly.gif"
+ label="&Sightly JS Use-Script">
+ <visibleWhen
+ checkEnabled="false">
+ <iterate ifEmpty="false">
+ <test
+
property="org.apache.sling.ide.eclipse.sightly.sightlyNature">
+ </test>
+ </iterate>
+ </visibleWhen>
+ </command>
</menuContribution>
</extension>
@@ -108,5 +128,10 @@
defaultHandler="org.apache.sling.ide.eclipse.sightly.ui.internal.NewSightlyFileHandler"
name="New Sightly File...">
</command>
+ <command
+
id="org.apache.sling.ide.eclipse.sightly.ui.internal.newSightlyJsUseScriptHandler"
+
defaultHandler="org.apache.sling.ide.eclipse.sightly.ui.internal.NewSightlyJsUseScriptHandler"
+ name="New Sightly Javascript Use-Object...">
+ </command>
</extension>
</plugin>
Copied:
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/AbstractNewSightlyFileWizard.java
(from r1731671,
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/AbstractNewSightlyFileWizard.java?p2=sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/AbstractNewSightlyFileWizard.java&p1=sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.java&r1=1731671&r2=1731672&rev=1731672&view=diff
==============================================================================
---
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.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:52 2016
@@ -33,54 +33,50 @@ import org.eclipse.ui.dialogs.WizardNewF
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.statushandlers.StatusManager;
-public class NewSightlyFileWizard extends Wizard implements INewWizard {
+public abstract class AbstractNewSightlyFileWizard extends Wizard implements
INewWizard {
private IWorkbench workbench;
private WizardNewFileCreationPage fileCreationPage;
- @Override
+ private String pageTitle;
+ private String wizardDescription;
+
+ public AbstractNewSightlyFileWizard(String pageTitle, String
wizardDescription) {
+ this.pageTitle = pageTitle;
+ this.wizardDescription = wizardDescription;
+ }
+
public void init(IWorkbench workbench, IStructuredSelection selection) {
-
+
this.workbench = workbench;
-
- fileCreationPage = new WizardNewFileCreationPage("New Sightly File",
selection) {
-
+
+ fileCreationPage = new WizardNewFileCreationPage(pageTitle, 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>"
- + "";
-
+ String contents =
AbstractNewSightlyFileWizard.this.getInitialContents();
+
return new ByteArrayInputStream(contents.getBytes());
}
};
- fileCreationPage.setTitle("Sighty");
- fileCreationPage.setDescription("Create a new Sightly file");
+
+ fileCreationPage.setTitle("Sightly");
+ fileCreationPage.setDescription(wizardDescription);
fileCreationPage.setImageDescriptor(SharedImages.SIGHTLY_WIZARD_BANNER);
-
-
- setWindowTitle("New Sightly File");
+
+ setWindowTitle(pageTitle);
addPage(fileCreationPage);
}
@Override
public boolean performFinish() {
-
- if ( !fileCreationPage.isPageComplete() ) {
+
+ if (!fileCreationPage.isPageComplete()) {
return false;
}
-
+
IFile file = fileCreationPage.createNewFile();
-
+
// copied from BasicNewFileResourceWizard
// Open editor on new file.
IWorkbenchWindow dw = workbench.getActiveWorkbenchWindow();
@@ -92,11 +88,13 @@ public class NewSightlyFileWizard extend
}
}
} catch (PartInitException e) {
- StatusManager.getManager().handle(new Status(IStatus.WARNING,
Constants.PLUGIN_ID, "Failed opening " + file + " in an editor", e),
+ StatusManager.getManager().handle(
+ new Status(IStatus.WARNING, Constants.PLUGIN_ID, "Failed
opening " + file + " in an editor", e),
StatusManager.SHOW | StatusManager.LOG);
}
-
+
return true;
}
-}
+ protected abstract String getInitialContents();
+}
\ No newline at end of file
Modified:
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=1731672&r1=1731671&r2=1731672&view=diff
==============================================================================
---
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.java
(original)
+++
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyFileWizard.java
Mon Feb 22 16:06:52 2016
@@ -16,87 +16,25 @@
*/
package org.apache.sling.ide.eclipse.sightly.ui.internal;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
+public class NewSightlyFileWizard extends AbstractNewSightlyFileWizard {
-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);
+ public NewSightlyFileWizard() {
+ super("New Sightly File", "Create a new Sightly file");
}
-
- @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;
+
+ protected String getInitialContents() {
+ return ""
+ + "<!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>"
+ + "";
}
}
Added:
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJsUseScriptHandler.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJsUseScriptHandler.java?rev=1731672&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJsUseScriptHandler.java
(added)
+++
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJsUseScriptHandler.java
Mon Feb 22 16:06:52 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 NewSightlyJsUseScriptHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+
+ NewSightlyJsUseScriptWizard wiz = new NewSightlyJsUseScriptWizard();
+ 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/NewSightlyJsUseScriptWizard.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJsUseScriptWizard.java?rev=1731672&view=auto
==============================================================================
---
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJsUseScriptWizard.java
(added)
+++
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJsUseScriptWizard.java
Mon Feb 22 16:06:52 2016
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+public class NewSightlyJsUseScriptWizard extends AbstractNewSightlyFileWizard {
+
+ public NewSightlyJsUseScriptWizard() {
+ super("New Sightly Javascript Use-Script", "Create a new Sightly
Javascript Use-Script");
+ }
+
+ @Override
+ protected String getInitialContents() {
+
+ return "" +
+ "\"use strict\";\n" +
+ "use(function() {\n" +
+ " return {\n" +
+ " date: new Date().toString()\n" +
+ " }\n" +
+ "});";
+ }
+
+}