Bug 71688 - Customization of initially folded regions
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntCommentNode.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntCommentNode.java
index ba1dbf1..747e7db 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntCommentNode.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntCommentNode.java
@@ -11,6 +11,10 @@
 
 package org.eclipse.ant.internal.ui.editor.model;
 
+import org.eclipse.ant.internal.ui.model.AntUIPlugin;
+import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+
 public class AntCommentNode extends AntElementNode {
 	public AntCommentNode() {
 		super("AntComment"); //$NON-NLS-1$
@@ -22,4 +26,12 @@
 	public boolean isStructuralNode() {
 		return false;
 	}
+	
+	public boolean collapseProjection() {
+		IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore();		
+		if (store.getBoolean(AntEditorPreferenceConstants.EDITOR_FOLDING_COMMENTS)) {
+			return true;
+		}
+		return false;
+	}
 }
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntDTDNode.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntDTDNode.java
index 662fc34..4fea22d 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntDTDNode.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntDTDNode.java
@@ -11,6 +11,10 @@
 
 package org.eclipse.ant.internal.ui.editor.model;
 
+import org.eclipse.ant.internal.ui.model.AntUIPlugin;
+import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+
 public class AntDTDNode extends AntElementNode {
 	public AntDTDNode(String name) {
 		super(name);
@@ -22,4 +26,12 @@
 	public boolean isStructuralNode() {
 		return false;
 	}
+	
+	public boolean collapseProjection() {
+		IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore();		
+		if (store.getBoolean(AntEditorPreferenceConstants.EDITOR_FOLDING_DTD)) {
+			return true;
+		}
+		return false;
+	}
 }
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntDefiningTaskNode.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntDefiningTaskNode.java
index 95714c1..3952d6b 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntDefiningTaskNode.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntDefiningTaskNode.java
@@ -102,4 +102,12 @@
 		super.setParent(node);
 		getProjectNode().addDefiningTaskNode(this);
 	}
+	
+	public boolean collapseProjection() {
+		IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore();		
+		if (store.getBoolean(AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING)) {
+			return true;
+		}
+		return false;
+	}
 }
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntElementNode.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntElementNode.java
index fd70544..51e9380 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntElementNode.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntElementNode.java
@@ -586,4 +586,8 @@
 	public boolean isStructuralNode() {
 		return true;
 	}
+	
+	public boolean collapseProjection() {
+		return false;
+	}
 }
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntTargetNode.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntTargetNode.java
index fa7ff7c..fd4f6f9 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntTargetNode.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/model/AntTargetNode.java
@@ -17,7 +17,10 @@
 import org.apache.tools.ant.Target;
 import org.eclipse.ant.internal.ui.editor.outline.XMLProblem;
 import org.eclipse.ant.internal.ui.model.AntUIImages;
+import org.eclipse.ant.internal.ui.model.AntUIPlugin;
 import org.eclipse.ant.internal.ui.model.IAntUIConstants;
+import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.resource.ImageDescriptor;
 
 public class AntTargetNode extends AntElementNode {
@@ -108,4 +111,12 @@
 		}
 		return null;
 	}
+	
+	public boolean collapseProjection() {
+		IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore();		
+		if (store.getBoolean(AntEditorPreferenceConstants.EDITOR_FOLDING_TARGETS)) {
+			return true;
+		}
+		return false;
+	}
 }
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/text/AntFoldingStructureProvider.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/text/AntFoldingStructureProvider.java
index da72507..70bc5fd 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/text/AntFoldingStructureProvider.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/text/AntFoldingStructureProvider.java
@@ -36,6 +36,11 @@
 	private AntEditor fEditor;
 	private IDocument fDocument;
 	
+	/**
+	 * A mapping of the foldable position to the <code>AntElementNode<code> that represent that region
+	 */
+	private Map fPositionToElement= new HashMap();
+	
 	public AntFoldingStructureProvider(AntEditor editor) {
 		super();
 		fEditor = editor;
@@ -46,7 +51,9 @@
 
 		Map additionsMap = new HashMap();
 		for (Iterator iter = currentRegions.iterator(); iter.hasNext();) {
-			additionsMap.put(new ProjectionAnnotation(), iter.next());
+			Object position= iter.next();
+			AntElementNode node= (AntElementNode)fPositionToElement.get(position);
+			additionsMap.put(new ProjectionAnnotation(node.collapseProjection()), position);
 		}
 
 		if ((deletions.length != 0 || additionsMap.size() != 0)) {
@@ -71,6 +78,7 @@
 	}
 
 	public void updateFoldingRegions(AntModel antModel) {
+		fPositionToElement= new HashMap();
 		try {
 			ProjectionAnnotationModel model = (ProjectionAnnotationModel) fEditor.getAdapter(ProjectionAnnotationModel.class);
 			if (model == null) {
@@ -108,6 +116,7 @@
 				int end= fDocument.getLineOffset(endLine) + fDocument.getLineLength(endLine);
 				Position position= new Position(start, end - start);
 				regions.add(position);
+				fPositionToElement.put(position, element);
 			}
 			
 			children= element.getChildNodes();
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java
index 733e8c9..c3bc833 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java
@@ -105,7 +105,7 @@
 	 * when formatting. If <code>true</code> the formatter inserts a tab character for indenting.
 	 * </p>
 	 */
-	public static String FORMATTER_TAB_CHAR= "formatter_tab_char"; //$NON-NLS-1$
+	public static final String FORMATTER_TAB_CHAR= "formatter_tab_char"; //$NON-NLS-1$
 	
 	/**
 	 * A named preference that specifies if the Ant formatter aligns the final
@@ -197,6 +197,47 @@
 	 * @since 3.1
 	 */
 	public static final String EDITOR_FOLDING_ENABLED= "editor_folding_enabled"; //$NON-NLS-1$
+	
+	/**
+	 * A named preference that stores the value for comment folding.
+	 * <p>
+	 * Value is of type <code>Boolean</code>.
+	 * </p>
+	 * 
+	 * @since 3.1
+	 */
+	public static final String EDITOR_FOLDING_COMMENTS= "editor_folding_comments"; //$NON-NLS-1$
+	
+	/**
+	 * A named preference that stores the value for target folding.
+	 * <p>
+	 * Value is of type <code>Boolean</code>.
+	 * </p>
+	 * 
+	 * @since 3.1
+	 */
+	public static final String EDITOR_FOLDING_TARGETS= "editor_folding_targets"; //$NON-NLS-1$
+	
+	/**
+	 * A named preference that stores the value for DTD folding.
+	 * <p>
+	 * Value is of type <code>Boolean</code>.
+	 * </p>
+	 * 
+	 * @since 3.1
+	 */
+	public static final String EDITOR_FOLDING_DTD= "editor_folding_dtd"; //$NON-NLS-1$
+	
+	/**
+	 * A named preference that stores the value for defining elements folding.
+	 * <p>
+	 * Value is of type <code>Boolean</code>.
+	 * </p>
+	 * 
+	 * @since 3.1
+	 */
+	public static final String EDITOR_FOLDING_DEFINING= "editor_folding_defining"; //$NON-NLS-1$
+
 
 	public static void initializeDefaultValues(IPreferenceStore store) {
 		TextEditorPreferenceConstants.initializeDefaultValues(store);
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java
index 61707df..6e51473 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java
@@ -319,6 +319,10 @@
 		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS));
 	
 		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_ENABLED));
+		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_COMMENTS));
+		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_DTD));
+		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING));
+		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_TARGETS));
 		
 		for (int i= 0; i < fSyntaxColorListModel.length; i++) {
 			String colorKey= fSyntaxColorListModel[i][1];
@@ -532,6 +536,14 @@
 		composite.setLayout(layout);
 		
 		addCheckBox(composite, AntPreferencesMessages.getString("AntEditorPreferencePage.20"), AntEditorPreferenceConstants.EDITOR_FOLDING_ENABLED, 0);  //$NON-NLS-1$
+		
+		Label label= new Label(composite, SWT.LEFT);
+		label.setText(AntPreferencesMessages.getString("AntEditorPreferencePage.21")); //$NON-NLS-1$
+		
+		addCheckBox(composite, AntPreferencesMessages.getString("AntEditorPreferencePage.22"), AntEditorPreferenceConstants.EDITOR_FOLDING_DTD, 0); //$NON-NLS-1$
+		addCheckBox(composite, AntPreferencesMessages.getString("AntEditorPreferencePage.23"), AntEditorPreferenceConstants.EDITOR_FOLDING_COMMENTS, 0); //$NON-NLS-1$
+		addCheckBox(composite, AntPreferencesMessages.getString("AntEditorPreferencePage.24"), AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING, 0); //$NON-NLS-1$
+		addCheckBox(composite, AntPreferencesMessages.getString("AntEditorPreferencePage.25"), AntEditorPreferenceConstants.EDITOR_FOLDING_TARGETS, 0); //$NON-NLS-1$
 		return composite;
 	}
 
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
index bbc194c..668b1ff 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
@@ -150,6 +150,11 @@
 AntEditorPreferencePage.19=&Folding
 AntEditorPreferencePage.2=Background color
 AntEditorPreferencePage.20=&Enable folding when opening a new editor
+AntEditorPreferencePage.21=Initially fold these region types:
+AntEditorPreferencePage.22=DTD &blocks
+AntEditorPreferencePage.23=&Comments
+AntEditorPreferencePage.24=Def&ining tasks
+AntEditorPreferencePage.25=&Targets
 AntEditorPreferencePage.4=C&ustom:
 AntEditorPreferencePage.5=Fore&ground:
 AntEditorPreferencePage.7=&Bold