[jbosstools-commits] JBoss Tools SVN: r6955 - trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Mar 17 09:27:26 EDT 2008


Author: dmaliarevich
Date: 2008-03-17 09:27:26 -0400 (Mon, 17 Mar 2008)
New Revision: 6955

Modified:
   trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInsertTemplate.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1904

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInsertTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInsertTemplate.java	2008-03-17 13:27:21 UTC (rev 6954)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesInsertTemplate.java	2008-03-17 13:27:26 UTC (rev 6955)
@@ -24,6 +24,7 @@
 
 import org.eclipse.core.resources.IFile;
 import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
 import org.jboss.tools.vpe.editor.context.VpePageContext;
 import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
 import org.jboss.tools.vpe.editor.template.VpeCreationData;
@@ -46,6 +47,11 @@
  */
 public class RichFacesInsertTemplate extends VpeAbstractTemplate {
 
+	private static String RESOURCE_NOT_FOUND_MESSAGE = "Resource was not found.";
+	private static String RESOURCE_READING_ERROR_MESSAGE = "Resource reading error.";
+	private static String HIGHLIGHT_ERROR_MESSAGE = "Error occured during highlight.";
+	private static String ERROR_MESSAGE_STYLE = "color: red; font-weight: bold;";
+	
     private static String SRC_ATTR_NAME = "src";
     private static String HIGHTLIGHT_ATTR_NAME = "highlight";
 
@@ -81,38 +87,38 @@
 
 	nsIDOMElement div = visualDocument
 		.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+	VpeCreationData vpeCreationData = new VpeCreationData(div);
 
 	String srcValue = ((Element) sourceNode).getAttribute(SRC_ATTR_NAME);
 	String highlightValue = ((Element) sourceNode)
 		.getAttribute(HIGHTLIGHT_ATTR_NAME);
-
-	VpeCreationData vpeCreationData = new VpeCreationData(div);
-
-	IFile iFile = VpeCreatorUtil.getFile(srcValue, pageContext);
 	String finalStr = "";
 	String buf = "";
 
+	// if there is no source show error message 
+	if ((null == srcValue) || ("".equalsIgnoreCase(srcValue))) {
+	    div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, ERROR_MESSAGE_STYLE);
+	    nsIDOMText text = visualDocument.createTextNode(RESOURCE_NOT_FOUND_MESSAGE);
+	    div.appendChild(text);
+	    return vpeCreationData;
+	}
+	
 	try {
+		IFile iFile = VpeCreatorUtil.getFile(srcValue, pageContext);
 	    File file = new File(iFile.getLocation().toOSString());
 	    BufferedReader br = new BufferedReader(new InputStreamReader(
 		    new FileInputStream(file)));
-
 	    while ((buf = br.readLine()) != null)
 		finalStr += buf + "\n";
 
 	} catch (Exception e) {
-	    finalStr = "Resources " + srcValue + " not found.";
-	    div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "color: red; "
-		    + "font-weight: bold;");
-	    nsIDOMText text = visualDocument.createTextNode(finalStr);
+		div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, ERROR_MESSAGE_STYLE);
+	    nsIDOMText text = visualDocument.createTextNode(RESOURCE_READING_ERROR_MESSAGE);
 	    div.appendChild(text);
 	    return vpeCreationData;
 	}
 
-	if (!serchInSupportedTypes(highlightValue))
-	    return vpeCreationData;
-
-	if (highlightValue == null) {
+	if ((highlightValue == null) || (!searchInSupportedTypes(highlightValue))){
 	    finalStr = finalStr.replace('\n', ' ');
 	    nsIDOMText text = visualDocument.createTextNode(finalStr);
 	    div.appendChild(text);
@@ -127,6 +133,9 @@
 	    Node node = parseTransformString(transformStr);
 	    buildVisualNode(node, div);
 	} catch (IOException e1) {
+		div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, ERROR_MESSAGE_STYLE);
+	    nsIDOMText text = visualDocument.createTextNode(HIGHLIGHT_ERROR_MESSAGE);
+	    div.appendChild(text);
 	    return vpeCreationData;
 	}
 	return vpeCreationData;
@@ -210,7 +219,7 @@
      * @return true of highlight value correct
      */
 
-    private boolean serchInSupportedTypes(String highlightValue) {
+    private boolean searchInSupportedTypes(String highlightValue) {
 
 	if (highlightValue == null)
 	    return true;
@@ -280,4 +289,11 @@
 	    nsIDOMElement visualNode, Object data, String name, String value) {
 	return true;
     }
+    
+    @Override
+    public void setSourceAttributeSelection(VpePageContext pageContext,
+	    Element sourceElement, int offset, int length, Object data) {
+	VpeSourceDomBuilder sourceBuilder = pageContext.getSourceBuilder();
+	sourceBuilder.setSelection(sourceElement, 0, 0);
+    }
 }
\ No newline at end of file




More information about the jbosstools-commits mailing list