/** * Shows the specified <code>status</code>'s children in the "Details" area of an information * dialog. * * @param event the live validation occurred event */ private void showLiveValidationDialog(final ValidationEvent event) { IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (workbenchWindow != null) { IStatus[] details = toStatusArray(event); String message = event.getSeverity() >= IStatus.ERROR ? ValidationUIMessages.Validation_liveError : null; // show the constraint message as the primary message // the dialog should show INFO severity for errors because // the corrective action has already been taken by the // system; the user is just being informed that everything // is still OK. Warnings, however, require corrective // action by the user. final int dialogSeverity = event.matches(IStatus.WARNING) ? IStatus.WARNING : IStatus.INFO; // get the first of the most severe error messages and use // it in the summary message presented to the user IStatus primary = getFirstStatus(details, event.getSeverity()); IStatus toDisplay; if (details.length > 1) { toDisplay = new MultiStatus( ValidationUIPlugin.getPlugin().getBundle().getSymbolicName(), 0, details, primary.getMessage(), null) { /** * Redefines the inherited method to always return the more appropriate severity for * the dialog. */ @Override public int getSeverity() { return dialogSeverity; } }; } else { toDisplay = new Status( dialogSeverity, primary.getPlugin(), primary.getCode(), primary.getMessage(), primary.getException()); } new LiveValidationDialog( Display.getCurrent().getActiveShell(), ValidationUIMessages.Validation_liveDialogTitle, message, toDisplay) .open(); } }
/* (non-Javadoc) * Implements the interface method. */ public void validationOccurred(ValidationEvent event) { if ((event.getEvaluationMode() == EvaluationMode.LIVE) && (event.getSeverity() >= IStatus.WARNING) && isSupportedClientContexts(event.getClientContextIds())) { showProblemMessages(event); } }
public void test_UniversalListener() { EObject object = OrderSystemFactory.eINSTANCE.createOrder(); batchValidator.validate(object); assertTrue(UniversalValidationListener.LAST_EVENT != null); ValidationEvent event = UniversalValidationListener.LAST_EVENT; assertTrue( event .getClientContextIds() .contains("org.eclipse.emf.validation.tests.junit")); // $NON-NLS-1$ }
/** * Converts a validation event to an array of statuses. * * @param event the validation event * @return its validation results, as a status array */ private static IStatus[] toStatusArray(ValidationEvent event) { List<IConstraintStatus> results = event.getValidationResults(); return results.toArray(new IStatus[results.size()]); }