Search in sources :

Example 1 with IPage

use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage in project scout.rt by eclipse.

the class AbstractOutline method nodesSelectedInternal.

@Override
protected void nodesSelectedInternal(Set<ITreeNode> oldSelection, Set<ITreeNode> newSelection) {
    super.nodesSelectedInternal(oldSelection, newSelection);
    IPage deselectedPage = null;
    if (CollectionUtility.hasElements(oldSelection)) {
        deselectedPage = (IPage) CollectionUtility.firstElement(oldSelection);
    }
    IPage newSelectedPage = null;
    if (CollectionUtility.hasElements(newSelection)) {
        newSelectedPage = (IPage) CollectionUtility.firstElement(newSelection);
    }
    handleActivePageChanged(deselectedPage, newSelectedPage);
}
Also used : IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)

Example 2 with IPage

use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage in project scout.rt by eclipse.

the class AbstractOutline method findPage.

@Override
public <T extends IPage> T findPage(final Class<T> pageType) {
    final Holder<T> result = new Holder<T>(pageType, null);
    ITreeVisitor v = new ITreeVisitor() {

        @Override
        @SuppressWarnings("unchecked")
        public boolean visit(ITreeNode node) {
            IPage<?> page = (IPage) node;
            Class<? extends IPage> pageClass = page.getClass();
            if (pageType.isAssignableFrom(pageClass)) {
                result.setValue((T) page);
            }
            return result.getValue() == null;
        }
    };
    visitNode(getRootNode(), v);
    return result.getValue();
}
Also used : IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) Holder(org.eclipse.scout.rt.platform.holders.Holder) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Example 3 with IPage

use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage 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 IPage

use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage in project scout.rt by eclipse.

the class AbstractOutline method refreshPages.

@Override
public void refreshPages(final List<Class<? extends IPage>> pageTypes) {
    final List<IPage<?>> candidates = new ArrayList<IPage<?>>();
    ITreeVisitor v = new ITreeVisitor() {

        @Override
        public boolean visit(ITreeNode node) {
            IPage<?> page = (IPage) node;
            if (page == null) {
                return true;
            }
            Class<? extends IPage> pageClass = page.getClass();
            for (Class<? extends IPage> c : pageTypes) {
                if (c.isAssignableFrom(pageClass)) {
                    candidates.add(page);
                }
            }
            return true;
        }
    };
    visitNode(getRootNode(), v);
    for (IPage<?> page : candidates) {
        if (page.getTree() != null) {
            page.dataChanged();
        }
    }
}
Also used : IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ArrayList(java.util.ArrayList) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Example 5 with IPage

use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage in project scout.rt by eclipse.

the class JsonOutlineTest method testTableNotSentIfInvisible.

/**
 * Node.detailTable must not be sent if node.tableVisible is set to false to reduce response size.
 */
@Test
public void testTableNotSentIfInvisible() throws JSONException {
    NodePageWithForm nodePage = new NodePageWithForm();
    // trigger table creation
    nodePage.getTable(true);
    nodePage.setTableVisible(false);
    List<IPage<?>> pages = new ArrayList<IPage<?>>();
    pages.add(nodePage);
    IOutline outline = new Outline(pages);
    JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, outline, null);
    JSONObject jsonNode = jsonOutline.toJson().getJSONArray("nodes").getJSONObject(0);
    Assert.assertNull(jsonNode.opt(IOutline.PROP_DETAIL_TABLE));
    nodePage.setTableVisible(true);
    JsonTestUtility.processBufferedEvents(m_uiSession);
    jsonNode = jsonOutline.toJson().getJSONArray("nodes").getJSONObject(0);
    Assert.assertNotNull(jsonNode.opt(IOutline.PROP_DETAIL_TABLE));
}
Also used : IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) JSONObject(org.json.JSONObject) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) NodePageWithForm(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.NodePageWithForm) Outline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) JsonTreeTest(org.eclipse.scout.rt.ui.html.json.tree.JsonTreeTest) Test(org.junit.Test)

Aggregations

IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)19 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)12 ArrayList (java.util.ArrayList)10 Outline (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline)9 Test (org.junit.Test)8 JsonTreeTest (org.eclipse.scout.rt.ui.html.json.tree.JsonTreeTest)7 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)6 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)4 TablePage (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.TablePage)4 JsonOutline (org.eclipse.scout.rt.ui.html.json.desktop.JsonOutline)3 NodePage (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.NodePage)3 JSONObject (org.json.JSONObject)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 IBookmarkAdapter (org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter)2 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)2 List (java.util.List)1 TreeMap (java.util.TreeMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IClientSession (org.eclipse.scout.rt.client.IClientSession)1