sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefane...@apache.org
Subject svn commit: r1602417 - in /sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions: JcrNewNodeAction.java NewNodeDialog.java
Date Fri, 13 Jun 2014 13:09:33 GMT
Author: stefanegli
Date: Fri Jun 13 13:09:32 2014
New Revision: 1602417

URL: http://svn.apache.org/r1602417
Log:
SLING-3660 related : allow node creation when server was never started, but 'at own risk'
(since node type checks and dependencies cannot be done properly)

Modified:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/NewNodeDialog.java

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java?rev=1602417&r1=1602416&r2=1602417&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
Fri Jun 13 13:09:32 2014
@@ -29,14 +29,17 @@ import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.wst.server.ui.internal.Messages;
 
 public class JcrNewNodeAction implements IObjectActionDelegate {
 
 	private ISelection selection;
 	private Shell shell;
+    private boolean doNotAskAgain;
 
 	public JcrNewNodeAction() {
 	}
@@ -56,9 +59,27 @@ public class JcrNewNodeAction implements
         Repository repository = ServerUtil.getDefaultRepository(node.getProject());
         NodeTypeRegistry ntManager = (repository==null) ? null : repository.getNodeTypeRegistry();
         if (ntManager == null) {
-            MessageDialog.openWarning(null, "Unable to create a new node", "Unable to create
a new node since project "
-                    + node.getProject().getName() + " is not associated with a server or
the server is not started.");
-            return;
+            
+            if (!doNotAskAgain) {
+                MessageDialog dialog = new MessageDialog(null,  "Unable to validate node
type", null,
+                        "Unable to validate node types since project " + node.getProject().getName()
+ " is not associated with a server or the server is not started.",
+                        MessageDialog.QUESTION_WITH_CANCEL, 
+                        new String[] {"Cancel", "Continue (do not ask again)", "Continue"},
1) {
+                    @Override
+                    protected void configureShell(Shell shell) {
+                        super.configureShell(shell);
+                        setShellStyle(getShellStyle() | SWT.SHEET);
+                    }
+                };
+                int choice = dialog.open();
+                if (choice <= 0) {
+                    return;
+                }
+                if (choice==1) {
+                    doNotAskAgain = true;
+                }
+            }
+
         }
         final NodeType nodeType = node.getNodeType();
         if (nodeType!=null && nodeType.getName()!=null && nodeType.getName().equals("nt:file"))
{

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/NewNodeDialog.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/NewNodeDialog.java?rev=1602417&r1=1602416&r2=1602417&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/NewNodeDialog.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/NewNodeDialog.java
Fri Jun 13 13:09:32 2014
@@ -31,6 +31,8 @@ import org.eclipse.swt.widgets.Shell;
 
 public class NewNodeDialog extends InputDialog {
 
+    private static String lastChosenNodeType = null;
+    
     private final String parentNodeType;
     private final NodeTypeRegistry ntManager;
     protected String comboSelection;
@@ -45,11 +47,13 @@ public class NewNodeDialog extends Input
                 "Enter name for new node under:\n path: "+node.getJcrPath(), "", null);
         this.parentNodeType = node.getPrimaryType();
         this.ntManager = ntManager;
-        final LinkedList<String> ac = new LinkedList<String>(ntManager.getAllowedPrimaryChildNodeTypes(parentNodeType));
-        final NodeType parentNt = ntManager.getNodeType(parentNodeType);
-        allChildNodeDefs = parentNt.getChildNodeDefinitions();
-        Collections.sort(ac);
-        this.allowedChildren = ac;
+        if (ntManager!=null) {
+            final LinkedList<String> ac = new LinkedList<String>(ntManager.getAllowedPrimaryChildNodeTypes(parentNodeType));
+            final NodeType parentNt = ntManager.getNodeType(parentNodeType);
+            allChildNodeDefs = parentNt.getChildNodeDefinitions();
+            Collections.sort(ac);
+            this.allowedChildren = ac;
+        }
     }
 
     @Override
@@ -76,7 +80,9 @@ public class NewNodeDialog extends Input
 
         combo = new Combo(composite, SWT.DROP_DOWN);
         combo.moveAbove(errorMessageText);
-        combo.setItems(allowedChildren.toArray(new String[0]));
+        if (allowedChildren!=null) {
+            combo.setItems(allowedChildren.toArray(new String[0]));
+        }
         combo.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
                 | GridData.HORIZONTAL_ALIGN_FILL));
         combo.addSelectionListener(new SelectionAdapter() {
@@ -123,10 +129,12 @@ public class NewNodeDialog extends Input
         // this variant opens auto-complete on each character
         proposalAdapter = new ContentProposalAdapter(combo, controlContentAdapter, proposalProvider,
null, null);
         // this variant opens auto-complete only when invoking the auto-complete hotkey
-//        proposalAdapter = new ContentAssistCommandAdapter(combo, controlContentAdapter,
-//            proposalProvider, null, new char[0], true);
-        if (allowedChildren.size()==1) {
+        if (allowedChildren!=null && allowedChildren.size()==1) {
             combo.setText(allowedChildren.iterator().next());
+        } else if (allowedChildren!=null) {
+            if (allowedChildren.contains(lastChosenNodeType)) {
+                combo.setText(lastChosenNodeType);
+            }
         }
         
         return composite;
@@ -143,6 +151,7 @@ public class NewNodeDialog extends Input
     }
     
     public String getChosenNodeType() {
+        lastChosenNodeType = comboSelection;
         return comboSelection;
     }
 
@@ -152,6 +161,8 @@ public class NewNodeDialog extends Input
         try {
             if (secondInput==null || secondInput.length()==0) {
                 setErrorMessage("");
+            } else if (ntManager==null) {
+                setErrorMessage(null);
             } else if (ntManager.isAllowedPrimaryChildNodeType(parentNodeType, secondInput))
{
                 // also check on the name, not only the type
                 if (allChildNodeDefs==null) {



Mime
View raw message