Search in sources :

Example 26 with ITree

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

the class AbstractPage method reloadPage.

@Override
public final void reloadPage() {
    ITree tree = getTree();
    if (tree == null) {
        return;
    }
    try {
        tree.setTreeChanging(true);
        loadChildren();
    } finally {
        tree.setTreeChanging(false);
    }
}
Also used : ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree)

Example 27 with ITree

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

the class AbstractPage method disposeInternal.

@Override
public void disposeInternal() {
    super.disposeInternal();
    try {
        interceptDisposePage();
        disposeDetailForm();
        disposeTable();
        fireAfterPageDispose();
    } catch (RuntimeException | PlatformError e) {
        BEANS.get(ExceptionHandler.class).handle(e);
    }
    // automatically remove all data change listeners
    ITree tree = getTree();
    if (tree != null) {
        tree.removeTreeListener(m_treeListener);
    }
    if (m_internalDataChangeListener != null) {
        IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
        if (desktop != null) {
            desktop.removeDataChangeListener(m_internalDataChangeListener);
        }
    }
}
Also used : PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop)

Example 28 with ITree

use of org.eclipse.scout.rt.client.ui.basic.tree.ITree 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 29 with ITree

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

the class TreeContextMenu method handleOwnerEnabledChanged.

protected void handleOwnerEnabledChanged() {
    ITree container = getContainer();
    if (container != null) {
        final boolean enabled = container.isEnabled();
        acceptVisitor(new IActionVisitor() {

            @Override
            public int visit(IAction action) {
                if (action instanceof IMenu) {
                    IMenu menu = (IMenu) action;
                    if (!menu.hasChildActions() && menu.isInheritAccessibility()) {
                        menu.setEnabledInheritAccessibility(enabled);
                    }
                }
                return CONTINUE;
            }
        });
    }
}
Also used : IActionVisitor(org.eclipse.scout.rt.client.ui.action.IActionVisitor) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree)

Example 30 with ITree

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

the class SmartFieldTest method testHierarchyNoResult.

@Test
public void testHierarchyNoResult() {
    StyleField f = m_styleField;
    f.setBrowseHierarchy(true);
    m_styleField.getUIFacade().openProposalChooserFromUI("unknown", false, false);
    waitForProposalResult(IProposalChooser.PROP_STATUS);
    // single result
    assertTrue(m_styleField.isProposalChooserRegistered());
    assertEquals("unknown", m_styleField.getDisplayText());
    // verifies tree is loaded containing a single node
    @SuppressWarnings("unchecked") TreeProposalChooser<Long> treeProposalChooser = (TreeProposalChooser<Long>) f.getProposalChooser();
    ITree tree = treeProposalChooser.getModel();
    ITreeNode rootNode = tree.getRootNode();
    assertEquals(0, rootNode.getChildNodes().size());
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) StyleField(org.eclipse.scout.rt.client.ui.form.fields.smartfield.SmartFieldTest.TestForm.MainBox.StyleField) Test(org.junit.Test)

Aggregations

ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)54 Test (org.junit.Test)40 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)30 ArrayList (java.util.ArrayList)17 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)13 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)11 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)6 JSONObject (org.json.JSONObject)5 List (java.util.List)4 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)4 StyleField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.SmartFieldTest.TestForm.MainBox.StyleField)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3 HashSet (java.util.HashSet)3 ITreeNodeFilter (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter)3 TreeAdapter (org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter)3 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)3 WeakReference (java.lang.ref.WeakReference)2 IAction (org.eclipse.scout.rt.client.ui.action.IAction)2 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)2