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();
}
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);
}
}
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();
}
}
}
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();
}
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();
}
Aggregations