[jbosstools-commits] JBoss Tools SVN: r23488 - in trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe: editor/menu/action and 3 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Jul 16 04:15:11 EDT 2010


Author: dmaliarevich
Date: 2010-07-16 04:15:10 -0400 (Fri, 16 Jul 2010)
New Revision: 23488

Modified:
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/SetupTemplateAction.java
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/TemplatesPreferencePage.java
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.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/messages/VpeUIMessages.java
   trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
https://jira.jboss.org/browse/JBIDE-6598 , validation was updated, error messages were updated.

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java	2010-07-16 07:50:43 UTC (rev 23487)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/MenuCreationHelper.java	2010-07-16 08:15:10 UTC (rev 23488)
@@ -379,7 +379,8 @@
 	private VpeAnyData editAnyData(StructuredTextEditor sourceEditor, boolean isCorrectNS, VpeAnyData data) {
 		Shell shell = sourceEditor.getEditorPart().getSite().getShell();
 		if (isCorrectNS) {
-			VpeEditAnyDialog editDialog = new VpeEditAnyDialog(shell, data);
+			VpeEditAnyDialog editDialog = new VpeEditAnyDialog(shell, data, 
+					VpeTemplateManager.getInstance().getAnyTemplates());
 			editDialog.open();
 		} else {
 			MessageBox message = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/SetupTemplateAction.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/SetupTemplateAction.java	2010-07-16 07:50:43 UTC (rev 23487)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/action/SetupTemplateAction.java	2010-07-16 08:15:10 UTC (rev 23488)
@@ -78,7 +78,8 @@
 		.getWorkbench().getActiveWorkbenchWindow().getShell();
 		
 		if (isCorrectNS) {
-			VpeEditAnyDialog editDialog = new VpeEditAnyDialog(shell, data);
+			VpeEditAnyDialog editDialog = new VpeEditAnyDialog(shell, data, 
+					VpeTemplateManager.getInstance().getAnyTemplates());
 			editDialog.open();
 		} else {
 			MessageBox message = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/TemplatesPreferencePage.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/TemplatesPreferencePage.java	2010-07-16 07:50:43 UTC (rev 23487)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/preferences/TemplatesPreferencePage.java	2010-07-16 08:15:10 UTC (rev 23488)
@@ -10,7 +10,15 @@
  ******************************************************************************/ 
 package org.jboss.tools.vpe.editor.preferences;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
 
 import org.eclipse.jface.preference.PreferencePage;
 import org.eclipse.jface.viewers.ColumnLayoutData;
@@ -132,11 +140,14 @@
 		return composite;
 	}
 
+	/**
+	 * Updates tags table according to the current <code>tagList</code>.
+	 */
 	private void updateTagsTable() {
 		/*
 		 * If widget is null or disposed - exit.
 		 */
-		if(tagsTable == null || tagsTable.isDisposed()) {
+		if(tagsTable == null || tagsTable.isDisposed() || tagsList == null) {
 			return;
 		}
 		/*
@@ -153,6 +164,14 @@
 		 * Recreate table items
 		 */
 		TableItem tableItem = null;
+		/*
+		 * Sort the templates
+		 */
+		Collections.sort(tagsList, new Comparator<VpeAnyData>() {
+			public int compare(VpeAnyData o1, VpeAnyData o2) {
+				return o1.getName().compareToIgnoreCase(o2.getName());
+			}
+		});
 		for (int i = 0; i < tagsList.size(); i++) {
 			if(tagsTable.getItemCount() > i) {
 				/*
@@ -238,7 +257,7 @@
 			 * Handle add event
 			 */
 			VpeAnyData data = new VpeAnyData(Constants.EMPTY, Constants.EMPTY, Constants.EMPTY);
-			VpeEditAnyDialog editDialog = new VpeEditAnyDialog(getShell(), data);
+			VpeEditAnyDialog editDialog = new VpeEditAnyDialog(getShell(), data, tagsList);
 			editDialog.open();
 			if(data.isChanged()) {
 				/*
@@ -253,7 +272,7 @@
 			 */
 			if (selectIndex > -1) {
 				VpeAnyData data = (VpeAnyData) tagsList.get(selectIndex);
-				VpeEditAnyDialog editDialog = new VpeEditAnyDialog(getShell(), data);
+				VpeEditAnyDialog editDialog = new VpeEditAnyDialog(getShell(), data, tagsList);
 				editDialog.open();
 				if(data.isChanged()) {
 					tagListWasChanged = true;
@@ -283,7 +302,10 @@
 	public boolean performOk() {
 		if(tagListWasChanged) {
 			/*
-			 * Commit changes to the file
+			 * Commit changes to the file.
+			 * While saving the templates' file will be rewritten from scratch.
+			 * Only the first URI will be used for templates with the same prefix,
+			 * other URI will be ignored.
 			 */
 			VpeTemplateManager.getInstance().setAnyTemplates(tagsList);
 		}
@@ -293,6 +315,12 @@
 	@Override
 	protected void performApply() {
 		performOk();
+		/*
+		 * After "Apply" button templates list should be updated
+		 * due to URI changes 
+		 */
+		tagsList = VpeTemplateManager.getInstance().getAnyTemplates();
+		updateTagsTable();
 	}
 
 	@Override

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java	2010-07-16 07:50:43 UTC (rev 23487)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java	2010-07-16 08:15:10 UTC (rev 23488)
@@ -13,12 +13,19 @@
 import java.io.IOException;
 import java.net.URL;
 import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.regex.Pattern;
 
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.dialogs.IMessageProvider;
@@ -61,18 +68,33 @@
  */
 public class VpeEditAnyDialog extends TitleAreaDialog {
 
+	/*
+	 * Current template
+	 */
 	private VpeAnyData data;
+	/*
+	 * List of already created templates
+	 */
+	List<VpeAnyData> tagsList;
+	Map<String, VpeAnyData> tagsNamesSet = new HashMap<String, VpeAnyData>();
 	Text tagName;
 	Text tagUri;
+	private String previousUri = Constants.EMPTY;
 	private Button childrenCheckbox;
 	private Text txtTagForDisplay;
 	private Text txtValue;
 	private Text txtStyle;
     private VpeEditAnyDialogValidator templateVerifier;
 
-	public VpeEditAnyDialog(Shell shell, VpeAnyData data) {
+	public VpeEditAnyDialog(Shell shell, VpeAnyData data, List<VpeAnyData> tagsList) {
 		super(shell);
 		this.data = data;
+		this.tagsList = tagsList; 
+		if (null != tagsList) {
+			for (VpeAnyData tag : tagsList) {
+				tagsNamesSet.put(tag.getName(), tag);
+			}
+		}
 		setHelpAvailable(false);
 	}
 
@@ -337,23 +359,74 @@
 		 */
 		private IMessageProvider validateTagName() {
 			Message message = null;
-			String[] parts = tagName.getText().split(":"); //$NON-NLS-1$
-			if (parts.length != 2 || tagName.getText().startsWith(":") //$NON-NLS-1$
-					|| tagName.getText().endsWith(":")) { //$NON-NLS-1$
+			String name = tagName.getText().trim();
+			String[] parts = name.split(":"); //$NON-NLS-1$
+			Pattern p = Pattern.compile("([a-zA-Z]+\\d*)+"); //$NON-NLS-1$
+			/*
+			 * Reset editable property for template URI
+			 * after it has been disabled.
+			 */
+			if (!tagUri.getEditable()) {
+				tagUri.removeModifyListener(templateVerifier);
+				if ((null != data) && (null != data.getName()) &&
+						data.getName().split(":")[0].equalsIgnoreCase(parts[0])) { //$NON-NLS-1$
+					/*
+					 * Restore initial URI
+					 */
+					previousUri = data.getUri();
+				} 
+				tagUri.setText(previousUri);
+				tagUri.setEditable(true);
+				tagUri.addModifyListener(templateVerifier);
+			}
+			/*
+			 * Check if tag's name is correct
+			 */
+			if (parts.length != 2 || name.startsWith(":") //$NON-NLS-1$
+					|| name.endsWith(":")) { //$NON-NLS-1$
 				message = new Message(
 						MessageFormat.format(VpeUIMessages.TAG_NAME_IS_NOT_VALID,
-								tagName.getText().trim()), IMessageProvider.ERROR);
-			} else {
-				/*
-				 * Matcher will accept only word characters with optional numbers.
-				 */
-				 Pattern p = Pattern.compile("([a-zA-Z]+\\d*)+"); //$NON-NLS-1$
-				if ((parts[0].length() == 0) || (parts[1].length() == 0)
+								name), IMessageProvider.ERROR);
+			} else if ((parts[0].length() == 0) || (parts[1].length() == 0)
 						|| (!p.matcher(parts[0]).matches()) 
 						|| (!p.matcher(parts[1]).matches())) {
+					/*
+					 * Matcher will accept only word characters with optional numbers.
+					 */
 					message = new Message(
 							MessageFormat.format(VpeUIMessages.TAG_NAME_IS_NOT_VALID,
-									tagName.getText().trim()), IMessageProvider.ERROR);
+									name), IMessageProvider.ERROR);
+			} else if (tagsNamesSet.keySet().contains(name)
+					&& (!tagsList.contains(data) 
+						|| (tagsList.contains(data) && !data.getName().equalsIgnoreCase(name)))) {
+				/*
+				 * Find duplicate tag names.
+				 */
+				message = new Message(
+						MessageFormat.format(VpeUIMessages.TAG_NAME_ALREADY_EXISTS,
+								name), IMessageProvider.ERROR);
+			} else {
+				/*
+				 * Inform that URI for the specified taglib namespace
+				 * is already defined in another templates.
+				 */
+				for (String templateName : tagsNamesSet.keySet()) {
+					if (parts[0].equalsIgnoreCase(templateName.split(":")[0]) //$NON-NLS-1$
+							&& (!tagsList.contains(data) || (tagsList.contains(data) && !data.getName().split(":")[0].equalsIgnoreCase(parts[0])))) { //$NON-NLS-1$
+						message = new Message(
+						MessageFormat.format(VpeUIMessages.URI_TAGLIB_NAMESPACE_ALREADY_DEFINED,
+								parts[0], tagsNamesSet.get(templateName).getUri()), IMessageProvider.WARNING);
+						/*
+						 * Set the URI and disable this field.
+						 * Remove the listener to avoid dead lock
+						 */
+						tagUri.removeModifyListener(templateVerifier);
+						previousUri = tagUri.getText();
+						tagUri.setText(tagsNamesSet.get(templateName).getUri());
+						tagUri.setEditable(false);
+						tagUri.addModifyListener(templateVerifier);
+						break;
+					}
 				}
 			}
 			return message;
@@ -411,27 +484,58 @@
 		 * @param updateMessage if it is {@code true}, the dialog's message will be updated.
 		 */
 		void validateAll(boolean updateMessage) {
-			IMessageProvider message = null;
+			/*
+			 * Initialize the message with the description
+			 */
+			IMessageProvider message = new Message(VpeUIMessages.UNKNOWN_TAGS_DIALOG_DESCRIPTION,
+					IMessageProvider.NONE);
+			List<IMessageProvider> statuses = new ArrayList<IMessageProvider>();
+			/*
+			 * Get messages from all validators
+			 */
+			statuses.add(validateTagForDisplay());
+			statuses.add(validateValue());
+			statuses.add(validateTagName());
+			/*
+			 * Find the message with the most severe status
+			 */
+			for (IMessageProvider status : statuses) {
+				if (null != status) {
+					message = message.getMessageType() >= status.getMessageType()
+					? message : status;
+				}
+			}
+			String messageText = message.getMessage();
+			switch (message.getMessageType()) {
+			case IMessageProvider.NONE:
+				setMessage(messageText, IMessageProvider.NONE);
+				setErrorMessage(null);
+				break;
 
-			IMessageProvider tagForDisplayMessage = validateTagForDisplay();
-			IMessageProvider valueMessage = validateValue();
-			IMessageProvider tagNameMessage = validateTagName();
+			case IMessageProvider.WARNING:
+				setMessage(messageText, IMessageProvider.WARNING);
+				setErrorMessage(null);
+				break;
 
-			if (tagNameMessage != null) {
-				message = tagNameMessage;
-			} else if (tagForDisplayMessage != null) {
-				message = tagForDisplayMessage;
-			} else if (valueMessage != null) {
-				message = valueMessage;
-			} else {
+			case IMessageProvider.INFORMATION:
+				setMessage(messageText, IMessageProvider.INFORMATION);
+				setErrorMessage(null);
+				break;
+
+			default:
 				/*
-				 * If everything is OK - set default message
+				 * Set ERROR message
 				 */
-				setMessage(VpeUIMessages.UNKNOWN_TAGS_DIALOG_DESCRIPTION);
-			}
-
+				if (messageText.length() == 0) {
+					messageText = null;
+				}
+				setMessage(null, IMessageProvider.NONE);
+				setErrorMessage(messageText);
+				break;
+			} // end switch
+			
 			Button okButton = getButton(IDialogConstants.OK_ID);
-			if ((message == null) || (message.getMessageType() <= IMessageProvider.INFORMATION)) {
+			if ((message == null) || (message.getMessageType() <= IMessageProvider.WARNING)) {
 				okButton.setEnabled(true);
 			} else {
 				okButton.setEnabled(false);

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	2010-07-16 07:50:43 UTC (rev 23487)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java	2010-07-16 08:15:10 UTC (rev 23488)
@@ -743,7 +743,9 @@
 				}
 			}
 		}
-
+		/*
+		 * URI is set separately from the taglib section.
+		 */
 		for (Iterator<VpeAnyData> iter = anyTemplateList.iterator(); iter.hasNext();) {
 			VpeAnyData element = iter.next();
 			String prefix = element.getPrefix();
@@ -754,7 +756,6 @@
 				element.setUri(uri);
 			}
 		}
-
 		return anyTemplateList;
 	}
 	
@@ -788,6 +789,10 @@
 				VpeAnyData data = iter.next();
 				root.appendChild(createNewTagElement(document, data));
 				String prefix = data.getPrefix();
+				/*
+				 * While saving other URIs for the same prefixes will be ignored
+				 * only the first URI will be used for this prefix.
+				 */
 				if ((prefix != null) && (prefix.length() > 0) && !prefixSet.contains(prefix)) {
 					root = appendTaglib(prefixSet, document, root, data);
 					prefixSet.add(prefix);

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java	2010-07-16 07:50:43 UTC (rev 23487)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java	2010-07-16 08:15:10 UTC (rev 23488)
@@ -48,6 +48,8 @@
 	public static String TAG_NAME_IS_NOT_VALID;
 	public static String TAG_FOR_DISPLAY_IS_NOT_VALID;
 	public static String VALUE_IS_NOT_VALID;
+	public static String TAG_NAME_ALREADY_EXISTS;
+	public static String URI_TAGLIB_NAMESPACE_ALREADY_DEFINED;
 	public static String BACKGROUND_COLOR;
 	public static String ERROR_OF_TYPE_CONVERSION;
 	public static String INCORRECT_PARAMETER_ERROR;

Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties	2010-07-16 07:50:43 UTC (rev 23487)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties	2010-07-16 08:15:10 UTC (rev 23488)
@@ -27,8 +27,10 @@
 CHILDREN=Allow tag children:
 VALUE=Value:
 TAG_NAME_IS_NOT_VALID=Tag name ({0}) is not valid. The pattern is "taglib:tag"
-TAG_FOR_DISPLAY_IS_NOT_VALID=Incorrect tag with name ({0}).
+TAG_FOR_DISPLAY_IS_NOT_VALID=Incorrect "Tag for display" with name ({0}).
 VALUE_IS_NOT_VALID=Value is not valid ({0}).
+TAG_NAME_ALREADY_EXISTS=Tag name ({0}) already exists. Please specify another one.
+URI_TAGLIB_NAMESPACE_ALREADY_DEFINED=URI for taglib namespace ({0}) is already defined.\n"{1}" URI will be used. 
 
 BACKGROUND_COLOR=Background Color
 ERROR_OF_TYPE_CONVERSION=Error of type conversion



More information about the jbosstools-commits mailing list