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