Search in sources :

Example 6 with MobileSmartSourceType

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

the class ComponentManager method loadBean.

public static IonBean loadBean(String jsonString) throws Exception {
    JSONObject jsonBean = new JSONObject(jsonString);
    String modelName = "Unknown";
    if (jsonBean.has(IonBean.Key.name.name())) {
        modelName = jsonBean.getString(IonBean.Key.name.name());
    }
    final IonBean model = instance.bCache.get(modelName);
    // The model exists
    if (model != null) {
        boolean hasChanged = false;
        IonBean dboBean = new IonBean(jsonString);
        IonBean ionBean = new IonBean(model.toString());
        for (IonProperty ionProperty : ionBean.getProperties().values()) {
            String propertyName = ionProperty.getName();
            IonProperty dboProperty = dboBean.getProperty(propertyName);
            if (dboProperty != null) {
                MobileSmartSourceType msst = dboProperty.getSmartType();
                if (msst != null) {
                    ionProperty.setSmartType(msst);
                    ionBean.putProperty(ionProperty);
                }
            } else {
                System.out.println("(ComponentManager) Ion property \"" + propertyName + "\" not found for model \"" + modelName + "\": ignore it.");
                if (Engine.isStarted) {
                    Engine.logBeans.warn("(ComponentManager) Ion property \"" + propertyName + "\" not found for model \"" + modelName + "\": ignore it.");
                }
                hasChanged = true;
            }
        }
        if (hasChanged) {
        // TODO
        }
        return ionBean;
    } else // The model doesn't exist (anymore)
    {
        System.out.println("(ComponentManager) Model \"" + modelName + "\" does not exist anymore in cache (" + jsonString + ").");
        if (Engine.isStarted) {
            Engine.logBeans.warn("(ComponentManager) Model \"" + modelName + "\" does not exist anymore in cache (" + jsonString + ").");
        }
        return new IonBean(jsonString);
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType)

Example 7 with MobileSmartSourceType

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

the class IonProperty method getSmartType.

public MobileSmartSourceType getSmartType() {
    MobileSmartSourceType msst = new MobileSmartSourceType() {

        private static final long serialVersionUID = 5907963275354985836L;

        @Override
        public Object getEditorData() {
            String smartValue = getSmartValue();
            return smartValue.equals("not set") ? "" : super.getEditorData();
        }
    };
    String mode = getMode();
    msst.setMode(Mode.valueOf(mode.toUpperCase()));
    Object value = getValue();
    msst.setSmartValue(value.equals(false) ? "not set" : value.toString());
    return msst;
}
Also used : MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 8 with MobileSmartSourceType

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

the class IonProperty method getSmartValue.

public String getSmartValue() {
    MobileSmartSourceType msst = getSmartType();
    String value = msst.getValue();
    if (isAttrPropertyBind()) {
        if (Mode.PLAIN.equals(msst.getMode())) {
            if (!value.startsWith("'") && !value.endsWith("'")) {
                value = "'" + MobileSmartSourceType.escapeStringForTpl(value) + "'";
            }
        }
    } else if (isAttrEventBind()) {
    } else {
        if (!Mode.PLAIN.equals(msst.getMode())) {
            value = "{{" + value + "}}";
        }
    }
    return value;
}
Also used : MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType)

Example 9 with MobileSmartSourceType

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

the class NgxUIComponentTreeObject method setPropertyValue.

@Override
public void setPropertyValue(Object id, Object value) {
    DatabaseObject dbo = getObject();
    if (dbo instanceof UIDynamicElement) {
        IonBean ionBean = ((UIDynamicElement) dbo).getIonBean();
        if (ionBean != null) {
            if (ionBean.hasProperty((String) id)) {
                if (value != null) {
                    if (value instanceof String) {
                        value = new MobileSmartSourceType((String) value);
                    }
                    Object oldValue = ionBean.getPropertyValue((String) id);
                    if (!value.equals(oldValue)) {
                        ionBean.setPropertyValue((String) id, value);
                        TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
                        hasBeenModified(true);
                        viewer.update(this, null);
                        TreeObjectEvent treeObjectEvent = new TreeObjectEvent(this, (String) id, oldValue, value);
                        ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent);
                        return;
                    }
                }
            }
        }
    }
    if (dbo instanceof UIAppGuard) {
        UIAppGuard dboGuard = (UIAppGuard) dbo;
        if ("guardType".equals(id)) {
            String guardType = (String) value;
            if (!guardType.equals(dboGuard.getGuardType().name())) {
                if (dboGuard.getApplication().hasGuard(AppGuardType.valueOf(guardType))) {
                    return;
                }
            }
        }
    }
    super.setPropertyValue(id, value);
}
Also used : UIAppGuard(com.twinsoft.convertigo.beans.ngx.components.UIAppGuard) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIDynamicElement(com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)

Example 10 with MobileSmartSourceType

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

the class NgxPickerComposite method lookupModelData.

private Map<String, Object> lookupModelData(TVObject tvObject) {
    Map<String, Object> data = new HashMap<String, Object>();
    Map<String, String> params = new HashMap<String, String>();
    DatabaseObject dbo = null;
    String searchPath = "";
    Object object = tvObject.getObject();
    JSONObject infos = tvObject.getInfos();
    if (object != null) {
        try {
            if (object instanceof RequestableObject) {
                dbo = (RequestableObject) object;
                searchPath = "";
            } else if (object instanceof DesignDocument) {
                dbo = (DesignDocument) object;
                DesignDocument dd = (DesignDocument) dbo;
                params.put("ddoc", dd.getName());
                params.put("view", tvObject.getParent().getName());
                params.put("include_docs", infos.has("include_docs") ? infos.getString("include_docs") : "false");
                searchPath = tvObject.getName().startsWith("get") ? ".rows.value" : "";
            } else if (object instanceof UIControlDirective) {
                dbo = (UIControlDirective) object;
                do {
                    UIControlDirective directive = (UIControlDirective) dbo;
                    String rootDboName = "";
                    if (directive.getPage() != null) {
                        rootDboName = directive.getPage().getName();
                    } else if (directive.getMenu() != null) {
                        rootDboName = directive.getMenu().getName();
                    }
                    MobileSmartSourceType msst = directive.getSourceSmartType();
                    MobileSmartSource mss = msst.getSmartSource();
                    if (mss != null) {
                        dbo = mss.getDatabaseObject(rootDboName);
                        params.putAll(mss.getParameters());
                        searchPath = mss.getModelPath().replaceAll("\\?\\.", ".") + searchPath;
                    } else {
                        dbo = null;
                    }
                } while (dbo != null && dbo instanceof UIControlDirective);
            } else if (object instanceof UIForm) {
                dbo = (UIForm) object;
                searchPath = "";
            } else if (object instanceof ApplicationComponent) {
                dbo = (ApplicationComponent) object;
                params.put("json", infos.toString());
                searchPath = "";
            } else if (object instanceof UIActionStack) {
                dbo = (UIActionStack) object;
                searchPath = "";
            } else if (object instanceof IAction) {
                if (object instanceof UIDynamicAction) {
                    dbo = (UIDynamicAction) object;
                    searchPath = "";
                } else if (object instanceof UICustomAction) {
                    dbo = (UICustomAction) object;
                    searchPath = "";
                }
            } else if (object instanceof UISharedComponent) {
                dbo = (UISharedComponent) object;
                searchPath = "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    data.put("databaseObject", dbo);
    data.put("params", params);
    data.put("searchPath", searchPath);
    return data;
}
Also used : RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) IAction(com.twinsoft.convertigo.beans.ngx.components.IAction) HashMap(java.util.HashMap) MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) UIControlDirective(com.twinsoft.convertigo.beans.ngx.components.UIControlDirective) UIForm(com.twinsoft.convertigo.beans.ngx.components.UIForm) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) PartInitException(org.eclipse.ui.PartInitException) JSONException(org.codehaus.jettison.json.JSONException) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) MobileSmartSource(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSource) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) JSONObject(org.codehaus.jettison.json.JSONObject) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UICustomAction(com.twinsoft.convertigo.beans.ngx.components.UICustomAction) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) TVObject(com.twinsoft.convertigo.eclipse.views.mobile.NgxPickerContentProvider.TVObject) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject)

Aggregations

MobileSmartSourceType (com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType)10 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)7 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)4 Sequence (com.twinsoft.convertigo.beans.core.Sequence)3 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)3 ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)3 PageComponent (com.twinsoft.convertigo.beans.ngx.components.PageComponent)3 UIActionStack (com.twinsoft.convertigo.beans.ngx.components.UIActionStack)3 UIDynamicAction (com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction)3 UIUseShared (com.twinsoft.convertigo.beans.ngx.components.UIUseShared)3 EngineException (com.twinsoft.convertigo.engine.EngineException)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 FullSyncConnector (com.twinsoft.convertigo.beans.connectors.FullSyncConnector)2 Project (com.twinsoft.convertigo.beans.core.Project)2 MobileSmartSource (com.twinsoft.convertigo.beans.ngx.components.MobileSmartSource)2 UIComponent (com.twinsoft.convertigo.beans.ngx.components.UIComponent)2 UIDynamicElement (com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement)2 UIDynamicInvoke (com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke)2 UIText (com.twinsoft.convertigo.beans.ngx.components.UIText)2 IonBean (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean)2