Search in sources :

Example 1 with ITreeVisitor

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

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

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

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

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor 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)16 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)16 HashSet (java.util.HashSet)4 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)4 ArrayList (java.util.ArrayList)3 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)3 IBookmarkService (org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkService)2 Holder (org.eclipse.scout.rt.platform.holders.Holder)2 BookmarkFolder (org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkFolder)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1 Order (org.eclipse.scout.rt.platform.Order)1 ConfigOperation (org.eclipse.scout.rt.platform.annotations.ConfigOperation)1 ExceptionHandler (org.eclipse.scout.rt.platform.exception.ExceptionHandler)1 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)1 Bookmark (org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark)1