incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefane...@apache.org
Subject svn commit: r1520324 - in /sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model: GenericJcrRootFile.java JcrNode.java
Date Thu, 05 Sep 2013 14:19:08 GMT
Author: stefanegli
Date: Thu Sep  5 14:19:08 2013
New Revision: 1520324

URL: http://svn.apache.org/r1520324
Log:
SLING-2985 : improvements in the content-browser : creation of new node for more cases supported

Modified:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.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/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java?rev=1520324&r1=1520323&r2=1520324&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
(original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java
Thu Sep  5 14:19:08 2013
@@ -37,6 +37,7 @@ import org.eclipse.core.resources.IResou
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
@@ -182,6 +183,15 @@ public class GenericJcrRootFile extends 
 		return file;
 	}
 	
+	@Override
+	public void createChild(String nodeName) {
+		Element element = document.createElement(nodeName);
+		element.setAttribute("jcr:primaryType", "nt:unstructured");
+		Node childDomNode = document.getFirstChild().appendChild(element);
+		JcrNode childNode = new JcrNode(this, childDomNode, null);
+		underlying.save();
+	}
+	
 	public void save() {
 		try {
 			TransformerFactory transformerFactory = TransformerFactory.newInstance();

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=1520324&r1=1520323&r2=1520324&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
Thu Sep  5 14:19:08 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.ide.eclipse.ui.nav.model;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
@@ -43,8 +44,11 @@ import org.eclipse.core.resources.mappin
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IActionFilter;
 import org.eclipse.ui.IContributorResourceAdapter;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
@@ -554,11 +558,34 @@ public class JcrNode implements IAdaptab
 	}
 
 	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();
+		if (domNode==null) {
+			// then we're not in the context of a .content.xml file yet
+			// so we need to create one
+			final String minimalContentXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><jcr:root
xmlns:sling=\"http://sling.apache.org/jcr/sling/1.0\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"/>";
+			if (resource instanceof IFolder) {
+				IFolder folder = (IFolder)resource;
+				IFile file = folder.getFile(nodeName+".xml");
+				try {
+					file.create(new ByteArrayInputStream(minimalContentXml.getBytes()), true, new NullProgressMonitor());
+				} catch (CoreException e) {
+					//TODO proper logging
+					e.printStackTrace();
+				}
+			} else {
+				MessageDialog.openInformation(Display.getDefault().getActiveShell(), 
+						"Cannot create JCR node on a File", "Creating a JCR node on a File is not yet supported");
+			}
+		} else {
+			try{
+				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();
+			} catch(Exception e) {
+				MessageDialog.openError(Display.getDefault().getActiveShell(), "Error creating new JCR
node", "The following error occurred: "+e.getMessage());
+			}
+		}
 	}
 
 	public void delete() {



Mime
View raw message