Search in sources :

Example 6 with PlatformError

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

the class AbstractForm method interceptInitConfig.

protected final void interceptInitConfig() {
    final Holder<RuntimeException> exceptionHolder = new Holder<>(RuntimeException.class, null);
    final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class, null);
    m_objectExtensions.initConfig(createLocalExtension(), new Runnable() {

        @Override
        public void run() {
            try {
                initConfig();
            } catch (RuntimeException e) {
                exceptionHolder.setValue(e);
            } catch (PlatformError e) {
                errorHolder.setValue(e);
            }
        }
    });
    if (exceptionHolder.getValue() != null) {
        throw exceptionHolder.getValue();
    } else if (errorHolder.getValue() != null) {
        throw errorHolder.getValue();
    }
}
Also used : PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IHolder(org.eclipse.scout.rt.platform.holders.IHolder) IPropertyHolder(org.eclipse.scout.rt.shared.data.form.IPropertyHolder) Holder(org.eclipse.scout.rt.platform.holders.Holder) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable)

Example 7 with PlatformError

use of org.eclipse.scout.rt.platform.exception.PlatformError 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 8 with PlatformError

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

the class AbstractForm method installFormCloseTimer.

/**
 * Installs the timer to close the Form once the given seconds elapse
 */
private IFuture<?> installFormCloseTimer(final long seconds) {
    final long startMillis = System.currentTimeMillis();
    final long delayMillis = TimeUnit.SECONDS.toMillis(seconds);
    return ModelJobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            final long elapsedMillis = System.currentTimeMillis() - startMillis;
            final long remainingSeconds = TimeUnit.MILLISECONDS.toSeconds(delayMillis - elapsedMillis);
            if (!isCloseTimerArmed()) {
                setSubTitle(null);
            } else if (remainingSeconds > 0) {
                setSubTitle("" + remainingSeconds);
            } else {
                // cancel the periodic action
                setCloseTimerArmed(false);
                try {
                    interceptCloseTimer();
                } catch (RuntimeException | PlatformError e) {
                    throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
                }
            }
        }
    }, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withName("Close timer").withExceptionHandling(null, false).withExecutionTrigger(Jobs.newExecutionTrigger().withSchedule(SimpleScheduleBuilder.repeatSecondlyForever())));
}
Also used : PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) PlatformExceptionTranslator(org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator) 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)

Example 9 with PlatformError

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

the class AbstractForm method exportFormData.

@Override
public void exportFormData(final AbstractFormData target) {
    // locally declared form properties
    Map<String, Object> properties = BeanUtility.getProperties(this, AbstractForm.class, new FormDataPropertyFilter());
    BeanUtility.setProperties(target, properties, false, null);
    // properties in extensions of form
    exportExtensionProperties(this, target);
    final Set<IFormField> exportedFields = new HashSet<IFormField>();
    // all fields
    Map<Integer, Map<String, AbstractFormFieldData>> /* qualified field id */
    breadthFirstMap = target.getAllFieldsRec();
    for (Map<String, AbstractFormFieldData> /* qualified field id */
    targetMap : breadthFirstMap.values()) {
        for (Map.Entry<String, AbstractFormFieldData> e : targetMap.entrySet()) {
            String fieldQId = e.getKey();
            AbstractFormFieldData data = e.getValue();
            FindFieldByFormDataIdVisitor v = new FindFieldByFormDataIdVisitor(fieldQId, this);
            visitFields(v);
            IFormField f = v.getField();
            if (f != null) {
                // field properties
                properties = BeanUtility.getProperties(f, AbstractFormField.class, new FormDataPropertyFilter());
                BeanUtility.setProperties(data, properties, false, null);
                exportExtensionProperties(f, data);
                // field state
                f.exportFormFieldData(data);
                // remember exported fields
                exportedFields.add(f);
            } else {
                LOG.warn("Cannot find field with id '{}' in form '{}' for DTO '{}'.", fieldQId, getClass().getName(), data.getClass().getName());
            }
        }
    }
    // visit remaining fields (there could be an extension with properties e.g. on a groupbox)
    final Holder<RuntimeException> exHolder = new Holder<>(RuntimeException.class);
    final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
    visitFields(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (exportedFields.contains(field)) {
                // already exported -> skip
                return true;
            }
            final IForm formOfField = field.getForm();
            if (formOfField == null) {
                // either form has not been initialized or the field is part of a composite field, that does not override setForminternal -> skip
                LOG.info("Extension properties are not exported for fields on which getForm() returns null. " + "Ensure that the form is initialized and that the field's parent invokes field.setFormInternal(IForm) [exportingForm={}, field={}]", AbstractForm.this.getClass().getName(), field.getClass().getName());
                return true;
            }
            if (formOfField != AbstractForm.this) {
                // field belongs to another form -> skip
                return true;
            }
            try {
                exportExtensionProperties(field, target);
            } catch (RuntimeException e) {
                exHolder.setValue(e);
            } catch (PlatformError e) {
                errorHolder.setValue(e);
            }
            return exHolder.getValue() == null && errorHolder.getValue() == null;
        }
    });
    if (exHolder.getValue() != null) {
        throw exHolder.getValue();
    } else if (errorHolder.getValue() != null) {
        throw errorHolder.getValue();
    }
}
Also used : AbstractFormField(org.eclipse.scout.rt.client.ui.form.fields.AbstractFormField) AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData) IHolder(org.eclipse.scout.rt.platform.holders.IHolder) IPropertyHolder(org.eclipse.scout.rt.shared.data.form.IPropertyHolder) Holder(org.eclipse.scout.rt.platform.holders.Holder) FormDataPropertyFilter(org.eclipse.scout.rt.client.ui.form.internal.FormDataPropertyFilter) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) FindFieldByFormDataIdVisitor(org.eclipse.scout.rt.client.ui.form.internal.FindFieldByFormDataIdVisitor) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 10 with PlatformError

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

the class AbstractPage method execDataChanged.

/**
 * Called by the data change listener registered with this page (and the current desktop) through
 * {@link #registerDataChangeListener(Object...)}. Use this callback method to react to data change events by
 * reloading current data, or throwing away cached data etc.
 * <p>
 * Subclasses can override this method.<br/>
 * This default implementation does the following:
 * <ol>
 * <li>if this page is an ancestor of the selected page (or is selected itself) and this page is in the active
 * outline, a full re-load of the page is performed
 * <li>else the children of this page are marked dirty and the page itself is unloaded
 * </ol>
 *
 * @see IDesktop#dataChanged(Object...)
 */
@ConfigOperation
@Order(55)
protected void execDataChanged(Object... dataTypes) {
    if (getTree() == null) {
        return;
    }
    // 
    HashSet<ITreeNode> pathsToSelections = new HashSet<ITreeNode>();
    for (ITreeNode node : getTree().getSelectedNodes()) {
        ITreeNode tmp = node;
        while (tmp != null) {
            pathsToSelections.add(tmp);
            tmp = tmp.getParentNode();
        }
    }
    IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
    final boolean isActiveOutline = (desktop != null ? desktop.getOutline() == this.getOutline() : false);
    final boolean isRootNode = pathsToSelections.isEmpty() && getTree() != null && getTree().getRootNode() == this;
    if (isActiveOutline && (pathsToSelections.contains(this) || isRootNode)) {
        try {
            // TODO [7.0] fko: maybe remove when bookmarks can be done on outline level? (currently only pages)
            if (isRootNode) {
                this.reloadPage();
            } else /*
         * Ticket 77332 (deleting a node in the tree) also requires a reload So
         * the selected and its ancestor nodes require same processing
         */
            if (desktop != null) {
                // NOSONAR
                Bookmark bm = desktop.createBookmark();
                setChildrenDirty(true);
                // activate bookmark without activating the outline, since this would hide active tabs.
                desktop.activateBookmark(bm, false);
            }
        } catch (RuntimeException | PlatformError e) {
            BEANS.get(ExceptionHandler.class).handle(e);
        }
    } else {
        // not active outline OR not on selection path
        setChildrenDirty(true);
        if (isExpanded()) {
            setExpanded(false);
        }
        try {
            if (isChildrenLoaded()) {
                getTree().unloadNode(this);
            }
        } catch (RuntimeException | PlatformError e) {
            BEANS.get(ExceptionHandler.class).handle(e);
        }
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) HashSet(java.util.HashSet) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Aggregations

PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)21 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)7 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)6 ArrayList (java.util.ArrayList)5 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)5 HashSet (java.util.HashSet)4 IForm (org.eclipse.scout.rt.client.ui.form.IForm)4 PlatformExceptionTranslator (org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator)4 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)4 Holder (org.eclipse.scout.rt.platform.holders.Holder)3 IHolder (org.eclipse.scout.rt.platform.holders.IHolder)3 IPropertyHolder (org.eclipse.scout.rt.shared.data.form.IPropertyHolder)3 IExtensibleObject (org.eclipse.scout.rt.shared.extension.IExtensibleObject)3 IOException (java.io.IOException)2 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)2 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)2 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)2 OrderedCollection (org.eclipse.scout.rt.platform.util.collection.OrderedCollection)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1