Search in sources :

Example 1 with UIDynamicElement

use of com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement 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 2 with UIDynamicElement

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

the class IonBean method createBean.

protected DatabaseObject createBean() {
    UIDynamicElement dbo = null;
    try {
        Object[] args = { getTag() };
        String dboclass = getClassName();
        Class<?> c = Class.forName(dboclass);
        dbo = (UIDynamicElement) c.getConstructor(String.class).newInstance(args);
        // dbo.setName(getName());
        dbo.setName(StringUtils.normalize(getDisplayName()));
        dbo.setSelfClose(isSelfClose());
        dbo.setBeanData(getJSONObject().toString());
        dbo.bNew = true;
        dbo.hasChanged = true;
    } catch (Exception e) {
        e.printStackTrace();
        dbo = null;
    }
    return dbo;
}
Also used : UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException)

Example 3 with UIDynamicElement

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

the class MobileUIComponentTreeObject 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;
                    }
                }
            }
        }
    }
    super.setPropertyValue(id, value);
}
Also used : IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)

Example 4 with UIDynamicElement

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

the class MobileUIComponentTreeObject 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 MobileSmartSourcePropertyDescriptor(id, displayName, tags, !isEditable);
                        ((MobileSmartSourcePropertyDescriptor) 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 = MobileUIComponentTreeObject.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.mobile.components.dynamic.IonProperty) PropertyDescriptor(org.eclipse.ui.views.properties.PropertyDescriptor) StringComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) Composite(org.eclipse.swt.widgets.Composite) IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) CellEditor(org.eclipse.jface.viewers.CellEditor) AbstractDialogCellEditor(com.twinsoft.convertigo.eclipse.property_editors.AbstractDialogCellEditor) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) 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)

Example 5 with UIDynamicElement

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

the class MobileUIComponentTreeObject method getNamedSourceSelector.

@Override
public NamedSourceSelector getNamedSourceSelector() {
    return new NamedSourceSelector() {

        @Override
        Object thisTreeObject() {
            return MobileUIComponentTreeObject.this;
        }

        @Override
        protected List<String> getPropertyNamesForSource(Class<?> c) {
            List<String> list = new ArrayList<String>();
            UIComponent object = getObject();
            if (object instanceof UIDynamicTab) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("tabpage");
                }
            } else if (object instanceof UIDynamicMenuItem) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("itempage");
                }
            } else if (object instanceof UIDynamicAnimate) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c) || MobileUIComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("identifiable");
                }
            } else if (object instanceof UIDynamicInvoke) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobileUIComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("stack");
                }
            } else if (object instanceof UIUseShared) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobileUIComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("sharedcomponent");
                }
            } else if (object instanceof UIDynamicInfiniteScroll) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c) || MobileUIComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("scrollaction");
                }
            } else if (object instanceof UIDynamicElement) {
                if (ProjectTreeObject.class.isAssignableFrom(c) || SequenceTreeObject.class.isAssignableFrom(c) || ConnectorTreeObject.class.isAssignableFrom(c)) {
                    list.add("requestable");
                }
                if (ProjectTreeObject.class.isAssignableFrom(c) || MobileApplicationTreeObject.class.isAssignableFrom(c) || MobileApplicationComponentTreeObject.class.isAssignableFrom(c) || MobilePageComponentTreeObject.class.isAssignableFrom(c)) {
                    list.add("page");
                }
                if (ProjectTreeObject.class.isAssignableFrom(c) || ConnectorTreeObject.class.isAssignableFrom(c) || DesignDocumentTreeObject.class.isAssignableFrom(c) || DesignDocumentViewTreeObject.class.isAssignableFrom(c)) {
                    list.add("fsview");
                }
            }
            return list;
        }

        @Override
        protected boolean isNamedSource(String propertyName) {
            UIComponent object = getObject();
            if (object instanceof UIDynamicTab) {
                return "tabpage".equals(propertyName);
            } else if (object instanceof UIDynamicMenuItem) {
                return "itempage".equals(propertyName);
            } else if (object instanceof UIDynamicAnimate) {
                return "identifiable".equals(propertyName);
            } else if (object instanceof UIDynamicInvoke) {
                return "stack".equals(propertyName);
            } else if (object instanceof UIUseShared) {
                return "sharedcomponent".equals(propertyName);
            } else if (object instanceof UIDynamicInfiniteScroll) {
                return "scrollaction".equals(propertyName);
            } else if (object instanceof UIDynamicElement) {
                return "requestable".equals(propertyName) || "fsview".equals(propertyName) || "page".equals(propertyName);
            }
            return false;
        }

        @Override
        public boolean isSelectable(String propertyName, Object nsObject) {
            UIComponent object = getObject();
            if (object instanceof UIDynamicTab) {
                if ("tabpage".equals(propertyName)) {
                    if (nsObject instanceof PageComponent) {
                        return (((PageComponent) nsObject).getProject().equals(object.getProject()));
                    }
                }
            } else if (object instanceof UIDynamicMenuItem) {
                if ("itempage".equals(propertyName)) {
                    if (nsObject instanceof PageComponent) {
                        return (((PageComponent) nsObject).getProject().equals(object.getProject()));
                    }
                }
            } else if (object instanceof UIDynamicAnimate) {
                if ("identifiable".equals(propertyName)) {
                    UIDynamicAnimate uda = (UIDynamicAnimate) object;
                    if (nsObject instanceof UIElement) {
                        UIElement ue = (UIElement) nsObject;
                        if (hasSameScriptComponent(uda, ue)) {
                            return !ue.getIdentifier().isEmpty();
                        }
                    }
                }
            } else if (object instanceof UIDynamicInvoke) {
                if ("stack".equals(propertyName)) {
                    return nsObject instanceof UIActionStack;
                }
            } else if (object instanceof UIUseShared) {
                if ("sharedcomponent".equals(propertyName)) {
                    return nsObject instanceof UISharedComponent;
                }
            } else if (object instanceof UIDynamicInfiniteScroll) {
                if ("scrollaction".equals(propertyName)) {
                    if (nsObject instanceof UIDynamicAction) {
                        UIDynamicAction uida = (UIDynamicAction) nsObject;
                        if (uida.getProject().equals(object.getProject())) {
                            if (uida.getIonBean().getName().equals("CallSequenceAction")) {
                                return true;
                            }
                            if (uida.getIonBean().getName().equals("FullSyncViewAction")) {
                                return true;
                            }
                        }
                    }
                }
            } else if (object instanceof UIDynamicElement) {
                if ("requestable".equals(propertyName)) {
                    UIDynamicElement cc = (UIDynamicElement) object;
                    if (cc.getIonBean().getName().equals("CallSequenceAction")) {
                        return nsObject instanceof Sequence;
                    }
                    if (cc.getIonBean().getName().equals("CallFullSyncAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncSyncAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncViewAction")) {
                        return nsObject instanceof DesignDocument;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncPostAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncGetAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncDeleteAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncPutAttachmentAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FullSyncDeleteAttachmentAction")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("FSImage")) {
                        return nsObject instanceof FullSyncConnector;
                    }
                    if (cc.getIonBean().getName().equals("AutoScrollComponent")) {
                        return nsObject instanceof Sequence;
                    }
                }
                if ("fsview".equals(propertyName)) {
                    UIDynamicElement cc = (UIDynamicElement) object;
                    if (cc.getIonBean().getName().equals("FullSyncViewAction")) {
                        return nsObject instanceof String;
                    }
                    if (cc.getIonBean().getName().equals("AutoScrollComponent")) {
                        return nsObject instanceof DesignDocument || nsObject instanceof String;
                    }
                }
                if ("page".equals(propertyName)) {
                    if (nsObject instanceof PageComponent) {
                        return (((PageComponent) nsObject).getProject().equals(object.getProject()));
                    }
                }
            }
            return false;
        }

        @Override
        protected void handleSourceCleared(String propertyName) {
        // nothing to do
        }

        @Override
        protected void handleSourceRenamed(String propertyName, String oldName, String newName) {
            if (isNamedSource(propertyName)) {
                boolean hasBeenRenamed = false;
                Object oValue = getPropertyValue(propertyName);
                String pValue;
                if (oValue instanceof MobileSmartSourceType) {
                    MobileSmartSourceType sst = (MobileSmartSourceType) oValue;
                    pValue = sst.getSmartValue();
                } else {
                    pValue = (String) oValue;
                }
                String _pValue = pValue;
                if (pValue != null && (pValue.startsWith(oldName + ".") || pValue.equals(oldName))) {
                    _pValue = newName + pValue.substring(oldName.length());
                    if (!pValue.equals(_pValue)) {
                        UIComponent object = getObject();
                        if (object instanceof UIDynamicTab) {
                            if ("tabpage".equals(propertyName)) {
                                ((UIDynamicTab) object).setTabPage(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicMenuItem) {
                            if ("itempage".equals(propertyName)) {
                                ((UIDynamicMenuItem) object).setItemPage(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicAnimate) {
                            if ("identifiable".equals(propertyName)) {
                                ((UIDynamicAnimate) object).setIdentifiable(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicInvoke) {
                            if ("stack".equals(propertyName)) {
                                ((UIDynamicInvoke) object).setSharedActionQName(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIUseShared) {
                            if ("sharedcomponent".equals(propertyName)) {
                                ((UIUseShared) object).setSharedComponentQName(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicInfiniteScroll) {
                            if ("scrollaction".equals(propertyName)) {
                                ((UIDynamicInfiniteScroll) object).setScrollAction(_pValue);
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIDynamicElement) {
                            if ("requestable".equals(propertyName)) {
                                ((UIDynamicElement) object).getIonBean().setPropertyValue("requestable", new MobileSmartSourceType(_pValue));
                                hasBeenRenamed = true;
                            }
                            if ("fsview".equals(propertyName)) {
                                ((UIDynamicElement) object).getIonBean().setPropertyValue("fsview", new MobileSmartSourceType(_pValue));
                                hasBeenRenamed = true;
                            }
                            if ("page".equals(propertyName)) {
                                ((UIDynamicElement) object).getIonBean().setPropertyValue("page", new MobileSmartSourceType(_pValue));
                                hasBeenRenamed = true;
                            }
                        } else if (object instanceof UIText) {
                            if ("textValue".equals(propertyName)) {
                                ((UIText) object).setTextSmartType(new MobileSmartSourceType(_pValue));
                                hasBeenRenamed = true;
                            }
                        }
                    }
                }
                if (hasBeenRenamed) {
                    hasBeenModified(true);
                    viewer.refresh();
                    ConvertigoPlugin.projectManager.getProjectExplorerView().updateTreeObject(MobileUIComponentTreeObject.this);
                    // refresh editors (e.g labels in combobox)
                    getDescriptors();
                    TreeObjectEvent treeObjectEvent = new TreeObjectEvent(MobileUIComponentTreeObject.this, propertyName, pValue, _pValue);
                    ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent);
                }
            }
        }

        @Override
        protected void refactorSmartSources(Class<?> c, String oldName, String newName) {
            try {
                // A project has been renamed
                if (ProjectTreeObject.class.isAssignableFrom(c)) {
                    UIComponent object = getObject();
                    for (java.beans.PropertyDescriptor pd : CachedIntrospector.getBeanInfo(object).getPropertyDescriptors()) {
                        if (pd.getPropertyType().equals(MobileSmartSourceType.class)) {
                            String propertyName = pd.getName();
                            Object oValue = getPropertyValue(propertyName);
                            MobileSmartSourceType msst = (MobileSmartSourceType) oValue;
                            MobileSmartSource mss = msst.getSmartSource();
                            boolean hasBeenChanged = false;
                            if (mss != null) {
                                if (oldName.equals(mss.getProjectName())) {
                                    mss.setProjectName(newName);
                                    msst.setSmartValue(mss.toJsonString());
                                    hasBeenChanged = true;
                                }
                            }
                            if (hasBeenChanged) {
                                Object nValue = getPropertyValue(propertyName);
                                hasBeenModified(true);
                                viewer.refresh();
                                ConvertigoPlugin.projectManager.getProjectExplorerView().updateTreeObject(MobileUIComponentTreeObject.this);
                                // refresh editors (e.g labels in combobox)
                                getDescriptors();
                                TreeObjectEvent treeObjectEvent = new TreeObjectEvent(MobileUIComponentTreeObject.this, propertyName, oValue, nValue);
                                ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent);
                            }
                        }
                    }
                }
            } catch (Exception e) {
            // TODO: handle exception
            }
        }
    };
}
Also used : UIElement(com.twinsoft.convertigo.beans.mobile.components.UIElement) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) ArrayList(java.util.ArrayList) UIDynamicTab(com.twinsoft.convertigo.beans.mobile.components.UIDynamicTab) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) UIDynamicInfiniteScroll(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInfiniteScroll) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) UIText(com.twinsoft.convertigo.beans.mobile.components.UIText) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) Sequence(com.twinsoft.convertigo.beans.core.Sequence) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UIDynamicAnimate(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAnimate) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) MobileSmartSource(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource) UIDynamicInvoke(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) UIDynamicMenuItem(com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenuItem) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)5 UIDynamicElement (com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement)5 MobileSmartSourceType (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType)3 IonBean (com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean)3 CoreException (org.eclipse.core.runtime.CoreException)3 UIComponent (com.twinsoft.convertigo.beans.mobile.components.UIComponent)2 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)2 IonProperty (com.twinsoft.convertigo.beans.mobile.components.dynamic.IonProperty)2 TreeObjectEvent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)2 EngineException (com.twinsoft.convertigo.engine.EngineException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 FullSyncConnector (com.twinsoft.convertigo.beans.connectors.FullSyncConnector)1 Sequence (com.twinsoft.convertigo.beans.core.Sequence)1 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)1 MobileSmartSource (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource)1 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)1 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)1 UICompVariable (com.twinsoft.convertigo.beans.mobile.components.UICompVariable)1