Search in sources :

Example 1 with UIComponent

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

the class SharedComponentWizard method createSharedComponent.

private UISharedComponent createSharedComponent() throws Exception {
    UIComponent uic = (UIComponent) getFirstInList();
    UISharedComponent uisc = new UISharedComponent();
    uisc.setName(shared_comp_name);
    uisc.hasChanged = true;
    uisc.bNew = true;
    // must be added before copy/paste !
    uic.getApplication().add(uisc);
    for (DatabaseObject dbo : objectList) {
        ConvertigoPlugin.clipboardManagerSystem.reset();
        ConvertigoPlugin.clipboardManagerSystem.isCopy = true;
        String sXml = ConvertigoPlugin.clipboardManagerSystem.copy(dbo);
        ConvertigoPlugin.clipboardManagerSystem.paste(sXml, uisc, false);
    }
    updateMobileSmartSources(uisc);
    for (String name : dlg_map.keySet()) {
        String value = getVariablesDefaultValue(name);
        uisc.add(createCompVariable(dlg_map.get(name), value));
    }
    return uisc;
}
Also used : UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)

Example 2 with UIComponent

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

the class SharedComponentWizard method scanForVariables.

private void scanForVariables(final UIComponent origin) throws Exception {
    final Set<String> identifierSet = new HashSet<String>();
    try {
        new WalkHelper() {

            private void addDeclaration(String var_name, String var_value) {
                if (var_name != null && !var_name.isEmpty() && !main_map.containsKey(var_name)) {
                    main_map.put(var_name, var_value == null ? "''" : var_value);
                }
            }

            private void getMainDeclarations() {
                try {
                    List<String> declarations = new ArrayList<String>();
                    String c8o_Declarations = "", markerId = "";
                    if (isInPage(origin)) {
                        markerId = "PageDeclaration";
                        String c8o_UserCustoms = origin.getPage().getScriptContent().getString();
                        c8o_Declarations = Ionic3Builder.getMarker(c8o_UserCustoms, markerId);
                    } else if (isInSharedComponent(origin)) {
                        markerId = "SharedCompDeclaration";
                        UISharedComponent uisc = origin.getSharedComponent();
                        for (UICompVariable var : uisc.getVariables()) {
                            c8o_Declarations += "let " + var.getVariableName() + " = " + var.getVariableValue() + ";" + System.lineSeparator();
                        }
                    } else if (isInApplication(origin)) {
                        markerId = "AppDeclaration";
                        String c8o_UserCustoms = origin.getApplication().getComponentScriptContent().getString();
                        c8o_Declarations = Ionic3Builder.getMarker(c8o_UserCustoms, markerId);
                    }
                    if (!c8o_Declarations.isEmpty()) {
                        for (String line : Arrays.asList(c8o_Declarations.split(System.lineSeparator()))) {
                            line = line.trim();
                            if (!line.isEmpty() && line.indexOf(markerId) == -1) {
                                declarations.add(line);
                            }
                        }
                    }
                    for (String line : declarations) {
                        // "(((\\w+)\\s(\\w+)([^\\=]+))(\\=([^\\=]+))?)"
                        Matcher matcher = d_var.matcher(line);
                        while (matcher.find()) {
                            String var_name = matcher.group(4);
                            String var_value = matcher.group(7);
                            if (var_value != null) {
                                var_value = var_value.trim();
                                if (var_value.charAt(var_value.length() - 1) == ';') {
                                    var_value = var_value.substring(0, var_value.length() - 1);
                                }
                                var_value = escapeString(var_value);
                            }
                            addDeclaration(var_name, var_value);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            private boolean isInForDirective(UIComponent uic) {
                return getForDirective(uic) != null;
            }

            private UIControlDirective getForDirective(UIComponent uic) {
                DatabaseObject databaseObject = uic;
                while (databaseObject != null && (!(databaseObject instanceof UIControlDirective) || !AttrDirective.ForEach.name().equals(((UIControlDirective) databaseObject).getDirectiveName()))) {
                    databaseObject = databaseObject.getParent();
                }
                if (databaseObject == null)
                    return null;
                else
                    return (UIControlDirective) databaseObject;
            }

            private void getForDirectiveVariables(UIComponent uic) {
                UIComponent uicomponent = uic;
                while (isInForDirective(uicomponent)) {
                    UIControlDirective uicd = getForDirective(uicomponent);
                    if (!uic.equals(uicd)) {
                        String item = "item" + uicd.priority;
                        addDeclaration(item, "[]");
                        addMapVariable(item, item, "this._params_." + item);
                        addMapVariable(item, uicd.toString() + " : found  variable which stands for the iterator's item");
                        String itemName = uicd.getDirectiveItemName();
                        addDeclaration(itemName, "{}");
                        addMapVariable(itemName, itemName, "this._params_." + itemName);
                        addMapVariable(itemName, uicd.toString() + " : found variable which stands for the customized iterator's item");
                        String indexName = uicd.getDirectiveIndexName();
                        addDeclaration(indexName, "0");
                        addMapVariable(indexName, indexName, "this._params_." + indexName);
                        addMapVariable(indexName, uicd.toString() + " : found variable which stands for the customized iterator's index");
                        String expression = uicd.getDirectiveExpression();
                        if (!expression.isEmpty()) {
                            Matcher matcher = null;
                            List<String> list = Arrays.asList(expression.split("\\;"));
                            for (String s : list) {
                                matcher = d_var_let.matcher(s);
                                while (matcher.find()) {
                                    String expvar = matcher.group(3);
                                    addDeclaration(expvar, "''");
                                    addMapVariable(expvar, expvar, "this._params_." + expvar);
                                    addMapVariable(expvar, uicd.toString() + " : found variable used by the customized iterator's expression");
                                }
                                matcher = d_var_as.matcher(s);
                                while (matcher.find()) {
                                    String expvar = matcher.group(4);
                                    addDeclaration(expvar, "''");
                                    addMapVariable(expvar, expvar, "this._params_." + expvar);
                                    addMapVariable(expvar, uicd.toString() + " : found variable used by the customized iterator's expression");
                                }
                            }
                        }
                    }
                    DatabaseObject dbo = uicd.getParent();
                    uicomponent = dbo instanceof UIComponent ? (UIComponent) dbo : null;
                }
            }

            private boolean checkVariable(String name) {
                if (name == null || name.isEmpty())
                    return false;
                if (identifierSet.contains(name)) {
                    return false;
                }
                if ("global".equals(name))
                    return false;
                if ("router".equals(name))
                    return false;
                return true;
            }

            private void addMapVariable(String name, String target, String replacement) {
                if (checkVariable(name)) {
                    String normalized_name = StringUtils.normalize(name);
                    String var_name = normalized_name;
                    if (ovarMap.containsKey(var_name)) {
                    // System.out.println("var_name: "+ var_name + " already in ovarMap");
                    } else {
                        ovarMap.put(var_name, new HashMap<String, String>());
                    }
                    ovarMap.get(var_name).put(target, replacement.replace("_params_." + name, "_params_.") + var_name);
                }
            }

            private void addMapVariable(String name, String infos) {
                if (checkVariable(name)) {
                    String normalized_name = StringUtils.normalize(name);
                    String var_name = normalized_name;
                    if (infoMap.containsKey(var_name)) {
                    // System.out.println("var_name: "+ var_name + " already in infoMap");
                    } else {
                        infoMap.put(var_name, infos);
                    }
                }
            }

            private void scanSmartSource(UIComponent uic, String p_name, MobileSmartSourceType msst) throws Exception {
                boolean extended = !forTemplate(uic);
                String s = null;
                if (Mode.SCRIPT.equals(msst.getMode())) {
                    s = msst.getValue(extended);
                }
                if (Mode.SOURCE.equals(msst.getMode())) {
                    s = msst.getSmartSource().toJsonString();
                }
                if (s != null) {
                    String infos = uic.toString() + " : found variable used by '" + p_name + "' property";
                    Matcher matcher = p_var.matcher(s);
                    while (matcher.find()) {
                        String group1 = matcher.group(1);
                        String group2 = matcher.group(2);
                        // String group3 = matcher.group(3);
                        String group4 = matcher.group(4);
                        String name = group4;
                        String target = group1;
                        String replacement = group2 + "._params_." + name;
                        if (isInControlEvent(uic)) {
                            if (forTemplate(uic)) {
                                replacement = "_params_." + name;
                            } else {
                                replacement = "scope._params_." + name;
                            }
                        }
                        addMapVariable(name, target, replacement);
                        addMapVariable(name, infos);
                    }
                }
            }

            @Override
            public void init(DatabaseObject databaseObject) throws Exception {
                getMainDeclarations();
                if (isInForDirective(origin)) {
                    getForDirectiveVariables(origin);
                }
                super.init(databaseObject);
            }

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                if (databaseObject instanceof UIComponent) {
                    UIComponent uic = (UIComponent) databaseObject;
                    if (uic.isEnabled() && !isInControlEvent(uic)) {
                        if (databaseObject instanceof UIDynamicElement) {
                            String identifier = ((UIDynamicElement) databaseObject).getIdentifier();
                            if (!identifier.isEmpty()) {
                                identifierSet.add(identifier);
                            }
                        }
                        for (java.beans.PropertyDescriptor pd : CachedIntrospector.getBeanInfo(databaseObject).getPropertyDescriptors()) {
                            if (pd.getPropertyEditorClass() != null) {
                                if (pd.getPropertyEditorClass().getSimpleName().equals("MobileSmartSourcePropertyDescriptor")) {
                                    Method getter = pd.getReadMethod();
                                    Object value = getter.invoke(databaseObject, new Object[] {});
                                    if (value != null && value instanceof MobileSmartSourceType) {
                                        MobileSmartSourceType msst = (MobileSmartSourceType) value;
                                        if (Mode.SCRIPT.equals(msst.getMode()) || Mode.SOURCE.equals(msst.getMode())) {
                                            scanSmartSource(uic, pd.getName(), msst);
                                        }
                                    }
                                }
                            }
                        }
                        if (databaseObject instanceof UIDynamicElement) {
                            UIDynamicElement uide = (UIDynamicElement) databaseObject;
                            IonBean ionBean = uide.getIonBean();
                            if (ionBean != null) {
                                for (IonProperty property : ionBean.getProperties().values()) {
                                    Object p_value = property.getValue();
                                    if (!p_value.equals(false)) {
                                        MobileSmartSourceType msst = property.getSmartType();
                                        if (Mode.SCRIPT.equals(msst.getMode()) || Mode.SOURCE.equals(msst.getMode())) {
                                            scanSmartSource(uide, property.getName(), msst);
                                        }
                                    }
                                }
                            }
                        }
                        super.walk(databaseObject);
                    }
                }
            }
        }.init(origin);
    } catch (Exception e) {
        throw new Exception("Unable to scan for variables", e);
    }
}
Also used : UICompVariable(com.twinsoft.convertigo.beans.mobile.components.UICompVariable) IonProperty(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonProperty) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UIControlDirective(com.twinsoft.convertigo.beans.mobile.components.UIControlDirective) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Method(java.lang.reflect.Method) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ArrayList(java.util.ArrayList) List(java.util.List) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) HashSet(java.util.HashSet)

Example 3 with UIComponent

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

the class MobilePickerComposite method setCurrentInput.

public void setCurrentInput(Object selected, String source) {
    if (isUpdating)
        return;
    currentMC = null;
    setWidgetsEnabled(true);
    if (selected instanceof MobileComponentTreeObject) {
        UIComponent uic = null;
        if (selected instanceof MobilePageComponentTreeObject) {
            currentMC = ((MobilePageComponentTreeObject) selected).getObject();
        } else if (selected instanceof MobileUIComponentTreeObject) {
            uic = ((MobileUIComponentTreeObject) selected).getObject();
            // currentMC = uic.getPage() != null ? uic.getPage() : (uic.getMenu() != null ?  uic.getMenu() : uic.getApplication());
            currentMC = currentMC == null ? uic.getPage() : currentMC;
            currentMC = currentMC == null ? uic.getMenu() : currentMC;
            currentMC = currentMC == null ? uic.getSharedAction() : currentMC;
            currentMC = currentMC == null ? uic.getSharedComponent() : currentMC;
            currentMC = currentMC == null ? uic.getApplication() : currentMC;
        }
        if (currentMC == null) {
            resetViewers();
        } else {
            if (!currentMC.equals(checkboxTreeViewer.getInput())) {
                resetViewers();
                checkboxTreeViewer.setInput(currentMC);
                initTreeSelection(checkboxTreeViewer, null);
            }
            MobileSmartSource cs = MobileSmartSource.valueOf(source);
            if (cs != null) {
                MobilePickerContentProvider contentProvider = (MobilePickerContentProvider) checkboxTreeViewer.getContentProvider();
                if (isParentDialog) {
                    // when dbo's property edition
                    contentProvider.setSelectedDbo(uic);
                }
                ToolItem buttonToSelect = btnSequence;
                currentSource = source;
                Filter filter = cs.getFilter();
                if (Filter.Sequence.equals(filter)) {
                    buttonToSelect = btnSequence;
                }
                if (Filter.Database.equals(filter)) {
                    buttonToSelect = btnDatabase;
                }
                if (Filter.Action.equals(filter)) {
                    buttonToSelect = btnAction;
                }
                if (Filter.Shared.equals(filter)) {
                    buttonToSelect = btnShared;
                }
                if (Filter.Iteration.equals(filter)) {
                    buttonToSelect = btnIteration;
                }
                if (Filter.Form.equals(filter)) {
                    buttonToSelect = btnForm;
                }
                if (Filter.Global.equals(filter)) {
                    buttonToSelect = btnGlobal;
                }
                buttonToSelect.notifyListeners(SWT.Selection, null);
            }
        }
        updateMessage();
    } else {
        resetViewers();
        updateMessage();
    }
}
Also used : MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) MobilePageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePageComponentTreeObject) MobileSmartSource(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource) Filter(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.Filter) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 4 with UIComponent

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

the class MobilePickerContentProvider method addIterations.

private void addIterations(TVObject tvi, Object object) {
    if (object != null) {
        List<UIComponent> list = null;
        if (object instanceof PageComponent) {
            list = ((PageComponent) object).getUIComponentList();
        } else if (object instanceof UIComponent) {
            list = ((UIComponent) object).getUIComponentList();
        }
        if (list != null) {
            for (UIComponent uic : list) {
                if (uic instanceof UIControlDirective) {
                    // do not add to prevent selection on itself or children
                    if (uic.equals(selected)) {
                        return;
                    }
                    // do not add if not parent of selected (popped picker only)
                    boolean showInPicker = true;
                    if (selected != null && selected instanceof UIComponent) {
                        String selectedQName = ((UIComponent) selected).getQName();
                        String uicQName = uic.getQName() + ".";
                        if (!selectedQName.startsWith(uicQName)) {
                            showInPicker = false;
                        }
                    }
                    UIControlDirective uicd = (UIControlDirective) uic;
                    if (showInPicker && AttrDirective.ForEach.equals(AttrDirective.getDirective(uicd.getDirectiveName()))) {
                        SourceData sd = null;
                        try {
                            sd = Filter.Iteration.toSourceData(new JSONObject().put("priority", uic.priority));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        TVObject tuic = tvi.add(new TVObject(uic.toString(), uic, sd));
                        addIterations(tuic, uic);
                    } else {
                        addIterations(tvi, uic);
                    }
                } else {
                    addIterations(tvi, uic);
                }
            }
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UIControlDirective(com.twinsoft.convertigo.beans.mobile.components.UIControlDirective) JSONException(org.codehaus.jettison.json.JSONException) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) SourceData(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData)

Example 5 with UIComponent

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

the class MobilePickerContentProvider method addForms.

private void addForms(TVObject tvi, Object object) {
    if (object != null) {
        List<UIComponent> list = null;
        if (object instanceof PageComponent) {
            list = ((PageComponent) object).getUIComponentList();
        } else if (object instanceof UIComponent) {
            list = ((UIComponent) object).getUIComponentList();
        }
        if (list != null) {
            for (UIComponent uic : list) {
                if (uic instanceof UIForm) {
                    // do not add to prevent selection on itself or children
                    if (uic.equals(selected)) {
                        return;
                    }
                    SourceData sd = null;
                    try {
                        sd = Filter.Form.toSourceData(new JSONObject().put("priority", uic.priority));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    TVObject tuic = tvi.add(new TVObject(uic.toString(), uic, sd));
                    addForms(tuic, uic);
                } else {
                    addForms(tvi, uic);
                }
            }
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) JSONException(org.codehaus.jettison.json.JSONException) UIForm(com.twinsoft.convertigo.beans.mobile.components.UIForm) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) SourceData(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData)

Aggregations

UIComponent (com.twinsoft.convertigo.beans.mobile.components.UIComponent)26 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)13 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)13 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)10 ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)9 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)9 EngineException (com.twinsoft.convertigo.engine.EngineException)8 CoreException (org.eclipse.core.runtime.CoreException)7 UIUseShared (com.twinsoft.convertigo.beans.mobile.components.UIUseShared)6 MobileSmartSourceType (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType)5 JSONException (org.codehaus.jettison.json.JSONException)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 MobileComponent (com.twinsoft.convertigo.beans.mobile.components.MobileComponent)4 SourceData (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData)4 UICustomAction (com.twinsoft.convertigo.beans.mobile.components.UICustomAction)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ArrayList (java.util.ArrayList)4 TreeObjectEvent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)3 File (java.io.File)3 FullSyncConnector (com.twinsoft.convertigo.beans.connectors.FullSyncConnector)2