incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefane...@apache.org
Subject svn commit: r1520037 - in /sling/trunk/tooling/ide/eclipse-ui: ./ src/org/apache/sling/ide/eclipse/ui/actions/ src/org/apache/sling/ide/eclipse/ui/nav/model/
Date Wed, 04 Sep 2013 14:47:50 GMT
Author: stefanegli
Date: Wed Sep  4 14:47:50 2013
New Revision: 1520037

URL: http://svn.apache.org/r1520037
Log:
SLING-2985 : basic add/rename/delete operations on child-nodes inside a .content.xml in the
content-browser

Added:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
  (with props)
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java
  (with props)
Modified:
    sling/trunk/tooling/ide/eclipse-ui/plugin.xml
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameAction.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java

Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1520037&r1=1520036&r2=1520037&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Wed Sep  4 14:47:50 2013
@@ -253,25 +253,6 @@
       </wizard>
    </extension>
    <extension
-         point="org.eclipse.ui.actionSets">
-      <actionSet
-            id="org.apache.sling.ide.eclipse-ui.actionSet"
-            label="Sling Action Set"
-            visible="true">
-         <action
-               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
-               icon="icons/obj16/sling.gif"
-               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
-               label="&amp;Rename JCR Node"
-               toolbarPath="sling"
-               tooltip="Rename JCR Node">
-            <selection
-                  class="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
-            </selection>
-         </action>
-      </actionSet>
-   </extension>
-   <extension
          point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
       <propertyContributor
             contributorId="org.apache.sling.ide.eclipse-ui.propertyContributor1"
@@ -354,6 +335,81 @@
       </objectContribution>
          
    </extension>
+
+   <extension
+         id="org.apache.sling.ide.eclipse.ui.pluginJcrNodeToolSet"
+         point="org.eclipse.ui.popupMenus">
+      <objectContribution
+            adaptable="true"
+            id="org.apache.sling.ide.eclipse.ui.pluginJcrNodeToolSet"
+            objectClass="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
+         <action
+               class="org.apache.sling.ide.eclipse.ui.actions.JcrNewNodeAction"
+               icon="icons/obj16/sling.gif"
+               id="org.apache.sling.ide.eclipse.ui.nav.NewJcrNodeAction"
+               label="&amp;New JCR Node"
+               menubarPath="jcr">
+         </action>
+         <action
+               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
+               icon="icons/obj16/sling.gif"
+               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
+               label="&amp;Rename JCR Node"
+               menubarPath="jcr">
+         </action>
+         <action
+               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteAction"
+               icon="icons/obj16/sling.gif"
+               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteAction"
+               label="&amp;Delete JCR Node"
+               menubarPath="jcr">
+         </action>
+         <visibility>
+               <objectState
+                     name="domNode"
+                     value="true">
+               </objectState>
+         </visibility>
+      </objectContribution>
+   </extension>
+
+   <extension
+         id="org.apache.sling.ide.eclipse.ui.pluginNonJcrNodeToolSet"
+         point="org.eclipse.ui.popupMenus">
+      <objectContribution
+            adaptable="true"
+            id="org.apache.sling.ide.eclipse.ui.pluginNonJcrNodeToolSet"
+            objectClass="org.apache.sling.ide.eclipse.ui.nav.model.JcrNode">
+         <action
+               class="org.apache.sling.ide.eclipse.ui.actions.JcrNewNodeAction"
+               icon="icons/obj16/sling.gif"
+               id="org.apache.sling.ide.eclipse.ui.nav.NewNonJcrNodeAction"
+               label="New JCR Node"
+               menubarPath="common.new.menu/jcr">
+         </action>
+         <action
+               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
+               icon="icons/obj16/sling.gif"
+               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeRenameAction"
+               label="&amp;Rename JCR Node"
+               toolbarPath="common.new.menu/jcr">
+         </action>
+         <action
+               class="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteAction"
+               icon="icons/obj16/sling.gif"
+               id="org.apache.sling.ide.eclipse.ui.actions.JcrNodeDeleteAction"
+               label="&amp;Delete JCR Node"
+               toolbarPath="common.new.menu/jcr">
+         </action>
+         <visibility>
+               <objectState
+                     name="nonDomNode"
+                     value="true">
+               </objectState>
+         </visibility>
+      </objectContribution>
+   </extension>
+   
    <extension
          point="org.eclipse.ui.decorators">
       <decorator

Added: 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=1520037&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
(added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
Wed Sep  4 14:47:50 2013
@@ -0,0 +1,58 @@
+package org.apache.sling.ide.eclipse.ui.actions;
+
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+public class JcrNewNodeAction implements IObjectActionDelegate {
+
+	private ISelection selection;
+	private Shell shell;
+
+	public JcrNewNodeAction() {
+	}
+
+	@Override
+	public void run(IAction action) {
+		if (selection==null || !(selection instanceof IStructuredSelection)) {
+			return;
+		}
+		IStructuredSelection ss = (IStructuredSelection)selection;
+		JcrNode node = (JcrNode) ss.getFirstElement();
+		InputDialog id = new InputDialog(shell, "Enter JCR node name", 
+				"Enter name for new JCR node under '"+node.getName()+"':", "", new IInputValidator()
{
+					
+					@Override
+					public String isValid(String newText) {
+						if (newText!=null && newText.trim().length()>0 && newText.trim().equals(newText))
{
+							return null;
+						} else {
+							return "Invalid input";
+						}
+					}
+				});
+		if (id.open() == IStatus.OK) {
+			node.createChild(id.getValue());
+		}
+	}
+
+	@Override
+	public void selectionChanged(IAction action, ISelection selection) {
+		this.selection = selection;
+	}
+
+	@Override
+	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+		this.shell = targetPart.getSite().getWorkbenchWindow().getShell();
+	}
+
+}

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNewNodeAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java?rev=1520037&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java
(added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java
Wed Sep  4 14:47:50 2013
@@ -0,0 +1,89 @@
+/*
+ * 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.ui.actions;
+
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+
+/** Testing action which renames a jcr node **/
+public class JcrNodeDeleteAction implements IObjectActionDelegate {
+
+	private ISelection selection;
+	private JcrNode node;
+	private Shell shell;
+
+	/**
+	 * The constructor.
+	 */
+	public JcrNodeDeleteAction() {
+	}
+
+	/**
+	 * The action has been activated. The argument of the
+	 * method represents the 'real' action sitting
+	 * in the workbench UI.
+	 * @see IWorkbenchWindowActionDelegate#run
+	 */
+	public void run(IAction action) {
+		if (this.node==null) {
+			return;
+		}
+		if (!MessageDialog.openConfirm(shell, "Delete JCR node", "Do you really want to delete
'"+node.getName()+"'?")) {
+			return;
+		}
+		node.delete();
+	}
+
+	/**
+	 * Selection in the workbench has been changed. We 
+	 * can change the state of the 'real' action here
+	 * if we want, but this can only happen after 
+	 * the delegate has been created.
+	 * @see IWorkbenchWindowActionDelegate#selectionChanged
+	 */
+	public void selectionChanged(IAction action, ISelection selection) {
+		if (selection instanceof IStructuredSelection) {
+			IStructuredSelection iss = (IStructuredSelection) selection;
+			Object element = iss.getFirstElement();
+			if (element instanceof JcrNode) {
+				final JcrNode n = (JcrNode)element;
+				if (n.canBeRenamed()) {
+					action.setEnabled(true);
+					this.node = n;
+					return;
+				}
+			}
+		}
+		action.setEnabled(false);
+		this.node = null;
+	}
+
+	@Override
+	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+		this.shell = targetPart.getSite().getWorkbenchWindow().getShell();
+	}
+}
\ No newline at end of file

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameAction.java?rev=1520037&r1=1520036&r2=1520037&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameAction.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeRenameAction.java
Wed Sep  4 14:47:50 2013
@@ -23,14 +23,18 @@ import org.eclipse.jface.dialogs.IInputV
 import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 
 /** Testing action which renames a jcr node **/
-public class JcrNodeRenameAction implements IWorkbenchWindowActionDelegate {
-	private IWorkbenchWindow window;
+public class JcrNodeRenameAction implements IObjectActionDelegate {
+
 	private ISelection selection;
 	private JcrNode node;
+	private Shell shell;
+
 	/**
 	 * The constructor.
 	 */
@@ -47,7 +51,7 @@ public class JcrNodeRenameAction impleme
 		if (this.node==null) {
 			return;
 		}
-		InputDialog id = new InputDialog(window.getShell(), "Change JCR node name", 
+		InputDialog id = new InputDialog(shell, "Change JCR node name", 
 				"Enter new name for JCR node '"+node.getDescription()+"':", node.getName(), new IInputValidator()
{
 					
 					@Override
@@ -88,20 +92,8 @@ public class JcrNodeRenameAction impleme
 		this.node = null;
 	}
 
-	/**
-	 * We can use this method to dispose of any system
-	 * resources we previously allocated.
-	 * @see IWorkbenchWindowActionDelegate#dispose
-	 */
-	public void dispose() {
-	}
-
-	/**
-	 * We will cache window object in order to
-	 * be able to provide parent shell for the message dialog.
-	 * @see IWorkbenchWindowActionDelegate#init
-	 */
-	public void init(IWorkbenchWindow window) {
-		this.window = window;
+	@Override
+	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+		this.shell = targetPart.getSite().getWorkbenchWindow().getShell();
 	}
 }
\ No newline at end of file

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java?rev=1520037&r1=1520036&r2=1520037&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
Wed Sep  4 14:47:50 2013
@@ -44,10 +44,12 @@ import org.eclipse.core.runtime.IAdaptab
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IActionFilter;
 import org.eclipse.ui.IContributorResourceAdapter;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
 import org.eclipse.ui.views.properties.IPropertySource;
 import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
@@ -396,7 +398,25 @@ public class JcrNode implements IAdaptab
 	}
 	
 	private Object doGetAdapter(Class adapter) {
-		if (adapter==ITabbedPropertySheetPageContributor.class && "christmas".equals("christmas"))
{
+		if (adapter==IActionFilter.class) {
+			return new IActionFilter() {
+				
+				@Override
+				public boolean testAttribute(Object target, String name, String value) {
+					if (!(target instanceof JcrNode)) {
+						return false;
+					}
+					final JcrNode node = (JcrNode)target;
+					if ("domNode".equals(name)) {
+						return node.domNode!=null;	
+					}
+					if ("nonDomNode".equals(name)) {
+						return node.domNode==null;	
+					}
+					return false;
+				}
+			};
+		} else if (adapter==ITabbedPropertySheetPageContributor.class && "christmas".equals("christmas"))
{
 			return new ITabbedPropertySheetPageContributor() {
 
 				@Override
@@ -530,4 +550,24 @@ public class JcrNode implements IAdaptab
 		return resource;
 	}
 
+	public void createChild(String nodeName) {
+		Element element = domNode.getOwnerDocument().createElement(nodeName);
+		element.setAttribute("jcr:primaryType", "nt:unstructured");
+		Node childDomNode = domNode.appendChild(element);
+		JcrNode childNode = new JcrNode(this, childDomNode, null);
+		underlying.save();
+	}
+
+	public void delete() {
+		if (parent==null) {
+			// then I dont know how to delete
+			return;
+		}
+		parent.children.remove(this);
+		if (domNode!=null) {
+			domNode.getParentNode().removeChild(domNode);
+		}
+		underlying.save();
+	}
+
 }



Mime
View raw message