Search in sources :

Example 1 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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 2 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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 3 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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 4 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class AbstractBookmarkTreeField method refreshBookmarkModel.

/**
 * Only some values have changed, just save the model
 */
private void refreshBookmarkModel() {
    getTree().visitTree(new ITreeVisitor() {

        @Override
        public boolean visit(ITreeNode node) {
            BookmarkFolder bmFolder = null;
            if (node == getTree().getRootNode()) {
                bmFolder = getBookmarkRootFolder();
            } else if (isFolderNode(node)) {
                bmFolder = (BookmarkFolder) node.getCell().getValue();
            }
            if (bmFolder != null) {
                bmFolder.getFolders().clear();
                bmFolder.getBookmarks().clear();
                for (ITreeNode n : node.getChildNodes()) {
                    if (isFolderNode(n)) {
                        bmFolder.getFolders().add((BookmarkFolder) n.getCell().getValue());
                    } else if (isBookmarkNode(n)) {
                        bmFolder.getBookmarks().add((Bookmark) n.getCell().getValue());
                    }
                }
            }
            return true;
        }
    });
    // save
    BEANS.get(IBookmarkService.class).storeBookmarks();
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) BookmarkFolder(org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkFolder) IBookmarkService(org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkService) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Example 5 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class AbstractBookmarkTreeField method rebuildBookmarkModel.

/**
 * The structure of the folders has changed, completely rebuild the model
 */
private void rebuildBookmarkModel() {
    getTree().visitTree(new ITreeVisitor() {

        @Override
        public boolean visit(ITreeNode node) {
            BookmarkFolder bmFolder = null;
            if (node == getTree().getRootNode()) {
                bmFolder = getBookmarkRootFolder();
            } else if (isFolderNode(node)) {
                bmFolder = (BookmarkFolder) node.getCell().getValue();
            }
            if (bmFolder != null) {
                bmFolder.getFolders().clear();
                bmFolder.getBookmarks().clear();
                // sort folders
                ArrayList<BookmarkFolder> folderList = new ArrayList<BookmarkFolder>();
                for (ITreeNode n : node.getChildNodes()) {
                    if (isFolderNode(n)) {
                        BookmarkFolder f = (BookmarkFolder) n.getCell().getValue();
                        folderList.add(f);
                    }
                }
                Collections.sort(folderList, new Comparator<BookmarkFolder>() {

                    @Override
                    public int compare(BookmarkFolder f1, BookmarkFolder f2) {
                        return StringUtility.compareIgnoreCase(f1.getTitle(), f2.getTitle());
                    }
                });
                bmFolder.getFolders().addAll(folderList);
                for (ITreeNode n : node.getChildNodes()) {
                    if (isBookmarkNode(n)) {
                        bmFolder.getBookmarks().add((Bookmark) n.getCell().getValue());
                    }
                }
            }
            return true;
        }
    });
    // save
    BEANS.get(IBookmarkService.class).storeBookmarks();
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark) BookmarkFolder(org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkFolder) ArrayList(java.util.ArrayList) IBookmarkService(org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkService) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor) Comparator(java.util.Comparator)

Aggregations

ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)95 Test (org.junit.Test)34 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)29 ArrayList (java.util.ArrayList)23 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)16 JSONObject (org.json.JSONObject)14 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)12 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)11 JSONArray (org.json.JSONArray)10 HashSet (java.util.HashSet)9 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)6 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)6 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)5 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)5 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)5 LinkedList (java.util.LinkedList)4 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)4 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)4 ITreeNodeFilter (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter)3 StyleField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.SmartFieldTest.TestForm.MainBox.StyleField)3