Search in sources :

Example 41 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class TreeBoxTest method testDefaultBehavior.

/**
 * Select a parent node in a tree box and check whether only this node is selected..
 * {@link AbstractTreeBox#getConfiguredAutoCheckChildNodes} returns false on the {@link SimpleTreeBox}. Bug 368107 -
 * Check child nodes when parent node is checked
 */
@Test
public void testDefaultBehavior() throws Exception {
    SimpleTreeBox treeBox = createSimpleTreeBox();
    ITree tree = treeBox.getTree();
    // A
    ITreeNode node = tree.findNode(1L);
    assertNotNull(node);
    tree.setNodeChecked(node, true);
    Set<Long> valueSet = new HashSet<Long>(treeBox.getValue());
    // only one node selected
    assertEquals(1, valueSet.size());
    // and the selected one is the node explicitly set before
    // A
    assertEquals(true, valueSet.contains(1L));
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 42 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class BookmarkUtility method bmLoadTablePage.

private static IPage<?> bmLoadTablePage(IPageWithTable tablePage, TablePageState tablePageState, boolean leafState, boolean resetViewAndWarnOnFail) {
    ITable table = tablePage.getTable();
    if (tablePageState.getTableCustomizerData() != null && tablePage.getTable().getTableCustomizer() != null) {
        byte[] newData = tablePageState.getTableCustomizerData();
        ITableCustomizer tc = tablePage.getTable().getTableCustomizer();
        byte[] curData = tc.getSerializedData();
        if (ObjectUtility.notEquals(curData, newData)) {
            tc.removeAllColumns();
            tc.setSerializedData(newData);
            table.resetColumnConfiguration();
            tablePage.setChildrenLoaded(false);
        }
    }
    // starts search form
    tablePage.getSearchFilter();
    // setup table
    try {
        table.setTableChanging(true);
        restoreTableColumns(tablePage.getTable(), tablePageState.getAvailableColumns());
    } finally {
        table.setTableChanging(false);
    }
    // setup user filter
    if (tablePageState.getUserFilterData() != null && tablePage.getTable().getUserFilterManager() != null) {
        byte[] newData = tablePageState.getUserFilterData();
        TableUserFilterManager ufm = tablePage.getTable().getUserFilterManager();
        byte[] curData = ufm.getSerializedData();
        if (ObjectUtility.notEquals(curData, newData)) {
            try {
                ufm.setSerializedData(newData);
            } catch (RuntimeException e) {
                LOG.error("User filters could not be restored. ", e);
            }
        }
    }
    // setup search
    if (tablePageState.getSearchFormState() != null) {
        ISearchForm searchForm = tablePage.getSearchFormInternal();
        if (searchForm != null) {
            boolean doSearch = true;
            String newSearchFilterState = tablePageState.getSearchFilterState();
            String oldSearchFilterState = "" + createSearchFilterCRC(searchForm.getSearchFilter());
            if (ObjectUtility.equals(oldSearchFilterState, newSearchFilterState)) {
                String newSearchFormState = tablePageState.getSearchFormState();
                String oldSearchFormState = searchForm.storeToXmlString();
                if (ObjectUtility.equals(oldSearchFormState, newSearchFormState)) {
                    doSearch = false;
                }
            }
            // in case search form is in correct state, but no search has been executed, force search
            if (tablePage.getTable().getRowCount() == 0) {
                doSearch = true;
            }
            if (doSearch) {
                searchForm.loadFromXmlString(tablePageState.getSearchFormState());
                if (tablePageState.isSearchFilterComplete()) {
                    searchForm.doSaveWithoutMarkerChange();
                }
            }
        }
    }
    IPage<?> childPage = null;
    boolean loadChildren = !leafState;
    if (tablePage.isChildrenDirty() || tablePage.isChildrenVolatile()) {
        loadChildren = true;
        tablePage.setChildrenLoaded(false);
    }
    if (loadChildren) {
        tablePage.ensureChildrenLoaded();
        tablePage.setChildrenDirty(false);
        CompositeObject childPk = tablePageState.getExpandedChildPrimaryKey();
        if (childPk != null) {
            for (int r = 0; r < table.getRowCount(); r++) {
                CompositeObject testPkLegacy = new CompositeObject(BookmarkUtility.makeSerializableKeys(table.getRowKeys(r), true));
                CompositeObject testPk = new CompositeObject(BookmarkUtility.makeSerializableKeys(table.getRowKeys(r), false));
                if (testPk.equals(childPk) || testPkLegacy.equals(childPk)) {
                    if (r < tablePage.getChildNodeCount()) {
                        childPage = tablePage.getChildPage(r);
                    }
                    break;
                }
            }
        } else {
            List<ITreeNode> filteredChildNodes = tablePage.getFilteredChildNodes();
            if (filteredChildNodes.size() > 0) {
                childPage = (IPage) CollectionUtility.firstElement(filteredChildNodes);
            } else if (tablePage.getChildNodeCount() > 0) {
                childPage = tablePage.getChildPage(0);
            }
        }
    }
    // load selections
    if (leafState) {
        if (tablePageState.getSelectedChildrenPrimaryKeys().size() > 0) {
            tablePage.ensureChildrenLoaded();
            HashSet<CompositeObject> selectionSet = new HashSet<CompositeObject>(tablePageState.getSelectedChildrenPrimaryKeys());
            ArrayList<ITableRow> rowList = new ArrayList<ITableRow>();
            for (ITableRow row : table.getRows()) {
                CompositeObject testPkLegacy = new CompositeObject(BookmarkUtility.makeSerializableKeys(row.getKeyValues(), true));
                CompositeObject testPk = new CompositeObject(BookmarkUtility.makeSerializableKeys(row.getKeyValues(), false));
                if ((selectionSet.contains(testPk) || selectionSet.contains(testPkLegacy)) && row.isFilterAccepted()) {
                    rowList.add(row);
                }
            }
            if (rowList.size() > 0) {
                table.selectRows(rowList);
            }
        }
        return childPage;
    }
    // check, whether table column filter must be reset
    if (resetViewAndWarnOnFail) {
        final boolean childPageHidden = childPage == null || (!childPage.isFilterAccepted() && table.getUserFilterManager() != null);
        if (childPageHidden) {
            table.getUserFilterManager().reset();
            tablePage.setTableStatus(new Status(TEXTS.get("BookmarkResetColumnFilters"), IStatus.WARNING));
        }
    }
    // child page is not available or filtered out
    if (childPage == null || !childPage.isFilterAccepted()) {
        if (resetViewAndWarnOnFail) {
            // set appropriate warning
            if (tablePage.isSearchActive() && tablePage.getSearchFormInternal() != null) {
                tablePage.setTableStatus(new Status(TEXTS.get("BookmarkResolutionCanceledCheckSearchCriteria"), IStatus.ERROR));
            } else {
                tablePage.setTableStatus(new Status(TEXTS.get("BookmarkResolutionCanceled"), IStatus.ERROR));
            }
        }
        childPage = null;
    }
    return childPage;
}
Also used : IStatus(org.eclipse.scout.rt.platform.status.IStatus) Status(org.eclipse.scout.rt.platform.status.Status) ArrayList(java.util.ArrayList) TableUserFilterManager(org.eclipse.scout.rt.client.ui.basic.table.userfilter.TableUserFilterManager) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) CompositeObject(org.eclipse.scout.rt.platform.util.CompositeObject) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ISearchForm(org.eclipse.scout.rt.client.ui.desktop.outline.pages.ISearchForm) ITableCustomizer(org.eclipse.scout.rt.client.ui.basic.table.customizer.ITableCustomizer) HashSet(java.util.HashSet)

Example 43 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class AbstractPageWithTable method loadChildrenImpl.

/**
 * load tree children<br>
 * this method delegates to the table reload<br>
 * when the table is loaded and this node is not a leaf node then the table rows are mirrored in child nodes
 */
@Override
protected final void loadChildrenImpl() {
    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();
        }
        List<Object> oldSelectedRowKeys = null;
        if (oldSelectedNode != null) {
            ITreeNode t = oldSelectedNode;
            while (t != null && t.getParentNode() != null) {
                if (t.getParentNode() == this) {
                    oldSelectionOwned = true;
                    oldSelectedRowKeys = getTableRowFor(t).getKeyValues();
                    oldSelectionDirectChildIndex = t.getChildNodeIndex();
                    break;
                }
                t = t.getParentNode();
            }
        }
        // 
        setChildrenLoaded(false);
        fireBeforeDataLoaded();
        try {
            loadTableDataImpl();
        } catch (ThreadInterruptedError | FutureCancelledError e) {
        // NOSONAR
        // NOOP
        } finally {
            fireAfterDataLoaded();
        }
        setChildrenLoaded(true);
        setChildrenDirty(false);
        // table events will handle automatic tree changes in case table is mirrored in tree.
        // restore currently selected tree node when it was owned by our table rows.
        // in case selection was lost, try to select similar index as before
        T table = getTable();
        if (tree != null && table != null && oldSelectionOwned && tree.getSelectedNode() == null) {
            ITreeNode newSelectedNode = null;
            ITableRow row = table.getSelectedRow();
            if (row != null) {
                newSelectedNode = getTreeNodeFor(row);
            } else {
                row = table.findRowByKey(oldSelectedRowKeys);
                if (row != null) {
                    newSelectedNode = getTreeNodeFor(row);
                } else if (oldSelectedNode != null && oldSelectedNode.getTree() == tree) {
                    // NOSONAR
                    newSelectedNode = oldSelectedNode;
                } else {
                    int index = Math.max(-1, Math.min(oldSelectionDirectChildIndex, getChildNodeCount() - 1));
                    if (index >= 0 && index < getChildNodeCount()) {
                        newSelectedNode = getChildNode(index);
                    } else {
                        newSelectedNode = this;
                    }
                }
            }
            if (newSelectedNode != null) {
                tree.selectNode(newSelectedNode);
            }
        }
    } finally {
        if (tree != null) {
            tree.setTreeChanging(false);
        }
    }
    IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
    if (desktop != null) {
        desktop.afterTablePageLoaded(this);
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) FutureCancelledError(org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError) ThreadInterruptedError(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop)

Example 44 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class AbstractBookmarkTreeField method getParentBookmarkFolder.

private BookmarkFolder getParentBookmarkFolder(ITreeNode node) {
    BookmarkFolder folder = getBookmarkRootFolder();
    ITreeNode parentNode = node.getParentNode();
    if (isFolderNode(parentNode)) {
        folder = (BookmarkFolder) parentNode.getCell().getValue();
    }
    return folder;
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) BookmarkFolder(org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkFolder)

Example 45 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class JsonTree method handleModelNodesInserted.

protected void handleModelNodesInserted(TreeEvent event) {
    JSONArray jsonNodes = new JSONArray();
    // TODO [7.0] cgu: why not inside loop? attaching for rejected nodes?
    attachNodes(event.getNodes(), true);
    for (ITreeNode node : event.getNodes()) {
        if (isNodeAccepted(node)) {
            jsonNodes.put(treeNodeToJson(node));
        }
    }
    if (jsonNodes.length() == 0) {
        return;
    }
    JSONObject jsonEvent = new JSONObject();
    putProperty(jsonEvent, PROP_NODES, jsonNodes);
    putProperty(jsonEvent, PROP_COMMON_PARENT_NODE_ID, getOrCreateNodeId(event.getCommonParentNode()));
    addActionEvent(EVENT_NODES_INSERTED, jsonEvent);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

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