Search in sources :

Example 61 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.

the class TransactionTreeObject method treeObjectRemoved.

@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
    super.treeObjectRemoved(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    if (!(treeObject.equals(this)) && (treeObject.getParents().contains(this))) {
        if (treeObject instanceof DatabaseObjectTreeObject) {
            DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
            // A variable has been removed
            if (databaseObject instanceof Variable) {
                String variableName = databaseObject.getName();
                // This is an AbstractHttpTransaction
                if (getObject() instanceof AbstractHttpTransaction) {
                    AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) getObject();
                    String transactionSubDir = httpTransaction.getSubDir();
                    List<String> pathVariableList = AbstractHttpTransaction.getPathVariableList(httpTransaction.getSubDir());
                    // Update transaction SubDir property
                    if (pathVariableList.contains(variableName)) {
                        transactionSubDir = transactionSubDir.replaceAll("\\{" + variableName + "\\}", "");
                        httpTransaction.setSubDir(transactionSubDir);
                        httpTransaction.hasChanged = true;
                        try {
                            getProjectExplorerView().updateTreeObject(this);
                        } catch (Exception e) {
                            ConvertigoPlugin.logWarning(e, "Could not update in tree Transaction \"" + databaseObject.getName() + "\" !");
                        }
                    }
                }
            }
        }
    }
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction)

Example 62 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.

the class TransactionTreeObject method treeObjectPropertyChanged.

@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
    super.treeObjectPropertyChanged(treeObjectEvent);
    String propertyName = (String) treeObjectEvent.propertyName;
    propertyName = ((propertyName == null) ? "" : propertyName);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
        // If a bean name has changed
        if ("name".equals(propertyName)) {
            handlesBeanNameChanged(treeObjectEvent);
        } else if ("sqlQuery".equals(propertyName)) {
            if (treeObject.equals(this)) {
                try {
                    SqlTransaction sqlTransaction = (SqlTransaction) databaseObject;
                    sqlTransaction.initializeQueries(true);
                    String oldValue = (String) treeObjectEvent.oldValue;
                    detectVariables(sqlTransaction.getSqlQuery(), oldValue, sqlTransaction.getVariablesList());
                    getProjectExplorerView().reloadTreeObject(this);
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
                }
            }
        } else if ("subDir".equals(propertyName)) {
            if (treeObject.equals(this)) {
                try {
                    Object oldValue = treeObjectEvent.oldValue;
                    Object newValue = treeObjectEvent.newValue;
                    AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) databaseObject;
                    List<String> oldPathVariableList = AbstractHttpTransaction.getPathVariableList(oldValue.toString());
                    List<String> newPathVariableList = AbstractHttpTransaction.getPathVariableList(newValue.toString());
                    // Check for variables to be renamed
                    if (oldValue.toString().replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{}").equals(newValue.toString().replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{}"))) {
                        for (int i = 0; i < oldPathVariableList.size(); i++) {
                            String oldVariableName = oldPathVariableList.get(i);
                            String newVariableName = newPathVariableList.get(i);
                            if (!oldVariableName.equals(newVariableName)) {
                                RequestableHttpVariable httpVariable = (RequestableHttpVariable) httpTransaction.getVariable(oldVariableName);
                                if (httpVariable != null) {
                                    try {
                                        VariableTreeObject2 vto = (VariableTreeObject2) findTreeObjectByUserObject(httpVariable);
                                        int update = TreeObjectEvent.UPDATE_NONE;
                                        CustomDialog customDialog = new CustomDialog(viewer.getControl().getShell(), "Update object references", "Do you want to update " + "variable" + " references ?\n You can replace '" + oldVariableName + "' by '" + newVariableName + "' in all loaded projects \n or replace '" + oldVariableName + "' by '" + newVariableName + "' in current project only.", 670, 200, new ButtonSpec("Replace in all loaded projects", true), new ButtonSpec("Replace in current project", false), new ButtonSpec("Do not replace anywhere", false));
                                        int response = customDialog.open();
                                        if (response == 0) {
                                            update = TreeObjectEvent.UPDATE_ALL;
                                        }
                                        if (response == 1) {
                                            update = TreeObjectEvent.UPDATE_LOCAL;
                                        }
                                        if (update != 0) {
                                            httpVariable.setName(newVariableName);
                                            httpVariable.hasChanged = true;
                                            TreeObjectEvent toEvent = new TreeObjectEvent(vto, "name", oldVariableName, newVariableName, update);
                                            getProjectExplorerView().fireTreeObjectPropertyChanged(toEvent);
                                        }
                                    } catch (Exception e) {
                                        ConvertigoPlugin.logWarning(e, "Could not rename variable for Transaction \"" + databaseObject.getName() + "\" !");
                                    }
                                }
                            }
                        }
                    } else {
                        // Check for variables to be added
                        for (String variableName : newPathVariableList) {
                            if (httpTransaction.getVariable(variableName) == null) {
                                RequestableHttpVariable httpVariable = new RequestableHttpVariable();
                                httpVariable.setName(variableName);
                                httpVariable.setHttpMethod("GET");
                                httpVariable.setHttpName("");
                                httpVariable.bNew = true;
                                httpVariable.hasChanged = true;
                                httpTransaction.addVariable(httpVariable);
                                httpTransaction.hasChanged = true;
                            }
                        }
                        // Check for variables to be deleted
                        for (String variableName : oldPathVariableList) {
                            RequestableHttpVariable httpVariable = (RequestableHttpVariable) httpTransaction.getVariable(variableName);
                            if (httpVariable != null) {
                                if (!newPathVariableList.contains(variableName)) {
                                    try {
                                        MessageBox messageBox = new MessageBox(viewer.getControl().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
                                        messageBox.setMessage("Do you want to delete the variable \"" + variableName + "\"?");
                                        messageBox.setText("Delete \"" + variableName + "\"?");
                                        if (messageBox.open() == SWT.YES) {
                                            httpVariable.delete();
                                            httpTransaction.hasChanged = true;
                                        }
                                    } catch (EngineException e) {
                                        ConvertigoPlugin.logException(e, "Error when deleting the variable \"" + variableName + "\"");
                                    }
                                }
                            }
                        }
                    }
                    if (httpTransaction.hasChanged) {
                        getProjectExplorerView().reloadTreeObject(this);
                    }
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
                }
            }
        }
    }
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) EngineException(com.twinsoft.convertigo.engine.EngineException) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) MessageBox(org.eclipse.swt.widgets.MessageBox) CustomDialog(com.twinsoft.convertigo.eclipse.dialogs.CustomDialog) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent) ButtonSpec(com.twinsoft.convertigo.eclipse.dialogs.ButtonSpec)

Example 63 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.

the class MobileApplicationComponentTreeObject method treeObjectAdded.

@Override
public void treeObjectAdded(TreeObjectEvent treeObjectEvent) {
    super.treeObjectAdded(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    String propertyName = (String) treeObjectEvent.propertyName;
    propertyName = ((propertyName == null) ? "" : propertyName);
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
        DatabaseObject dbo = doto.getObject();
        try {
            // we add a page to this app
            if (dbo instanceof PageComponent && getObject().equals(dbo.getParent())) {
                PageComponent page = (PageComponent) dbo;
                if (page.bNew) {
                    page.markPageAsDirty();
                }
            }
        } catch (Exception e) {
        }
    }
}
Also used : DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) InvalidParameterException(java.security.InvalidParameterException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 64 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject 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 65 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.

the class MobileApplicationTreeObject method treeObjectPropertyChanged.

@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
    super.treeObjectPropertyChanged(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    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 {
            if (this.equals(doto)) {
                if (propertyName.equals("applicationName")) {
                    if (!newValue.equals(oldValue)) {
                        ApplicationComponent app = (ApplicationComponent) ((MobileApplication) dbo).getApplicationComponent();
                        app.markPwaAsDirty();
                    }
                }
            }
        } catch (Exception e) {
        }
    }
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)296 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)98 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)97 EngineException (com.twinsoft.convertigo.engine.EngineException)88 Shell (org.eclipse.swt.widgets.Shell)46 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)45 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)43 Cursor (org.eclipse.swt.graphics.Cursor)42 Display (org.eclipse.swt.widgets.Display)42 Sequence (com.twinsoft.convertigo.beans.core.Sequence)41 Project (com.twinsoft.convertigo.beans.core.Project)38 CoreException (org.eclipse.core.runtime.CoreException)36 IOException (java.io.IOException)35 Step (com.twinsoft.convertigo.beans.core.Step)33 ActionModel (com.twinsoft.convertigo.engine.studio.ActionModel)33 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)31 Element (org.w3c.dom.Element)30 ObjectsFolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject)27 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)27 PartInitException (org.eclipse.ui.PartInitException)26