Author: stefanegli Date: Mon May 26 13:38:24 2014 New Revision: 1597582 URL: http://svn.apache.org/r1597582 Log: SLING-3238 : support all variants of nodes' deletion and remaming
Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java 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/DirNode.java 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 sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java Modified: 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=1597582&r1=1597581&r2=1597582&view=diff ============================================================================== --- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java (original) +++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/JcrNodeDeleteAction.java Mon May 26 13:38:24 2014 @@ -52,7 +52,7 @@ public class JcrNodeDeleteAction impleme if (this.node==null) { return; } - if (!MessageDialog.openConfirm(shell, "Delete JCR node", "Do you really want to delete '"+node.getName()+"'?")) { + if (!MessageDialog.openConfirm(shell, "Delete JCR node", "Do you really want to delete '"+node.getLabel()+"'?")) { return; } node.delete(); @@ -71,7 +71,7 @@ public class JcrNodeDeleteAction impleme Object element = iss.getFirstElement(); if (element instanceof JcrNode) { final JcrNode n = (JcrNode)element; - if (n.canBeRenamed()) { + if (n.canBeDeleted()) { action.setEnabled(true); this.node = n; return; 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=1597582&r1=1597581&r2=1597582&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 Mon May 26 13:38:24 2014 @@ -52,7 +52,7 @@ public class JcrNodeRenameAction impleme return; } InputDialog id = new InputDialog(shell, "Change JCR node name", - "Enter new name for JCR node '"+node.getDescription()+"':", node.getName(), new IInputValidator() { + "Enter new name for JCR node '"+node.getDescription()+"':", node.getLabel(), new IInputValidator() { @Override public String isValid(String newText) { Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java?rev=1597582&r1=1597581&r2=1597582&view=diff ============================================================================== --- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java (original) +++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/DirNode.java Mon May 26 13:38:24 2014 @@ -132,4 +132,9 @@ public class DirNode extends JcrNode { return false; } + @Override + public boolean canBeDeleted() { + return false; + } + } 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=1597582&r1=1597581&r2=1597582&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 Mon May 26 13:38:24 2014 @@ -25,6 +25,7 @@ import java.util.List; import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.io.IOUtils; +import org.apache.sling.ide.eclipse.core.internal.Activator; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -93,6 +94,7 @@ public class GenericJcrRootFile extends DirNode dirNodeParent = (DirNode)parent; JcrNode dirNodeParentParent = dirNodeParent.getParent(); JcrNode effectiveSibling = dirNodeParent.getEffectiveSibling(); + effectiveSibling.dirSibling = dirNodeParent; handleProperties(element, effectiveSibling.properties); effectiveParent = parent; dirNodeParentParent.hide(parent); @@ -209,4 +211,32 @@ public class GenericJcrRootFile extends SyncDirManager.syncDirChanged(getSyncDir()); } + @Override + public boolean canBeRenamed() { + return true; + } + + @Override + public boolean canBeDeleted() { + return true; + } + + @Override + public void rename(String string) { + try { + file.move(file.getParent().getFullPath().append(string+".xml"), true, new NullProgressMonitor()); + } catch (CoreException e) { + Activator.getDefault().getPluginLogger().error("Error renaming resource ("+file+"): "+e, e); + } + } + + @Override + public void delete() { + try { + file.delete(true, new NullProgressMonitor()); + } catch (CoreException e) { + Activator.getDefault().getPluginLogger().error("Error deleting resource ("+file+"): "+e, e); + } + } + } 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=1597582&r1=1597581&r2=1597582&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 Mon May 26 13:38:24 2014 @@ -59,11 +59,14 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.mapping.ResourceMapping; import org.eclipse.core.resources.mapping.ResourceMappingContext; import org.eclipse.core.resources.mapping.ResourceTraversal; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; @@ -122,6 +125,8 @@ public class JcrNode implements IAdaptab final GenericJcrRootFile underlying; JcrNode parent; + + DirNode dirSibling; final List<JcrNode> children = new LinkedList<JcrNode>(); @@ -699,21 +704,41 @@ public class JcrNode implements IAdaptab return null; } - public void rename(String string) { + public void rename(final String string) { if (domElement!=null && underlying!=null) { domElement.setName(string); underlying.save(); } + if (resource!=null) { + IWorkspaceRunnable r = new IWorkspaceRunnable() { + + @Override + public void run(IProgressMonitor monitor) throws CoreException { + final IPath fileRenamePath = resource.getParent().getFullPath().append(string); + resource.move(fileRenamePath, true, monitor); + if (dirSibling!=null) { + final IPath dirRenamePath = dirSibling.getResource().getParent().getFullPath().append(string+".dir"); + dirSibling.getResource().move(dirRenamePath, true, monitor); + } + } + }; + try { + ResourcesPlugin.getWorkspace().run(r, null); + } catch (CoreException e) { + Activator.getDefault().getPluginLogger().error("Error renaming resource ("+resource+"): "+e, e); + } + } } public boolean canBeRenamed() { - if (resource!=null) { - return false; - } + if (parent==null) { + return false; + } + if (resource!=null) { + // can be a file or a folder (project is virtually impossible) + return true; + } if (domElement!=null && underlying!=null) { - if (getDomName().equals("jcr:content")) { - return false; - } return true; } return false; @@ -875,12 +900,43 @@ public class JcrNode implements IAdaptab effectiveUnderlying.save(); } + public boolean canBeDeleted() { + if (parent==null) { + return false; + } + if (resource!=null) { + // can be a file or a folder (project is virtually impossible) + return true; + } + if (domElement!=null && underlying!=null) { + return true; + } + return false; + } + public void delete() { if (parent==null) { // then I dont know how to delete return; } parent.children.remove(this); + if (resource!=null) { + IWorkspaceRunnable r = new IWorkspaceRunnable() { + + @Override + public void run(IProgressMonitor monitor) throws CoreException { + resource.delete(true, monitor); + if (dirSibling!=null) { + dirSibling.getResource().delete(true, monitor); + } + } + }; + try { + ResourcesPlugin.getWorkspace().run(r, null); + } catch (CoreException e) { + Activator.getDefault().getPluginLogger().error("Error renaming resource ("+resource+"): "+e, e); + } + } if (domElement!=null) { Element parentNode = domElement.getParentElement(); domElement.remove(); @@ -906,7 +962,9 @@ public class JcrNode implements IAdaptab } } } - underlying.save(); + if (underlying!=null) { + underlying.save(); + } } public IProject getProject() { Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java?rev=1597582&r1=1597581&r2=1597582&view=diff ============================================================================== --- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java (original) +++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/SyncDir.java Mon May 26 13:38:24 2014 @@ -99,4 +99,14 @@ public class SyncDir extends JcrNode { return node; } + @Override + public boolean canBeRenamed() { + return false; + } + + @Override + public boolean canBeDeleted() { + return false; + } + }