[105002] [ui] There is no validation for the attribute's name when outline popup menu 'Add Attribute/New Attribute' is used
diff --git a/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/error_obj.gif b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/error_obj.gif
new file mode 100644
index 0000000..0bc6068
--- /dev/null
+++ b/bundles/org.eclipse.wst.xml.ui/icons/full/obj16/error_obj.gif
Binary files differ
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
index c3804a2..ac34fb9 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
@@ -135,6 +135,7 @@
public static String _UI_NAMESPACE_DECLARATIONS;
public static String _UI_TARGET_NAMESPACE;
public static String _ERROR_XML_ATTRIBUTE_ALREADY_EXISTS;
+ public static String _ERROR_XML_ATTRIBUTE_IS_INVALID;
public static String error_message_goes_here;
public static String SurroundWithNewElementQuickAssistProposal_0;
public static String SurroundWithNewElementQuickAssistProposal_1;
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
index d0bf600..f7161e2 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
@@ -368,4 +368,5 @@
Missing_quotes=Missing q&uotes:
Namespace_in_pi_target=In&valid name space in PI:
Tag_name_missing=Missing tag n&ame:
-Whitespace_at_start=Inva&lid white space at start:
\ No newline at end of file
+Whitespace_at_start=Inva&lid white space at start:
+_ERROR_XML_ATTRIBUTE_IS_INVALID=\"{0}\" is not a valid attribute name
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditAttributeDialog.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditAttributeDialog.java
index e95af80..9cdbc5b 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditAttributeDialog.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/dialogs/EditAttributeDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
+ * Copyright (c) 2001, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,10 +14,11 @@
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -27,7 +28,11 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.xml.core.internal.document.JSPTag;
+import org.eclipse.wst.xml.core.internal.provisional.NameValidator;
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
+import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
+import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
import org.eclipse.wst.xml.ui.internal.util.XMLCommonUIContextIds;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
@@ -38,6 +43,7 @@
protected Text attributeNameField;
protected String attributeValue;
protected Text attributeValueField;
+ protected Label errorMessageIcon;
protected Label errorMessageLabel;
protected Button okButton;
protected Element ownerElement;
@@ -110,16 +116,32 @@
attributeValueField.setLayoutData(gd);
attributeValueField.setText(getDisplayValue(attribute != null ? attribute.getValue() : "")); //$NON-NLS-1$
- // error message
- errorMessageLabel = new Label(composite, SWT.WRAP);
+ // Error message
+ Composite message = new Composite(composite, SWT.NONE);
+ layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginWidth = 0;
+ message.setLayout(layout);
+
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ message.setLayoutData(gd);
+
+ errorMessageIcon = new Label(message, SWT.NONE);
+ gd = new GridData();
+ gd.horizontalSpan = 1;
+ gd.verticalAlignment = SWT.TOP;
+ errorMessageIcon.setLayoutData(gd);
+ errorMessageIcon.setImage(null);
+
+ errorMessageLabel = new Label(message, SWT.WRAP);
errorMessageLabel.setText(XMLUIMessages.error_message_goes_here);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.widthHint = 200;
gd.heightHint = Math.max(30, errorMessageLabel.computeSize(0, 0, false).y * 2);
- gd.horizontalSpan = 2;
+ gd.horizontalSpan = 1;
+ gd.verticalAlignment = SWT.TOP;
errorMessageLabel.setLayoutData(gd);
- Color color = new Color(errorMessageLabel.getDisplay(), 200, 0, 0);
- errorMessageLabel.setForeground(color);
return dialogArea;
}
@@ -150,15 +172,19 @@
protected void updateErrorMessage() {
String errorMessage = null;
+ Image image = null;
String name = attributeNameField.getText().trim();
if (name.length() > 0) {
Attr matchingAttribute = ownerElement.getAttributeNode(name);
if ((matchingAttribute != null) && (matchingAttribute != attribute)) {
errorMessage = XMLUIMessages._ERROR_XML_ATTRIBUTE_ALREADY_EXISTS;
+ image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ERROR_OBJ);
}
else {
- // TODO get checkName from Model
- // errorMessage = ValidateHelper.checkXMLName(name);
+ if (!isValidName(name)){
+ errorMessage = NLS.bind(XMLUIMessages._ERROR_XML_ATTRIBUTE_IS_INVALID, name);
+ image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ERROR_OBJ);
+ }
}
}
else {
@@ -166,7 +192,17 @@
}
errorMessageLabel.setText(errorMessage != null ? errorMessage : ""); //$NON-NLS-1$
+ errorMessageIcon.setImage(image);
errorMessageLabel.getParent().layout();
okButton.setEnabled(errorMessage == null);
}
+
+ private boolean isValidName(String name) {
+ if (NameValidator.isValid(name))
+ return true;
+ // special for JSP tag in tag name
+ if (name.startsWith(JSPTag.TAG_OPEN))
+ return true;
+ return false;
+ }
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImages.java
index 52c379a..b82c4b8 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImages.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/editor/XMLEditorPluginImages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2007 IBM Corporation and others.
+ * Copyright (c) 2001, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -48,6 +48,7 @@
public static final String IMG_OBJ_TAG_MACRO = "icons/full/obj16/tag-macro.gif"; //$NON-NLS-1$
public static final String IMG_OBJ_TXTEXT = "icons/full/obj16/text.gif"; //$NON-NLS-1$
public static final String IMG_OBJ_WARNING_OBJ = "icons/full/obj16/warning_obj.gif"; //$NON-NLS-1$
+ public static final String IMG_OBJ_ERROR_OBJ = "icons/full/obj16/error_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJ_XSDFILE = "icons/full/obj16/XSDFile.gif"; //$NON-NLS-1$
public static final String IMG_OVR_ERROR = "icons/full/ovr16/error_ovr.gif"; //$NON-NLS-1$