Search in sources :

Example 11 with MobileSmartSourceType

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

the class MobileUIComponentTreeObject method refactorSmartSources.

protected void refactorSmartSources(TreeObjectEvent treeObjectEvent) {
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    String propertyName = (String) treeObjectEvent.propertyName;
    propertyName = ((propertyName == null) ? "" : propertyName);
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    if (getProjectTreeObject() == null) {
        // System.out.println("dbo ignored because it has been deleted: "+ getObject().priority);
        return;
    }
    // Case of DatabaseObjectTreeObject
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
        DatabaseObject dbo = doto.getObject();
        try {
            boolean sourcesUpdated = false;
            // A bean name has changed
            if (propertyName.equals("name")) {
                boolean fromSameProject = getProjectTreeObject().equals(doto.getProjectTreeObject());
                if ((treeObjectEvent.update == TreeObjectEvent.UPDATE_ALL) || ((treeObjectEvent.update == TreeObjectEvent.UPDATE_LOCAL) && fromSameProject)) {
                    try {
                        if (dbo instanceof Project) {
                            String oldName = (String) oldValue;
                            String newName = (String) newValue;
                            if (!newValue.equals(oldValue)) {
                                if (getObject().updateSmartSource("'" + oldName + "\\.", "'" + newName + ".")) {
                                    sourcesUpdated = true;
                                }
                                if (getObject().updateSmartSource("\\/" + oldName + "\\.", "/" + newName + ".")) {
                                    sourcesUpdated = true;
                                }
                            }
                        } else if (dbo instanceof Sequence) {
                            String oldName = (String) oldValue;
                            String newName = (String) newValue;
                            String projectName = dbo.getProject().getName();
                            if (!newValue.equals(oldValue)) {
                                if (getObject().updateSmartSource("'" + projectName + "\\." + oldName, "'" + projectName + "." + newName)) {
                                    sourcesUpdated = true;
                                }
                            }
                        } else if (dbo instanceof FullSyncConnector) {
                            String oldName = (String) oldValue;
                            String newName = (String) newValue;
                            String projectName = dbo.getProject().getName();
                            if (!newValue.equals(oldValue)) {
                                if (getObject().updateSmartSource("\\/" + projectName + "\\." + oldName + "\\.", "/" + projectName + "." + newName + ".")) {
                                    sourcesUpdated = true;
                                }
                                if (getObject().updateSmartSource("\\/" + oldName + "\\.", "/" + newName + ".")) {
                                    sourcesUpdated = true;
                                }
                            }
                        } else if (dbo instanceof DesignDocument) {
                            String oldName = (String) oldValue;
                            String newName = (String) newValue;
                            if (!newValue.equals(oldValue)) {
                                if (getObject().updateSmartSource("ddoc='" + oldName + "'", "ddoc='" + newName + "'")) {
                                    sourcesUpdated = true;
                                }
                            }
                        }
                        if (dbo instanceof UIComponent) {
                            if (!newValue.equals(oldValue)) {
                                try {
                                    String oldName = (String) oldValue;
                                    String newName = (String) newValue;
                                    // SC mode
                                    if (getObject().updateSmartSource("\\?\\." + oldName, "?." + newName)) {
                                        sourcesUpdated = true;
                                    }
                                    // TS mode
                                    if (getObject().getSharedComponent() != null) {
                                        long priority = getObject().getSharedComponent().priority;
                                        if (getObject().updateSmartSource("params" + priority + "\\." + oldName, "params" + priority + "." + newName)) {
                                            sourcesUpdated = true;
                                        }
                                    }
                                } catch (Exception e) {
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            if (dbo instanceof UIComponent) {
                UIComponent uic = (UIComponent) dbo;
                if (hasSameScriptComponent(getObject(), uic)) {
                    // A FormControlName property has changed
                    if (propertyName.equals("FormControlName") || uic.isFormControlAttribute()) {
                        if (!newValue.equals(oldValue)) {
                            try {
                                String oldSmart = ((MobileSmartSourceType) oldValue).getSmartValue();
                                String newSmart = ((MobileSmartSourceType) newValue).getSmartValue();
                                if (uic.getUIForm() != null) {
                                    String form = uic.getUIForm().getFormGroupName();
                                    if (getObject().updateSmartSource(form + "\\?\\.controls\\['" + oldSmart + "'\\]", form + "?.controls['" + newSmart + "']")) {
                                        sourcesUpdated = true;
                                    }
                                }
                            } catch (Exception e) {
                            }
                        }
                    }
                }
            }
            // Need TS regeneration
            if (sourcesUpdated) {
                hasBeenModified(true);
                viewer.refresh();
                markMainAsDirty(getObject());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else // Case of DesignDocumentViewTreeObject
    if (treeObject instanceof DesignDocumentViewTreeObject) {
        DesignDocumentViewTreeObject ddvto = (DesignDocumentViewTreeObject) treeObject;
        try {
            boolean sourcesUpdated = false;
            // View name changed
            if (propertyName.equals("name")) {
                boolean fromSameProject = getProjectTreeObject().equals(ddvto.getProjectTreeObject());
                if ((treeObjectEvent.update == TreeObjectEvent.UPDATE_ALL) || ((treeObjectEvent.update == TreeObjectEvent.UPDATE_LOCAL) && fromSameProject)) {
                    try {
                        String oldName = (String) oldValue;
                        String newName = (String) newValue;
                        if (!newValue.equals(oldValue)) {
                            if (getObject().updateSmartSource("view='" + oldName + "'", "view='" + newName + "'")) {
                                sourcesUpdated = true;
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            // Need TS regeneration
            if (sourcesUpdated) {
                hasBeenModified(true);
                viewer.refresh();
                markMainAsDirty(getObject());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) Sequence(com.twinsoft.convertigo.beans.core.Sequence) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IProject(org.eclipse.core.resources.IProject) Project(com.twinsoft.convertigo.beans.core.Project) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 12 with MobileSmartSourceType

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

the class SharedComponentWizard method createControlVariable.

private UIControlVariable createControlVariable(String varName, String varValue) throws Exception {
    MobileSmartSourceType var_msst = new MobileSmartSourceType();
    var_msst.setMode(Mode.SCRIPT);
    var_msst.setSmartValue(varValue);
    UIControlVariable controlVariable = new UIControlVariable();
    controlVariable.setName(varName);
    controlVariable.setVarSmartType(var_msst);
    controlVariable.hasChanged = true;
    controlVariable.bNew = true;
    return controlVariable;
}
Also used : MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) UIControlVariable(com.twinsoft.convertigo.beans.mobile.components.UIControlVariable)

Example 13 with MobileSmartSourceType

use of com.twinsoft.convertigo.beans.mobile.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.mobile.components.MobileSmartSourceType)

Aggregations

MobileSmartSourceType (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType)13 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)5 ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)4 UIComponent (com.twinsoft.convertigo.beans.mobile.components.UIComponent)4 EngineException (com.twinsoft.convertigo.engine.EngineException)4 Project (com.twinsoft.convertigo.beans.core.Project)3 Sequence (com.twinsoft.convertigo.beans.core.Sequence)3 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)3 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)3 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)3 UIDynamicAction (com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction)3 UIDynamicElement (com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement)3 UIUseShared (com.twinsoft.convertigo.beans.mobile.components.UIUseShared)3 IonBean (com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ArrayList (java.util.ArrayList)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 FullSyncConnector (com.twinsoft.convertigo.beans.connectors.FullSyncConnector)2 MobileSmartSource (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource)2