Search in sources :

Example 1 with TriState

use of org.eclipse.scout.rt.platform.util.TriState 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 2 with TriState

use of org.eclipse.scout.rt.platform.util.TriState in project scout.rt by eclipse.

the class AbstractSmartField2 method callBrowseLookupInBackground.

@Override
public IFuture<List<ILookupRow<VALUE>>> callBrowseLookupInBackground(String browseHint, boolean cancelRunningJobs) {
    TriState activeState = isActiveFilterEnabled() ? getActiveFilter() : TriState.TRUE;
    final ILookupRowProvider<VALUE> provider = newByAllLookupRowProvider(browseHint, activeState);
    return callInBackground(provider, cancelRunningJobs);
}
Also used : TriState(org.eclipse.scout.rt.platform.util.TriState)

Example 3 with TriState

use of org.eclipse.scout.rt.platform.util.TriState in project scout.rt by eclipse.

the class AbstractSqlStyle method toPlainText.

@Override
public String toPlainText(Object value) {
    if (value instanceof IHolder) {
        value = ((IHolder) value).getValue();
    }
    // 
    if (value == null) {
        return "null";
    } else if (value instanceof Boolean) {
        Boolean b = (Boolean) value;
        return b ? "1" : "0";
    } else if (value instanceof TriState) {
        TriState t = (TriState) value;
        return "" + t.toString();
    } else if (value instanceof String) {
        String s = (String) value;
        if (s.length() > MAX_SQL_STRING_LENGTH) {
            s = s.substring(0, MAX_SQL_STRING_LENGTH);
            LOG.warn("toPlainText of a String with more than {} characters failed; truncated to '{}'", MAX_SQL_STRING_LENGTH, s);
            return "'" + s.replaceAll("'", "''") + "'";
        }
        return "'" + s.replaceAll("'", "''") + "'";
    } else if (value instanceof char[]) {
        if (((char[]) value).length > MAX_SQL_STRING_LENGTH) {
            String s = new String((char[]) value, 0, MAX_SQL_STRING_LENGTH);
            LOG.warn("toPlainText of a CLOB with more than {} characters failed; truncated to '{}'", MAX_SQL_STRING_LENGTH, s);
            return "'" + s.replaceAll("'", "''") + "'";
        }
        String s = new String((char[]) value);
        return "'" + s.replaceAll("'", "''") + "'";
    } else if (value instanceof byte[]) {
        LOG.warn("toPlainText of a BLOB failed; using NULL");
        return "NULL";
    } else if (value instanceof Date) {
        Date d = (Date) value;
        SimpleDateFormat fmt = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
        return "to_date('" + fmt.format(d) + "','dd.mm.yyyy hh24:mi:ss')";
    } else if (value instanceof Collection || value.getClass().isArray()) {
        Object array;
        if (value instanceof Collection) {
            array = ((Collection) value).toArray();
        } else {
            array = value;
        }
        int n = Array.getLength(array);
        StringBuilder buf = new StringBuilder();
        buf.append("(");
        if (n > 0) {
            for (int i = 0; i < n; i++) {
                if (i > 0) {
                    buf.append(",");
                }
                buf.append(toPlainText(Array.get(array, i)));
            }
        } else {
            buf.append("-1");
        }
        buf.append(")");
        return buf.toString();
    } else {
        return value.toString();
    }
}
Also used : IHolder(org.eclipse.scout.rt.platform.holders.IHolder) Collection(java.util.Collection) TriState(org.eclipse.scout.rt.platform.util.TriState) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with TriState

use of org.eclipse.scout.rt.platform.util.TriState in project scout.rt by eclipse.

the class AbstractContentAssistField method callBrowseLookupInBackground.

@Override
public IFuture<List<ILookupRow<LOOKUP_KEY>>> callBrowseLookupInBackground(String browseHint, boolean cancelRunningJobs) {
    TriState activeState = isActiveFilterEnabled() ? getActiveFilter() : TriState.TRUE;
    final ILookupRowProvider<LOOKUP_KEY> provider = newByAllLookupRowProvider(browseHint, activeState);
    return callInBackground(provider, cancelRunningJobs);
}
Also used : TriState(org.eclipse.scout.rt.platform.util.TriState)

Aggregations

TriState (org.eclipse.scout.rt.platform.util.TriState)4 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 Date (java.util.Date)1 ISmartField2 (org.eclipse.scout.rt.client.ui.form.fields.smartfield2.ISmartField2)1 SmartField2Result (org.eclipse.scout.rt.client.ui.form.fields.smartfield2.SmartField2Result)1 IHolder (org.eclipse.scout.rt.platform.holders.IHolder)1 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)1 LookupRow (org.eclipse.scout.rt.shared.services.lookup.LookupRow)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1