Search in sources :

Example 1 with VetoException

use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.

the class AbstractMixedSmartField method handleMissingLookupRow.

@Override
protected VALUE handleMissingLookupRow(String text) {
    doSearch(text, false, true);
    IContentAssistFieldDataFetchResult<LOOKUP_KEY> fetchResult = getLookupRowFetcher().getResult();
    int numResults = 0;
    if (fetchResult != null && fetchResult.getLookupRows() != null) {
        numResults = fetchResult.getLookupRows().size();
        if (numResults == 1) {
            ILookupRow<LOOKUP_KEY> singleMatchLookupRow = CollectionUtility.firstElement(fetchResult.getLookupRows());
            setCurrentLookupRow(singleMatchLookupRow);
            return returnLookupRowAsValue(singleMatchLookupRow);
        }
    }
    VetoException veto = new VetoException(TEXTS.get("SmartFieldCannotComplete", text));
    veto.withCode(numResults > 1 ? NOT_UNIQUE_ERROR_CODE : NO_RESULTS_ERROR_CODE);
    throw veto;
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException)

Example 2 with VetoException

use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.

the class AbstractDateField method validateValueInternal.

@Override
protected Date validateValueInternal(Date rawValue) {
    rawValue = super.validateValueInternal(rawValue);
    if (rawValue == null) {
        return null;
    }
    // Check if date is allowed (if allowed dates are set)
    if (getAllowedDates().size() > 0) {
        Date truncDate = DateUtility.truncDate(rawValue);
        boolean found = false;
        for (Date allowedDate : getAllowedDates()) {
            if (allowedDate.compareTo(truncDate) == 0) {
                found = true;
                break;
            }
        }
        if (!found) {
            throw new VetoException(new ProcessingStatus(TEXTS.get("DateIsNotAllowed"), IStatus.ERROR));
        }
    }
    return rawValue;
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) ProcessingStatus(org.eclipse.scout.rt.platform.exception.ProcessingStatus) Date(java.util.Date)

Example 3 with VetoException

use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.

the class BookmarkUtility method activateBookmark.

/**
 * Load a {@link Bookmark} on the specified {@link IDesktop} model.
 * <p>
 * First the specific {@link Bookmark#getOutlineClassName()} is evaluated and, if activateOutline is true, activated.
 * Afterwards every page from the {@link Bookmark#getPath()} will be selected (respecting the
 * {@link AbstractPageState}).
 * </p>
 * Finally the path will be expanded. Possible exceptions might occur if no outline is set in the {@link Bookmark} or
 * the outline is not available.
 */
public static void activateBookmark(IDesktop desktop, Bookmark bm, boolean activateOutline) {
    if (bm.getOutlineClassName() == null) {
        return;
    }
    IOutline outline = BookmarkUtility.resolveOutline(desktop.getAvailableOutlines(), bm.getOutlineClassName());
    if (outline == null) {
        throw new ProcessingException("outline '" + bm.getOutlineClassName() + "' was not found");
    }
    if (!(outline.isVisible() && outline.isEnabled())) {
        throw new VetoException(TEXTS.get("BookmarkActivationFailedOutlineNotAvailable", outline.getTitle()));
    }
    if (activateOutline) {
        desktop.activateOutline(outline);
    }
    try {
        outline.setTreeChanging(true);
        // 
        IPage<?> parentPage = outline.getRootPage();
        boolean pathFullyRestored = true;
        List<AbstractPageState> path = bm.getPath();
        AbstractPageState parentPageState = path.get(0);
        boolean resetViewAndWarnOnFail = bm.getId() != 0;
        for (int i = 1; i < path.size(); i++) {
            // try to find correct child page (next parentPage)
            IPage<?> childPage = null;
            AbstractPageState childState = path.get(i);
            if (parentPageState instanceof TablePageState) {
                TablePageState tablePageState = (TablePageState) parentPageState;
                if (parentPage instanceof IPageWithTable) {
                    IPageWithTable tablePage = (IPageWithTable) parentPage;
                    childPage = bmLoadTablePage(tablePage, tablePageState, false, resetViewAndWarnOnFail);
                }
            } else if (parentPageState instanceof NodePageState) {
                NodePageState nodePageState = (NodePageState) parentPageState;
                if (parentPage instanceof IPageWithNodes) {
                    IPageWithNodes nodePage = (IPageWithNodes) parentPage;
                    childPage = bmLoadNodePage(nodePage, nodePageState, childState, resetViewAndWarnOnFail);
                }
            }
            // next
            if (childPage != null) {
                parentPage = childPage;
                parentPageState = childState;
            } else if (i < path.size()) {
                pathFullyRestored = false;
                break;
            }
        }
        if (pathFullyRestored) {
            if (parentPageState instanceof TablePageState && parentPage instanceof IPageWithTable) {
                bmLoadTablePage((IPageWithTable) parentPage, (TablePageState) parentPageState, true, resetViewAndWarnOnFail);
            } else if (parentPage instanceof IPageWithNodes) {
                bmLoadNodePage((IPageWithNodes) parentPage, (NodePageState) parentPageState, null, resetViewAndWarnOnFail);
            }
        }
        /*
       * Expansions of the restored tree path
       */
        IPage<?> p = parentPage;
        // last element
        if (pathFullyRestored && parentPageState.isExpanded() != null) {
            p.setExpanded(parentPageState.isExpanded());
        } else {
            if (!(p instanceof IPageWithTable)) {
                p.setExpanded(true);
            }
        }
        // ancestor elements
        p = p.getParentPage();
        while (p != null) {
            p.setExpanded(true);
            p = p.getParentPage();
        }
        outline.selectNode(parentPage, false);
    } finally {
        outline.setTreeChanging(false);
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) AbstractPageState(org.eclipse.scout.rt.shared.services.common.bookmark.AbstractPageState) IPageWithTable(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) IPageWithNodes(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes) NodePageState(org.eclipse.scout.rt.shared.services.common.bookmark.NodePageState) TablePageState(org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 4 with VetoException

use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.

the class AbstractForm method doCancel.

@Override
public void doCancel() {
    if (!isBlockingInternal()) {
        return;
    }
    m_closeType = IButton.SYSTEM_TYPE_CANCEL;
    try {
        // ensure all fields have the right save-needed-state
        checkSaveNeeded();
        // find any fields that needs save
        P_AbstractCollectingFieldVisitor<IFormField> collector = new P_AbstractCollectingFieldVisitor<IFormField>() {

            @Override
            public boolean visitField(IFormField field, int level, int fieldIndex) {
                if (field.isSaveNeeded()) {
                    collect(field);
                    return false;
                } else {
                    return true;
                }
            }
        };
        visitFields(collector);
        if (collector.getCollectionCount() > 0 && isAskIfNeedSave()) {
            int result = MessageBoxes.createYesNoCancel().withDisplayParent(this).withHeader(getCancelVerificationText()).withSeverity(IStatus.INFO).show();
            if (result == IMessageBox.YES_OPTION) {
                doOk();
                return;
            } else if (result == IMessageBox.NO_OPTION) {
                doClose();
                return;
            } else {
                VetoException e = new VetoException(TEXTS.get("UserCancelledOperation"));
                e.consume();
                throw e;
            }
        }
        discardStateInternal();
        doFinally();
        disposeFormInternal();
    } catch (RuntimeException | PlatformError e) {
        m_closeType = IButton.SYSTEM_TYPE_NONE;
        throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) PlatformExceptionTranslator(org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator)

Example 5 with VetoException

use of org.eclipse.scout.rt.platform.exception.VetoException in project scout.rt by eclipse.

the class FormStoredWithVetoTest method assertHandledVetoException.

private void assertHandledVetoException() {
    // Ensure 'JUnitExceptionHandler' to be installed.
    JUnitExceptionHandler exceptionHandler = BEANS.get(JUnitExceptionHandler.class);
    assertTrue(String.format("this test expects 'JUnitExceptionHandler' to be installed [actual=%s]", exceptionHandler), exceptionHandler instanceof JUnitExceptionHandler);
    try {
        exceptionHandler.throwOnError();
        fail("VetoException excepted to be handled in 'JUnitExceptionHandler'");
    } catch (Throwable e) {
        assertTrue("VetoException expected [actual=" + e.getClass() + "]", e instanceof VetoException);
        assertFalse("exception.isConsumed()", ((VetoException) e).isConsumed());
        assertEquals("exception.getMessage()", FormToStore.VETO_EXCEPTION_TEXT, ((VetoException) e).getStatus().getBody());
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) JUnitExceptionHandler(org.eclipse.scout.rt.testing.platform.runner.JUnitExceptionHandler)

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