Search in sources :

Example 31 with ITreeNode

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);
        }
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree)

Example 32 with ITreeNode

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);
        }
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) HashSet(java.util.HashSet) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Example 33 with ITreeNode

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;
}
Also used : OutlineMenuWrapper(org.eclipse.scout.rt.client.ui.desktop.outline.OutlineMenuWrapper) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ArrayList(java.util.ArrayList) IActionFilter(org.eclipse.scout.rt.client.ui.action.IActionFilter) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 34 with ITreeNode

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);
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ArrayList(java.util.ArrayList) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree)

Example 35 with ITreeNode

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);
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TableRow(org.eclipse.scout.rt.client.ui.basic.table.TableRow) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

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