[jbosstools-commits] JBoss Tools SVN: r9445 - in trunk/seam/plugins: org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Jul 31 05:20:36 EDT 2008


Author: dazarov
Date: 2008-07-31 05:20:36 -0400 (Thu, 31 Jul 2008)
New Revision: 9445

Modified:
   trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/handlers/AddViewSupport.java
   trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/ViewIDDirectEditPolicy.java
   trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/ViewIDEditManager.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-1189 Updated view id validator

Modified: trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/handlers/AddViewSupport.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/handlers/AddViewSupport.java	2008-07-31 09:04:49 UTC (rev 9444)
+++ trunk/seam/plugins/org.jboss.tools.seam.pages.xml/src/org/jboss/tools/seam/pages/xml/model/handlers/AddViewSupport.java	2008-07-31 09:20:36 UTC (rev 9445)
@@ -75,7 +75,7 @@
 		return list[0];
 	}
 	
-	public String getExtension(String template) {
+	public static String getExtension(String template) {
 		if(template != null) {
 			int i = template.trim().lastIndexOf('.');
 			if(i > 0) {
@@ -222,7 +222,7 @@
 		return path;
 	}
 
-	String revalidatePath(String path, String template) {
+	public static String revalidatePath(String path, String template) {
 		if(path != null) path = path.trim();
 		if(path == null || path.length() == 0) return path;
 		if(!path.startsWith("/") && !path.startsWith("*")) path = "/" + path;
@@ -253,7 +253,7 @@
 	
 	static String FORBIDDEN_INDICES = "\"\n\t\\:<>?|"; //* is allowed anywhere
 	
-	static boolean isCorrectPath(String path) {
+	public static boolean isCorrectPath(String path) {
 		if(path == null || path.equals("/") || path.indexOf("//") >= 0) return false;
 		if(path.endsWith("/") || path.indexOf("../") >= 0) return false;
 		if(path.endsWith("..")) return false;

Modified: trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/ViewIDDirectEditPolicy.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/ViewIDDirectEditPolicy.java	2008-07-31 09:04:49 UTC (rev 9444)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/ViewIDDirectEditPolicy.java	2008-07-31 09:20:36 UTC (rev 9445)
@@ -47,16 +47,21 @@
 
 		PagesElement node;
 		String value;
+		XModelObject object;
 
 		public FlowNameCommand(PagesElement node, String value) {
 			this.node = node;
 			this.value = value;
+			object = (XModelObject)node.getPagesModel().getData();
 		}
 
 		public boolean canExecute() {
-			if (value == null)
-				return false;
-			return true;
+			ViewIDValidator val = new ViewIDValidator(object);
+			String message = val.isValid(value);
+			
+			if (message == null || "".equals(message))
+				return true;
+			return false;
 		}
 
 		public boolean canUndo() {
@@ -67,8 +72,8 @@
 			Properties props = new Properties();
 			props.setProperty("mouse.x", ""+node.getLocation().x);
 			props.setProperty("mouse.y", ""+node.getLocation().y);
-			XModelObject object = (XModelObject)node.getPagesModel().getData();
 			
+			
 			if(node instanceof Page)
 				AddPageOnDiagramHandler.createPage(object, value, props);
 			else if(node instanceof PageException)

Modified: trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/ViewIDEditManager.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/ViewIDEditManager.java	2008-07-31 09:04:49 UTC (rev 9444)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/ViewIDEditManager.java	2008-07-31 09:20:36 UTC (rev 9445)
@@ -37,6 +37,7 @@
 import org.eclipse.ui.part.CellEditorActionHandler;
 import org.jboss.tools.common.model.XModelObject;
 import org.jboss.tools.seam.pages.xml.SeamPagesXMLMessages;
+import org.jboss.tools.seam.pages.xml.model.handlers.AddViewSupport;
 import org.jboss.tools.seam.pages.xml.model.helpers.SeamPagesDiagramHelper;
 import org.jboss.tools.seam.ui.pages.editor.ecore.pages.PagesElement;
 import org.jboss.tools.seam.ui.pages.editor.figures.ExceptionFigure;
@@ -56,12 +57,8 @@
 		}
 	};
 
-	private XModelObject target;
+	XModelObject target;
 
-	private XModelObject getTarget() {
-		return target;
-	}
-
 	public ViewIDEditManager(GraphicalEditPart source, CellEditorLocator locator) {
 		super(source, null, locator);
 		target = (XModelObject) ((PagesDiagramEditPart) source.getParent())
@@ -123,8 +120,9 @@
 							new Object[] { value }));
 				} else {
 					setErrorMessage("");
+					valueChanged(oldValidState, newValidState);
 				}
-				valueChanged(oldValidState, newValidState);
+				
 			}
 
 			protected Control createControl(Composite parent) {
@@ -165,7 +163,7 @@
 		actionHandler = new CellEditorActionHandler(actionBars);
 		actionHandler.addCellEditor(getCellEditor());
 		actionBars.updateActionBars();
-		getCellEditor().setValidator(new ViewIDValidator());
+		getCellEditor().setValidator(new ViewIDValidator(target));
 	}
 
 	private void restoreSavedActions(IActionBars actionBars) {
@@ -210,47 +208,39 @@
 			text.setFont(scaledFont = new Font(null, fd));
 		}
 	}
+}
 
-	static String FORBIDDEN_INDICES = "\"\n\t\\:<>?|"; // * is allowed anywhere
+class ViewIDValidator implements ICellEditorValidator {
+	private XModelObject target;
+	
+	public ViewIDValidator(XModelObject target){
+		super();
+		this.target = target;
+	}
 
-	static boolean isCorrectPath(String path) {
-		if (path == null || path.equals("/") || path.indexOf("//") >= 0)
-			return false;
-		if (path.endsWith("/") || path.indexOf("../") >= 0)
-			return false;
-		if (path.endsWith(".."))
-			return false;
-		if (path.endsWith("*"))
-			return true;
-		for (int i = 0; i < FORBIDDEN_INDICES.length(); i++) {
-			if (path.indexOf(FORBIDDEN_INDICES.charAt(i)) >= 0) {
-				return false;
-			}
-		}
-		return true;
+	private XModelObject getTarget() {
+		return target;
 	}
 
-	class ViewIDValidator implements ICellEditorValidator {
-		public String isValid(Object value) {
-			if (value == null)
-				return null;
+	public String isValid(Object value) {
+		if (value == null)
+			return null;
 
-			String message = "";
-			String viewID = value.toString();
+		String message = "";
+		String viewID = value.toString();
+		String path = AddViewSupport.revalidatePath(viewID, "");
 
-			if (!isCorrectPath(viewID)) {
-				message = SeamPagesXMLMessages.ATTRIBUTE_VIEW_ID_IS_NOT_CORRECT;
-				return message;
-			}
+		if (!AddViewSupport.isCorrectPath(path)) {
+			message = SeamPagesXMLMessages.ATTRIBUTE_VIEW_ID_IS_NOT_CORRECT;
+			return message;
+		}
 
-			boolean doNotCreateEmptyRule = false;
-			String pp = SeamPagesDiagramHelper.toNavigationRulePathPart(viewID);
-			boolean exists = getTarget().getChildByPath(pp) != null;
-			if (doNotCreateEmptyRule && exists) {
-				message = "View exists.";
-				return message;
-			}
-			return null;
+		String pp = SeamPagesDiagramHelper.toNavigationRulePathPart(path);
+		boolean exists = getTarget().getChildByPath(pp) != null;
+		if (exists) {
+			message = "View exists.";
+			return message;
 		}
+		return null;
 	}
 }
\ No newline at end of file




More information about the jbosstools-commits mailing list