Search in sources :

Example 6 with TreeEvent

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

the class JsonTree method applyFilterChangedEventToUiRec.

/**
 * Recursively traverses through the given nodes (and its child nodes) and checks which of the model nodes are hidden
 * by tree filters.
 * <ul>
 * <li>For every newly hidden node (i.e. a node that is currently visible on the UI) a NODES_DELETED event is created.
 * <li>For every newly visible node (i.e. a node that is currently invisible on the UI) a NODES_INSERTED event is
 * created.
 * </ul>
 * All new events are added to the event buffer, where they might be coalesced later.
 */
protected void applyFilterChangedEventToUiRec(List<ITreeNode> nodes) {
    for (ITreeNode node : nodes) {
        boolean processChildNodes = true;
        if (!isInvisibleRootNode(node) && node.getTree() != null) {
            String existingNodeId = optNodeId(node);
            if (node.isFilterAccepted()) {
                if (existingNodeId == null) {
                    // Node is not filtered but JsonTree does not know it yet --> handle as insertion event
                    m_eventBuffer.add(new TreeEvent(node.getTree(), TreeEvent.TYPE_NODES_INSERTED, node));
                    // Stop recursion, because this node (including its child nodes) is already inserted
                    processChildNodes = false;
                }
            } else if (!node.isRejectedByUser()) {
                if (existingNodeId != null) {
                    // Node is filtered, but JsonTree has it in its list --> handle as deletion event
                    m_eventBuffer.add(new TreeEvent(node.getTree(), TreeEvent.TYPE_NODES_DELETED, node));
                }
                // Stop recursion, because this node (including its child nodes) is already deleted
                processChildNodes = false;
            }
        }
        // Recursion
        if (processChildNodes) {
            applyFilterChangedEventToUiRec(node.getChildNodes());
        }
    }
}
Also used : TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)

Example 7 with TreeEvent

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

the class JsonTree method init.

@Override
public void init() {
    super.init();
    // Replay missed events
    IEventHistory<TreeEvent> eventHistory = getModel().getEventHistory();
    if (eventHistory != null) {
        for (TreeEvent event : eventHistory.getRecentEvents()) {
            // Immediately execute events (no buffering), because this method is not called
            // from the model but from the JSON layer. If Response.toJson() is in progress,
            // adding this adapter to the list of buffered event providers would cause
            // an exception.
            processBufferedEvent(event);
        }
    }
}
Also used : TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)

Example 8 with TreeEvent

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

the class JsonTreeTest method testDeletionOfAllChildrenOfUnknownNode.

@Test
public void testDeletionOfAllChildrenOfUnknownNode() throws Exception {
    IOutline outline = new Outline(new ArrayList<IPage<?>>());
    ITreeNode parent = new TablePage(0);
    ITreeNode node1 = new TablePage(0);
    node1.setParentNodeInternal(parent);
    ITreeNode node2 = new TablePage(0);
    node2.setParentNodeInternal(parent);
    ITreeNode node3 = new TablePage(0);
    node3.setParentNodeInternal(parent);
    outline.addChildNode(outline.getRootNode(), parent);
    outline.addChildNode(parent, node1);
    outline.addChildNode(parent, node2);
    outline.addChildNode(parent, node3);
    JsonOutline<IOutline> jsonOutline = m_uiSession.createJsonAdapter(outline, null);
    List<ITreeNode> allChildren = CollectionUtility.arrayList(node1, node2, node3);
    jsonOutline.bufferModelEvent(new TreeEvent(outline, TreeEvent.TYPE_ALL_CHILD_NODES_DELETED, parent, allChildren));
    try {
        jsonOutline.processBufferedEvents();
    } catch (UiException e) {
        fail("Regression of ticket 210096: Tree does not contain node whose children are to be deleted.");
    }
}
Also used : TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TablePage(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.TablePage) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) Outline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline) JsonOutline(org.eclipse.scout.rt.ui.html.json.desktop.JsonOutline) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) UiException(org.eclipse.scout.rt.ui.html.UiException) Test(org.junit.Test)

Example 9 with TreeEvent

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

the class AbstractTreeBox method initConfig.

@SuppressWarnings("unchecked")
@Override
protected void initConfig() {
    m_fields = CollectionUtility.emptyArrayList();
    m_movedFormFieldsByClass = new HashMap<Class<? extends IFormField>, IFormField>();
    super.initConfig();
    setFilterActiveNodes(getConfiguredFilterActiveNodes());
    setFilterActiveNodesValue(TriState.TRUE);
    setFilterCheckedNodes(getConfiguredFilterCheckedNodes());
    setFilterCheckedNodesValue(getConfiguredFilterCheckedNodes());
    setAutoExpandAll(getConfiguredAutoExpandAll());
    setLoadIncremental(getConfiguredLoadIncremental());
    List<ITree> contributedTrees = m_contributionHolder.getContributionsByClass(ITree.class);
    m_tree = CollectionUtility.firstElement(contributedTrees);
    if (m_tree == null) {
        Class<? extends ITree> configuredTree = getConfiguredTree();
        if (configuredTree != null) {
            m_tree = ConfigurationUtility.newInnerInstance(this, configuredTree);
        }
    }
    if (m_tree != null) {
        if (m_tree instanceof AbstractTree) {
            ((AbstractTree) m_tree).setContainerInternal(this);
        }
        m_tree.setRootNode(getTreeNodeBuilder().createTreeNode(new LookupRow(null, "Root"), ITreeNode.STATUS_NON_CHANGED, false));
        m_tree.setAutoDiscardOnDelete(false);
        updateActiveNodesFilter();
        updateCheckedNodesFilter();
        m_tree.addTreeListener(new TreeAdapter() {

            @Override
            public void treeChanged(TreeEvent e) {
                switch(e.getType()) {
                    case TreeEvent.TYPE_NODES_SELECTED:
                        {
                            if (!getTree().isCheckable()) {
                                syncTreeToValue();
                            }
                            break;
                        }
                    case TreeEvent.TYPE_NODES_CHECKED:
                        {
                            if (getTree().isCheckable()) {
                                syncTreeToValue();
                            }
                            break;
                        }
                }
            }
        });
        m_tree.setEnabled(isEnabled());
        // default icon
        if (this.getConfiguredIconId() != null) {
            m_tree.setDefaultIconId(this.getConfiguredIconId());
        }
    } else {
        LOG.warn("there is no inner class of type ITree in {}", getClass().getName());
    }
    getTree().setAutoCheckChildNodes(getConfiguredAutoCheckChildNodes());
    Class<? extends ILookupCall<T>> lookupCallClass = getConfiguredLookupCall();
    if (lookupCallClass != null) {
        ILookupCall<T> call = BEANS.get(lookupCallClass);
        setLookupCall(call);
    }
    // code type
    if (getConfiguredCodeType() != null) {
        setCodeTypeClass(getConfiguredCodeType());
    }
    // local property listener
    addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if (m_tree == null) {
                return;
            }
            String name = e.getPropertyName();
            if (PROP_ENABLED_COMPUTED.equals(name)) {
                boolean newEnabled = ((Boolean) e.getNewValue()).booleanValue();
                m_tree.setEnabled(newEnabled);
            } else if (PROP_FILTER_CHECKED_NODES_VALUE.equals(name)) {
                updateCheckedNodesFilter();
            } else if (PROP_FILTER_ACTIVE_NODES_VALUE.equals(name)) {
                updateActiveNodesFilter();
            }
        }
    });
    // add fields
    List<Class<? extends IFormField>> configuredFields = getConfiguredFields();
    List<IFormField> contributedFields = m_contributionHolder.getContributionsByClass(IFormField.class);
    List<IFormField> fieldList = new ArrayList<IFormField>(configuredFields.size() + contributedFields.size());
    for (Class<? extends IFormField> fieldClazz : configuredFields) {
        fieldList.add(ConfigurationUtility.newInnerInstance(this, fieldClazz));
    }
    fieldList.addAll(contributedFields);
    Collections.sort(fieldList, new OrderedComparator());
    for (IFormField f : fieldList) {
        f.setParentFieldInternal(this);
    }
    m_fields = fieldList;
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) PropertyChangeEvent(java.beans.PropertyChangeEvent) AbstractTree(org.eclipse.scout.rt.client.ui.basic.tree.AbstractTree) PropertyChangeListener(java.beans.PropertyChangeListener) ArrayList(java.util.ArrayList) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) TreeAdapter(org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter) TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator)

Aggregations

TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)9 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)5 ArrayList (java.util.ArrayList)4 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)4 Test (org.junit.Test)4 TreeAdapter (org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)2 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)2 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)2 AbstractTree (org.eclipse.scout.rt.client.ui.basic.tree.AbstractTree)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)1 RootNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.RootNode)1 OrderedComparator (org.eclipse.scout.rt.platform.OrderedComparator)1 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)1 LookupRow (org.eclipse.scout.rt.shared.services.lookup.LookupRow)1 UiException (org.eclipse.scout.rt.ui.html.UiException)1 JsonOutline (org.eclipse.scout.rt.ui.html.json.desktop.JsonOutline)1