Search in sources :

Example 1 with TreeAdapter

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

the class JsonTreeTest method testInsertAndDeleteInSameRequest.

@Test
public void testInsertAndDeleteInSameRequest() throws Exception {
    // Note: A test for the same problem (but without a real tree) can be found here:
    // org.eclipse.scout.rt.client.ui.basic.tree.TreeEventBufferTest.testInsertAndRemoveInSameRequest()
    ITree tree = new Tree();
    tree.setRootNode(new TreeNode("Root"));
    final List<TreeEvent> treeEventCollector = new ArrayList<>();
    tree.addTreeListener(new TreeAdapter() {

        @Override
        public void treeChanged(TreeEvent e) {
            treeEventCollector.add(e);
        }
    });
    IJsonAdapter<? super ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    m_uiSession.currentJsonResponse().addAdapter(jsonTree);
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #1: " + response);
    JsonTestUtility.endRequest(m_uiSession);
    // ----------------
    // (root)
    // +-[A]
    // +-[B]
    ITreeNode nodeA = new TreeNode("A");
    ITreeNode nodeB = new TreeNode("B");
    // Insert A and B in one "tree changing" batch
    // -> TreeEventBuffer should remove the second event (because B is a sub-node of A)
    tree.setTreeChanging(true);
    tree.addChildNode(tree.getRootNode(), nodeA);
    tree.addChildNode(nodeA, nodeB);
    tree.setTreeChanging(false);
    assertEquals(1, treeEventCollector.size());
    treeEventCollector.clear();
    // Remove B, then A (in two separate calls)
    // -> TreeEventBuffer should remove the second event (because B is a sub-node of A), altough
    // only an insertion event for A exists (and A.getChildNodes() returns nothing)
    tree.removeAllChildNodes(nodeA);
    tree.removeAllChildNodes(tree.getRootNode());
    assertEquals(2, treeEventCollector.size());
    treeEventCollector.clear();
    assertEquals(0, nodeA.getChildNodeCount());
    assertEquals(0, tree.getRootNode().getChildNodeCount());
    // Process the buffer
    // -> TreeEventBuffer should remove all events
    JsonTestUtility.processBufferedEvents(m_uiSession);
    List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(0, events.size());
    response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #2: " + response);
    JsonTestUtility.endRequest(m_uiSession);
}
Also used : ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) 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) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) Tree(org.eclipse.scout.rt.ui.html.json.tree.fixtures.Tree) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 2 with TreeAdapter

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

the class AbstractComposerField method initConfig.

@Override
protected void initConfig() {
    m_uiFacade = BEANS.get(ModelContextProxy.class).newProxy(new P_UIFacade(), ModelContext.copyCurrent());
    super.initConfig();
    m_dataModel = interceptCreateDataModel();
    // tree
    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) {
        RootNode rootNode = interceptCreateRootNode();
        rootNode.getCellForUpdate().setText(getLabel());
        m_tree.setRootNode(rootNode);
        m_tree.setNodeExpanded(rootNode, true);
        m_tree.setEnabled(isEnabled());
        m_tree.addTreeListener(new TreeAdapter() {

            @Override
            public void treeChanged(TreeEvent e) {
                switch(e.getType()) {
                    case TreeEvent.TYPE_NODES_DELETED:
                    case TreeEvent.TYPE_ALL_CHILD_NODES_DELETED:
                    case TreeEvent.TYPE_NODES_INSERTED:
                    case TreeEvent.TYPE_NODES_UPDATED:
                    case TreeEvent.TYPE_NODES_CHECKED:
                        {
                            checkSaveNeeded();
                            checkEmpty();
                            break;
                        }
                }
            }
        });
        // local enabled listener
        addPropertyChangeListener(PROP_ENABLED_COMPUTED, new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent e) {
                if (m_tree == null) {
                    return;
                }
                boolean newEnabled = ((Boolean) e.getNewValue()).booleanValue();
                m_tree.setEnabled(newEnabled);
            }
        });
    } else {
        LOG.warn("there is no inner class of type ITree in {}", getClass().getName());
    }
}
Also used : TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) RootNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.RootNode) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) TreeAdapter(org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter)

Example 3 with TreeAdapter

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

ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)3 TreeAdapter (org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter)3 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 ArrayList (java.util.ArrayList)2 AbstractTree (org.eclipse.scout.rt.client.ui.basic.tree.AbstractTree)1 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)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 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)1 Tree (org.eclipse.scout.rt.ui.html.json.tree.fixtures.Tree)1 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1