Search in sources :

Example 1 with IonProperty

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty in project convertigo by convertigo.

the class UIDynamicAction method computeActionInputs.

protected String computeActionInputs(boolean forTemplate) {
    boolean extended = !forTemplate;
    if (isEnabled()) {
        IonBean ionBean = getIonBean();
        if (ionBean != null) {
            StringBuilder sbProps = initProps(forTemplate);
            for (IonProperty property : ionBean.getProperties().values()) {
                String p_name = property.getName();
                Object p_value = property.getValue();
                sbProps.append(sbProps.length() > 0 ? ", " : "");
                sbProps.append(p_name).append(": ");
                // case value is set
                if (!p_value.equals(false)) {
                    MobileSmartSourceType msst = property.getSmartType();
                    String smartValue = msst.getValue(extended);
                    // Case plain string
                    if (Mode.PLAIN.equals(msst.getMode())) {
                        if (property.getType().equalsIgnoreCase("string")) {
                            smartValue = forTemplate ? "\'" + MobileSmartSourceType.escapeStringForTpl(smartValue) + "\'" : "\'" + MobileSmartSourceType.escapeStringForTs(smartValue) + "\'";
                        }
                    }
                    // Special case for ClearDataSourceAction
                    if ("ClearDataSourceAction".equals(getActionName())) {
                        if (Mode.SOURCE.equals(msst.getMode())) {
                            MobileSmartSource mss = msst.getSmartSource();
                            if (mss != null) {
                                smartValue = mss.getSources().toString();
                            }
                        }
                    }
                    // Case ts code in HTML template (single action)
                    if (forTemplate) {
                        smartValue = "" + smartValue;
                    } else // Case ts code in ActionBeans.service (stack of actions)
                    {
                        smartValue = smartValue.replaceAll("\\?\\.", ".");
                        smartValue = smartValue.replaceAll("this\\.", "c8oPage.");
                        if (paramsPattern.matcher(smartValue).lookingAt()) {
                            smartValue = "scope." + smartValue;
                        }
                        smartValue = "get('" + p_name + "', `" + smartValue + "`)";
                    }
                    sbProps.append(smartValue);
                } else // case value is not set
                {
                    sbProps.append("null");
                }
            }
            StringBuilder sbVars = new StringBuilder();
            Iterator<UIComponent> it = getUIComponentList().iterator();
            while (it.hasNext()) {
                UIComponent component = (UIComponent) it.next();
                if (component instanceof UIControlVariable) {
                    UIControlVariable uicv = (UIControlVariable) component;
                    if (uicv.isEnabled()) {
                        // Case code generated in HTML
                        if (forTemplate) {
                            String varValue = uicv.getVarValue();
                            if (!varValue.isEmpty()) {
                                sbVars.append(sbVars.length() > 0 ? ", " : "");
                                sbVars.append(uicv.getVarName()).append(": ");
                                sbVars.append(varValue);
                            }
                        } else // Case code generated in TS
                        {
                            MobileSmartSourceType msst = uicv.getVarSmartType();
                            String smartValue = msst.getValue(extended);
                            if (Mode.PLAIN.equals(msst.getMode())) {
                                smartValue = "\'" + MobileSmartSourceType.escapeStringForTs(smartValue) + "\'";
                            }
                            smartValue = smartValue.replaceAll("\\?\\.", ".");
                            smartValue = smartValue.replaceAll("this\\.", "c8oPage.");
                            if (paramsPattern.matcher(smartValue).lookingAt()) {
                                smartValue = "scope." + smartValue;
                            }
                            if (!smartValue.isEmpty()) {
                                sbVars.append(sbVars.length() > 0 ? ", " : "");
                                sbVars.append(uicv.getVarName()).append(": ");
                                sbVars.append("get('" + uicv.getVarName() + "', `" + smartValue + "`)");
                            }
                        }
                    }
                }
            }
            return "{props:{" + sbProps + "}, vars:{" + sbVars + "}}";
        }
    }
    return "";
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 2 with IonProperty

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty in project convertigo by convertigo.

the class UIDynamicAction method addInfos.

@Override
protected void addInfos(Set<UIComponent> done, Map<String, Set<String>> infoMap) {
    super.addInfos(done, infoMap);
    IonBean ionBean = getIonBean();
    if (ionBean != null) {
        String beanName = ionBean.getName();
        if (ionBean.hasProperty("marker")) {
            JSONObject json = new JSONObject();
            String key = null;
            for (IonProperty property : ionBean.getProperties().values()) {
                MobileSmartSourceType msst = property.getSmartType();
                String p_name = property.getName();
                Object p_value = property.getValue();
                if (!p_value.equals(false)) {
                    if (beanName.equals("FullSyncViewAction")) {
                        if (p_name.equals("fsview")) {
                            key = p_value.toString() + ".view";
                        }
                    } else if (beanName.equals("FullSyncGetAction")) {
                        if (p_name.equals("requestable")) {
                            key = p_value.toString() + ".get";
                        }
                    } else if (beanName.equals("CallSequenceAction")) {
                        if (p_name.equals("requestable")) {
                            key = p_value.toString();
                        }
                    } else if (beanName.equals("CallFullSyncAction")) {
                        if (p_name.equals("requestable")) {
                            key = p_value.toString();
                            Object p_verb = ionBean.getProperty("verb").getValue();
                            if (!p_verb.equals(false)) {
                                key += "." + p_verb.toString();
                            }
                        }
                    }
                }
                try {
                    if (p_name.equals("marker")) {
                        json.put(p_name, !p_value.equals(false) ? msst.getValue() : "");
                    }
                    if (p_name.equals("include_docs")) {
                        json.put(p_name, !p_value.equals(false) ? msst.getValue() : "false");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            if (key != null && !key.isEmpty()) {
                Set<String> infos = infoMap.get(key);
                if (infos == null) {
                    infos = new HashSet<String>();
                }
                String info = json.toString();
                if (!info.isEmpty()) {
                    infos.add(info);
                }
                infoMap.put(key, infos);
            }
        }
    }
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) JSONObject(org.codehaus.jettison.json.JSONObject) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) JSONException(org.codehaus.jettison.json.JSONException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 3 with IonProperty

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty in project convertigo by convertigo.

the class UIComponent method preconfigure.

@Override
public void preconfigure(Element element) throws Exception {
    super.preconfigure(element);
    String version = element.getAttribute("version");
    long priority = Long.valueOf(element.getAttribute("priority")).longValue();
    // TODO: REMOVE BEFORE RELEASE !!!
    boolean doMigration = false;
    if (!doMigration) {
        return;
    }
    if (VersionUtils.compare(version, "7.9.0") < 0) {
        try {
            NodeList properties = element.getElementsByTagName("property");
            int len = properties.getLength();
            Element propElement;
            for (int i = 0; i < len; i++) {
                propElement = (Element) properties.item(i);
                if (propElement != null && propElement.getParentNode().equals(element)) {
                    String propertyName = propElement.getAttribute("name");
                    Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
                    if (valueElement != null) {
                        Document document = valueElement.getOwnerDocument();
                        Object content = XMLUtils.readObjectFromXml(valueElement);
                        // This is data of the peusdo-bean
                        if ("beanData".equals(propertyName) && content instanceof String) {
                            try {
                                boolean needChange = false;
                                List<String> logList = new ArrayList<String>();
                                IonBean ionBean = new IonBean((String) content);
                                List<IonProperty> propertyList = new ArrayList<IonProperty>();
                                propertyList.addAll(ionBean.getProperties().values());
                                // Walk through properties
                                for (IonProperty ionProperty : propertyList) {
                                    String ionPropertyName = ionProperty.getName();
                                    String modeUpperCase = ionProperty.getMode().toUpperCase();
                                    if (Mode.SOURCE.equals(Mode.valueOf(modeUpperCase))) {
                                        MobileSmartSourceType msst = ionProperty.getSmartType();
                                        String smartValue = msst.getSmartValue();
                                        if (smartValue != null && !smartValue.isEmpty()) {
                                            try {
                                                MobileSmartSource mss = MobileSmartSource.migrate(smartValue);
                                                if (mss != null) {
                                                    boolean migrated = !smartValue.equals(mss.toJsonString());
                                                    if (migrated) {
                                                        msst.setSmartValue(mss.toJsonString());
                                                        ionBean.setPropertyValue(ionPropertyName, msst);
                                                        needChange = true;
                                                        logList.add("Done migration of \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")");
                                                    }
                                                }
                                            } catch (Exception e) {
                                                if (e instanceof InvalidSourceException) {
                                                    Engine.logBeans.warn("Failed to migrate \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + "): " + e.getMessage());
                                                } else {
                                                    Engine.logBeans.error("Failed to migrate \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
                                                }
                                            }
                                        }
                                    }
                                }
                                // Store new beandata property value
                                if (needChange) {
                                    String beanData = ionBean.toBeanData();
                                    Element newValueElement = (Element) XMLUtils.writeObjectToXml(document, beanData);
                                    propElement.replaceChild(newValueElement, valueElement);
                                    hasChanged = true;
                                    logList.forEach(s -> Engine.logBeans.warn(s));
                                }
                            } catch (Exception e) {
                                Engine.logBeans.error("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
                            }
                        } else // This is a MobileSmartSourceType property
                        if (content instanceof MobileSmartSourceType) {
                            MobileSmartSourceType msst = (MobileSmartSourceType) content;
                            // Property is in 'SRC' mode
                            if (Mode.SOURCE.equals(msst.getMode())) {
                                try {
                                    String smartValue = msst.getSmartValue();
                                    if (smartValue != null && !smartValue.isEmpty()) {
                                        MobileSmartSource mss = MobileSmartSource.migrate(smartValue);
                                        if (mss != null) {
                                            boolean migrated = !smartValue.equals(mss.toJsonString());
                                            if (migrated) {
                                                msst.setSmartValue(mss.toJsonString());
                                                // Store new property value
                                                Element newValueElement = (Element) XMLUtils.writeObjectToXml(document, msst);
                                                propElement.replaceChild(newValueElement, valueElement);
                                                hasChanged = true;
                                                Engine.logBeans.warn("Done migration of \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")");
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    if (e instanceof InvalidSourceException) {
                                        Engine.logBeans.warn("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + "): " + e.getMessage());
                                    } else {
                                        Engine.logBeans.error("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new EngineException("Unable to preconfigure the mobile uicomponent \"" + getName() + "\".", e);
        }
    }
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) EngineException(com.twinsoft.convertigo.engine.EngineException) Document(org.w3c.dom.Document) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 4 with IonProperty

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty in project convertigo by convertigo.

the class UIDynamicElement method initAttrClasses.

@Override
protected StringBuilder initAttrClasses() {
    StringBuilder attrclasses = super.initAttrClasses();
    IonBean ionBean = getIonBean();
    if (ionBean != null) {
        for (IonProperty property : ionBean.getProperties().values()) {
            // String name = property.getName();
            String attr = property.getAttr();
            Object value = property.getValue();
            // case value is set
            if (!value.equals(false)) {
                String smartValue = property.getSmartValue();
                if (attr.equals("class")) {
                    attrclasses.append(attrclasses.length() > 0 ? " " : "").append(smartValue);
                }
            }
        }
    }
    return attrclasses;
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 5 with IonProperty

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty in project convertigo by convertigo.

the class NgxUIComponentTreeObject method getDynamicPropertyDescriptors.

@Override
protected List<PropertyDescriptor> getDynamicPropertyDescriptors() {
    List<PropertyDescriptor> l = super.getDynamicPropertyDescriptors();
    DatabaseObject dbo = getObject();
    if (dbo instanceof UIDynamicElement) {
        IonBean ionBean = ((UIDynamicElement) dbo).getIonBean();
        if (ionBean != null) {
            for (IonProperty property : ionBean.getProperties().values()) {
                String id = property.getName();
                String displayName = property.getLabel();
                String editor = property.getEditor();
                Object[] values = property.getValues();
                int len = values.length;
                if (property.isHidden()) {
                    continue;
                }
                PropertyDescriptor propertyDescriptor = null;
                if (editor.isEmpty()) {
                    if (len == 0) {
                        propertyDescriptor = new TextPropertyDescriptor(id, displayName);
                    } else if (len == 1) {
                        propertyDescriptor = new PropertyDescriptor(id, displayName);
                    } else {
                        boolean isEditable = values[len - 1].equals(true);
                        int size = isEditable ? len - 1 : len;
                        String[] tags = new String[size];
                        for (int i = 0; i < size; i++) {
                            Object value = values[i];
                            tags[i] = value.equals(false) ? "not set" : value.toString();
                        }
                        // propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, !isEditable);
                        propertyDescriptor = new NgxSmartSourcePropertyDescriptor(id, displayName, tags, !isEditable);
                        ((NgxSmartSourcePropertyDescriptor) propertyDescriptor).databaseObjectTreeObject = this;
                    }
                } else {
                    if (editor.equals("StringComboBoxPropertyDescriptor")) {
                        try {
                            Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
                            Method getTags = c.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
                            String[] tags = (String[]) getTags.invoke(null, new Object[] { this, id });
                            propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, true);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        propertyDescriptor = new PropertyDescriptor(id, displayName) {

                            @Override
                            public CellEditor createPropertyEditor(Composite parent) {
                                CellEditor cellEditor = null;
                                try {
                                    Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
                                    cellEditor = (CellEditor) c.getConstructor(Composite.class).newInstance(parent);
                                    if (cellEditor instanceof AbstractDialogCellEditor) {
                                        ((AbstractDialogCellEditor) cellEditor).databaseObjectTreeObject = NgxUIComponentTreeObject.this;
                                        ((AbstractDialogCellEditor) cellEditor).propertyDescriptor = this;
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                return cellEditor;
                            }
                        };
                    }
                }
                propertyDescriptor.setCategory(property.getCategory());
                propertyDescriptor.setDescription(cleanDescription(property.getDescription()));
                propertyDescriptor.setValidator(getValidator(id));
                l.add(propertyDescriptor);
            }
        }
    }
    return l;
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) NgxSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) PropertyDescriptor(org.eclipse.ui.views.properties.PropertyDescriptor) StringComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) Composite(org.eclipse.swt.widgets.Composite) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) CellEditor(org.eclipse.jface.viewers.CellEditor) AbstractDialogCellEditor(com.twinsoft.convertigo.eclipse.property_editors.AbstractDialogCellEditor) UIDynamicElement(com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement) NgxSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) Method(java.lang.reflect.Method) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AbstractDialogCellEditor(com.twinsoft.convertigo.eclipse.property_editors.AbstractDialogCellEditor) StringComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor)

Aggregations

IonProperty (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty)9 IonBean (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean)8 JSONObject (org.codehaus.jettison.json.JSONObject)8 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)4 EngineException (com.twinsoft.convertigo.engine.EngineException)3 HashMap (java.util.HashMap)2 JSONException (org.codehaus.jettison.json.JSONException)2 EvaluatorException (org.mozilla.javascript.EvaluatorException)2 JavaScriptException (org.mozilla.javascript.JavaScriptException)2 UIDynamicElement (com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement)1 AbstractDialogCellEditor (com.twinsoft.convertigo.eclipse.property_editors.AbstractDialogCellEditor)1 NgxSmartSourcePropertyDescriptor (com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor)1 StringComboBoxPropertyDescriptor (com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor)1 InvalidSourceException (com.twinsoft.convertigo.engine.InvalidSourceException)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1