Bug 517644 - Field validation for Name in Application Editor should be
ERROR
Changed the validation of field name to ERROR.
Added possibility to define the decoration type in the CreateTextField
method
Change-Id: I3bc07137843f8c28fc6d0806bc090eab865c6d94
Signed-off-by: Olivier Prouvost <olivier.prouvost@opcoach.com>
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
index 6dd52c1..ea00cf1 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
@@ -394,7 +394,7 @@
BindingContextEditor_Description=Description
BindingContextEditor_Subcontexts=Subcontexts
BindingContextEditor_AddContext=Binding Context
-BindingContextEditor_NameWarning=Binding Context name should not be empty
+BindingContextEditor_NameWarning=Binding Context name must not be empty
CommandParameterEditor_TreeLabel=Command Parameter
CommandParameterEditor_TreeLabelDescritpion=Command Parameter
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/BindingContextEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/BindingContextEditor.java
index 2645a2c..0863e07 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/BindingContextEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/BindingContextEditor.java
@@ -42,6 +42,7 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.databinding.swt.IWidgetValueProperty;
import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
@@ -169,9 +170,9 @@
ControlFactory.createTextField(parent, Messages.ModelTooling_Common_Id, master, context, textProp,
EMFEditProperties
.value(getEditingDomain(), ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID));
- ControlFactory.createTextField(parent, Messages.BindingContextEditor_Name, master, context, textProp,
+ ControlFactory.createTextField(parent, Messages.BindingContextEditor_Name, null, master, context, textProp,
EMFEditProperties.value(getEditingDomain(), CommandsPackageImpl.Literals.BINDING_CONTEXT__NAME),
- Messages.BindingContextEditor_NameWarning);
+ Messages.BindingContextEditor_NameWarning, FieldDecorationRegistry.DEC_ERROR);
ControlFactory.createTextField(parent, Messages.BindingContextEditor_Description, master, context, textProp,
EMFEditProperties.value(getEditingDomain(), CommandsPackageImpl.Literals.BINDING_CONTEXT__DESCRIPTION));
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java
index 1ea6d17..997a29b 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java
@@ -26,6 +26,7 @@
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.common.ContributionURIValidator;
@@ -387,12 +388,37 @@
* @param textProp
* @param modelProp
* @param warningText
- * Non null warningText means that a warning with this non-null
- * text will be shown when the field is left empty
+ * Non null warningText means that a warning with this non-null text
+ * will be shown when the field is left empty
*/
public static void createTextField(Composite parent, String label, String tooltip, IObservableValue master,
EMFDataBindingContext context, IWidgetValueProperty textProp, IEMFEditValueProperty modelProp,
final String warningText) {
+ createTextField(parent, label, tooltip, master, context, textProp, modelProp, warningText,
+ FieldDecorationRegistry.DEC_WARNING);
+ }
+
+ /**
+ *
+ * @param parent
+ * @param label
+ * @param master
+ * @param context
+ * @param textProp
+ * @param modelProp
+ * @param decorationText
+ * Non null decorationText means that a message with this non-null
+ * text will be shown when the field is left empty
+ * @param decorationType
+ * Non null decorationType describes the type of the decoration.
+ * Supported types: FieldDecorationRegistry.DEC_ERROR,
+ * FieldDecorationRegistry.DEC_WARNING,
+ * FieldDecorationRegistry.DEC_INFORMATION
+ *
+ */
+ public static void createTextField(Composite parent, String label, String tooltip, IObservableValue master,
+ EMFDataBindingContext context, IWidgetValueProperty textProp, IEMFEditValueProperty modelProp,
+ final String decorationText, final String decorationType) {
final Label l = new Label(parent, SWT.NONE);
l.setText(label);
if (tooltip != null) {
@@ -405,23 +431,26 @@
gd.horizontalSpan = 2;
t.setLayoutData(gd);
TextPasteHandler.createFor(t);
- if (warningText != null) {
+ if (decorationText != null) {
final ControlDecoration controlDecoration = new ControlDecoration(t, SWT.LEFT | SWT.TOP);
- controlDecoration.setDescriptionText(warningText);
+ controlDecoration.setDescriptionText(decorationText);
final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
- FieldDecorationRegistry.DEC_WARNING);
+ decorationType);
controlDecoration.setImage(fieldDecoration.getImage());
final IValidator iv = value -> {
if (value == null) {
controlDecoration.show();
- return ValidationStatus.warning(warningText);
+ return ValidationStatus.warning(decorationText);
}
if (value instanceof String) {
final String text = (String) value;
if (text.trim().length() == 0) {
controlDecoration.show();
- return ValidationStatus.warning(warningText);
+ return getValidationStatus(decorationType, decorationText);
}
+
+ controlDecoration.hide();
+ return Status.OK_STATUS;
}
controlDecoration.hide();
@@ -469,6 +498,23 @@
// }
}
+ private static IStatus getValidationStatus(String decorationType, String decorationText) {
+ switch (decorationType) {
+ case FieldDecorationRegistry.DEC_ERROR:
+ return ValidationStatus.error(decorationText);
+ case FieldDecorationRegistry.DEC_WARNING:
+ return ValidationStatus.warning(decorationText);
+ case FieldDecorationRegistry.DEC_INFORMATION:
+ return ValidationStatus.info(decorationText);
+
+ default:
+ break;
+ }
+
+ return ValidationStatus.warning(decorationText);
+ }
+
+
public static void createFindImport(Composite parent, final Messages Messages,
final AbstractComponentEditor editor, EMFDataBindingContext context) {
final IWidgetValueProperty textProp = WidgetProperties.text(SWT.Modify);