Search in sources :

Example 1 with PlatformError

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

the class AbstractDesktop method closeInternal.

@Override
public void closeInternal() {
    setOpenedInternal(false);
    detachGui();
    List<IForm> showedForms = new ArrayList<IForm>();
    // Remove showed forms
    for (IForm form : m_formStore.values()) {
        hideForm(form);
        showedForms.add(form);
    }
    // extensions
    for (IDesktopExtension ext : getDesktopExtensions()) {
        try {
            ContributionCommand cc = ext.desktopClosingDelegate();
            if (cc == ContributionCommand.Stop) {
                break;
            }
        } catch (RuntimeException | PlatformError t) {
            LOG.error("extension {}", ext, t);
        }
    }
    // close messageboxes
    for (IMessageBox m : getMessageBoxes()) {
        if (m != null) {
            try {
                m.getUIFacade().setResultFromUI(IMessageBox.CANCEL_OPTION);
            } catch (RuntimeException | PlatformError e) {
                LOG.error("Exception while closing messagebox", e);
            }
        }
    }
    // close filechoosers
    for (IFileChooser f : getFileChoosers()) {
        if (f != null) {
            try {
                f.getUIFacade().setResultFromUI(Collections.<BinaryResource>emptyList());
            } catch (RuntimeException | PlatformError e) {
                LOG.error("Exception while closing filechooser", e);
            }
        }
    }
    // close client callbacks
    for (ClientCallback<?> c : CollectionUtility.arrayList(m_pendingPositionResponses)) {
        if (c != null) {
            try {
                c.cancel(true);
                c.failed(new ThreadInterruptedError("desktop is closing"));
            } catch (RuntimeException | PlatformError e) {
                LOG.error("Exception while closing client callback", e);
            }
        }
    }
    // close open forms
    for (IForm form : showedForms) {
        if (form != null) {
            try {
                form.doClose();
            } catch (RuntimeException | PlatformError e) {
                LOG.error("Exception while closing form", e);
            }
        }
    }
    // dispose outlines
    for (IOutline outline : getAvailableOutlines()) {
        try {
            outline.disposeTree();
        } catch (RuntimeException | PlatformError e) {
            LOG.warn("Exception while disposing outline.", e);
        }
    }
    ActionUtility.disposeActions(getActions());
    fireDesktopClosed();
}
Also used : IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) ThreadInterruptedError(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError) IForm(org.eclipse.scout.rt.client.ui.form.IForm) IMessageBox(org.eclipse.scout.rt.client.ui.messagebox.IMessageBox) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IFileChooser(org.eclipse.scout.rt.client.ui.basic.filechooser.IFileChooser)

Example 2 with PlatformError

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

the class AbstractDesktop method getSimilarViewForms.

@Override
public List<IForm> getSimilarViewForms(final IForm form) {
    if (form == null) {
        return CollectionUtility.emptyArrayList();
    }
    final Object formKey;
    try {
        formKey = form.computeExclusiveKey();
    } catch (final RuntimeException | PlatformError e) {
        BEANS.get(ExceptionHandler.class).handle(e);
        return CollectionUtility.emptyArrayList();
    }
    if (formKey == null) {
        return CollectionUtility.emptyArrayList();
    }
    final IForm currentDetailForm = getPageDetailForm();
    final IForm currentSearchForm = getPageSearchForm();
    final List<IForm> similarForms = new ArrayList<>();
    for (final IForm candidateView : m_formStore.getViewsByKey(formKey)) {
        if (candidateView == currentDetailForm) {
            continue;
        }
        if (candidateView == currentSearchForm) {
            continue;
        }
        if (candidateView.getClass().equals(form.getClass())) {
            similarForms.add(candidateView);
        }
    }
    return similarForms;
}
Also used : PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) ArrayList(java.util.ArrayList) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) IForm(org.eclipse.scout.rt.client.ui.form.IForm)

Example 3 with PlatformError

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

the class AbstractOutline method releaseUnusedPages.

@Override
public void releaseUnusedPages() {
    final HashSet<IPage> preservationSet = new HashSet<IPage>();
    IPage<?> oldSelection = (IPage) getSelectedNode();
    IPage<?> p = oldSelection;
    if (p != null) {
        while (p != null) {
            preservationSet.add(p);
            p = p.getParentPage();
        }
    }
    ITreeVisitor v = new ITreeVisitor() {

        @Override
        public boolean visit(ITreeNode node) {
            IPage<?> page = (IPage) node;
            if (preservationSet.contains(page)) {
            // nop
            } else if (page.isChildrenLoaded() && (!page.isExpanded() || !(page.getParentPage() != null && page.getParentPage().isChildrenLoaded()))) {
                try {
                    unloadNode(page);
                } catch (RuntimeException | PlatformError e) {
                    BEANS.get(ExceptionHandler.class).handle(e);
                }
            }
            return true;
        }
    };
    try {
        setTreeChanging(true);
        visitNode(getRootNode(), v);
        if (oldSelection != null) {
            IPage<?> selectedPage = (IPage) getSelectedNode();
            if (selectedPage == null) {
                try {
                    getRootNode().ensureChildrenLoaded();
                    List<ITreeNode> children = getRootNode().getFilteredChildNodes();
                    if (CollectionUtility.hasElements(children)) {
                        selectNode(CollectionUtility.firstElement(children));
                    }
                } catch (RuntimeException | PlatformError e) {
                    LOG.warn("Exception while selecting first page in outline [{}]", getClass().getName(), e);
                }
            }
        }
    } finally {
        setTreeChanging(false);
    }
}
Also used : ExceptionHandler(org.eclipse.scout.rt.platform.exception.ExceptionHandler) IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) HashSet(java.util.HashSet) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Example 4 with PlatformError

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

the class DefaultPageChangeStrategy method pageChanged.

@Override
public void pageChanged(final IOutline outline, final IPage<?> deselectedPage, final IPage<?> selectedPage) {
    if (outline == null) {
        return;
    }
    outline.clearContextPage();
    IForm detailForm = null;
    ITable detailTable = null;
    ISearchForm searchForm = null;
    // new active page
    outline.makeActivePageToContextPage();
    IPage<?> activePage = outline.getActivePage();
    if (activePage != null) {
        try {
            activePage.ensureChildrenLoaded();
        } catch (RuntimeException | PlatformError e1) {
            BEANS.get(ExceptionHandler.class).handle(e1);
        }
        if (activePage instanceof IPageWithTable) {
            IPageWithTable tablePage = (IPageWithTable) activePage;
            detailForm = activePage.getDetailForm();
            if (activePage.isTableVisible()) {
                detailTable = tablePage.getTable(false);
            }
            if (tablePage.isSearchActive()) {
                searchForm = tablePage.getSearchFormInternal();
            }
        } else if (activePage instanceof IPageWithNodes) {
            IPageWithNodes nodePage = (IPageWithNodes) activePage;
            if (activePage.isDetailFormVisible()) {
                detailForm = activePage.getDetailForm();
            }
            if (activePage.isTableVisible()) {
                detailTable = nodePage.getTable(false);
            }
        }
    }
    // remove first
    if (detailForm == null) {
        outline.setDetailForm(null);
    }
    if (detailTable == null) {
        outline.setDetailTable(null);
    }
    if (searchForm == null) {
        outline.setSearchForm(null);
    }
    // add new
    if (detailForm != null) {
        outline.setDetailForm(detailForm);
    }
    if (detailTable != null) {
        outline.setDetailTable(detailTable);
    }
    if (searchForm != null) {
        outline.setSearchForm(searchForm);
    }
}
Also used : IPageWithTable(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IPageWithNodes(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IForm(org.eclipse.scout.rt.client.ui.form.IForm) ISearchForm(org.eclipse.scout.rt.client.ui.desktop.outline.pages.ISearchForm)

Example 5 with PlatformError

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

the class AbstractWizard method initConfig.

@SuppressWarnings({ "boxing", "unchecked" })
protected void initConfig() {
    setTitle(getConfiguredTitle());
    setSubTitle(getConfiguredSubTitle());
    // initially the wizard is in state "closed"
    setClosedInternal(true);
    setCloseTypeInternal(CloseType.Unknown);
    m_contributionHolder = new ContributionComposite(AbstractWizard.this);
    m_containerForm = createContainerForm();
    Assertions.assertNotNull(m_containerForm, "Missing container form");
    interceptDecorateContainerForm();
    // Run the initialization on behalf of the container form.
    runWithinContainerForm(new IRunnable() {

        @Override
        public void run() throws Exception {
            // steps
            List<Class<? extends IWizardStep<? extends IForm>>> configuredAvailableSteps = getConfiguredAvailableSteps();
            List<IWizardStep> contributedSteps = m_contributionHolder.getContributionsByClass(IWizardStep.class);
            OrderedCollection<IWizardStep<? extends IForm>> steps = new OrderedCollection<IWizardStep<? extends IForm>>();
            for (Class<? extends IWizardStep<? extends IForm>> element : configuredAvailableSteps) {
                IWizardStep<? extends IForm> step = ConfigurationUtility.newInnerInstance(AbstractWizard.this, element);
                steps.addOrdered(step);
            }
            for (IWizardStep step : contributedSteps) {
                steps.addOrdered(step);
            }
            injectStepsInternal(steps);
            ExtensionUtility.moveModelObjects(steps);
            setAvailableSteps(steps.getOrderedList());
            // add listener to listen on any field in active form
            m_anyFieldChangeListener = new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent e) {
                    try {
                        interceptAnyFieldChanged((IFormField) e.getSource());
                    } catch (RuntimeException | PlatformError t) {
                        LOG.error("{} {}={}", e.getSource(), e.getPropertyName(), e.getNewValue(), t);
                    }
                }
            };
            propertySupport.addPropertyChangeListener(PROP_WIZARD_FORM, new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent e) {
                    IForm oldForm = (IForm) e.getOldValue();
                    IForm newForm = (IForm) e.getNewValue();
                    if (oldForm != null) {
                        oldForm.getRootGroupBox().removeSubtreePropertyChangeListener(IValueField.PROP_VALUE, m_anyFieldChangeListener);
                    }
                    if (newForm != null) {
                        newForm.getRootGroupBox().addSubtreePropertyChangeListener(IValueField.PROP_VALUE, m_anyFieldChangeListener);
                    }
                }
            });
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ContributionComposite(org.eclipse.scout.rt.shared.extension.ContributionComposite) OrderedCollection(org.eclipse.scout.rt.platform.util.collection.OrderedCollection) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IForm(org.eclipse.scout.rt.client.ui.form.IForm) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) List(java.util.List) ArrayList(java.util.ArrayList)

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