Search in sources :

Example 1 with LookupRow

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

the class KeyStrokeLookupCall method execCreateLookupRows.

@Override
protected List<ILookupRow<String>> execCreateLookupRows() {
    final HashMap<String, Integer> keyStrokesUpper = new HashMap<String, Integer>();
    // build possible keyStrokes
    for (int i = 1; i <= 12; i++) {
        keyStrokesUpper.put("SHIFT-F" + i, Integer.valueOf(i));
    }
    // remove used keyStrokes
    IBookmarkService service = BEANS.get(IBookmarkService.class);
    IBookmarkVisitor v = new IBookmarkVisitor() {

        @Override
        public boolean visitFolder(List<BookmarkFolder> path) {
            return true;
        }

        @Override
        public boolean visitBookmark(List<BookmarkFolder> path, Bookmark b) {
            String keyStroke = b.getKeyStroke();
            if (keyStroke != null) {
                if (m_currentKeyStroke != null && m_currentKeyStroke.equalsIgnoreCase(keyStroke)) {
                // keep it
                } else {
                    keyStrokesUpper.remove(keyStroke.toUpperCase(Locale.ENGLISH));
                }
            }
            return true;
        }
    };
    service.getBookmarkData().getGlobalBookmarks().visit(v);
    service.getBookmarkData().getUserBookmarks().visit(v);
    // 
    TreeSet<Integer> availableNumbers = new TreeSet<Integer>(keyStrokesUpper.values());
    ArrayList<ILookupRow<String>> resultList = new ArrayList<ILookupRow<String>>();
    for (Integer i : availableNumbers) {
        String key = "Shift-F" + i;
        String text = "Shift-F" + i;
        ILookupRow<String> row = new LookupRow<String>(key, text);
        resultList.add(row);
    }
    return resultList;
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark) IBookmarkVisitor(org.eclipse.scout.rt.shared.services.common.bookmark.IBookmarkVisitor) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) IBookmarkService(org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkService)

Example 2 with LookupRow

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

the class JsonSmartField2 method initJsonProperties.

@Override
protected void initJsonProperties(MODEL model) {
    super.initJsonProperties(model);
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(IValueField.PROP_VALUE, model) {

        @Override
        protected VALUE modelValue() {
            return getModel().getValue();
        }

        @Override
        @SuppressWarnings("unchecked")
        public Object prepareValueForToJson(Object value) {
            return JsonSmartField2.this.valueToJson((VALUE) value);
        }
    });
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(ISmartField2.PROP_RESULT, model) {

        @Override
        protected Object modelValue() {
            return getModel().getResult();
        }

        @Override
        @SuppressWarnings("unchecked")
        public Object prepareValueForToJson(Object value) {
            return resultToJson((SmartField2Result<VALUE>) value);
        }
    });
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(ISmartField2.PROP_LOOKUP_ROW, model) {

        @Override
        protected Object modelValue() {
            return getModel().getLookupRow();
        }

        @Override
        @SuppressWarnings("unchecked")
        public Object prepareValueForToJson(Object value) {
            return lookupRowToJson((LookupRow<VALUE>) value, hasMultipleColumns());
        }
    });
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(ISmartField2.PROP_BROWSE_MAX_ROW_COUNT, model) {

        @Override
        protected Integer modelValue() {
            return getModel().getBrowseMaxRowCount();
        }
    });
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(ISmartField2.PROP_BROWSE_AUTO_EXPAND_ALL, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isBrowseAutoExpandAll();
        }
    });
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(ISmartField2.PROP_BROWSE_LOAD_INCREMENTAL, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isBrowseLoadIncremental();
        }
    });
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(ISmartField2.PROP_ACTIVE_FILTER_ENABLED, model) {

        @Override
        protected Boolean modelValue() {
            return getModel().isActiveFilterEnabled();
        }
    });
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(ISmartField2.PROP_ACTIVE_FILTER, model) {

        @Override
        protected TriState modelValue() {
            return getModel().getActiveFilter();
        }
    });
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(ISmartField2.PROP_ACTIVE_FILTER_LABELS, model) {

        @Override
        protected String[] modelValue() {
            return getModel().getActiveFilterLabels();
        }

        @Override
        public Object prepareValueForToJson(Object value) {
            return new JSONArray(value);
        }
    });
    putJsonProperty(new JsonProperty<ISmartField2<VALUE>>(ISmartField2.PROP_COLUMN_DESCRIPTORS, model) {

        @Override
        protected ColumnDescriptor[] modelValue() {
            return getModel().getColumnDescriptors();
        }

        @Override
        public Object prepareValueForToJson(Object value) {
            return columnDescriptorsToJson(value);
        }
    });
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) SmartField2Result(org.eclipse.scout.rt.client.ui.form.fields.smartfield2.SmartField2Result) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) TriState(org.eclipse.scout.rt.platform.util.TriState) ISmartField2(org.eclipse.scout.rt.client.ui.form.fields.smartfield2.ISmartField2)

Example 3 with LookupRow

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

the class JsonSmartField2 method handleUiAcceptInput.

@Override
protected void handleUiAcceptInput(JsonEvent event) {
    JSONObject data = event.getData();
    boolean valueSet = false;
    VALUE valueFromUi = null;
    if (data.has(IValueField.PROP_DISPLAY_TEXT)) {
        handleUiDisplayTextChange(data);
    }
    // When we have a lookup row, we prefer the lookup row over the value
    if (data.has(ISmartField2.PROP_LOOKUP_ROW)) {
        valueFromUi = valueFromJsonLookupRow(data);
        handleUiLookupRowChange(data);
        valueSet = true;
    } else if (data.has(IValueField.PROP_VALUE)) {
        valueFromUi = valueFromJsonValue(data);
        handleUiValueChange(data);
        valueSet = true;
    }
    // execValidateValue is overridden.
    if (valueSet) {
        VALUE valueFromModel = getModel().getValue();
        if (!ObjectUtility.equals(valueFromUi, valueFromModel)) {
            addPropertyChangeEvent(ISmartField2.PROP_LOOKUP_ROW, lookupRowToJson((LookupRow<?>) getModel().getLookupRow(), hasMultipleColumns()));
            String displayTextFromModel = getModel().getDisplayText();
            addPropertyChangeEvent(IValueField.PROP_DISPLAY_TEXT, displayTextFromModel);
        }
        return;
    }
    // Don't use error status from UI when value has been set
    if (data.has(IValueField.PROP_ERROR_STATUS)) {
        handleUiErrorStatusChange(data);
    }
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) JSONObject(org.json.JSONObject)

Example 4 with LookupRow

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

the class IncrementalTreeBuilderTest method testCreatePaths_NonEmpty.

@Test
public void testCreatePaths_NonEmpty() {
    @SuppressWarnings("unchecked") IKeyLookupProvider<Long> mockProvider = Mockito.mock(IKeyLookupProvider.class);
    ITree tree = createTestTree();
    IncrementalTreeBuilder<Long> builder = new IncrementalTreeBuilder<Long>(mockProvider);
    ArrayList<ILookupRow<Long>> rows = new ArrayList<>();
    rows.add(new LookupRow<Long>(1L, ""));
    rows.add(new LookupRow<Long>(2L, "").withParentKey(1L));
    List<List<ILookupRow<Long>>> paths = builder.createPaths(rows, tree);
    assertTrue(paths.size() == 2);
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ArrayList(java.util.ArrayList) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 5 with LookupRow

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

the class IncrementalTreeBuilderTest method testCreatePaths_NullKeyLookupRow.

@Test
public void testCreatePaths_NullKeyLookupRow() {
    final Map<Long, ILookupRow<Long>> lookupRowsMap = new HashMap<>();
    lookupRowsMap.put(1L, new LookupRow<Long>(1L, "A"));
    lookupRowsMap.put(2L, new LookupRow<Long>(2L, "A-B").withParentKey(1L));
    lookupRowsMap.put(null, new LookupRow<Long>(null, "(none)"));
    Collection<ILookupRow<Long>> rows = lookupRowsMap.values();
    IKeyLookupProvider<Long> provider = new IKeyLookupProvider<Long>() {

        @Override
        public ILookupRow<Long> getLookupRow(Long key) {
            return lookupRowsMap.get(key);
        }
    };
    ITree tree = createTestTree();
    IncrementalTreeBuilder<Long> builder = new IncrementalTreeBuilder<Long>(provider);
    List<List<ILookupRow<Long>>> paths = builder.createPaths(rows, tree);
    assertEquals(3, paths.size());
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) HashMap(java.util.HashMap) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

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