use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.
the class AbstractForm method startInternal.
/**
* This method is called from the implemented handler methods in a explicit form subclass
*/
protected IForm startInternal(final IFormHandler handler) {
ClientRunContexts.copyCurrent().withForm(this).run(new IRunnable() {
@Override
public void run() throws Exception {
if (isBlockingInternal()) {
throw new IllegalStateException("The form " + getFormId() + " has already been started");
}
// Ensure that boolean is set not only once by the constructor
setFormLoading(true);
setHandler(handler);
m_closeType = IButton.SYSTEM_TYPE_NONE;
m_blockingCondition.setBlocking(true);
try {
initForm();
loadStateInternal();
// if form was disposed during initForm() or loadStateInternal()
if (!isBlockingInternal()) {
return;
}
if (getHandler().isGuiLess()) {
// make sure the form is storing since it is not showing
storeStateInternal();
markSaved();
doFinally();
disposeFormInternal();
return;
}
} catch (RuntimeException | PlatformError e) {
disposeFormInternal();
PlatformException pe = BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", AbstractForm.this.getClass().getName());
if (pe instanceof VetoException) {
VetoException ve = (VetoException) pe;
interceptOnVetoException(ve, ve.getStatus().getCode());
}
throw pe;
}
setButtonsArmed(true);
setCloseTimerArmed(true);
setFormStarted(true);
// Notify the UI to display this form.
if (isShowOnStart()) {
IDesktop desktop = getDesktop();
if (desktop == null || !desktop.isOpened()) {
throw new ProcessingException("There is no desktop or it is not open in the UI.");
} else {
desktop.showForm(AbstractForm.this);
}
}
}
});
return this;
}
use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.
the class AbstractForm method storeStateInternal.
/**
* Store state of form, regardless of validity and completeness do not use or override this internal method directly
*/
protected void storeStateInternal() {
if (!m_blockingCondition.isBlocking()) {
String msg = TEXTS.get("FormDisposedMessage", getTitle());
LOG.error(msg);
throw new VetoException(msg);
}
fireFormStoreBefore();
setFormStored(true);
try {
rebuildSearchFilter();
m_searchFilter.setCompleted(true);
getHandler().onStore();
interceptStored();
if (!isFormStored()) {
// the form was marked as not stored in AbstractFormHandler#execStore() or AbstractForm#execStored().
ProcessingException e = new ProcessingException("Form was marked as not stored.");
e.consume();
throw e;
}
} catch (RuntimeException | PlatformError e) {
// clear search
if (m_searchFilter != null) {
m_searchFilter.clear();
}
// store was not successfully stored
setFormStored(false);
if (e instanceof RuntimeException) {
// NOSONAR
throwVetoExceptionInternal((RuntimeException) e);
} else if (e instanceof PlatformError) {
// NOSONAR
throw e;
}
// if exception was caught and suppressed, this form was after all successfully stored
// normally this code is not reached since the exception will be passed out
setFormStored(true);
}
fireFormStoreAfter();
}
use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.
the class AbstractForm method throwVetoExceptionInternal.
/**
* do not use or override this internal method
*/
protected void throwVetoExceptionInternal(final RuntimeException e) {
PlatformException pe = BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
if (pe instanceof VetoException && !pe.isConsumed()) {
VetoException ve = (VetoException) pe;
interceptOnVetoException(ve, ve.getStatus().getCode());
// if it was not re-thrown it is assumed to be consumed
ve.consume();
}
throw e;
}
use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.
the class AbstractForm method validateForm.
@Override
public void validateForm() {
if (!interceptCheckFields()) {
VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
veto.consume();
throw veto;
}
if (!getHandler().onCheckFields()) {
VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
veto.consume();
throw veto;
}
// check all fields that might be invalid
final ArrayList<String> invalidTexts = new ArrayList<String>();
final ArrayList<String> mandatoryTexts = new ArrayList<String>();
P_AbstractCollectingFieldVisitor<IValidateContentDescriptor> v = new P_AbstractCollectingFieldVisitor<IValidateContentDescriptor>() {
@Override
public boolean visitField(IFormField f, int level, int fieldIndex) {
IValidateContentDescriptor desc = f.validateContent();
if (desc != null) {
if (desc.getErrorStatus() != null) {
invalidTexts.add(desc.getDisplayText() + ": " + desc.getErrorStatus().getMessage());
} else {
mandatoryTexts.add(desc.getDisplayText());
}
if (getCollectionCount() == 0) {
collect(desc);
}
}
return true;
}
};
visitFields(v);
if (v.getCollectionCount() > 0) {
IValidateContentDescriptor firstProblem = v.getCollection().get(0);
if (LOG.isInfoEnabled()) {
LOG.info("there are fields with errors");
}
if (firstProblem != null) {
firstProblem.activateProblemLocation();
}
throw new VetoException().withHtmlMessage(createValidationMessageBoxHtml(invalidTexts, mandatoryTexts));
}
if (!interceptValidate()) {
VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
veto.consume();
throw veto;
}
if (!getHandler().onValidate()) {
VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
veto.consume();
throw veto;
}
}
use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.
the class AbstractFormTest method testValidForm_ErrorStatus.
/**
* Tests that validating a valid form with an ok status should not result in any error.
*/
@Test
public void testValidForm_ErrorStatus() {
String errorMessage = "";
try {
TestForm form = new TestForm();
form.getMainBox().addErrorStatus(new Status("ErrorMessage"));
form.validateForm();
} catch (VetoException ve) {
errorMessage = ve.getDisplayMessage();
}
final String expectedTextPart = "Main Box: ErrorMessage";
assertTrue("expected errorMessage contains: '" + expectedTextPart + "', but was '" + errorMessage + "'", errorMessage.contains(expectedTextPart));
}
Aggregations