[jbosstools-commits] JBoss Tools SVN: r7188 - in trunk/vpe/plugins/org.jboss.tools.vpe: src/org/jboss/tools/vpe/editor/template and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Mar 28 14:31:43 EDT 2008


Author: mareshkau
Date: 2008-03-28 14:31:42 -0400 (Fri, 28 Mar 2008)
New Revision: 7188

Added:
   trunk/vpe/plugins/org.jboss.tools.vpe/resources/textFormatting.xml
Modified:
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/FormatAttributeData.java
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/FormatData.java
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-1494

Added: trunk/vpe/plugins/org.jboss.tools.vpe/resources/textFormatting.xml
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/resources/textFormatting.xml	                        (rev 0)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/resources/textFormatting.xml	2008-03-28 18:31:42 UTC (rev 7188)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Author Max Areshkau
+	In this file contains configurations vpe:textFormatting tag
+-->
+<vpe:textFormatting>
+	<vpe:format type="UnderlineFormat">
+		<vpe:formatAttribute type="style" />
+	</vpe:format>
+	<vpe:format type="BoldFormat">
+		<vpe:formatAttribute type="style" />
+	</vpe:format>
+	<vpe:format type="ItalicFormat">
+		<vpe:formatAttribute type="style" />
+	</vpe:format>
+	<vpe:format type="FontNameFormat">
+		<vpe:formatAttribute type="style" />
+	</vpe:format>
+	<vpe:format type="FontSizeFormat">
+		<vpe:formatAttribute type="style" />
+	</vpe:format>
+	<vpe:format type="BackgroundColorFormat">
+		<vpe:formatAttribute type="style" />
+	</vpe:format>
+	<vpe:format type="ForegroundColorFormat">
+		<vpe:formatAttribute type="style" />
+	</vpe:format>
+</vpe:textFormatting>

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java	2008-03-28 18:31:35 UTC (rev 7187)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java	2008-03-28 18:31:42 UTC (rev 7188)
@@ -38,6 +38,11 @@
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
 
+/**
+ *  Class which response for configuration template element from 
+ *  configuration file.
+ *
+ */
 public abstract class VpeAbstractTemplate implements VpeTemplate {
 	protected boolean caseSensitive;
 	protected boolean children;
@@ -53,97 +58,97 @@
 	private TextFormatingData textFormatingData;
 	private VpePseudoContentCreator pseudoContentCreator;
 
-	private static final String TAG_BREAKER = VpeTemplateManager.VPE_PREFIX + "breaker";
-	private static final String ATTR_BREAKER_TYPE = "type";
-	private static final String ATTR_BREAKER_TYPE_IGNORE = "ignore";
-	private static final String ATTR_BREAKER_TYPE_SELECTITEM = "selectItem";
+	private static final String TAG_BREAKER = VpeTemplateManager.VPE_PREFIX + "breaker"; //$NON-NLS-1$
+	private static final String ATTR_BREAKER_TYPE = "type"; //$NON-NLS-1$
+	private static final String ATTR_BREAKER_TYPE_IGNORE = "ignore"; //$NON-NLS-1$
+	private static final String ATTR_BREAKER_TYPE_SELECTITEM = "selectItem"; //$NON-NLS-1$
 	private static final int BREAKER_TYPE_NONE = 0;
 	private static final int BREAKER_TYPE_IGNORE = 1;
 	private static final int BREAKER_TYPE_SELECTITEM = 2;
 
-	private static final String TAG_PSEUDOCONTENT = VpeTemplateManager.VPE_PREFIX + "pseudoContent";
-	private static final String ATTR_PSEUDOCONTENT_DEFAULTTEXT = "defaultText";
-	private static final String ATTR_PSEUDOCONTENT_ATTRNAME = "attrName";
+	private static final String TAG_PSEUDOCONTENT = VpeTemplateManager.VPE_PREFIX + "pseudoContent"; //$NON-NLS-1$
+	private static final String ATTR_PSEUDOCONTENT_DEFAULTTEXT = "defaultText"; //$NON-NLS-1$
+	private static final String ATTR_PSEUDOCONTENT_ATTRNAME = "attrName"; //$NON-NLS-1$
 
 	private int breakerType = BREAKER_TYPE_NONE;
 
 	static private HashSet<String> inlineTags = new HashSet<String>();
 	static{
-		inlineTags.add("b");
-		inlineTags.add("i");
-		inlineTags.add("u");
-		inlineTags.add("img");
-		inlineTags.add("sub");
-		inlineTags.add("sup");
-		inlineTags.add("strike");
-		inlineTags.add("font");
-		inlineTags.add("a");
-		inlineTags.add("input");
-		inlineTags.add("textarea");
-		inlineTags.add("span");
-		inlineTags.add("button");
-		inlineTags.add("label");
+		inlineTags.add("b"); //$NON-NLS-1$
+		inlineTags.add("i"); //$NON-NLS-1$
+		inlineTags.add("u"); //$NON-NLS-1$
+		inlineTags.add("img"); //$NON-NLS-1$ 
+		inlineTags.add("sub"); //$NON-NLS-1$
+		inlineTags.add("sup"); //$NON-NLS-1$
+		inlineTags.add("strike"); //$NON-NLS-1$
+		inlineTags.add("font"); //$NON-NLS-1$
+		inlineTags.add("a"); //$NON-NLS-1$
+		inlineTags.add("input"); //$NON-NLS-1$
+		inlineTags.add("textarea"); //$NON-NLS-1$
+		inlineTags.add("span"); //$NON-NLS-1$
+		inlineTags.add("button"); //$NON-NLS-1$
+		inlineTags.add("label"); //$NON-NLS-1$
 	}
 	static private HashMap<String, Integer> tagResizeConstrans = new HashMap<String, Integer>();
 	static{
-		tagResizeConstrans.put("table", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_ALL));
-		tagResizeConstrans.put("tr", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_ALL));
-		tagResizeConstrans.put("br", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
-		tagResizeConstrans.put("b", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
-		tagResizeConstrans.put("i", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
-		tagResizeConstrans.put("u", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
-		tagResizeConstrans.put("sub", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
-		tagResizeConstrans.put("sup", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
-		tagResizeConstrans.put("strike", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
-		tagResizeConstrans.put("font", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
-		tagResizeConstrans.put("a", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE));
+		tagResizeConstrans.put("table", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_ALL)); //$NON-NLS-1$
+		tagResizeConstrans.put("tr", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_ALL)); //$NON-NLS-1$
+		tagResizeConstrans.put("br", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
+		tagResizeConstrans.put("b", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
+		tagResizeConstrans.put("i", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
+		tagResizeConstrans.put("u", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
+		tagResizeConstrans.put("sub", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
+		tagResizeConstrans.put("sup", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
+		tagResizeConstrans.put("strike", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
+		tagResizeConstrans.put("font", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
+		tagResizeConstrans.put("a", Integer.valueOf(VpeTagDescription.RESIZE_CONSTRAINS_NONE)); //$NON-NLS-1$
 	}
 	
 	static private HashSet<String> breakWithParagraphTags = new HashSet<String>();
 	static{
-		breakWithParagraphTags.add("b");
-		breakWithParagraphTags.add("a");
-		breakWithParagraphTags.add("abbr");
-		breakWithParagraphTags.add("acronym");
-		breakWithParagraphTags.add("b");
-		breakWithParagraphTags.add("bdo");
-		breakWithParagraphTags.add("big");
-		breakWithParagraphTags.add("blink");
-		breakWithParagraphTags.add("cite");
-		breakWithParagraphTags.add("code");
-		breakWithParagraphTags.add("del");
-		breakWithParagraphTags.add("dfn");
-		breakWithParagraphTags.add("em");
-		breakWithParagraphTags.add("font");
-		breakWithParagraphTags.add("ins");
-		breakWithParagraphTags.add("kbd");
-		breakWithParagraphTags.add("nobr");
-		breakWithParagraphTags.add("q");
-		breakWithParagraphTags.add("s");
-		breakWithParagraphTags.add("samp");
-		breakWithParagraphTags.add("small");
-		breakWithParagraphTags.add("span");
-		breakWithParagraphTags.add("strike");
-		breakWithParagraphTags.add("strong");
-		breakWithParagraphTags.add("tt");
-		breakWithParagraphTags.add("u");
-		breakWithParagraphTags.add("var");
+		breakWithParagraphTags.add("b"); //$NON-NLS-1$
+		breakWithParagraphTags.add("a"); //$NON-NLS-1$
+		breakWithParagraphTags.add("abbr"); //$NON-NLS-1$
+		breakWithParagraphTags.add("acronym"); //$NON-NLS-1$
+		breakWithParagraphTags.add("b"); //$NON-NLS-1$
+		breakWithParagraphTags.add("bdo"); //$NON-NLS-1$
+		breakWithParagraphTags.add("big"); //$NON-NLS-1$
+		breakWithParagraphTags.add("blink"); //$NON-NLS-1$
+		breakWithParagraphTags.add("cite"); //$NON-NLS-1$
+		breakWithParagraphTags.add("code"); //$NON-NLS-1$
+		breakWithParagraphTags.add("del"); //$NON-NLS-1$
+		breakWithParagraphTags.add("dfn"); //$NON-NLS-1$
+		breakWithParagraphTags.add("em"); //$NON-NLS-1$
+		breakWithParagraphTags.add("font"); //$NON-NLS-1$
+		breakWithParagraphTags.add("ins"); //$NON-NLS-1$
+		breakWithParagraphTags.add("kbd"); //$NON-NLS-1$
+		breakWithParagraphTags.add("nobr"); //$NON-NLS-1$
+		breakWithParagraphTags.add("q"); //$NON-NLS-1$
+		breakWithParagraphTags.add("s"); //$NON-NLS-1$
+		breakWithParagraphTags.add("samp"); //$NON-NLS-1$
+		breakWithParagraphTags.add("small"); //$NON-NLS-1$
+		breakWithParagraphTags.add("span"); //$NON-NLS-1$
+		breakWithParagraphTags.add("strike"); //$NON-NLS-1$
+		breakWithParagraphTags.add("strong"); //$NON-NLS-1$
+		breakWithParagraphTags.add("tt"); //$NON-NLS-1$
+		breakWithParagraphTags.add("u"); //$NON-NLS-1$
+		breakWithParagraphTags.add("var"); //$NON-NLS-1$
 	}
 	static private HashSet<String> breakWithoutParagraphTags = new HashSet<String>();
 	static{
-		breakWithoutParagraphTags.add("p");
-		breakWithoutParagraphTags.add("address");
-		breakWithoutParagraphTags.add("blockquote");
-		breakWithoutParagraphTags.add("center");
-		breakWithoutParagraphTags.add("div");
-		breakWithoutParagraphTags.add("h1");
-		breakWithoutParagraphTags.add("h2");
-		breakWithoutParagraphTags.add("h3");
-		breakWithoutParagraphTags.add("h4");
-		breakWithoutParagraphTags.add("h5");
-		breakWithoutParagraphTags.add("h6");
-		breakWithoutParagraphTags.add("p");
-		breakWithoutParagraphTags.add("pre");
+		breakWithoutParagraphTags.add("p"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("address"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("blockquote"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("center"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("div"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("h1"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("h2"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("h3"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("h4"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("h5"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("h6"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("p"); //$NON-NLS-1$
+		breakWithoutParagraphTags.add("pre"); //$NON-NLS-1$
 	}
 	
 	/**
@@ -153,13 +158,13 @@
 	 */
 	public void init(Element templateElement, boolean caseSensitive) {
 		this.caseSensitive = caseSensitive;
-		children = "yes".equals(templateElement.getAttribute(VpeTemplateManager.ATTR_TEMPLATE_CHILDREN));
-		modify = "yes".equals(templateElement.getAttribute(VpeTemplateManager.ATTR_TEMPLATE_MODIFY));
+		children = "yes".equals(templateElement.getAttribute(VpeTemplateManager.ATTR_TEMPLATE_CHILDREN)); //$NON-NLS-1$
+		modify = "yes".equals(templateElement.getAttribute(VpeTemplateManager.ATTR_TEMPLATE_MODIFY)); //$NON-NLS-1$
 		
 		String strHaveVisualPreview = templateElement.getAttribute(VpeTemplateManager.ATTR_TEMPLATE_HAVE_VISUAL_PREVIEW);
 		
 		if (strHaveVisualPreview != null && strHaveVisualPreview.length() != 0 ) {
-			haveVisualPreview = "yes".equals(strHaveVisualPreview);			
+			haveVisualPreview = "yes".equals(strHaveVisualPreview); //$NON-NLS-1$			
 		} else {
 			haveVisualPreview = true;
 		}
@@ -239,7 +244,7 @@
 	
 	private void initPseudoContentHandler(Element templateSection) {
 		if (pseudoContentCreator == null) {
-			if ("yes".equalsIgnoreCase(templateSection.getAttribute(ATTR_PSEUDOCONTENT_DEFAULTTEXT))) {
+			if ("yes".equalsIgnoreCase(templateSection.getAttribute(ATTR_PSEUDOCONTENT_DEFAULTTEXT))) { //$NON-NLS-1$
 				pseudoContentCreator = new VpeTextPseudoContentCreator(null, templateSection.getAttribute(ATTR_PSEUDOCONTENT_ATTRNAME));
 			} else {
 				NodeList children = templateSection.getChildNodes();
@@ -350,7 +355,7 @@
 		clearRegionToFormat();
 		Node focusNode = selection.getFocusNode();
 		int focusNodeType = focusNode.getNodeType();
-		if (sourceNode.getNodeName().equalsIgnoreCase("li")) {
+		if (sourceNode.getNodeName().equalsIgnoreCase("li")) { //$NON-NLS-1$
 			Node where = null;
 			if (selection.getFocusOffset() == 0) {
 				where = sourceNode;
@@ -405,13 +410,13 @@
 			updateRegionToFormat(newLi);
 			reformatCallback(pageContext);
 			return true;
-		} else if (focusNodeType == Node.ELEMENT_NODE && focusNode.getNodeName().equalsIgnoreCase("br")) {
-			Node newNode = focusNode.getParentNode().insertBefore(focusNode.getOwnerDocument().createElement("br"), focusNode);
+		} else if (focusNodeType == Node.ELEMENT_NODE && focusNode.getNodeName().equalsIgnoreCase("br")) { //$NON-NLS-1$
+			Node newNode = focusNode.getParentNode().insertBefore(focusNode.getOwnerDocument().createElement("br"), focusNode); //$NON-NLS-1$
 			updateRegionToFormat(focusNode);
 			updateRegionToFormat(newNode);
 			reformatCallback(pageContext);
 			return true;
-		} else if (focusNodeType == Node.ELEMENT_NODE && focusNode.getNodeName().equalsIgnoreCase("p")) {
+		} else if (focusNodeType == Node.ELEMENT_NODE && focusNode.getNodeName().equalsIgnoreCase("p")) { //$NON-NLS-1$
 			Node nextElement = focusNode.getNextSibling();
 			Node parent = focusNode.getParentNode();
 			if (parent != null) {
@@ -427,16 +432,16 @@
 			updateRegionToFormat(focusNode);
 			reformatCallback(pageContext);
 			return true;
-		} else if (focusNodeType == Node.TEXT_NODE && focusNode.getParentNode().getNodeName().equalsIgnoreCase("td")) {
+		} else if (focusNodeType == Node.TEXT_NODE && focusNode.getParentNode().getNodeName().equalsIgnoreCase("td")) { //$NON-NLS-1$
 			Text newNode = ((Text)focusNode).splitText(selection.getFocusOffset());
 			setCursor(pageContext, newNode);
 			updateRegionToFormat(focusNode);
 			updateRegionToFormat(newNode);
 			reformatCallback(pageContext);
 			return true;
-		} else if (sourceNode.getNodeType() == Node.ELEMENT_NODE && sourceNode.getNodeName().equalsIgnoreCase("tr")) {
+		} else if (sourceNode.getNodeType() == Node.ELEMENT_NODE && sourceNode.getNodeName().equalsIgnoreCase("tr")) { //$NON-NLS-1$
 			return true;
-		} else if (focusNodeType == Node.TEXT_NODE && !focusNode.getParentNode().getNodeName().equalsIgnoreCase("body")) {
+		} else if (focusNodeType == Node.TEXT_NODE && !focusNode.getParentNode().getNodeName().equalsIgnoreCase("body")) { //$NON-NLS-1$
 			Node parent = focusNode.getParentNode();
 			if (parent != null) {
 				String parentName = parent.getNodeName();
@@ -444,14 +449,14 @@
 					Node p1 = null, p2 = null;
 					Node parentParent = parent.getParentNode();
 					if (parentParent != null) {
-						if (!parentParent.getNodeName().equalsIgnoreCase("p")) {
+						if (!parentParent.getNodeName().equalsIgnoreCase("p")) { //$NON-NLS-1$
 							if (parentParent.getNodeType() != Node.DOCUMENT_NODE) {
-								p1 = parentParent.getOwnerDocument().createElement("p");
+								p1 = parentParent.getOwnerDocument().createElement("p"); //$NON-NLS-1$
 								parentParent.insertBefore(p1, parent);
 								parent = parentParent.removeChild(parent);
 								p1.appendChild(parent);
 							} else {
-								p1 = ((Document)parentParent).createElement("p");
+								p1 = ((Document)parentParent).createElement("p"); //$NON-NLS-1$
 								parentParent.insertBefore(p1, parent);
 								parent = parentParent.removeChild(parent);
 								p1.appendChild(parent);
@@ -548,9 +553,9 @@
 					}
 				}
 			}
-		} else if (focusNodeType == Node.TEXT_NODE && focusNode.getParentNode().getNodeName().equalsIgnoreCase("body")) {
-			Node p1 = focusNode.getOwnerDocument().createElement("p");
-			Node p2 = focusNode.getOwnerDocument().createElement("p");
+		} else if (focusNodeType == Node.TEXT_NODE && focusNode.getParentNode().getNodeName().equalsIgnoreCase("body")) { //$NON-NLS-1$
+			Node p1 = focusNode.getOwnerDocument().createElement("p"); //$NON-NLS-1$
+			Node p2 = focusNode.getOwnerDocument().createElement("p"); //$NON-NLS-1$
 			Text newNode = ((Text)focusNode).splitText(selection.getFocusOffset());
 			focusNode.getParentNode().insertBefore(p1, focusNode);
 			focusNode.getParentNode().insertBefore(p2, newNode);
@@ -567,7 +572,7 @@
 
 			return true;
 		} else if (focusNodeType == Node.ELEMENT_NODE && selection.getFocusOffset() == 0) {
-			Node newNode = focusNode.getParentNode().insertBefore(focusNode.getOwnerDocument().createElement("br"), focusNode);
+			Node newNode = focusNode.getParentNode().insertBefore(focusNode.getOwnerDocument().createElement("br"), focusNode); //$NON-NLS-1$
 			updateRegionToFormat(focusNode);
 			updateRegionToFormat(newNode);
 			reformatCallback(pageContext);
@@ -581,12 +586,12 @@
 		if (parent != null) {
 			boolean isH = false;
 			for (int i = 1; i < 7 && !isH; i++) {
-				isH = parent.getNodeName().equalsIgnoreCase("h" + i);
+				isH = parent.getNodeName().equalsIgnoreCase("h" + i); //$NON-NLS-1$
 			}
 			if (!isH || clone) {
 				newParent = parent.cloneNode(false);
 			} else {
-				newParent = parent.getOwnerDocument().createElement("p");
+				newParent = parent.getOwnerDocument().createElement("p"); //$NON-NLS-1$
 			}
 		}
 		return newParent;

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java	2008-03-28 18:31:35 UTC (rev 7187)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java	2008-03-28 18:31:42 UTC (rev 7188)
@@ -27,7 +27,9 @@
 import org.jboss.tools.jst.web.tld.TaglibData;
 import org.jboss.tools.vpe.VpePlugin;
 import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.textformating.TextFormatingData;
 import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.VpeDebugUtil;
 import org.jboss.tools.vpe.editor.util.XmlUtil;
 import org.osgi.framework.Bundle;
 import org.w3c.dom.Document;
@@ -37,7 +39,6 @@
 
 public class VpeTemplateManager {
 	
-	static final String TEMPLATES_FILE_LIST_NAME = "vpe-templates-list.xml"; //$NON-NLS-1$
 	static final String AUTO_TEMPLATES_FILE_NAME = "templates/vpe-templates-auto.xml"; //$NON-NLS-1$
 	static final String TEMPLATES_FOLDER = File.separator + "templates" + File.separator; //$NON-NLS-1$
 	public static final String VPE_PREFIX = "vpe:"; //$NON-NLS-1$
@@ -96,7 +97,7 @@
 	static final String TAG_FACET = VPE_PREFIX + "facet"; //$NON-NLS-1$
 	static final String TAG_MY_FACES_PAGE_LAYOUT = VPE_PREFIX + "panellayout"; //$NON-NLS-1$	
 	
-	public static final String TAG_TEXT_FORMATING = VPE_PREFIX + "textFormating"; //$NON-NLS-1$
+	public static final String TAG_TEXT_FORMATING = VPE_PREFIX + "textFormatting"; //$NON-NLS-1$
 	public static final String TAG_FORMAT = VPE_PREFIX + "format"; //$NON-NLS-1$
 	public static final String TAG_FORMAT_ATTRIBUTE = VPE_PREFIX + "formatAttribute"; //$NON-NLS-1$
 
@@ -121,7 +122,7 @@
 
 	static final String ATTR_TAG_NAME = "name"; //$NON-NLS-1$
 	static final String ATTR_TAG_CASE_SENSITIVE = "case-sensitive"; //$NON-NLS-1$
-	static final String ATTR_VALUE_YES = "yes"; //$NON-NLS-1$
+	public static final String ATTR_VALUE_YES = "yes"; //$NON-NLS-1$
 	static final String ATTR_VALUE_NO = "no"; //$NON-NLS-1$
 
 	static final String ATTR_IF_TEST = "test"; //$NON-NLS-1$
@@ -226,6 +227,19 @@
 	private Set<String> withoutWhitespaceContainerSet = new HashSet<String>();
 	private Set<String> withoutPseudoElementContainerSet = new HashSet<String>();
 	
+	/**
+	 * added by Max Areshkau, JBIDE-1494
+	 * Contains default text formating data
+	 */
+	private static TextFormatingData defaultTextFormattingData;
+	/**
+	 * contains default text formating file name
+	 */
+	private static final String DEFAUL_TEXT_FORMATTING_CONF_FILE_NAME= File.separator+"resources"+File.separator+"textFormatting.xml"; //$NON-NLS-1$ //$NON-NLS-2$
+	/**
+	 * Property which indicates that with this tag will be added default formats
+	 */
+	public static final String ATTR_USE_DEFAULT_FORMATS="use-default-formats"; //$NON-NLS-1$
 	/*
 	 * Added by Max Areshkau(mareshkau at exadel.com)
 	 */ 
@@ -235,7 +249,6 @@
 	 */
 	private static final String NAMESPACE_IDENTIFIER_ATTRIBUTE = "namespaceIdentifier"; //$NON-NLS-1$
 	
-
 	private VpeTemplateManager() {
 	}
 
@@ -312,7 +325,13 @@
 	private void load() {
 		initWithoutWhitespaceContainerSet();
 		initPseudoElementContainerSet();
+		/*
+		 * loads templates configurations files
+		 */
 		templateFileList.load();
+		/*
+		 * load templates
+		 */
 		loadImpl();
 	}
 
@@ -861,4 +880,24 @@
 		}
 		return defTemplate;
 	}
+
+	/**
+	 * Initialize and returns default text formatting data
+	 * @return the defaultTextFormatingData
+	 */
+	public static TextFormatingData getDefaultTextFormattingData() {
+		
+		if(defaultTextFormattingData==null) {
+			
+			try {
+				IPath path = VpeTemplateFileList.getFilePath(DEFAUL_TEXT_FORMATTING_CONF_FILE_NAME, null);
+				Element root = XMLUtilities.getElement(path.toFile(), null);
+				defaultTextFormattingData = new TextFormatingData(root);
+			} catch (Exception e) {
+				
+				VpePlugin.getPluginLog().logError(e);
+			}
+		}
+		return defaultTextFormattingData;
+	}
 }

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/FormatAttributeData.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/FormatAttributeData.java	2008-03-28 18:31:35 UTC (rev 7187)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/FormatAttributeData.java	2008-03-28 18:31:42 UTC (rev 7188)
@@ -17,9 +17,9 @@
 /**
  * @author Igels
  */
-public class FormatAttributeData {
+public class FormatAttributeData implements Cloneable{
 
-	public static final String STYLE_TYPE = "style";
+	public static final String STYLE_TYPE = "style"; //$NON-NLS-1$
 
 	private String type;
 	private String name;
@@ -27,6 +27,24 @@
 	private boolean caseSensitive = false;
 	private FormatData parentFormatData;
 
+	
+	/* (non-Javadoc)
+	 * @see java.lang.Object#clone()
+	 */
+	@Override
+	public FormatAttributeData clone() throws CloneNotSupportedException {
+		
+		FormatAttributeData result = new FormatAttributeData(parentFormatData, null);
+		
+		result.type = new String(this.type);
+		result.name = new String(this.name);
+		result.value = new String(this.value);
+		result.caseSensitive = caseSensitive;
+		result.parentFormatData =  this.parentFormatData;
+		
+		return result;
+	}
+
 	/**
 	 * @param formatAttribute - Element <vpe:formatAttribute>
 	 */
@@ -75,4 +93,11 @@
 	public FormatData getParentFormatData() {
 		return parentFormatData;
 	}
+
+	/**
+	 * @param parentFormatData the parentFormatData to set
+	 */
+	public void setParentFormatData(FormatData parentFormatData) {
+		this.parentFormatData = parentFormatData;
+	}
 }
\ No newline at end of file

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/FormatData.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/FormatData.java	2008-03-28 18:31:35 UTC (rev 7187)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/FormatData.java	2008-03-28 18:31:42 UTC (rev 7188)
@@ -19,7 +19,7 @@
  * FormatData describe vpe template text formating part for tag.
  * @author Igels
  */
-public class FormatData {
+public class FormatData implements Cloneable{
 
 	private FormatAttributeData[] formatAttributes;
 	private String type;
@@ -51,12 +51,48 @@
 		addChildren = formatElement.getAttribute(VpeTemplateManager.ATTR_FORMAT_ADD_CHILDREN);
 		addChildrenHandler = formatElement.getAttribute(VpeTemplateManager.ATTR_FORMAT_ADD_CHILDREN_HANDLER);
 		handler = formatElement.getAttribute(VpeTemplateManager.ATTR_FORMAT_HANDLER);
-		setDefault = "true".equals(formatElement.getAttribute(VpeTemplateManager.ATTR_FORMAT_SET_DEFAULT));
+		setDefault = "true".equals(formatElement.getAttribute(VpeTemplateManager.ATTR_FORMAT_SET_DEFAULT)); //$NON-NLS-1$
 		setAddChildrenFlags();
 		addParent = formatElement.getAttribute(VpeTemplateManager.ATTR_FORMAT_ADD_PARENT);
 		setAddParentFlags();
 	}
 
+	private FormatData() {
+		
+	}
+	
+	/* (non-Javadoc)
+	 * @see java.lang.Object#clone()
+	 */
+	@Override
+	public FormatData clone() throws CloneNotSupportedException {
+		
+		FormatData result = new FormatData();
+		
+		result.formatAttributes  = new FormatAttributeData[formatAttributes.length];
+		//clone format attributes
+		for(int i=0;i<formatAttributes.length;i++) {
+			result.formatAttributes[i]=this.formatAttributes[i].clone();
+			result.formatAttributes[i].setParentFormatData(result);
+		}
+		result.addChildren =  new String(this.addChildren);
+		result.addChildrenByItself = this.addChildrenByItself;
+		result.addChildrenHandler = new String(this.addChildrenHandler);
+		result.addChildrenIsAllow = this.addChildrenIsAllow;
+		result.addChildrenIsAllowIfParentDoesntDeny = this.addChildrenIsAllowIfParentDoesntDeny;
+		result.addChildrenIsDeny=this.addChildrenIsDeny;
+		result.addParent = new String(this.addParent);
+		result.addParentByItself = this.addParentByItself;
+		result.addParentIsAllow = this.addParentIsAllow;
+		result.addParentIsAllowIfParentDoesntDeny = this.addParentIsAllowIfParentDoesntDeny;
+		result.addParentIsDeny = this.addParentIsDeny;
+		result.handler = new String(this.handler);
+		result.setDefault=this.setDefault;
+		result.type= new String(this.type);
+		return result;
+	}
+
+
 	private void setAddChildrenFlags() {
 		if(VpeTemplateManager.ATTR_FORMAT_ADD_CHILDREN_ALLOW_VALUE.equals(addChildren)) {
 			addChildrenIsAllow = true;

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java	2008-03-28 18:31:35 UTC (rev 7187)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java	2008-03-28 18:31:42 UTC (rev 7188)
@@ -11,6 +11,7 @@
 package org.jboss.tools.vpe.editor.template.textformating;
 
 import java.util.ArrayList;
+import java.util.List;
 
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -26,18 +27,65 @@
 	private FormatData[] formats;
 
 	/**
-	 * @param templateTextFormatingElement - Element <vpe:textFormating>
+	 * @param templateTextFormatingElement - Element <vpe:textFormatting>
 	 */
 	public TextFormatingData(Element templateTextFormatingElement) {
 		NodeList list = templateTextFormatingElement.getElementsByTagName(VpeTemplateManager.TAG_FORMAT);
-		formats = new FormatData[list.getLength()];
-		for(int i=0; i<list.getLength(); i++) {
+		
+		List<FormatData> defaultFormats = new ArrayList<FormatData>();
+		
+		if(VpeTemplateManager.ATTR_VALUE_YES.
+				equals(templateTextFormatingElement.getAttribute(VpeTemplateManager.ATTR_USE_DEFAULT_FORMATS))) {
+			//adds default format data
+			FormatData[] formats =VpeTemplateManager.getDefaultTextFormattingData().getAllFormatData();
+			for (FormatData formatData :formats) {
+				
+				defaultFormats.add(formatData);
+			} 
+		}
+		List<FormatData> localFormats=new ArrayList<FormatData>();
+		
+		for(int i=0;i<list.getLength();i++) {
 			Element element = (Element)list.item(i);
-			formats[i] = new FormatData(element);
+			localFormats.add(new FormatData(element));
 		}
+		formats=(FormatData[])mergeLocalAndDefaultFormats(defaultFormats, localFormats).toArray(new FormatData[0]);
 	}
-
 	/**
+	 * Merges  local and default formats.
+	 * If format with some type exist in local copy and remote, we use 
+	 * local format
+	 * 
+	 * @return merged list
+	 */
+	private List<FormatData> mergeLocalAndDefaultFormats(List<FormatData> defaultFormats,List<FormatData> localFormats) {
+	
+		List<FormatData> result = new ArrayList<FormatData>(localFormats);
+		for (FormatData formatData : defaultFormats) {
+			if(!isFormatExistInList(result,formatData)) {
+				result.add(formatData);
+			}
+		}
+		return result;
+	}
+	
+	private boolean isFormatExistInList(List<FormatData> formatData, FormatData data) {
+	
+		if(data.getType()==null) {
+			
+			return false;
+		}
+		
+		for (FormatData format : formatData) {
+			
+			if(data.getType().equals(format.getType())) {
+				return true;
+			}
+		}
+		
+		return false;
+	}
+	/**
 	 * @return children - <vpe:format>
 	 */
 	public FormatData[] getAllFormatData() {
@@ -65,4 +113,5 @@
 	public boolean hasFormatData(String type) {
 		return getFormatDatas(type).length>0;
 	}
+
 }
\ No newline at end of file




More information about the jbosstools-commits mailing list