Search in sources :

Example 1 with ComponentFormat

use of com.servoy.j2db.component.ComponentFormat in project servoy-client by Servoy.

the class WebDataButton method onBeforeRender.

/**
 * @see org.apache.wicket.Component#onBeforeRender()
 */
@Override
protected void onBeforeRender() {
    super.onBeforeRender();
    IModel<?> model = getInnermostModel();
    if (needEntireState && model instanceof RecordItemModel) {
        if (dataProviderID != null) {
            Object val = getModelObject();
            if (val instanceof byte[]) {
                setIcon((byte[]) val);
            } else if (icon != null) {
                setIcon(null);
            } else {
                try {
                    ComponentFormat fp = getScriptObject().getComponentFormat();
                    if (fp == null) {
                        bodyText = Text.processTags((String) val, resolver);
                    } else {
                        bodyText = Text.processTags(TagResolver.formatObject(val, application.getLocale(), fp.parsedFormat, (fp.parsedFormat.getDisplayFormat() != null ? new ServoyMaskFormatter(fp.parsedFormat.getDisplayFormat(), true) : null)), resolver);
                    }
                } catch (ParseException e) {
                    Debug.error(e);
                }
            }
        } else {
            bodyText = Text.processTags(tagText, resolver);
        }
        if (bodyText != null) {
            if (HtmlUtils.startsWithHtml(bodyText)) {
                bodyText = StripHTMLTagsConverter.convertBodyText(this, bodyText, getScriptObject().trustDataAsHtml(), application.getFlattenedSolution()).getBodyTxt();
            } else {
                // convert the text
                final IConverter converter = getConverter(String.class);
                bodyText = converter.convertToString(bodyText, getLocale());
            }
        }
    } else {
        Object modelObject = getModelObject();
        if (modelObject instanceof byte[]) {
            setIcon((byte[]) modelObject);
        } else if (icon != null) {
            setIcon(null);
        } else {
            ComponentFormat cf = getScriptObject().getComponentFormat();
            if (cf == null) {
                bodyText = Text.processTags(getDefaultModelObjectAsString(), resolver);
            } else {
                try {
                    bodyText = TagResolver.formatObject(modelObject, application.getLocale(), cf.parsedFormat, (cf.parsedFormat.getDisplayFormat() != null ? new ServoyMaskFormatter(cf.parsedFormat.getDisplayFormat(), true) : null));
                } catch (ParseException e) {
                    Debug.error(e);
                }
            }
            if (HtmlUtils.startsWithHtml(modelObject)) {
                // ignore script/header contributions for now
                bodyText = StripHTMLTagsConverter.convertBodyText(this, bodyText, getScriptObject().trustDataAsHtml(), application.getFlattenedSolution()).getBodyTxt();
            }
        }
    }
    if (model instanceof RecordItemModel) {
        ((RecordItemModel) model).updateRenderedValue(this);
    }
}
Also used : ServoyMaskFormatter(com.servoy.j2db.util.text.ServoyMaskFormatter) ParseException(java.text.ParseException) IConverter(org.apache.wicket.util.convert.IConverter) ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Example 2 with ComponentFormat

use of com.servoy.j2db.component.ComponentFormat in project servoy-client by Servoy.

the class WebDataLabel method onBeforeRender.

/**
 * @see org.apache.wicket.Component#onBeforeRender()
 */
@Override
protected void onBeforeRender() {
    super.onBeforeRender();
    IModel<?> model = getInnermostModel();
    hasHTML = false;
    if (needEntireState && model instanceof RecordItemModel) {
        if (dataProviderID != null) {
            Object val = getDefaultModelObject();
            if (val instanceof byte[]) {
                setIcon((byte[]) val);
            } else if (icon != null) {
                setIcon(null);
            } else {
                ComponentFormat cf = getComponentFormat();
                if (cf == null) {
                    bodyText = Text.processTags((String) val, resolver);
                } else {
                    try {
                        bodyText = Text.processTags(TagResolver.formatObject(val, application.getLocale(), cf.parsedFormat, (cf.parsedFormat.getDisplayFormat() != null ? new ServoyMaskFormatter(cf.parsedFormat.getDisplayFormat(), true) : null)), resolver);
                    } catch (ParseException e) {
                        Debug.error(e);
                    }
                }
            }
        } else {
            bodyText = Text.processTags(tagText, resolver);
        }
        if (bodyText != null) {
            if (HtmlUtils.startsWithHtml(bodyText)) {
                bodyText = StripHTMLTagsConverter.convertBodyText(this, bodyText, getScriptObject().trustDataAsHtml(), application.getFlattenedSolution()).getBodyTxt();
                hasHTML = true;
            } else {
                // convert the text (strip html if needed)
                final IConverter converter = getConverter(String.class);
                bodyText = converter.convertToString(bodyText, getLocale());
            }
        }
    } else {
        Object modelObject = getDefaultModelObject();
        if (modelObject instanceof byte[]) {
            setIcon((byte[]) modelObject);
        } else if (icon != null) {
            setIcon(null);
        } else {
            ComponentFormat cf = getComponentFormat();
            if (cf == null) {
                bodyText = Text.processTags(getDefaultModelObjectAsString(), resolver);
            } else {
                try {
                    bodyText = TagResolver.formatObject(modelObject, application.getLocale(), cf.parsedFormat, (cf.parsedFormat.getDisplayFormat() != null ? new ServoyMaskFormatter(cf.parsedFormat.getDisplayFormat(), true) : null));
                } catch (ParseException e) {
                    Debug.error(e);
                }
            }
            if (HtmlUtils.startsWithHtml(modelObject)) {
                // ignore script/header contributions for now
                bodyText = StripHTMLTagsConverter.convertBodyText(this, bodyText, getScriptObject().trustDataAsHtml(), application.getFlattenedSolution()).getBodyTxt();
                hasHTML = true;
            }
        }
    }
    if (model instanceof RecordItemModel) {
        ((RecordItemModel) model).updateRenderedValue(this);
    }
}
Also used : ServoyMaskFormatter(com.servoy.j2db.util.text.ServoyMaskFormatter) ParseException(java.text.ParseException) IConverter(org.apache.wicket.util.convert.IConverter) ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Example 3 with ComponentFormat

use of com.servoy.j2db.component.ComponentFormat in project servoy-client by Servoy.

the class AbstractRuntimeLabel method setFormat.

public void setFormat(String formatString) {
    String oldFormatString = getFormat();
    if (!Utils.safeEquals(formatString, oldFormatString)) {
        setComponentFormat(new ComponentFormat(FormatParser.parseFormatProperty(application.getI18NMessageIfPrefixed(formatString)), componentFormat == null ? IColumnTypes.TEXT : componentFormat.dpType, componentFormat == null ? IColumnTypes.TEXT : componentFormat.uiType));
        firePropertyChange("format", oldFormatString, formatString);
        getChangesRecorder().setChanged();
        clearRenderableWrapperProperty(RenderableWrapper.PROPERTY_FORMAT);
        fireOnRender();
    }
}
Also used : ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Example 4 with ComponentFormat

use of com.servoy.j2db.component.ComponentFormat in project servoy-client by Servoy.

the class DataProviderEditor method fillDataProviderList.

protected void fillDataProviderList() {
    try {
        ITable table = null;
        if (definedTable == null) {
            FormManager fm = (FormManager) application.getFormManager();
            FormController fc = fm.getCurrentMainShowingFormController();
            if (fc != null) {
                Form form = fc.getForm();
                table = application.getFlattenedSolution().getTable(form.getDataSource());
            }
        } else {
            if (!showRelatedOptionsOnly)
                table = definedTable;
        }
        DefaultListModel model = (DefaultListModel) list.getModel();
        model.removeAllElements();
        if (showNoneOption)
            model.addElement("-none-");
        if (!showColumnsOnly)
            model.addElement("*columns");
        Object o = relationsComboBox.getSelectedItem();
        if (o != null) {
            if (o instanceof String) {
            // table = form.getTable();
            } else {
                table = application.getFlattenedSolution().getTable(((Relation) o).getForeignDataSource());
            }
            if (table != null) {
                Iterator<Column> it = table.getColumnsSortedByName();
                while (it.hasNext()) {
                    IColumn c = it.next();
                    ColumnInfo ci = c.getColumnInfo();
                    if (ci != null && ci.isExcluded()) {
                        continue;
                    }
                    if (hideMediaColumns) {
                        // use dataprovider type as defined by column converter
                        ComponentFormat componentFormat = ComponentFormat.getComponentFormat(null, c, application);
                        if (componentFormat.dpType == IColumnTypes.MEDIA) {
                            continue;
                        }
                    }
                    model.addElement(c);
                }
            }
        }
        FlattenedSolution s = application.getFlattenedSolution();
        if (table != null && !showColumnsOnly) {
            Iterator it = s.getScriptCalculations(table, true);
            if (it.hasNext()) {
                model.addElement("*calculations");
            }
            while (it.hasNext()) {
                ScriptCalculation sc = (ScriptCalculation) it.next();
                for (int i = 0; i < model.size(); i++) {
                    Object obj = model.elementAt(i);
                    if (obj instanceof IDataProvider) {
                        IDataProvider dp = (IDataProvider) obj;
                        if (dp.getDataProviderID().equals(sc.getDataProviderID())) {
                            // remove the column from the list if use by
                            model.remove(i);
                            // stored calc
                            break;
                        }
                    }
                }
                model.addElement(sc);
            }
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
            Iterator it3 = s.getAggregateVariables(table, true);
            if (it3.hasNext()) {
                model.addElement("*aggregates");
            }
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (table != null && showColumnsOnly && showSortableOnly) {
            Iterator it3 = s.getAggregateVariables(table, true);
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (showGlobalsOption && showColumnsOnly) {
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
}
Also used : FormController(com.servoy.j2db.FormController) Form(com.servoy.j2db.persistence.Form) DefaultListModel(javax.swing.DefaultListModel) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IDataProvider(com.servoy.j2db.persistence.IDataProvider) ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) Relation(com.servoy.j2db.persistence.Relation) FormManager(com.servoy.j2db.FormManager) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) Iterator(java.util.Iterator) ITable(com.servoy.j2db.persistence.ITable) ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Example 5 with ComponentFormat

use of com.servoy.j2db.component.ComponentFormat in project servoy-client by Servoy.

the class DataButton method setValueObject.

public void setValueObject(Object obj) {
    if (needEntireState) {
        if (resolver != null) {
            if (dataProviderID != null) {
                try {
                    ComponentFormat cf = getScriptObject().getComponentFormat();
                    setText(Text.processTags(obj != null ? TagResolver.formatObject(obj, application.getLocale(), cf.parsedFormat, (cf.parsedFormat.getDisplayFormat() != null ? new ServoyMaskFormatter(cf.parsedFormat.getDisplayFormat(), true) : null)) : "", resolver));
                } catch (ParseException e) {
                    Debug.error(e);
                }
            } else {
                setText(Text.processTags(tagText, resolver));
            }
        } else {
            // $NON-NLS-1$
            setText("");
        }
        if (tooltip != null) {
            // empty tooltip will unregister from tooltip manager //$NON-NLS-1$
            super.setToolTipText("button");
        }
    } else {
        if (obj != null) {
            if (obj instanceof byte[]) {
                setIcon((byte[]) obj);
            } else {
                ComponentFormat cf = getScriptObject().getComponentFormat();
                try {
                    setText(TagResolver.formatObject(obj, application.getLocale(), cf.parsedFormat, (cf.parsedFormat.getDisplayFormat() != null ? new ServoyMaskFormatter(cf.parsedFormat.getDisplayFormat(), true) : null)));
                } catch (ParseException e) {
                    Debug.error(e);
                }
            }
        } else {
            if (value instanceof byte[]) {
                setIcon((Icon) null);
            } else if (value != null) {
                // $NON-NLS-1$
                setText("");
            }
        }
        this.value = obj;
    }
    fireOnRender(false);
}
Also used : ServoyMaskFormatter(com.servoy.j2db.util.text.ServoyMaskFormatter) ParseException(java.text.ParseException) ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Aggregations

ComponentFormat (com.servoy.j2db.component.ComponentFormat)14 ServoyMaskFormatter (com.servoy.j2db.util.text.ServoyMaskFormatter)5 ParseException (java.text.ParseException)5 ITable (com.servoy.j2db.persistence.ITable)3 Form (com.servoy.j2db.persistence.Form)2 IDataProvider (com.servoy.j2db.persistence.IDataProvider)2 Relation (com.servoy.j2db.persistence.Relation)2 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)2 FoundsetTypeSabloValue (com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue)2 IConverter (org.apache.wicket.util.convert.IConverter)2 IBaseColumn (com.servoy.base.persistence.IBaseColumn)1 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)1 FormController (com.servoy.j2db.FormController)1 FormManager (com.servoy.j2db.FormManager)1 GlobalMethodValueList (com.servoy.j2db.dataprocessing.GlobalMethodValueList)1 IValueList (com.servoy.j2db.dataprocessing.IValueList)1 Column (com.servoy.j2db.persistence.Column)1 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)1 IColumn (com.servoy.j2db.persistence.IColumn)1