Search in sources :

Example 11 with VetoException

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;
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 12 with VetoException

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();
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 13 with VetoException

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;
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Example 14 with VetoException

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;
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) IValidateContentDescriptor(org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor) ArrayList(java.util.ArrayList)

Example 15 with VetoException

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));
}
Also used : Status(org.eclipse.scout.rt.platform.status.Status) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) Test(org.junit.Test)

Aggregations

VetoException (org.eclipse.scout.rt.platform.exception.VetoException)16 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)6 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)3 Test (org.junit.Test)3 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)2 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)2 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Semaphore (java.util.concurrent.Semaphore)1 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1 IPageWithNodes (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes)1 IPageWithTable (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable)1 IValidateContentDescriptor (org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor)1 IMessageBox (org.eclipse.scout.rt.client.ui.messagebox.IMessageBox)1 IProcessingStatus (org.eclipse.scout.rt.platform.exception.IProcessingStatus)1 PlatformExceptionTranslator (org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator)1 ProcessingStatus (org.eclipse.scout.rt.platform.exception.ProcessingStatus)1