Search in sources :

Example 1 with ITree

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

the class JsonTree method initJsonProperties.

@Override
protected void initJsonProperties(TREE model) {
    super.initJsonProperties(model);
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_TITLE, model) {

        @Override
        protected String modelValue() {
            return getModel().getTitle();
        }
    });
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_ICON_ID, model) {

        @Override
        protected String modelValue() {
            return getModel().getIconId();
        }

        @Override
        public Object prepareValueForToJson(Object value) {
            return BinaryResourceUrlUtility.createIconUrl((String) value);
        }
    });
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_CSS_CLASS, model) {

        @Override
        protected String modelValue() {
            return getModel().getCssClass();
        }
    });
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_CHECKABLE, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isCheckable();
        }
    });
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_MULTI_CHECK, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isMultiCheck();
        }
    });
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_ENABLED, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isEnabled();
        }
    });
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_LAZY_EXPANDING_ENABLED, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isLazyExpandingEnabled();
        }
    });
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_AUTO_CHECK_CHILDREN, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isAutoCheckChildNodes();
        }
    });
    putJsonProperty(new JsonProperty<ITree>(ITree.PROP_SCROLL_TO_SELECTION, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isScrollToSelection();
        }
    });
    putJsonProperty(new JsonProperty<ITree>(ITree.PROP_DROP_TYPE, model) {

        @Override
        protected Integer modelValue() {
            return getModel().getDropType();
        }
    });
    putJsonProperty(new JsonProperty<ITree>(ITree.PROP_DROP_MAXIMUM_SIZE, model) {

        @Override
        protected Long modelValue() {
            return getModel().getDropMaximumSize();
        }
    });
    putJsonProperty(new JsonAdapterProperty<ITree>(ITree.PROP_KEY_STROKES, model, getUiSession()) {

        @Override
        protected JsonAdapterPropertyConfig createConfig() {
            return new JsonAdapterPropertyConfigBuilder().filter(new DisplayableActionFilter<IAction>()).build();
        }

        @Override
        protected List<IKeyStroke> modelValue() {
            return getModel().getKeyStrokes();
        }
    });
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_DISPLAY_STYLE, model) {

        @Override
        protected String modelValue() {
            return getModel().getDisplayStyle();
        }
    });
    putJsonProperty(new JsonProperty<TREE>(ITree.PROP_TOGGLE_BREADCRUMB_STYLE_ENABLED, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isToggleBreadcrumbStyleEnabled();
        }
    });
}
Also used : JsonAdapterPropertyConfig(org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterPropertyConfig) IAction(org.eclipse.scout.rt.client.ui.action.IAction) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) JsonAdapterPropertyConfigBuilder(org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterPropertyConfigBuilder) ResourceListTransferObject(org.eclipse.scout.rt.client.ui.dnd.ResourceListTransferObject) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ITree

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

the class JsonOutlineTest method testDispose.

@Test
public void testDispose() {
    ITree tree = new OutlineWithOneNode();
    JsonTree<ITree> object = UiSessionTestUtility.newJsonAdapter(m_uiSession, tree, null);
    WeakReference<JsonTree> ref = new WeakReference<JsonTree>(object);
    object.dispose();
    m_uiSession = null;
    object = null;
    TestingUtility.assertGC(ref);
}
Also used : OutlineWithOneNode(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineWithOneNode) JsonTree(org.eclipse.scout.rt.ui.html.json.tree.JsonTree) WeakReference(java.lang.ref.WeakReference) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) JsonTreeTest(org.eclipse.scout.rt.ui.html.json.tree.JsonTreeTest) Test(org.junit.Test)

Example 3 with ITree

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

the class JsonTreeTest method testIgnorableSelectionEvent.

/**
 * Response must not contain the selection event if the selection was triggered by the request
 */
@Test
public void testIgnorableSelectionEvent() throws JSONException {
    ITree tree = createTreeWithOneNode();
    ITreeNode node = tree.getRootNode().getChildNode(0);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    JsonEvent event = createJsonSelectedEvent(jsonTree.getOrCreateNodeId(node));
    jsonTree.handleUiEvent(event);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODES_SELECTED);
    assertTrue(responseEvents.size() == 0);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 4 with ITree

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

the class JsonTreeTest method testNodeFilter.

@Test
public void testNodeFilter() throws JSONException {
    TreeNode nodeToFilter = new TreeNode();
    nodeToFilter.setEnabled(false);
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(nodeToFilter);
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    String node0Id = jsonTree.getOrCreateNodeId(nodes.get(0));
    assertNotNull(node0Id);
    assertNotNull(jsonTree.optTreeNodeForNodeId(node0Id));
    tree.addNodeFilter(new ITreeNodeFilter() {

        @Override
        public boolean accept(ITreeNode node, int level) {
            return node.isEnabled();
        }
    });
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertNull(jsonTree.optNodeId(nodes.get(0)));
    assertNull(jsonTree.optTreeNodeForNodeId(node0Id));
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) ITreeNodeFilter(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter) ArrayList(java.util.ArrayList) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 5 with ITree

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

the class JsonTreeTest method testWrongEventOrder.

/**
 * Tests that events are ignored when nodes are not yet inserted.
 */
@Test
public void testWrongEventOrder() throws JSONException {
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    TreeNode newNode = new TreeNode();
    jsonTree.handleModelTreeEvent(new TreeEvent(tree, TreeEvent.TYPE_NODE_EXPANDED, newNode));
    jsonTree.handleModelTreeEvent(new TreeEvent(tree, TreeEvent.TYPE_NODES_INSERTED, nodes.get(0), Collections.singletonList(newNode)));
    JsonTestUtility.processBufferedEvents(m_uiSession);
    List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(1, events.size());
    assertEquals("nodesInserted", events.get(0).getType());
}
Also used : TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) 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