You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by st...@apache.org on 2014/06/02 11:45:55 UTC
svn commit: r1599143 -
/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
Author: stefanegli
Date: Mon Jun 2 09:45:55 2014
New Revision: 1599143
URL: http://svn.apache.org/r1599143
Log:
SLING-3622 : support changing jcr:primaryType from/to nt:folder
Modified:
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/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=1599143&r1=1599142&r2=1599143&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 Jun 2 09:45:55 2014
@@ -1037,7 +1037,63 @@ public class JcrNode implements IAdaptab
}
public void setPropertyValue(Object key, Object value) {
- properties.setPropertyValue(key, value);
+ if ("jcr:primaryType".equals(key)) {
+ changePrimaryType(String.valueOf(value));
+ } else {
+ properties.setPropertyValue(key, value);
+ }
+ }
+
+ private void changePrimaryType(String newPrimaryType) {
+ if ("nt:folder".equals(getPrimaryType())) {
+ // switching away from an nt:folder might require creating a .content.xml
+ createVaultFile((IFolder) resource, ".content.xml", newPrimaryType);
+ } else if ("nt:folder".equals(newPrimaryType)) {
+ // switching *to* an nt:folder also has its challenges..:
+ // 1) nt:folder doesn't allow arbitrary children for one
+ // 2) but it also doesn't have an extra .content.xml - so that one would disappear
+
+ Repository repository = ServerUtil.getDefaultRepository(getProject());
+ if (repository == null) {
+ MessageDialog.openWarning(null, "Unable to create a new node", "Unable to create a new node since project "
+ + getProject().getName() + " is not associated with a server or the server is not started.");
+ return;
+ }
+ NodeTypeRegistry ntManager = repository.getNodeTypeRegistry();
+
+ // verify 1)
+ Object[] cn = getChildren(true);
+ for (int i = 0; i < cn.length; i++) {
+ JcrNode node = (JcrNode) cn[i];
+ try {
+ if (!ntManager.isAllowedPrimaryChildNodeType("nt:folder", node.getPrimaryType())) {
+ MessageDialog.openWarning(null, "Unable to change primaryType", "Unable to change jcr:primaryType to nt:folder"
+ + " since nt:folder cannot have child of type "+node.getPrimaryType());
+ return;
+ }
+ } catch (RepositoryException e) {
+ PluginLogger logger = Activator.getDefault().getPluginLogger();
+ logger.error("Could not determine allowed primary child node types", e);
+ }
+ }
+ if (resource instanceof IFolder) {
+ IFolder folder = (IFolder)resource;
+ // 2) delete the .content.xml
+ IFile contentXml = folder.getFile(".content.xml");
+ if (contentXml.exists()) {
+ try {
+ contentXml.delete(true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ PluginLogger logger = Activator.getDefault().getPluginLogger();
+ logger.error("Could not delete "+contentXml.getFullPath()+", e="+e, e);
+ MessageDialog.openError(null, "Could not delete file",
+ "Could not delete "+contentXml.getFullPath()+", "+e);
+ }
+ }
+ }
+ } else {
+ properties.setPropertyValue("jcr:primaryType", newPrimaryType);
+ }
}
public void addProperty(String name, String value) {
@@ -1106,7 +1162,7 @@ public class JcrNode implements IAdaptab
}
}
} catch(Exception e) {
- Activator.getDefault().getPluginLogger().warn("Exception occurred during analyzing propertyType ("+propertyName+") for "+this, e);
+// Activator.getDefault().getPluginLogger().warn("Exception occurred during analyzing propertyType ("+propertyName+") for "+this, e);
}
return -1;
}