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 13:10:04 UTC
svn commit: r1599165 -
/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java
Author: stefanegli
Date: Mon Jun 2 11:10:03 2014
New Revision: 1599165
URL: http://svn.apache.org/r1599165
Log:
SLING-3621 : format an element after adding/removing to make sure indenting is correct
Modified:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java
Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java?rev=1599165&r1=1599164&r2=1599165&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/ModifiableProperties.java Mon Jun 2 11:10:03 2014
@@ -30,6 +30,9 @@ import org.eclipse.ui.views.properties.T
import de.pdark.decentxml.Attribute;
import de.pdark.decentxml.Element;
+import de.pdark.decentxml.Node;
+import de.pdark.decentxml.Parent;
+import de.pdark.decentxml.Text;
public class ModifiableProperties implements IPropertySource {
@@ -134,14 +137,49 @@ public class ModifiableProperties implem
public void deleteProperty(String displayName) {
domElement.removeAttribute(displayName);
+ reformat();
genericJcrRootFile.save();
}
public void addProperty(String name, String value) {
domElement.addAttribute(name, value);
+ reformat();
genericJcrRootFile.save();
}
+ private void reformat() {
+ List<Attribute> list = domElement.getAttributes();
+ if (list.size()==0) {
+ // then there are no attributes at all - nothing to format
+ return;
+ } else if (list.size()==1) {
+ // only one attribute - make sure it has no preSpace
+ Attribute first = list.get(0);
+ first.setPreSpace("");
+ } else {
+ final String NL = System.getProperty("line.separator");
+ final String INDENT = " ";
+ // otherwise, make sure each element has the correct preSpace
+ final String correctPreSpace;
+ Element parent = domElement.getParentElement();
+ List<Node> nodes = parent.getNodes();
+ if (nodes.size()>1 && (nodes.get(0) instanceof Text) && (nodes.get(0).toXML().startsWith(NL))) {
+ correctPreSpace = nodes.get(0).toXML() + INDENT;
+ } else {
+ String totalIndent = INDENT;
+ while(parent!=null) {
+ totalIndent = totalIndent + INDENT;
+ parent = parent.getParentElement();
+ }
+ correctPreSpace = NL + totalIndent;
+ }
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ Attribute attribute = (Attribute) it.next();
+ attribute.setPreSpace(correctPreSpace);
+ }
+ }
+ }
+
public void renameProperty(String oldKey, String newKey) {
Attribute a = domElement.getAttribute(oldKey);
a.setName(newKey);