Search in sources :

Example 6 with LookupRow

use of org.eclipse.scout.rt.shared.services.lookup.LookupRow in project scout.rt by eclipse.

the class JsonTableTest method testTableEventCoalesceInUi_ReplaceRows.

@Test
public void testTableEventCoalesceInUi_ReplaceRows() throws Exception {
    ListBoxTable listbox = new ListBoxTable();
    ILookupRow<Long> row1 = new LookupRow<Long>(1L, "Row1");
    ILookupRow<Long> row2 = new LookupRow<Long>(2L, "Row2").withActive(false);
    ILookupRow<Long> row3 = new LookupRow<Long>(3L, "Row3");
    ILookupRow<Long> row4 = new LookupRow<Long>(4L, "Row4");
    ArrayList<ITableRow> rowsInitial = new ArrayList<ITableRow>();
    rowsInitial.add(listbox.getTableRowBuilder().createTableRow(row1));
    rowsInitial.add(listbox.getTableRowBuilder().createTableRow(row2));
    rowsInitial.add(listbox.getTableRowBuilder().createTableRow(row3));
    ITable table = listbox.getTable();
    table.addRows(rowsInitial);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    m_uiSession.currentJsonResponse().addAdapter(jsonTable);
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    JSONArray events = response.optJSONArray("events");
    ArrayList<ITableRow> rowsUpdate = new ArrayList<ITableRow>();
    rowsUpdate.add(listbox.getTableRowBuilder().createTableRow(row1));
    rowsUpdate.add(listbox.getTableRowBuilder().createTableRow(row2));
    rowsUpdate.add(listbox.getTableRowBuilder().createTableRow(row3));
    rowsUpdate.add(listbox.getTableRowBuilder().createTableRow(row4));
    table.replaceRows(rowsUpdate);
    response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    events = response.optJSONArray("events");
    JSONObject lastEvent = events.optJSONObject(events.length() - 1);
    assertEquals(lastEvent.optString("type"), "rowOrderChanged");
    JSONArray rowIds = lastEvent.optJSONArray("rowIds");
    assertTrue(rowIds.length() == 3);
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) ListBoxTable(org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable) Test(org.junit.Test)

Example 7 with LookupRow

use of org.eclipse.scout.rt.shared.services.lookup.LookupRow 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

ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)7 LookupRow (org.eclipse.scout.rt.shared.services.lookup.LookupRow)7 ArrayList (java.util.ArrayList)5 List (java.util.List)3 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)3 JSONObject (org.json.JSONObject)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 JSONArray (org.json.JSONArray)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 TreeSet (java.util.TreeSet)1 IBookmarkService (org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkService)1 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)1 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)1 AbstractTree (org.eclipse.scout.rt.client.ui.basic.tree.AbstractTree)1 TreeAdapter (org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter)1 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)1 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)1 ISmartField2 (org.eclipse.scout.rt.client.ui.form.fields.smartfield2.ISmartField2)1