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;
}
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);
}
});
}
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);
}
}
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);
}
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());
}
Aggregations