Search in sources :

Example 1 with UIComponent

use of com.twinsoft.convertigo.beans.ngx.components.UIComponent 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 UIComponent

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

the class NgxUIComponentTreeObject method refactorSmartSources.

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

Example 3 with UIComponent

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

the class NgxUIComponentTreeObject method treeObjectRemoved.

@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
    super.treeObjectRemoved(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    Set<Object> done = checkDone(treeObjectEvent);
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObjectTreeObject deletedTreeObject = (DatabaseObjectTreeObject) treeObject;
        try {
            if (deletedTreeObject != null && this.equals(deletedTreeObject.getParentDatabaseObjectTreeObject())) {
                UIComponent currentDbo = getObject();
                UIActionStack uisa = currentDbo.getSharedAction();
                UISharedComponent uisc = currentDbo.getSharedComponent();
                if (uisa != null) {
                    notifyDataseObjectPropertyChanged(uisa, "", null, null, done);
                } else if (uisc != null) {
                    notifyDataseObjectPropertyChanged(uisc, "", null, null, done);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with UIComponent

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

the class NgxUIComponentTreeObject method treeObjectPropertyChanged.

@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
    super.treeObjectPropertyChanged(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    Set<Object> done = checkDone(treeObjectEvent);
    String propertyName = (String) treeObjectEvent.propertyName;
    propertyName = ((propertyName == null) ? "" : propertyName);
    refactorSmartSources(treeObjectEvent);
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
        DatabaseObject dbo = doto.getObject();
        try {
            if (this.equals(treeObject)) {
                markMainAsDirty(getObject(), done);
                UIActionStack uisa = ((UIComponent) dbo).getSharedAction();
                UISharedComponent uisc = ((UIComponent) dbo).getSharedComponent();
                if (uisa != null && !uisa.equals(getObject())) {
                    notifyDataseObjectPropertyChanged(uisa, "", null, null, done);
                }
                if (uisc != null && !uisc.equals(getObject())) {
                    notifyDataseObjectPropertyChanged(uisc, "", null, null, done);
                }
            } else {
                if (propertyName.equals("name")) {
                    handlesBeanNameChanged(treeObjectEvent);
                }
                if (dbo instanceof UIActionStack) {
                    handleSharedActionChanged((UIActionStack) dbo, done);
                } else if (dbo instanceof UISharedComponent) {
                    handleSharedComponentChanged((UISharedComponent) dbo, done);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with UIComponent

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

the class NgxUIComponentTreeObject method launchEditor.

@Override
public void launchEditor(String editorType) {
    UIComponent uic = getObject();
    if (uic instanceof UICustom) {
        openHtmlFileEditor();
    } else if (uic instanceof UIStyle) {
        openCssFileEditor();
    } else if (uic instanceof UICustomAction) {
        String functionMarker = "function:" + ((UICustomAction) uic).getActionName();
        editFunction(uic, functionMarker, "actionValue");
    } else {
        super.launchEditor(editorType);
    }
}
Also used : UICustom(com.twinsoft.convertigo.beans.ngx.components.UICustom) UIStyle(com.twinsoft.convertigo.beans.ngx.components.UIStyle) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) UICustomAction(com.twinsoft.convertigo.beans.ngx.components.UICustomAction)

Aggregations

UIComponent (com.twinsoft.convertigo.beans.ngx.components.UIComponent)19 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 UIActionStack (com.twinsoft.convertigo.beans.ngx.components.UIActionStack)9 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)9 PageComponent (com.twinsoft.convertigo.beans.ngx.components.PageComponent)8 EngineException (com.twinsoft.convertigo.engine.EngineException)8 ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 SourceData (com.twinsoft.convertigo.beans.ngx.components.MobileSmartSource.SourceData)4 UICustomAction (com.twinsoft.convertigo.beans.ngx.components.UICustomAction)4 UIUseShared (com.twinsoft.convertigo.beans.ngx.components.UIUseShared)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 JSONException (org.codehaus.jettison.json.JSONException)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 CoreException (org.eclipse.core.runtime.CoreException)4 MobileSmartSourceType (com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType)3 FullSyncConnector (com.twinsoft.convertigo.beans.connectors.FullSyncConnector)2 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)2 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)2