Author: dsakovich
Date: 2008-06-03 06:32:26 -0400 (Tue, 03 Jun 2008)
New Revision: 8501
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/BlockFormatController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/BlockFormatHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/BoldFormatHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/HandlerFactory.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/ItalicFormatHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/SimpleTagHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/UnderlineFormatHandler.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-2029
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/BlockFormatController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/BlockFormatController.java 2008-06-02
19:44:03 UTC (rev 8500)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/BlockFormatController.java 2008-06-03
10:32:26 UTC (rev 8501)
@@ -130,7 +130,7 @@
*/
private String getNodeName(Node node) {
- String nodeName = "";
+ String nodeName = ""; //$NON-NLS-1$
do {
nodeName = node.getNodeName();
node = node.getParentNode();
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/BlockFormatHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/BlockFormatHandler.java 2008-06-02
19:44:03 UTC (rev 8500)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/BlockFormatHandler.java 2008-06-03
10:32:26 UTC (rev 8501)
@@ -7,7 +7,7 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.toolbar.format.handler;
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
@@ -16,59 +16,81 @@
import org.jboss.tools.vpe.editor.toolbar.format.BlockFormatController;
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
+import org.jboss.tools.vpe.editor.util.HTML;
/**
* @author Igels
*/
public class BlockFormatHandler extends FormatHandler {
- public BlockFormatHandler() {
- super();
+ public BlockFormatHandler() {
+ super();
+ }
+
+ public BlockFormatHandler(FormatControllerManager manager) {
+ super(manager);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.vpe.editor.toolbar.format.handler.FormatHandler#run()
+ */
+ protected void run() {
+ BlockFormatController formatController = (BlockFormatController) controller;
+ String tagName = formatController.getTagName();
+ if (tagName == null || tagName.trim().length() == 0) {
+ return;
}
- public BlockFormatHandler(FormatControllerManager manager) {
- super(manager);
+ boolean normal = false;
+ if ("normal".equals(tagName)) {
+ normal = true;
}
- /* (non-Javadoc)
- * @see org.jboss.tools.vpe.editor.toolbar.format.handler.FormatHandler#run()
- */
- protected void run() {
- BlockFormatController formatController = (BlockFormatController)controller;
- String tagName = formatController.getTagName();
- if(tagName==null || tagName.trim().length()==0) {
- return;
- }
+ Node selectedNode = manager.getCurrentSelectedNodeInfo().getNode();
- boolean normal = false;
- if("normal".equals(tagName)) {
- normal = true;
- }
+ StructuredTextViewer viewer = manager.getVpeController()
+ .getPageContext().getSourceBuilder().getStructuredTextViewer();
- Node selectedNode = manager.getCurrentSelectedNodeInfo().getNode();
+ Node replacedNode = null;
+ //Node parentNode = selectedNode.getParentNode();
+ Node formatNode = getCurrentNodeWithoutFormatingTag(selectedNode);
+ Node parentNode = formatNode.getParentNode();
+ if (isBlockFormatNode(selectedNode)) {
+ replacedNode = selectedNode;
+ } else if (isBlockFormatNode(parentNode)) {
+ replacedNode = parentNode;
+ }
+ if (replacedNode instanceof ElementImpl) {
+ // Replase old node
+ if (normal) {
+ stripElement((ElementImpl) replacedNode, selectedNode, viewer);
+ } else {
+ replaseElementName((ElementImpl) replacedNode, tagName, viewer,
+ selectedNode);
+ }
+ } else if (!normal) {
+ insertNewElementAroundNode(tagName, formatNode, viewer, true);
+ }
+ }
- StructuredTextViewer viewer =
manager.getVpeController().getPageContext().getSourceBuilder().getStructuredTextViewer();
+ private boolean isBlockFormatNode(Node node) {
+ return node != null
+ && BlockFormatController.TAGS.get(node.getNodeName()
+ .toLowerCase()) != null;
+ }
- Node replacedNode = null;
- Node parentNode = selectedNode.getParentNode();
- if(isBlockFormatNode(selectedNode)) {
- replacedNode = selectedNode;
- } else if(isBlockFormatNode(parentNode)) {
- replacedNode = parentNode;
- }
- if(replacedNode instanceof ElementImpl) {
- // Replase old node
- if(normal) {
- stripElement((ElementImpl)replacedNode, selectedNode, viewer);
- } else {
- replaseElementName((ElementImpl)replacedNode, tagName, viewer, selectedNode);
- }
- } else if(!normal) {
- insertNewElementAroundNode(tagName, selectedNode, viewer, true);
- }
+ private Node getCurrentNodeWithoutFormatingTag(Node node) {
+ Node currentNode = node;
+ while (currentNode.getParentNode() != null
+ && (currentNode.getParentNode().getNodeName().equalsIgnoreCase(HTML.TAG_B)
+ || currentNode.getParentNode().getNodeName()
+ .equalsIgnoreCase(HTML.TAG_I) || currentNode.getParentNode()
+ .getNodeName().equalsIgnoreCase(HTML.TAG_U))) {
+ currentNode = currentNode.getParentNode();
}
+ return currentNode;
+ }
- private boolean isBlockFormatNode(Node node) {
- return node!=null &&
BlockFormatController.TAGS.get(node.getNodeName().toLowerCase())!=null;
- }
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/BoldFormatHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/BoldFormatHandler.java 2008-06-02
19:44:03 UTC (rev 8500)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/BoldFormatHandler.java 2008-06-03
10:32:26 UTC (rev 8501)
@@ -15,7 +15,11 @@
*/
public class BoldFormatHandler extends SimpleTagHandler {
- private static String TAG_NAME = "b";
+ private static String TAG_NAME = "b"; //$NON-NLS-1$
+
+ private static String TAG_STYLE = "FONT-WEIGHT"; //$NON-NLS-1$
+
+ private static String TAG_STYLE_VALUE = "bold"; //$NON-NLS-1$
/**
* Constructor
@@ -37,4 +41,22 @@
protected String getWrappingTagName() {
return TAG_NAME;
}
+
+ /**
+ *
+ * @return
+ */
+ protected String getWrappingTagStyle() {
+ return TAG_STYLE;
+ }
+
+ @Override
+ protected boolean equalsWrappingTagStyle(String tagStyle) {
+ return TAG_STYLE.equalsIgnoreCase(tagStyle);
+ }
+
+ @Override
+ protected String getWrappingTagStyleValue() {
+ return TAG_STYLE_VALUE;
+ }
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/HandlerFactory.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/HandlerFactory.java 2008-06-02
19:44:03 UTC (rev 8500)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/HandlerFactory.java 2008-06-03
10:32:26 UTC (rev 8501)
@@ -12,8 +12,6 @@
import java.util.HashMap;
-import org.eclipse.core.runtime.Status;
-
import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.template.textformating.FormatData;
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
@@ -24,7 +22,7 @@
public class HandlerFactory {
private FormatControllerManager manager;
- private HashMap handlers = new HashMap();
+ private HashMap<String,IFormatHandler> handlers = new
HashMap<String,IFormatHandler>();
/**
* Constructor
@@ -58,11 +56,11 @@
handlers.put(handlerClassName, handler);
return handler;
} else {
- VpePlugin.getPluginLog().logError("Wrong format handler. Class - " +
handlerClassName + ". Handler must be instance of
org.jboss.tools.vpe.editor.toolbar.format.handler.IFormatHandler",
- new Exception("Handler must be instance of
org.jboss.tools.vpe.editor.toolbar.format.handler.IFormatHandler"));
+ VpePlugin.getPluginLog().logError("Wrong format handler. Class - " +
handlerClassName + ". Handler must be instance of
org.jboss.tools.vpe.editor.toolbar.format.handler.IFormatHandler",
//$NON-NLS-1$//$NON-NLS-2$
+ new Exception("Handler must be instance of
org.jboss.tools.vpe.editor.toolbar.format.handler.IFormatHandler")); //$NON-NLS-1$
}
} catch (Exception e) {
- VpePlugin.getPluginLog().logError("Can't create format handler. Class:
" + handlerClassName, e);
+ VpePlugin.getPluginLog().logError("Can't create format handler. Class:
" + handlerClassName, e); //$NON-NLS-1$
}
}
return null;
@@ -77,4 +75,13 @@
// TODO
return null;
}
+
+ /**
+ * Get count of handlers
+ *
+ * @return count of handlers
+ */
+ public int getCountHandlers() {
+ return handlers.size();
+ }
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/ItalicFormatHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/ItalicFormatHandler.java 2008-06-02
19:44:03 UTC (rev 8500)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/ItalicFormatHandler.java 2008-06-03
10:32:26 UTC (rev 8501)
@@ -12,8 +12,12 @@
public class ItalicFormatHandler extends SimpleTagHandler {
- private static String TAG_NAME = "i";
+ private static String TAG_NAME = "i"; //$NON-NLS-1$
+ private static String TAG_STYLE = "FONT-STYLE"; //$NON-NLS-1$
+
+ private static String TAG_STYLE_VALUE = "italic"; //$NON-NLS-1$
+
/**
* Constructor
*/
@@ -34,4 +38,22 @@
protected String getWrappingTagName() {
return TAG_NAME;
}
+
+ /**
+ *
+ * @return
+ */
+ protected String getWrappingTagStyle() {
+ return TAG_STYLE;
+ }
+
+ @Override
+ protected boolean equalsWrappingTagStyle(String tagStyle) {
+ return TAG_STYLE.equalsIgnoreCase(tagStyle);
+ }
+
+ @Override
+ protected String getWrappingTagStyleValue() {
+ return TAG_STYLE_VALUE;
+ }
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/SimpleTagHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/SimpleTagHandler.java 2008-06-02
19:44:03 UTC (rev 8500)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/SimpleTagHandler.java 2008-06-03
10:32:26 UTC (rev 8501)
@@ -12,10 +12,11 @@
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.w3c.dom.Node;
-
import org.jboss.tools.vpe.editor.toolbar.format.IFormatItemSelector;
import org.jboss.tools.vpe.editor.toolbar.format.ToolItemFormatController;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Node;
/**
* @author Igels
@@ -34,31 +35,66 @@
*/
protected void run() {
StructuredTextViewer viewer =
manager.getVpeController().getPageContext().getSourceBuilder().getStructuredTextViewer();
+ Node parentNode = null;
Node selectedNode = manager.getCurrentSelectedNodeInfo().getNode();
if(selectedNode==null) {
return;
}
if(equalsWrappingTagName(selectedNode.getNodeName())) {
stripElement((ElementImpl)selectedNode, selectedNode, viewer);
- } else if(isParentWrappingTag()) {
- Node parentNode = selectedNode.getParentNode();
+ } else if((parentNode = getParentWrappingTagNode()) != null) {
+ if (getWrappingTagName().equalsIgnoreCase(parentNode.getNodeName()))
stripElement((ElementImpl)parentNode, selectedNode, viewer);
} else {
insertNewElementAroundNode(getWrappingTagName(), selectedNode, viewer, false);
}
}
+ /**
+ * Get parent wrapping tag
+ * @return node
+ */
+ private Node getParentWrappingTagNode() {
+ Node parentNode = manager.getCurrentSelectedNodeInfo().getNode();
+ for (int i = 0; i < manager.getHandlerFactory().getCountHandlers(); i++) {
+ parentNode = parentNode.getParentNode();
+ if (parentNode == null)
+ return null;
+ if (parentNode instanceof ElementImpl) {
+ ElementImpl element = (ElementImpl) parentNode;
+ String attr = element.getAttribute("style");
+ if (attr != null) {
+ attr = attr.replaceAll(" ", "");
+ if(equalsWrappingTagStyle(attr)) {
+ return parentNode;
+ }
+ }
+ }
+ if(equalsWrappingTagName(parentNode.getNodeName())) {
+ return parentNode;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Parent is format tag
+ *
+ * @return
+ */
private boolean isParentWrappingTag() {
- Node selectedNode = manager.getCurrentSelectedNodeInfo().getNode();
- Node parentNode = selectedNode.getParentNode();
-// if(selectedNode instanceof IDOMText) {
-// }
- if(parentNode!=null) {
- return equalsWrappingTagName(parentNode.getNodeName());
+ Node parentNode = manager.getCurrentSelectedNodeInfo().getNode();
+ for (int i = 0; i < manager.getHandlerFactory().getCountHandlers(); i++) {
+ parentNode = parentNode.getParentNode();
+ if (parentNode == null)
+ return false;
+ if(equalsWrappingTagName(parentNode.getNodeName())) {
+ return true;
+ }
}
return false;
}
-
+
/**
* @return
*/
@@ -69,8 +105,23 @@
* @return
*/
abstract protected String getWrappingTagName();
+
+ /**
+ * @return
+ */
+ abstract protected String getWrappingTagStyle();
+
+ /**
+ * @return
+ */
+ abstract protected String getWrappingTagStyleValue();
/**
+ * @return
+ */
+ abstract protected boolean equalsWrappingTagStyle(String tagStyle);
+
+ /**
* @see
org.jboss.tools.vpe.editor.toolbar.format.IFormatItemSelector#setToolbarItemEnabled(boolean)
*/
public void setToolbarItemEnabled(boolean enabled) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/UnderlineFormatHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/UnderlineFormatHandler.java 2008-06-02
19:44:03 UTC (rev 8500)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/handler/UnderlineFormatHandler.java 2008-06-03
10:32:26 UTC (rev 8501)
@@ -15,8 +15,11 @@
*/
public class UnderlineFormatHandler extends SimpleTagHandler {
- private static String TAG_NAME = "u";
+ private static String TAG_NAME = "u"; //$NON-NLS-1$
+
+ private static String TAG_STYLE = "TEXT-DECORATION"; //$NON-NLS-1$
+ private static String TAG_STYLE_VALUE = "underline"; //$NON-NLS-1$
/**
* Constructor
*/
@@ -37,4 +40,22 @@
protected String getWrappingTagName() {
return TAG_NAME;
}
+
+ /**
+ *
+ * @return
+ */
+ protected String getWrappingTagStyle() {
+ return TAG_STYLE;
+ }
+
+ @Override
+ protected boolean equalsWrappingTagStyle(String tagStyle) {
+ return TAG_STYLE.equalsIgnoreCase(tagStyle);
+ }
+
+ @Override
+ protected String getWrappingTagStyleValue() {
+ return TAG_STYLE_VALUE;
+ }
}
\ No newline at end of file
Modified: trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml 2008-06-02
19:44:03 UTC (rev 8500)
+++ trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml 2008-06-03
10:32:26 UTC (rev 8501)
@@ -147,7 +147,7 @@
</vpe:drop>
</vpe:dnd>
<vpe:textFormatting use-default-formats="yes">
- <vpe:format type="BlockFormat" addChildren="deny"
+ <vpe:format type="BlockFormat" addChildren="allow"
handler="org.jboss.tools.vpe.editor.toolbar.format.handler.BlockFormatHandler"
/>
<vpe:format type="BoldFormat"
handler="org.jboss.tools.vpe.editor.toolbar.format.handler.BoldFormatHandler"
/>
<vpe:format type="ItalicFormat"
handler="org.jboss.tools.vpe.editor.toolbar.format.handler.ItalicFormatHandler"
/>
@@ -1044,10 +1044,16 @@
<vpe:drop container="yes" />
</vpe:dnd>
<vpe:textFormatting>
- <vpe:format type="BlockFormat" addChildren="deny"
+ <vpe:format type="BlockFormat" addChildren="allow"
handler="org.jboss.tools.vpe.editor.toolbar.format.handler.BlockFormatHandler"
/>
<vpe:format type="BoldFormat"
handler="org.jboss.tools.vpe.editor.toolbar.format.handler.BoldFormatHandler"
/>
+ <vpe:format type="BoldFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
<vpe:format type="ItalicFormat"
handler="org.jboss.tools.vpe.editor.toolbar.format.handler.ItalicFormatHandler"
/>
+ <vpe:format type="ItalicFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
<vpe:format type="UnderlineFormat" addChildren="allow"
handler="org.jboss.tools.vpe.editor.toolbar.format.handler.UnderlineFormatHandler"
/>
<vpe:format type="UnderlineFormat">
<vpe:formatAttribute type="style" />
@@ -2062,8 +2068,10 @@
<vpe:format type="UnderlineFormat" setDefault="true">
<vpe:formatAttribute type="style" />
</vpe:format>
- <vpe:format type="BoldFormat">
- <vpe:formatAttribute type="style"/>
+ <vpe:format type="BoldFormat" addChildren="allow"
+ handler="org.jboss.tools.vpe.editor.toolbar.format.handler.BoldFormatHandler"
/>
+ <vpe:format type="BoldFormat">
+ <vpe:formatAttribute type="style" />
</vpe:format>
<vpe:format type="ItalicFormat" addChildren="allow"
handler="org.jboss.tools.vpe.editor.toolbar.format.handler.ItalicFormatHandler"
/>