use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class OutlineMediator method mediateTableRowAction.
public void mediateTableRowAction(TableEvent e, IPage<?> page) {
if (e.isConsumed()) {
return;
}
ITreeNode node = page.getTreeNodeFor(e.getFirstRow());
if (node != null) {
e.consume();
ITree tree = page.getTree();
if (tree != null) {
tree.getUIFacade().setNodeSelectedAndExpandedFromUI(node);
}
}
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class AbstractPage method execDataChanged.
/**
* Called by the data change listener registered with this page (and the current desktop) through
* {@link #registerDataChangeListener(Object...)}. Use this callback method to react to data change events by
* reloading current data, or throwing away cached data etc.
* <p>
* Subclasses can override this method.<br/>
* This default implementation does the following:
* <ol>
* <li>if this page is an ancestor of the selected page (or is selected itself) and this page is in the active
* outline, a full re-load of the page is performed
* <li>else the children of this page are marked dirty and the page itself is unloaded
* </ol>
*
* @see IDesktop#dataChanged(Object...)
*/
@ConfigOperation
@Order(55)
protected void execDataChanged(Object... dataTypes) {
if (getTree() == null) {
return;
}
//
HashSet<ITreeNode> pathsToSelections = new HashSet<ITreeNode>();
for (ITreeNode node : getTree().getSelectedNodes()) {
ITreeNode tmp = node;
while (tmp != null) {
pathsToSelections.add(tmp);
tmp = tmp.getParentNode();
}
}
IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
final boolean isActiveOutline = (desktop != null ? desktop.getOutline() == this.getOutline() : false);
final boolean isRootNode = pathsToSelections.isEmpty() && getTree() != null && getTree().getRootNode() == this;
if (isActiveOutline && (pathsToSelections.contains(this) || isRootNode)) {
try {
// TODO [7.0] fko: maybe remove when bookmarks can be done on outline level? (currently only pages)
if (isRootNode) {
this.reloadPage();
} else /*
* Ticket 77332 (deleting a node in the tree) also requires a reload So
* the selected and its ancestor nodes require same processing
*/
if (desktop != null) {
// NOSONAR
Bookmark bm = desktop.createBookmark();
setChildrenDirty(true);
// activate bookmark without activating the outline, since this would hide active tabs.
desktop.activateBookmark(bm, false);
}
} catch (RuntimeException | PlatformError e) {
BEANS.get(ExceptionHandler.class).handle(e);
}
} else {
// not active outline OR not on selection path
setChildrenDirty(true);
if (isExpanded()) {
setExpanded(false);
}
try {
if (isChildrenLoaded()) {
getTree().unloadNode(this);
}
} catch (RuntimeException | PlatformError e) {
BEANS.get(ExceptionHandler.class).handle(e);
}
}
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class AbstractPageWithNodes method updateContextMenusForSelection.
protected void updateContextMenusForSelection() {
// remove old
if (m_pageMenusOfSelection != null) {
getTable().getContextMenu().removeChildActions(m_pageMenusOfSelection);
m_pageMenusOfSelection = null;
}
List<IMenu> pageMenus = new ArrayList<IMenu>();
List<ITableRow> selectedRows = getTable().getSelectedRows();
if (CollectionUtility.size(selectedRows) == 1) {
ITreeNode node = getTreeNodeFor(CollectionUtility.firstElement(selectedRows));
if (node instanceof IPageWithNodes) {
IPageWithNodes pageWithNodes = (IPageWithNodes) node;
IActionFilter filter = ActionUtility.createMenuFilterMenuTypes(CollectionUtility.hashSet(TreeMenuType.SingleSelection), false);
List<IMenu> menus = ActionUtility.getActions(pageWithNodes.getMenus(), filter);
for (IMenu m : menus) {
pageMenus.add(new OutlineMenuWrapper(m, TREE_MENU_TYPE_MAPPER, filter));
}
}
}
getTable().getContextMenu().addChildActions(pageMenus);
m_pageMenusOfSelection = pageMenus;
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class AbstractPageWithNodes method loadChildrenImpl.
/**
* load tree children and fill table
*/
@Override
protected void loadChildrenImpl() {
List<IPage<?>> pageList = new ArrayList<IPage<?>>();
createChildPagesInternal(pageList);
// load tree
ITree tree = getTree();
try {
if (tree != null) {
tree.setTreeChanging(true);
}
//
// backup currently selected tree node and its path to root
boolean oldSelectionOwned = false;
int oldSelectionDirectChildIndex = -1;
ITreeNode oldSelectedNode = null;
if (tree != null) {
oldSelectedNode = tree.getSelectedNode();
}
String oldSelectedText = null;
if (oldSelectedNode != null) {
ITreeNode t = oldSelectedNode;
while (t != null && t.getParentNode() != null) {
if (t.getParentNode() == this) {
oldSelectionOwned = true;
oldSelectedText = t.getCell().getText();
oldSelectionDirectChildIndex = t.getChildNodeIndex();
break;
}
t = t.getParentNode();
}
}
setChildrenLoaded(false);
fireBeforeDataLoaded();
try {
if (tree != null) {
tree.removeAllChildNodes(this);
tree.addChildNodes(this, pageList);
}
} finally {
fireAfterDataLoaded();
}
setChildrenLoaded(true);
setChildrenDirty(false);
// in case selection was lost, try to select similar index as before
if (tree != null && oldSelectionOwned && tree.getSelectedNode() == null) {
if (oldSelectedNode != null && oldSelectedNode.getTree() == tree) {
// NOSONAR
tree.selectNode(oldSelectedNode);
} else {
int index = Math.max(-1, Math.min(oldSelectionDirectChildIndex, getChildNodeCount() - 1));
if (index >= 0 && index < getChildNodeCount() && ObjectUtility.equals(oldSelectedText, getChildNode(index).getCell().getText())) {
tree.selectNode(getChildNode(index));
} else if (index >= 0 && index < getChildNodeCount()) {
tree.selectNode(getChildNode(index));
} else {
tree.selectNode(this);
}
}
}
} finally {
if (tree != null) {
tree.setTreeChanging(false);
}
}
// copy to table
try {
getTable().setTableChanging(true);
rebuildTableInternal();
setTableStatus(null);
} finally {
getTable().setTableChanging(false);
}
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class AbstractPageWithNodes method rebuildTableInternal.
@Override
public void rebuildTableInternal() {
List<ITreeNode> childNodes = getChildNodes();
try {
getTable().setTableChanging(true);
//
unlinkAllTableRowWithPage();
getTable().discardAllRows();
for (ITreeNode childNode : childNodes) {
ITableRow row = new TableRow(getTable().getColumnSet());
updateCellFromPageCell(row.getCellForUpdate(0), childNode.getCell());
ITableRow insertedRow = getTable().addRow(row);
linkTableRowWithPage(insertedRow, (IPage) childNode);
}
} finally {
getTable().setTableChanging(false);
}
}
Aggregations