Author: rombert
Date: Wed Feb 24 15:22:48 2016
New Revision: 1732168

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

Validate that the Java Use-Script file name ends with '.java' .

Modified:
    
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/AbstractNewSightlyFileWizard.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/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=1732168&r1=1732167&r2=1732168&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
 Wed Feb 24 15:22:48 2016
@@ -24,6 +24,7 @@ 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.jface.wizard.WizardPage;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
@@ -58,6 +59,11 @@ public abstract class AbstractNewSightly
 
                 return new ByteArrayInputStream(contents.getBytes());
             }
+            
+            @Override
+            protected boolean validatePage() {
+                return super.validatePage() && validateFileToBeCreated() ;
+            }
         };
 
         fileCreationPage.setTitle("Sightly");
@@ -97,4 +103,17 @@ public abstract class AbstractNewSightly
     }
 
     protected abstract String getInitialContents();
+    
+    /**
+     * Allows sub-classes to hook in the validation process for the file
+     * 
+     * <p>Only invoked if the superclass validation is successful. If this 
method
+     * returns false it <b>must</b> invoke {@link 
WizardPage#setErrorMessage(String)}
+     * on the <tt>fileCreationPage</tt> field to notify the user of what must 
be changed</tt>.
+     * 
+     * @return true if the file to be created is valid, false otherwise
+     */
+    protected boolean validateFileToBeCreated() {
+        return true;
+    }
 }
\ No newline at end of file

Modified: 
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=1732168&r1=1732167&r2=1732168&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptWizard.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-sightly-ui/src/org/apache/sling/ide/eclipse/sightly/ui/internal/NewSightlyJavaUseScriptWizard.java
 Wed Feb 24 15:22:48 2016
@@ -47,5 +47,15 @@ public class NewSightlyJavaUseScriptWiza
                "    }\n" +
                "}";
     }
+    
+    @Override
+    protected boolean validateFileToBeCreated() {
+        if ( ! fileCreationPage.getFileName().endsWith(".java") ) {
+            fileCreationPage.setErrorMessage("File extension must be 'java'");
+            return false;
+        }
+        
+        return true;
+    }
 
 }


Reply via email to