Search in sources :

Example 11 with PlatformError

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

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

the class AbstractForm method closeFormInternal.

private void closeFormInternal(boolean kill) {
    if (isBlockingInternal()) {
        try {
            // check if there is an active close, cancel or finish button
            final Set<Integer> enabledSystemTypes = new HashSet<Integer>();
            final Set<IButton> enabledSystemButtons = new HashSet<IButton>();
            IFormFieldVisitor v = new IFormFieldVisitor() {

                @Override
                public boolean visitField(IFormField field, int level, int fieldIndex) {
                    if (field instanceof IButton) {
                        IButton b = (IButton) field;
                        if (b.isEnabled() && b.isVisible()) {
                            enabledSystemTypes.add(b.getSystemType());
                            enabledSystemButtons.add(b);
                        }
                    }
                    return true;
                }
            };
            visitFields(v);
            interceptOnCloseRequest(kill, enabledSystemTypes);
        } catch (RuntimeException | PlatformError e) {
            throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
        }
    }
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IButton(org.eclipse.scout.rt.client.ui.form.fields.button.IButton) PlatformExceptionTranslator(org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator) HashSet(java.util.HashSet)

Example 13 with PlatformError

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

the class AbstractForm method doReset.

@Override
public void doReset() {
    setFormLoading(true);
    // reset values
    P_AbstractCollectingFieldVisitor v = new P_AbstractCollectingFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (field instanceof IValueField) {
                IValueField f = (IValueField) field;
                f.resetValue();
            } else if (field instanceof IComposerField) {
                IComposerField f = (IComposerField) field;
                f.resetValue();
            }
            return true;
        }
    };
    try {
        visitFields(v);
        // init again
        initForm();
        // load again
        loadStateInternal();
    } catch (RuntimeException | PlatformError e) {
        throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
    }
}
Also used : 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) IValueField(org.eclipse.scout.rt.client.ui.form.fields.IValueField) IComposerField(org.eclipse.scout.rt.client.ui.form.fields.composer.IComposerField)

Example 14 with PlatformError

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

the class AbstractForm method storeToXml.

@Override
public void storeToXml(Element root) {
    root.setAttribute("formId", getFormId());
    root.setAttribute("formQname", getClass().getName());
    // add custom properties
    Element xProps = root.getOwnerDocument().createElement("properties");
    root.appendChild(xProps);
    IPropertyFilter filter = new IPropertyFilter() {

        @Override
        public boolean accept(FastPropertyDescriptor descriptor) {
            if (descriptor.getPropertyType().isInstance(IFormField.class)) {
                return false;
            }
            if (!descriptor.getPropertyType().isPrimitive() && !Serializable.class.isAssignableFrom(descriptor.getPropertyType())) {
                return false;
            }
            if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null) {
                return false;
            }
            return true;
        }
    };
    Map<String, Object> props = BeanUtility.getProperties(this, AbstractForm.class, filter);
    storePropertiesToXml(xProps, props);
    // add extension properties
    for (IExtension<?> ex : getAllExtensions()) {
        Map<String, Object> extensionProps = BeanUtility.getProperties(ex, AbstractFormExtension.class, filter);
        if (extensionProps.isEmpty()) {
            continue;
        }
        Element xExtension = root.getOwnerDocument().createElement("extension");
        xProps.appendChild(xExtension);
        xExtension.setAttribute("extensionId", ex.getClass().getSimpleName());
        xExtension.setAttribute("extensionQname", ex.getClass().getName());
        storePropertiesToXml(xExtension, extensionProps);
    }
    // add fields
    final Element xFields = root.getOwnerDocument().createElement("fields");
    root.appendChild(xFields);
    final Holder<RuntimeException> exceptionHolder = new Holder<>(RuntimeException.class);
    final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
    P_AbstractCollectingFieldVisitor v = new P_AbstractCollectingFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (field.getForm() != AbstractForm.this) {
                // field is part of a wrapped form and is handled by the AbstractWrappedFormField
                return true;
            }
            Element xField = xFields.getOwnerDocument().createElement("field");
            try {
                field.storeToXml(xField);
                xFields.appendChild(xField);
            } catch (RuntimeException e) {
                exceptionHolder.setValue(e);
                return false;
            } catch (PlatformError e) {
                errorHolder.setValue(e);
                return false;
            }
            return true;
        }
    };
    visitFields(v);
    if (exceptionHolder.getValue() != null) {
        throw exceptionHolder.getValue();
    } else if (errorHolder.getValue() != null) {
        throw errorHolder.getValue();
    }
}
Also used : IHtmlListElement(org.eclipse.scout.rt.platform.html.IHtmlListElement) Element(org.w3c.dom.Element) 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) FastPropertyDescriptor(org.eclipse.scout.rt.platform.reflect.FastPropertyDescriptor) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) IPropertyFilter(org.eclipse.scout.rt.platform.reflect.IPropertyFilter)

Example 15 with PlatformError

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

the class AbstractDesktop method initConfig.

protected void initConfig() {
    m_eventHistory = createEventHistory();
    // add convenience observer for event history
    addDesktopListener(new DesktopListener() {

        @Override
        public void desktopChanged(DesktopEvent e) {
            IEventHistory<DesktopEvent> h = getEventHistory();
            if (h != null) {
                h.notifyEvent(e);
            }
        }
    });
    ClientSessionProvider.currentSession().getMemoryPolicy().registerDesktop(this);
    BEANS.get(IDeviceTransformationService.class).install(this);
    initDesktopExtensions();
    setTitle(getConfiguredTitle());
    setCssClass(getConfiguredCssClass());
    setSelectViewTabsKeyStrokesEnabled(getConfiguredSelectViewTabsKeyStrokesEnabled());
    setSelectViewTabsKeyStrokeModifier(getConfiguredSelectViewTabsKeyStrokeModifier());
    setLogoId(getConfiguredLogoId());
    setDisplayStyle(getConfiguredDisplayStyle());
    initDisplayStyle(getDisplayStyle());
    setCacheSplitterPosition(getConfiguredCacheSplitterPosition());
    List<IDesktopExtension> extensions = getDesktopExtensions();
    m_contributionHolder = new ContributionComposite(this);
    // outlines
    OrderedCollection<IOutline> outlines = new OrderedCollection<IOutline>();
    for (IDesktopExtension ext : extensions) {
        try {
            ext.contributeOutlines(outlines);
        } catch (Exception t) {
            LOG.error("contributing outlines by {}", ext, t);
        }
    }
    List<IOutline> contributedOutlines = m_contributionHolder.getContributionsByClass(IOutline.class);
    outlines.addAllOrdered(contributedOutlines);
    // move outlines
    ExtensionUtility.moveModelObjects(outlines);
    setAvailableOutlines(outlines.getOrderedList());
    // actions (keyStroke, menu, viewButton, toolButton)
    List<IAction> actionList = new ArrayList<IAction>();
    for (IDesktopExtension ext : extensions) {
        try {
            ext.contributeActions(actionList);
        } catch (Exception t) {
            LOG.error("contributing actions by {}", ext, t);
        }
    }
    List<IAction> contributedActions = m_contributionHolder.getContributionsByClass(IAction.class);
    actionList.addAll(contributedActions);
    // build complete menu and viewButton lists
    // only top level menus
    OrderedComparator orderedComparator = new OrderedComparator();
    List<IMenu> menuList = new ActionFinder().findActions(actionList, IMenu.class, false);
    ExtensionUtility.moveModelObjects(menuList);
    Collections.sort(menuList, orderedComparator);
    m_menus = menuList;
    List<IViewButton> viewButtonList = new ActionFinder().findActions(actionList, IViewButton.class, false);
    ExtensionUtility.moveModelObjects(viewButtonList);
    Collections.sort(viewButtonList, orderedComparator);
    m_viewButtons = viewButtonList;
    // add dynamic keyStrokes
    List<IKeyStroke> ksList = new ActionFinder().findActions(actionList, IKeyStroke.class, true);
    for (IKeyStroke ks : ksList) {
        try {
            ks.initAction();
        } catch (RuntimeException | PlatformError e) {
            LOG.error("could not initialize key stroke '{}'.", ks, e);
        }
    }
    addKeyStrokes(ksList.toArray(new IKeyStroke[ksList.size()]));
    // init outlines
    for (IOutline o : m_availableOutlines) {
        try {
            o.initTree();
        } catch (Exception e) {
            LOG.error("Could not init outline {}", o, e);
        }
    }
    addPropertyChangeListener(new P_LocalPropertyChangeListener());
}
Also used : IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) IEventHistory(org.eclipse.scout.rt.client.ui.IEventHistory) IKeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke) OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction) ContributionComposite(org.eclipse.scout.rt.shared.extension.ContributionComposite) OrderedCollection(org.eclipse.scout.rt.platform.util.collection.OrderedCollection) DeepLinkException(org.eclipse.scout.rt.client.deeplink.DeepLinkException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IViewButton(org.eclipse.scout.rt.client.ui.action.view.IViewButton) IDeviceTransformationService(org.eclipse.scout.rt.client.transformation.IDeviceTransformationService) ActionFinder(org.eclipse.scout.rt.client.ui.action.ActionFinder)

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