Search in sources :

Example 1 with IonBean

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

the class NgxUIComponentTreeObject method handlesBeanNameChanged.

protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
    DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
    DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    int update = treeObjectEvent.update;
    if (update != TreeObjectEvent.UPDATE_NONE) {
        // Case a UIStackVariable has been renamed
        if (databaseObject instanceof UIStackVariable) {
            UIStackVariable variable = (UIStackVariable) databaseObject;
            UIActionStack stack = variable.getSharedAction();
            if (stack != null) {
                // rename variable for InvokeAction
                if (getObject() instanceof UIDynamicInvoke) {
                    UIDynamicInvoke udi = (UIDynamicInvoke) getObject();
                    if (udi.getSharedActionQName().equals(stack.getQName())) {
                        boolean isLocalProject = variable.getProject().equals(udi.getProject());
                        boolean isSameValue = variable.getName().equals(oldValue);
                        boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                        if (!isSameValue && shouldUpdate) {
                            Iterator<UIComponent> it = udi.getUIComponentList().iterator();
                            while (it.hasNext()) {
                                UIComponent component = (UIComponent) it.next();
                                if (component instanceof UIControlVariable) {
                                    UIControlVariable uicv = (UIControlVariable) component;
                                    if (uicv.getName().equals(oldValue)) {
                                        try {
                                            uicv.setName((String) newValue);
                                            uicv.hasChanged = true;
                                            viewer.refresh();
                                            markMainAsDirty(udi);
                                            notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
                                            break;
                                        } catch (EngineException e) {
                                            ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for InvokeAction !");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // Case a UICompVariable has been renamed
        if (databaseObject instanceof UICompVariable) {
            UICompVariable variable = (UICompVariable) databaseObject;
            UISharedComponent comp = variable.getSharedComponent();
            if (comp != null) {
                // rename variable for UseShared
                if (getObject() instanceof UIUseShared) {
                    UIUseShared uus = (UIUseShared) getObject();
                    if (uus.getSharedComponentQName().equals(comp.getQName())) {
                        boolean isLocalProject = variable.getProject().equals(uus.getProject());
                        boolean isSameValue = variable.getName().equals(oldValue);
                        boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                        if (!isSameValue && shouldUpdate) {
                            Iterator<UIComponent> it = uus.getUIComponentList().iterator();
                            while (it.hasNext()) {
                                UIComponent component = (UIComponent) it.next();
                                if (component instanceof UIControlVariable) {
                                    UIControlVariable uicv = (UIControlVariable) component;
                                    if (uicv.getName().equals(oldValue)) {
                                        try {
                                            uicv.setName((String) newValue);
                                            uicv.hasChanged = true;
                                            viewer.refresh();
                                            markMainAsDirty(uus);
                                            notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
                                            break;
                                        } catch (EngineException e) {
                                            ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for UseShared !");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else // Case a RequestableVariable has been renamed
        if (databaseObject instanceof RequestableVariable) {
            RequestableVariable variable = (RequestableVariable) databaseObject;
            DatabaseObject parent = variable.getParent();
            if (getObject() instanceof UIDynamicAction) {
                UIDynamicAction uia = (UIDynamicAction) getObject();
                IonBean ionBean = uia.getIonBean();
                if (ionBean != null) {
                    // rename variable for CallSequenceAction
                    if (ionBean.getName().equals("CallSequenceAction")) {
                        Object p_val = ionBean.getProperty("requestable").getValue();
                        if (!p_val.equals(false)) {
                            if (parent.getQName().equals(p_val.toString())) {
                                boolean isLocalProject = variable.getProject().equals(uia.getProject());
                                boolean isSameValue = variable.getName().equals(oldValue);
                                boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                                if (!isSameValue && shouldUpdate) {
                                    Iterator<UIComponent> it = uia.getUIComponentList().iterator();
                                    while (it.hasNext()) {
                                        UIComponent component = (UIComponent) it.next();
                                        if (component instanceof UIControlVariable) {
                                            UIControlVariable uicv = (UIControlVariable) component;
                                            if (uicv.getName().equals(oldValue)) {
                                                try {
                                                    uicv.setName((String) newValue);
                                                    uicv.hasChanged = true;
                                                    viewer.refresh();
                                                    markMainAsDirty(uia);
                                                    notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
                                                    break;
                                                } catch (EngineException e) {
                                                    ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for CallSequenceAction !");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : UICompVariable(com.twinsoft.convertigo.beans.ngx.components.UICompVariable) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) EngineException(com.twinsoft.convertigo.engine.EngineException) UIStackVariable(com.twinsoft.convertigo.beans.ngx.components.UIStackVariable) UIControlVariable(com.twinsoft.convertigo.beans.ngx.components.UIControlVariable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) UIDynamicInvoke(com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke) Iterator(java.util.Iterator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) HashSet(java.util.HashSet)

Example 2 with IonBean

use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean 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 3 with IonBean

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

the class UIDynamicAction method getContributor.

@Override
protected Contributor getContributor() {
    Contributor contributor = super.getContributor();
    return new Contributor() {

        @Override
        public boolean isNgModuleForApp() {
            if (!getModuleNgImports().isEmpty() || !getModuleNgProviders().isEmpty()) {
                return true;
            }
            return false;
        }

        @Override
        public Map<String, String> getActionTsFunctions() {
            Map<String, String> functions = new HashMap<String, String>();
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                String actionName = getActionName();
                String actionCode = ComponentManager.getActionTsCode(actionName);
                if (compareToTplVersion("7.5.2.0") < 0) {
                    actionCode = actionCode.replaceFirst("C8oPageBase", "C8oPage");
                    actionCode = actionCode.replaceAll("C8oCafUtils\\.merge", "page.merge");
                }
                functions.put(actionName, actionCode);
            }
            return functions;
        }

        @Override
        public Map<String, String> getActionTsImports() {
            Map<String, String> imports = new HashMap<String, String>();
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                Map<String, List<String>> map = ionBean.getConfig().getActionTsImports();
                if (map.size() > 0) {
                    for (String from : map.keySet()) {
                        for (String component : map.get(from)) {
                            imports.put(component.trim(), from);
                        }
                    }
                }
                if (ionBean.getName().equals("ModalAction") || ionBean.getName().equals("PopoverAction")) {
                    try {
                        String pageQName = ionBean.getProperty("page").getSmartValue();
                        if (!pageQName.isBlank()) {
                            String pageName = pageQName.substring(pageQName.lastIndexOf(".") + 1);
                            String pageLower = pageName.toLowerCase();
                            String pagePath = "../pages/" + pageLower + "/" + pageLower;
                            imports.put(pageName, pagePath);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            return imports;
        }

        @Override
        public Map<String, File> getCompBeanDir() {
            return contributor.getCompBeanDir();
        }

        @Override
        public Map<String, String> getModuleTsImports() {
            Map<String, String> map = contributor.getModuleTsImports();
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                if (ionBean.getName().equals("ModalAction") || ionBean.getName().equals("PopoverAction")) {
                    try {
                        String pageQName = ionBean.getProperty("page").getSmartValue();
                        if (!pageQName.isBlank()) {
                            String pageName = pageQName.substring(pageQName.lastIndexOf(".") + 1);
                            String pageLower = pageName.toLowerCase();
                            String pageModuleName = pageName + "Module";
                            String pageModulepath = "../" + pageLower + "/" + pageLower + ".module";
                            map.put(pageModuleName, pageModulepath);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            return map;
        }

        @Override
        public Set<String> getModuleNgImports() {
            Set<String> imports = contributor.getModuleNgImports();
            IonBean ionBean = getIonBean();
            if (ionBean != null) {
                if (ionBean.getName().equals("ModalAction") || ionBean.getName().equals("PopoverAction")) {
                    try {
                        String pageQName = ionBean.getProperty("page").getSmartValue();
                        if (!pageQName.isBlank()) {
                            String pageName = pageQName.substring(pageQName.lastIndexOf(".") + 1);
                            String pageModuleName = pageName + "Module";
                            imports.add(pageModuleName);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            return imports;
        }

        @Override
        public Set<String> getModuleNgProviders() {
            return contributor.getModuleNgProviders();
        }

        @Override
        public Set<String> getModuleNgDeclarations() {
            return contributor.getModuleNgDeclarations();
        }

        @Override
        public Set<String> getModuleNgComponents() {
            return contributor.getModuleNgComponents();
        }

        @Override
        public Map<String, String> getPackageDependencies() {
            return contributor.getPackageDependencies();
        }

        @Override
        public Map<String, String> getConfigPlugins() {
            return contributor.getConfigPlugins();
        }

        @Override
        public Set<String> getModuleNgRoutes(String pageSegment) {
            return contributor.getModuleNgRoutes(pageSegment);
        }
    };
}
Also used : HashMap(java.util.HashMap) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) List(java.util.List) File(java.io.File) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 4 with IonBean

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

the class UIDynamicAction method computeScripts.

@Override
public void computeScripts(JSONObject jsonScripts) {
    IScriptComponent main = getMainScriptComponent();
    if (main == null) {
        return;
    }
    try {
        String imports = jsonScripts.getString("imports");
        IonBean ionBean = getIonBean();
        if (ionBean != null) {
            if (ionBean.getName().equals("ModalAction") || ionBean.getName().equals("PopoverAction")) {
                try {
                    String pageQName = ionBean.getProperty("page").getSmartValue();
                    if (!pageQName.isBlank()) {
                        String pageName = pageQName.substring(pageQName.lastIndexOf(".") + 1);
                        String pageLower = pageName.toLowerCase();
                        String pagePath = "../" + pageLower + "/" + pageLower;
                        if (main.addImport(pageName, pagePath)) {
                            imports += "import {" + pageName + "} from '" + pagePath + "';" + System.lineSeparator();
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        if (main.addImport("* as ts", "typescript")) {
            imports += "import * as ts from 'typescript';" + System.lineSeparator();
        }
        jsonScripts.put("imports", imports);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    // DatabaseObject parent = getParent();
    // if (parent != null && !(parent instanceof IAction) && !(parent instanceof UIActionEvent)) {
    // try {
    // String functions = jsonScripts.getString("functions");
    // String fname = getFunctionName();
    // String fcode = computeActionFunction();
    // if (main.addFunction(fname, fcode)) {
    // functions += System.lineSeparator() + fcode;
    // }
    // jsonScripts.put("functions", functions);
    // } catch (JSONException e) {
    // e.printStackTrace();
    // }
    // }
    super.computeScripts(jsonScripts);
}
Also used : IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) JSONException(org.codehaus.jettison.json.JSONException) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 5 with IonBean

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

the class UIDynamicAction method initProps.

protected StringBuilder initProps(boolean forTemplate) {
    String tplVersion = getTplVersion();
    tplVersion = tplVersion == null ? "" : tplVersion;
    StringBuilder sbProps = new StringBuilder();
    sbProps.append("tplVersion").append(": ").append("'" + tplVersion + "'");
    sbProps.append(", actionName").append(": ").append("'" + getName() + "'");
    sbProps.append(", actionFunction").append(": ").append("'" + getActionName() + "'");
    IonBean ionBean = getIonBean();
    if (ionBean != null) {
        if (ionBean.getName().equals("ModalAction") || ionBean.getName().equals("PopoverAction")) {
            try {
                String pageQName = ionBean.getProperty("page").getSmartValue();
                if (!pageQName.isBlank()) {
                    String pageClass = pageQName.substring(pageQName.lastIndexOf(".") + 1);
                    sbProps.append(", component").append(": ").append(pageClass);
                } else {
                    sbProps.append(", component").append(": ").append("null");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return sbProps;
}
Also used : IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

IonBean (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean)23 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 EngineException (com.twinsoft.convertigo.engine.EngineException)9 IonProperty (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty)8 JSONObject (org.codehaus.jettison.json.JSONObject)8 JSONException (org.codehaus.jettison.json.JSONException)6 UIDynamicAction (com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction)4 HashMap (java.util.HashMap)4 UIActionStack (com.twinsoft.convertigo.beans.ngx.components.UIActionStack)3 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)3 UIUseShared (com.twinsoft.convertigo.beans.ngx.components.UIUseShared)3 File (java.io.File)3 Project (com.twinsoft.convertigo.beans.core.Project)2 ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)2 MobileSmartSourceType (com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType)2 UICompVariable (com.twinsoft.convertigo.beans.ngx.components.UICompVariable)2 UIControlVariable (com.twinsoft.convertigo.beans.ngx.components.UIControlVariable)2 UIDynamicElement (com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement)2 UIDynamicInvoke (com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke)2 UIStackVariable (com.twinsoft.convertigo.beans.ngx.components.UIStackVariable)2