Search in sources :

Example 6 with MobileSmartSourceType

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

the class ComponentManager method loadBean.

public static IonBean loadBean(String jsonString) throws Exception {
    JSONObject jsonBean = new JSONObject(jsonString);
    String modelName = jsonBean.getString(IonBean.Key.name.name());
    final IonBean model = instance.bCache.get(modelName);
    // The model exists
    if (model != null) {
        boolean hasChanged = false;
        IonBean dboBean = new IonBean(jsonString);
        IonBean ionBean = new IonBean(model.toString());
        for (IonProperty ionProperty : ionBean.getProperties().values()) {
            String propertyName = ionProperty.getName();
            IonProperty dboProperty = dboBean.getProperty(propertyName);
            if (dboProperty != null) {
                MobileSmartSourceType msst = dboProperty.getSmartType();
                if (msst != null) {
                    ionProperty.setSmartType(msst);
                    ionBean.putProperty(ionProperty);
                }
            } else {
                System.out.println("(ComponentManager) Ion property \"" + propertyName + "\" not found for model \"" + modelName + "\": ignore it.");
                if (Engine.isStarted) {
                    Engine.logBeans.warn("(ComponentManager) Ion property \"" + propertyName + "\" not found for model \"" + modelName + "\": ignore it.");
                }
                hasChanged = true;
            }
        }
        if (hasChanged) {
        // TODO
        }
        return ionBean;
    } else // The model doesn't exist (anymore)
    {
        System.out.println("(ComponentManager) Model \"" + modelName + "\" does not exist anymore in cache.");
        if (Engine.isStarted) {
            Engine.logBeans.warn("(ComponentManager) Model \"" + modelName + "\" does not exist anymore in cache.");
        }
        return new IonBean(jsonString);
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType)

Example 7 with MobileSmartSourceType

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

the class MobileComponentImportVariablesAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            Object databaseObject = treeObject.getObject();
            if (databaseObject != null) {
                if (databaseObject instanceof UIDynamicAction) {
                    UIDynamicAction dynAction = (UIDynamicAction) databaseObject;
                    IonBean ionBean = ((UIDynamicAction) dynAction).getIonBean();
                    if (ionBean != null) {
                        // Case of CallSequenceAction
                        if (ionBean.getName().equals("CallSequenceAction")) {
                            Object value = ionBean.getProperty("requestable").getValue();
                            if (!value.equals(false)) {
                                String target = value.toString();
                                if (!target.isEmpty()) {
                                    try {
                                        String projectName = target.substring(0, target.indexOf('.'));
                                        String sequenceName = target.substring(target.indexOf('.') + 1);
                                        Project p = Engine.theApp.databaseObjectsManager.getProjectByName(projectName);
                                        Sequence sequence = p.getSequenceByName(sequenceName);
                                        int size = sequence.numberOfVariables();
                                        for (int i = 0; i < size; i++) {
                                            RequestableVariable variable = (RequestableVariable) sequence.getVariable(i);
                                            if (variable != null) {
                                                String variableName = variable.getName();
                                                if (dynAction.getVariable(variableName) == null) {
                                                    if (!StringUtils.isNormalized(variableName))
                                                        throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
                                                    UIControlVariable uiVariable = new UIControlVariable();
                                                    uiVariable.setName(variableName);
                                                    uiVariable.setComment(variable.getDescription());
                                                    uiVariable.setVarSmartType(new MobileSmartSourceType(variable.getDefaultValue().toString()));
                                                    dynAction.addUIComponent(uiVariable);
                                                    uiVariable.bNew = true;
                                                    uiVariable.hasChanged = true;
                                                    dynAction.hasChanged = true;
                                                }
                                            }
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                            }
                        } else // Case of InvokeAction
                        if (ionBean.getName().equals("InvokeAction")) {
                            UIDynamicInvoke dynInvoke = (UIDynamicInvoke) databaseObject;
                            UIActionStack stack = dynInvoke.getTargetSharedAction();
                            if (stack != null) {
                                for (UIStackVariable variable : stack.getVariables()) {
                                    String variableName = variable.getName();
                                    if (dynAction.getVariable(variableName) == null) {
                                        if (!StringUtils.isNormalized(variableName))
                                            throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
                                        UIControlVariable uiVariable = new UIControlVariable();
                                        uiVariable.setName(variableName);
                                        uiVariable.setComment(variable.getComment());
                                        MobileSmartSourceType msst = new MobileSmartSourceType();
                                        msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
                                        msst.setSmartValue(variable.getVariableValue());
                                        uiVariable.setVarSmartType(msst);
                                        dynAction.addUIComponent(uiVariable);
                                        uiVariable.bNew = true;
                                        uiVariable.hasChanged = true;
                                        dynAction.hasChanged = true;
                                    }
                                }
                            }
                        }
                        if (dynAction.hasChanged) {
                            IScriptComponent main = dynAction.getMainScriptComponent();
                            if (main != null) {
                                if (main instanceof ApplicationComponent) {
                                    ((ApplicationComponent) main).markApplicationAsDirty();
                                }
                                if (main instanceof PageComponent) {
                                    ((PageComponent) main).markPageAsDirty();
                                }
                            }
                            explorerView.reloadTreeObject(treeObject);
                            StructuredSelection structuredSelection = new StructuredSelection(treeObject);
                            ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
                        }
                    }
                } else if (databaseObject instanceof UIUseShared) {
                    UIUseShared useShared = (UIUseShared) databaseObject;
                    UISharedComponent sharedComp = useShared.getTargetSharedComponent();
                    if (sharedComp != null) {
                        for (UICompVariable variable : sharedComp.getVariables()) {
                            String variableName = variable.getName();
                            if (useShared.getVariable(variableName) == null) {
                                if (!StringUtils.isNormalized(variableName))
                                    throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
                                UIControlVariable uiVariable = new UIControlVariable();
                                uiVariable.setName(variableName);
                                uiVariable.setComment(variable.getComment());
                                MobileSmartSourceType msst = new MobileSmartSourceType();
                                msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
                                msst.setSmartValue(variable.getVariableValue());
                                uiVariable.setVarSmartType(msst);
                                useShared.addUIComponent(uiVariable);
                                uiVariable.bNew = true;
                                uiVariable.hasChanged = true;
                                useShared.hasChanged = true;
                            }
                        }
                        if (useShared.hasChanged) {
                            IScriptComponent main = useShared.getMainScriptComponent();
                            if (main != null) {
                                if (main instanceof ApplicationComponent) {
                                    ((ApplicationComponent) main).markApplicationAsDirty();
                                }
                                if (main instanceof PageComponent) {
                                    ((PageComponent) main).markPageAsDirty();
                                }
                            }
                            explorerView.reloadTreeObject(treeObject);
                            StructuredSelection structuredSelection = new StructuredSelection(treeObject);
                            ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to add variables to action !");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) EngineException(com.twinsoft.convertigo.engine.EngineException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UIControlVariable(com.twinsoft.convertigo.beans.mobile.components.UIControlVariable) Cursor(org.eclipse.swt.graphics.Cursor) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) UICompVariable(com.twinsoft.convertigo.beans.mobile.components.UICompVariable) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) IScriptComponent(com.twinsoft.convertigo.beans.mobile.components.IScriptComponent) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) UIStackVariable(com.twinsoft.convertigo.beans.mobile.components.UIStackVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) UIDynamicInvoke(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 8 with MobileSmartSourceType

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

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

the class MobileApplicationComponentTreeObject 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);
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
        DatabaseObject dbo = doto.getObject();
        try {
            ApplicationComponent ac = getObject();
            // for Page or Menu or Route
            if (ac.equals(dbo.getParent())) {
                markApplicationAsDirty(done);
            } else // for any component inside a route
            if (ac.equals(dbo.getParent().getParent())) {
                markApplicationAsDirty(done);
            } else // for any UI component inside a menu or a stack
            if (dbo instanceof UIComponent) {
                UIComponent uic = (UIComponent) dbo;
                UIDynamicMenu menu = uic.getMenu();
                if (menu != null) {
                    if (ac.equals(menu.getParent())) {
                        if (propertyName.equals("FormControlName") || uic.isFormControlAttribute()) {
                            if (!newValue.equals(oldValue)) {
                                try {
                                    String oldSmart = ((MobileSmartSourceType) oldValue).getSmartValue();
                                    String newSmart = ((MobileSmartSourceType) newValue).getSmartValue();
                                    if (uic.getUIForm() != null) {
                                        String form = uic.getUIForm().getFormGroupName();
                                        if (menu.updateSmartSource(form + "\\?\\.controls\\['" + oldSmart + "'\\]", form + "?.controls['" + newSmart + "']")) {
                                            this.viewer.refresh();
                                        }
                                    }
                                } catch (Exception e) {
                                }
                            }
                        }
                        markApplicationAsDirty(done);
                    }
                }
            } else // for this application
            if (this.equals(doto)) {
                if (propertyName.equals("isPWA")) {
                    if (!newValue.equals(oldValue)) {
                        markPwaAsDirty();
                    }
                } else if (propertyName.equals("componentScriptContent")) {
                    if (!newValue.equals(oldValue)) {
                        markComponentTsAsDirty();
                        markApplicationAsDirty(done);
                    }
                } else if (propertyName.equals("useClickForTap")) {
                    for (TreeObject to : this.getChildren()) {
                        if (to instanceof ObjectsFolderTreeObject) {
                            ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
                            if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
                                for (TreeObject cto : ofto.getChildren()) {
                                    if (cto instanceof MobilePageComponentTreeObject) {
                                        ((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
                                    }
                                }
                            }
                        }
                    }
                    markApplicationAsDirty(done);
                } else if (propertyName.equals("tplProjectName")) {
                    // close app editor and reinitialize builder
                    Project project = ac.getProject();
                    closeAllEditors(false);
                    MobileBuilder.releaseBuilder(project);
                    MobileBuilder.initBuilder(project);
                    IProject iproject = ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName());
                    iproject.refreshLocal(IResource.DEPTH_INFINITE, null);
                    // force app sources regeneration
                    for (TreeObject to : this.getChildren()) {
                        if (to instanceof ObjectsFolderTreeObject) {
                            ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
                            if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
                                for (TreeObject cto : ofto.getChildren()) {
                                    if (cto instanceof MobilePageComponentTreeObject) {
                                        ((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
                                    }
                                }
                            }
                        }
                    }
                    markApplicationAsDirty(done);
                    // delete node modules and alert user
                    final File nodeModules = new File(project.getDirPath(), "/_private/ionic/node_modules");
                    if (nodeModules.exists()) {
                        ProgressMonitorDialog dialog = new ProgressMonitorDialog(ConvertigoPlugin.getMainShell());
                        dialog.open();
                        dialog.run(true, false, new IRunnableWithProgress() {

                            @Override
                            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                                monitor.beginTask("deleting node modules", IProgressMonitor.UNKNOWN);
                                String alert = "template changed!";
                                if (com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules)) {
                                    alert = "You have just changed the template.\nPackages have been deleted and will be reinstalled next time you run your application again.";
                                } else {
                                    alert = "You have just changed the template: packages could not be deleted!\nDo not forget to reinstall the packages before running your application again, otherwise it may be corrupted!";
                                }
                                monitor.done();
                                ConvertigoPlugin.infoMessageBox(alert);
                            }
                        });
                    }
                } else {
                    markApplicationAsDirty(done);
                }
            }
        } catch (Exception e) {
        }
    }
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) MobileSmartSourceType(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UIDynamicMenu(com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) InvalidParameterException(java.security.InvalidParameterException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProject(org.eclipse.core.resources.IProject) Project(com.twinsoft.convertigo.beans.core.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 10 with MobileSmartSourceType

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

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