Search in sources :

Example 56 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject 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;
        DatabaseObject deletedObject = deletedTreeObject.getObject();
        try {
            if (deletedTreeObject != null && this.equals(deletedTreeObject.getParentDatabaseObjectTreeObject())) {
                UIComponent parentDbo = getObject();
                if (deletedObject instanceof UIUseShared) {
                    UIUseShared use = (UIUseShared) deletedObject;
                    String compQName = use.getSharedComponentQName();
                    String useQNname = parentDbo.getQName() + "." + deletedObject.getName();
                    ComponentRefManager.get(Mode.use).removeConsumer(compQName, useQNname);
                }
                UIActionStack uisa = parentDbo.getSharedAction();
                UISharedComponent uisc = parentDbo.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) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) 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 57 with DatabaseObject

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

the class ProjectTreeObject method treeObjectAdded.

@Override
public void treeObjectAdded(TreeObjectEvent treeObjectEvent) {
    super.treeObjectAdded(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
        if (databaseObject instanceof CouchDbConnector) {
            CouchDbConnector couchDbConnector = (CouchDbConnector) databaseObject;
            if (couchDbConnector.bNew) {
                Engine.execute(() -> {
                    CouchDbManager.syncDocument(couchDbConnector);
                });
            }
        }
        if (databaseObject instanceof JsonIndex) {
            JsonIndex jsonIndex = (JsonIndex) databaseObject;
            if (jsonIndex.bNew && jsonIndex.getConnector() != null) {
                Engine.execute(() -> {
                    CouchDbManager.syncDocument(jsonIndex.getConnector());
                });
            }
        }
        if (this.equals(treeObject.getProjectTreeObject())) {
            checkMissingProjects();
            Engine.theApp.schemaManager.clearCache(getName());
        }
    }
}
Also used : DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JsonIndex(com.twinsoft.convertigo.beans.couchdb.JsonIndex) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector)

Example 58 with DatabaseObject

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

the class StatementTreeObject method treeObjectRemoved.

@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
    super.treeObjectRemoved(treeObjectEvent);
    // Avoid the cast between "UnloadedProjectTreeObject" and "DatabaseObjectTreeObject
    if (!(treeObjectEvent.getSource() instanceof UnloadedProjectTreeObject)) {
        DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
        DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
        Statement statement = getObject();
        boolean change = false;
        // Case this is a screen class
        if (databaseObject instanceof ScreenClass) {
            ScreenClassTreeObject sto = (ScreenClassTreeObject) treeObjectEvent.getSource();
            String screenClassName = StringUtils.normalize(databaseObject.getName());
            // ScreenClass and Statement must have the same connector!
            if (statement.getConnector().equals(sto.getConnectorTreeObject().getObject())) {
                if (statement instanceof ITriggerOwner) {
                    ITriggerOwner ito = (ITriggerOwner) statement;
                    AbstractTrigger atrigger = ito.getTrigger().getTrigger();
                    if (atrigger instanceof ScreenClassTrigger) {
                        ScreenClassTrigger sct = (ScreenClassTrigger) atrigger;
                        List<String> screenClasses = sct.getScreenClasses();
                        for (int i = 0; i < screenClasses.size(); i++) {
                            if (screenClasses.get(i).equals(screenClassName)) {
                                screenClasses.remove(i);
                                change = true;
                            }
                        }
                        // Add default root screen class if all have been removed
                        if (screenClasses.isEmpty()) {
                            IScreenClassContainer<?> iscc = (IScreenClassContainer<?>) sto.getConnectorTreeObject().getObject();
                            String defaultScreenClassName = StringUtils.normalize(iscc.getDefaultScreenClass().getName());
                            screenClasses.add(defaultScreenClassName);
                            change = true;
                        }
                        if (change)
                            ito.setTrigger(new TriggerXMLizer(sct));
                    }
                }
            }
        }
        if (change)
            try {
                hasBeenModified(true);
                getProjectExplorerView().refreshTreeObject(this);
            } catch (Exception e) {
                ConvertigoPlugin.logWarning(e, "Could not refresh in tree ScHandlerStatement \"" + statement.getName() + "\" !");
            }
    }
}
Also used : TriggerXMLizer(com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer) ScreenClassTrigger(com.twinsoft.convertigo.engine.parsers.triggers.ScreenClassTrigger) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) SimpleStatement(com.twinsoft.convertigo.beans.statements.SimpleStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) IScreenClassContainer(com.twinsoft.convertigo.beans.core.IScreenClassContainer) ITriggerOwner(com.twinsoft.convertigo.engine.parsers.triggers.ITriggerOwner) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractTrigger(com.twinsoft.convertigo.engine.parsers.triggers.AbstractTrigger) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 59 with DatabaseObject

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

the class StatementTreeObject 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;
    Statement statement = getObject();
    boolean change = false;
    if (databaseObject instanceof ScreenClass) {
        String oldScreenClassName = StringUtils.normalize((String) oldValue);
        String newScreenClassName = StringUtils.normalize((String) newValue);
        // ScreenClass and Statement must have the same connector!
        if (statement.getConnector().equals(databaseObject.getConnector())) {
            // Modify screenclass handlers name
            if (statement instanceof ScHandlerStatement) {
                ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
                if (scHandlerStatement.getNormalizedScreenClassName().equals(oldScreenClassName)) {
                    String handlerType = scHandlerStatement.getHandlerType();
                    String beanName = "on" + newScreenClassName + handlerType;
                    try {
                        scHandlerStatement.setName(beanName);
                        scHandlerStatement.setNormalizedScreenClassName(newScreenClassName);
                        change = true;
                    } catch (EngineException e) {
                        ConvertigoPlugin.logWarning(e, "Could not rename ScHandlerStatement from \"" + scHandlerStatement.getName() + "\" to \"" + beanName + "\" !");
                    }
                }
            }
            if (statement instanceof ITriggerOwner) {
                ITriggerOwner ito = (ITriggerOwner) statement;
                AbstractTrigger atrigger = ito.getTrigger().getTrigger();
                if (atrigger instanceof ScreenClassTrigger) {
                    ScreenClassTrigger sct = (ScreenClassTrigger) atrigger;
                    List<String> screenClasses = sct.getScreenClasses();
                    for (int i = 0; i < screenClasses.size(); i++) if (screenClasses.get(i).equals(oldScreenClassName) && (change = true))
                        screenClasses.set(i, newScreenClassName);
                    if (change)
                        ito.setTrigger(new TriggerXMLizer(sct));
                }
            }
        }
    } else // Case of connector rename
    if (databaseObject instanceof SiteClipperConnector) {
        if (statement instanceof ContinueWithSiteClipperStatement) {
            boolean isLocalProject = statement.getProject().equals(databaseObject.getProject());
            boolean isSameValue = ((ContinueWithSiteClipperStatement) statement).getSiteClipperConnectorName().equals(oldValue);
            if (isSameValue && isLocalProject) {
                ((ContinueWithSiteClipperStatement) statement).setSiteClipperConnectorName((String) newValue);
                hasBeenModified(true);
                viewer.refresh();
                // refresh editors (e.g labels in combobox)
                getDescriptors();
            }
        }
    }
    if (statement instanceof CallFunctionStatement && databaseObject.getClass().equals(FunctionStatement.class) && ((FunctionStatement) databaseObject).getParentTransaction().equals(statement.getParentTransaction())) {
        CallFunctionStatement callfunction = (CallFunctionStatement) statement;
        if (callfunction.getFunctionName().equals(oldValue) && (change = true))
            callfunction.setFunctionName(newValue.toString());
    }
    if (change)
        try {
            hasBeenModified(true);
            getProjectExplorerView().refreshTreeObject(this);
        } catch (Exception e) {
            ConvertigoPlugin.logWarning(e, "Could not refresh in tree ScHandlerStatement \"" + statement.getName() + "\" !");
        }
}
Also used : TriggerXMLizer(com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer) ScreenClassTrigger(com.twinsoft.convertigo.engine.parsers.triggers.ScreenClassTrigger) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) SimpleStatement(com.twinsoft.convertigo.beans.statements.SimpleStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) EngineException(com.twinsoft.convertigo.engine.EngineException) ITriggerOwner(com.twinsoft.convertigo.engine.parsers.triggers.ITriggerOwner) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) AbstractTrigger(com.twinsoft.convertigo.engine.parsers.triggers.AbstractTrigger) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement)

Example 60 with DatabaseObject

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

the class TransactionTreeObject 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;
    if (databaseObject instanceof ScreenClass) {
        String oldName = StringUtils.normalize((String) oldValue);
        String newName = StringUtils.normalize((String) newValue);
        Transaction transaction = getObject();
        // Modify Screenclass name in Transaction handlers
        if (!(transaction instanceof HtmlTransaction)) {
            // ScreenClass and Transaction must have the same connector!
            if (transaction.getConnector().equals(databaseObject.getConnector())) {
                String oldHandlerPrefix = "on" + StringUtils.normalize(oldName);
                String newHandlerPrefix = "on" + StringUtils.normalize(newName);
                if (transaction.handlers.indexOf(oldHandlerPrefix) != -1) {
                    StringEx sx = new StringEx(transaction.handlers);
                    // Updating comments
                    sx.replaceAll("handler for screen class \"" + oldName + "\"", "handler for screen class \"" + newName + "\"");
                    // Updating functions def & calls
                    sx.replaceAll(oldHandlerPrefix + "Entry", newHandlerPrefix + "Entry");
                    sx.replaceAll(oldHandlerPrefix + "Exit", newHandlerPrefix + "Exit");
                    String newHandlers = sx.toString();
                    if (!newHandlers.equals(transaction.handlers)) {
                        transaction.handlers = newHandlers;
                        hasBeenModified(true);
                    }
                    // Update the opened handlers editor if any
                    JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
                    if (jsinput != null) {
                        jsinput.reload();
                    }
                    try {
                        getProjectExplorerView().reloadTreeObject(this);
                    } catch (Exception e) {
                        ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
                    }
                }
            }
        }
    }
    if (databaseObject instanceof Variable) {
        String oldVariableName = oldValue.toString();
        String newVariableName = newValue.toString();
        // A variable of this transaction has been renamed
        if (getObject().equals(databaseObject.getParent())) {
            if (getObject() instanceof AbstractHttpTransaction) {
                AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) getObject();
                try {
                    // Check for variables to be renamed in SubDir property
                    String transactionSubDir = httpTransaction.getSubDir();
                    List<String> pathVariableList = AbstractHttpTransaction.getPathVariableList(transactionSubDir);
                    if (pathVariableList.contains(oldVariableName)) {
                        transactionSubDir = transactionSubDir.replaceAll("\\{" + oldVariableName + "\\}", "{" + newVariableName + "}");
                        httpTransaction.setSubDir(transactionSubDir);
                        httpTransaction.hasChanged = true;
                    }
                    getProjectExplorerView().refreshTreeObject(this);
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
                }
            }
        }
    }
    // Case of this transaction rename : update transaction's schema
    if (treeObject.equals(this)) {
        String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME + "/" + getConnectorTreeObject().getName();
        String oldPath = path + "/" + (String) oldValue + ".xsd";
        String newPath = path + "/" + (String) newValue + ".xsd";
        IFile file = getProjectTreeObject().getFile(oldPath);
        try {
            file.getParent().refreshLocal(IResource.DEPTH_ONE, null);
            if (file.exists()) {
                // rename file (xsd/internal/connector/transaction.xsd)
                file.move(new Path((String) newValue + ".xsd"), true, null);
                // make replacements in schema files
                List<Replacement> replacements = new ArrayList<Replacement>();
                replacements.add(new Replacement("__" + (String) oldValue, "__" + (String) newValue));
                IFile newFile = file.getParent().getFile(new Path((String) newValue + ".xsd"));
                String newFilePath = newFile.getLocation().makeAbsolute().toString();
                try {
                    ProjectUtils.makeReplacementsInFile(replacements, newFilePath);
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not rename \"" + oldValue + "\" to \"" + newValue + "\" in schema file \"" + newPath + "\" !");
                }
                // refresh file
                file.refreshLocal(IResource.DEPTH_ZERO, null);
                Engine.theApp.schemaManager.clearCache(getProjectTreeObject().getName());
            }
        } catch (Exception e) {
            ConvertigoPlugin.logWarning(e, "Could not rename schema file from \"" + oldPath + "\" to \"" + newPath + "\" !");
        }
    }
}
Also used : JScriptEditorInput(com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput) Path(org.eclipse.core.runtime.Path) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) IFile(org.eclipse.core.resources.IFile) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ArrayList(java.util.ArrayList) Replacement(com.twinsoft.convertigo.engine.util.Replacement) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) StringEx(com.twinsoft.util.StringEx)

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