Skip to content

Commit

Permalink
Merge pull request #116 from elvisisking/teiiddes-1140
Browse files Browse the repository at this point in the history
TEIIDDES-1140 Model Extension Definition Validation Should Report All Validation Messages And Not Stop When It Finds The First Error
  • Loading branch information
blafond committed Mar 6, 2013
2 parents 59da275 + 46cbd7c commit e9be638
Show file tree
Hide file tree
Showing 17 changed files with 989 additions and 478 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,14 @@ private void updateState() {
}
}

if (this.valueError.isOk()) {
this.scrolledForm.getMessageManager().removeMessage(this.valueError.getKey(), this.valueError.getControl());
this.valueError.update(this.scrolledForm.getMessageManager());

if (this.valueError.isOk()) {
// eclipse bug keeps font foreground red after an error when setting to NONE so set to INFO first as workaround
if (!Messages.allowedValueDialogMessage.equals(this.scrolledForm.getMessage())) {
// eclipse bug keeps font foreground red after an error when setting to NONE so set to INFO first as workaround
this.scrolledForm.setMessage(Messages.allowedValueDialogMessage, IMessageProvider.INFORMATION);
this.scrolledForm.setMessage(Messages.allowedValueDialogMessage, IMessageProvider.NONE);
}
} else {
this.scrolledForm.getMessageManager().addMessage(this.valueError.getKey(), this.valueError.getMessage(), null,
this.valueError.getMessageType(), this.valueError.getControl());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,7 @@ public EditPropertyDialog(Shell shell,
}

private void addMessage(ErrorMessage errorMsg) {
if (errorMsg.isOk()) {
this.scrolledForm.getMessageManager().removeMessage(errorMsg.getKey(), errorMsg.getControl());
} else {
this.scrolledForm.getMessageManager().addMessage(errorMsg.getKey(), errorMsg.getMessage(), null,
errorMsg.getMessageType(), errorMsg.getControl());
}
errorMsg.update(this.scrolledForm.getMessageManager());
}

private void configureColumn(TableViewerColumn viewerColumn,
Expand Down Expand Up @@ -1334,7 +1329,6 @@ void handleHasInitialValueSelected() {
}

validateInitialValue(hasInitialValue, valueIsFixed);
addMessage(this.initialValueError);
updateState();
}

Expand Down Expand Up @@ -1364,6 +1358,7 @@ void handleMaskedChanged(boolean newValue) {
}

void handlePropertyChanged(PropertyChangeEvent e) {
this.scrolledForm.getMessageManager().setAutoUpdate(false);
String propName = e.getPropertyName();

if (PropertyName.ADVANCED.toString().equals(propName)) {
Expand Down Expand Up @@ -1420,6 +1415,7 @@ void handlePropertyChanged(PropertyChangeEvent e) {

// update buttons enabled state and dialog message
updateState();
this.scrolledForm.getMessageManager().setAutoUpdate(true);
}

void handleRemoveAllowedValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,6 @@ private boolean isEditMode() {
return (this.translationBeingEdited != null);
}

private void updateMessage( ErrorMessage errorMsg ) {
if (!errorMsg.isError()) {
this.scrolledForm.getMessageManager().removeMessage(errorMsg.getKey(), errorMsg.getControl());
} else {
this.scrolledForm.getMessageManager().addMessage(errorMsg.getKey(), errorMsg.getMessage(), null,
errorMsg.getMessageType(), errorMsg.getControl());
}
}

private void updateState() {
boolean enable = false;

Expand Down Expand Up @@ -329,11 +320,11 @@ private void validate() {
this.localeError.setStatus(ModelExtensionDefinitionValidator.validateTranslations(this.translationType, temp, false));
}

updateMessage(this.localeError);
this.localeError.update(this.scrolledForm.getMessageManager());

// validate translation text
this.translationError.setStatus(ModelExtensionDefinitionValidator.validateTranslationText(this.translation));
updateMessage(this.translationError);
this.translationError.update(this.scrolledForm.getMessageManager());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,34 @@
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.forms.IMessage;
import org.eclipse.ui.forms.IMessageManager;
import org.teiid.core.designer.util.CoreStringUtil;
import org.teiid.designer.extension.definition.MedStatus;
import org.teiid.designer.extension.definition.ValidationStatus;


/**
* An error message used in the {@link ModelExtensionDefinitionEditor}.
*/
final class ErrorMessage implements IMessage {

private static int getMessageType(final MedStatus medStatus) {
if (medStatus.isError()) {
return IMessageProvider.ERROR;
}

if (medStatus.isWarning()) {
return IMessageProvider.WARNING;
}

if (medStatus.isInfo()) {
return IMessageProvider.INFORMATION;
}

/**
* The error message (can be <code>null</code> or empty)
*/
private String message;
return IMessageProvider.NONE;
}

/**
* The message type.
*/
private int messageType = IMessageProvider.NONE;
private MedStatus status;

/**
* The UI control where the error can be fixed.
Expand Down Expand Up @@ -78,7 +88,7 @@ public Object getKey() {
*/
@Override
public String getMessage() {
return this.message;
return this.status.getMessage();
}

/**
Expand All @@ -88,7 +98,7 @@ public String getMessage() {
*/
@Override
public int getMessageType() {
return this.messageType;
return getMessageType(this.status);
}

/**
Expand All @@ -105,28 +115,28 @@ public String getPrefix() {
* @return <code>true</code> if the validation status has an error severity
*/
public boolean isError() {
return (this.messageType == IMessageProvider.ERROR);
return this.status.isError();
}

/**
* @return <code>true</code> if the validation status has an information severity
*/
public boolean isInfo() {
return (this.messageType == IMessageProvider.INFORMATION);
return this.status.isInfo();
}

/**
* @return <code>true</code> if the validation status has an OK severity
*/
public boolean isOk() {
return (this.messageType == IMessageProvider.NONE);
return this.status.isOk();
}

/**
* @return <code>true</code> if the validation status has a warning severity
*/
public boolean isWarning() {
return (this.messageType == IMessageProvider.WARNING);
return this.status.isWarning();
}

/**
Expand All @@ -140,21 +150,29 @@ public void setControl( Control newControl ) {
* @param newMessage the new message (can be <code>null</code> or empty)
*/
public void setMessage( String newMessage ) {
this.message = newMessage;
this.messageType = (CoreStringUtil.isEmpty(this.message) ? IMessageProvider.NONE : IMessageProvider.ERROR);
setStatus(CoreStringUtil.isEmpty(newMessage) ? ValidationStatus.OK_STATUS : ValidationStatus.createErrorMessage(newMessage));
}

public void setStatus( final MedStatus status ) {
this.status = status;
}

public void setStatus( ValidationStatus status ) {
this.message = status.getMessage();
/**
* @param msgMgr the message manager where the message should be updated (cannot be <code>null</code>)
*/
public void update(final IMessageManager msgMgr) {
msgMgr.removeMessages(getControl());

if (!this.status.isOk()) {
if (this.status.isMulti()) {
int i = 0;

if (status.isError()) {
this.messageType = IMessageProvider.ERROR;
} else if (status.isWarning()) {
this.messageType = IMessageProvider.WARNING;
} else if (status.isInfo()) {
this.messageType = IMessageProvider.INFORMATION;
} else if (status.isOk()) {
this.messageType = IMessageProvider.NONE;
for (final MedStatus medStatus : this.status.getChildren()) {
msgMgr.addMessage(i++, medStatus.getMessage(), null, getMessageType(medStatus), getControl());
}
} else {
msgMgr.addMessage(getKey(), getMessage(), null, getMessageType(), getControl());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,21 @@ public void setFocus() {
/**
* @param errorMessage the message being updated in the {@link IMessageManager message manager} (never <code>null</code>)
*/
protected void updateMessage( ErrorMessage errorMessage ) {
protected void updateMessage(ErrorMessage errorMessage) {
assert (errorMessage != null) : "errorMessage is null"; //$NON-NLS-1$
IMessageManager msgMgr = ((ModelExtensionDefinitionEditor)getEditor()).getMessageManager();

if (errorMessage.isOk()) {
if (errorMessage.getControl() == null) {
if (errorMessage.getControl() == null) {
if (errorMessage.isOk()) {
msgMgr.removeMessage(errorMessage.getKey());
} else {
msgMgr.removeMessage(errorMessage.getKey(), errorMessage.getControl());
}
} else {
if (errorMessage.getControl() == null) {
msgMgr.addMessage(errorMessage.getKey(), errorMessage.getMessage(), errorMessage.getData(),
msgMgr.addMessage(errorMessage.getKey(),
errorMessage.getMessage(),
errorMessage.getData(),
errorMessage.getMessageType());
} else {
msgMgr.addMessage(errorMessage.getKey(), errorMessage.getMessage(), errorMessage.getData(),
errorMessage.getMessageType(), errorMessage.getControl());
}
} else {
errorMessage.update(msgMgr);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,9 @@ public final void propertyChange( PropertyChangeEvent e ) {

// pass event on to medEditorPages
for (MedEditorPage page : this.medEditorPages.keySet()) {
getMessageManager().setAutoUpdate(false);
page.handlePropertyChanged(e);
getMessageManager().setAutoUpdate(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.teiid.designer.core.extension.ModelTypeMetaclassNameFactory;
import org.teiid.designer.extension.ExtensionPlugin;
import org.teiid.designer.extension.definition.ExtendableMetaclassNameProvider;
import org.teiid.designer.extension.definition.MedStatus;
import org.teiid.designer.extension.definition.ModelExtensionDefinition.PropertyName;
import org.teiid.designer.extension.definition.ModelExtensionDefinitionValidator;
import org.teiid.designer.extension.definition.ValidationStatus;
Expand Down Expand Up @@ -896,7 +897,7 @@ private void validateMetaclasses() {
final String[] metaclasses = getMed().getExtendedMetaclasses();

// validate with MED validator
ValidationStatus status = ModelExtensionDefinitionValidator.validateMetaclassNames(metaclasses, true);
MedStatus status = ModelExtensionDefinitionValidator.validateMetaclassNames(metaclasses, true);

if (!status.isError()) {
// validate against metamodel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import org.eclipse.swt.widgets.Text;
import org.teiid.core.designer.util.CoreStringUtil;
import org.teiid.designer.extension.ExtensionPlugin;
import org.teiid.designer.extension.definition.MedStatus;
import org.teiid.designer.extension.definition.ModelExtensionDefinition;
import org.teiid.designer.extension.definition.ModelExtensionDefinitionValidator;
import org.teiid.designer.extension.definition.ValidationStatus;
import org.teiid.designer.extension.registry.ModelExtensionRegistry;
import org.teiid.designer.extension.ui.Activator;
import org.teiid.designer.extension.ui.Messages;
Expand Down Expand Up @@ -369,13 +369,14 @@ public Collection<String> getSupportedModelTypes() {
* @since 7.6
*/
private void validatePage() {
ValidationStatus nsPrefixStatus = ModelExtensionDefinitionValidator.validateNamespacePrefix(getNamespacePrefix(), getRegistry().getAllNamespacePrefixes());
ValidationStatus nsUriStatus = ModelExtensionDefinitionValidator.validateNamespaceUri(getNamespaceUri(),
getRegistry().getAllNamespaceUris());
ValidationStatus metaModelUriStatus = ModelExtensionDefinitionValidator.validateMetamodelUri(getMetamodelUri(),
getRegistry().getExtendableMetamodelUris());
ValidationStatus definitionStatus = ModelExtensionDefinitionValidator.validateDescription(getDescription());
ValidationStatus versionStatus = ModelExtensionDefinitionValidator.validateVersion(getVersion());
MedStatus nsPrefixStatus = ModelExtensionDefinitionValidator.validateNamespacePrefix(getNamespacePrefix(),
getRegistry().getAllNamespacePrefixes());
MedStatus nsUriStatus = ModelExtensionDefinitionValidator.validateNamespaceUri(getNamespaceUri(),
getRegistry().getAllNamespaceUris());
MedStatus metaModelUriStatus = ModelExtensionDefinitionValidator.validateMetamodelUri(getMetamodelUri(),
getRegistry().getExtendableMetamodelUris());
MedStatus definitionStatus = ModelExtensionDefinitionValidator.validateDescription(getDescription());
MedStatus versionStatus = ModelExtensionDefinitionValidator.validateVersion(getVersion());

StringBuffer sb = new StringBuffer();
addStatusMessage(sb, nsPrefixStatus);
Expand All @@ -390,8 +391,8 @@ private void validatePage() {
setPageComplete(true);
}

private void addStatusMessage( StringBuffer sb,
ValidationStatus status ) {
private void addStatusMessage( final StringBuffer sb,
final MedStatus status ) {
if (status.isError()) {
sb.append(TOKEN_ERROR + status.getMessage() + CR);
} else if (status.isWarning()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public class Messages extends NLS {
public static String uriInvalidValidationMsg;
public static String versionIsNotAnIntegerValidationMsg;
public static String versionLessThanDefaultValidationMsg;
public static String appendPropertyId;

public static String propertyAllowedValue;
public static String propertyDefaultValue;
public static String propertyFixedValue;
public static String propertyValue;

public static String translationToString;

Expand Down

0 comments on commit e9be638

Please sign in to comment.