Search in sources :

Example 1 with Replacement

use of com.twinsoft.convertigo.engine.util.Replacement 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 {
                        ConvertigoPlugin.getDefault().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;
                    }
                    ConvertigoPlugin.getDefault().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)

Example 2 with Replacement

use of com.twinsoft.convertigo.engine.util.Replacement in project convertigo by convertigo.

the class ConnectorTreeObject 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;
    Connector connector = this.getObject();
    if (databaseObject instanceof Transaction) {
        Transaction transaction = (Transaction) databaseObject;
        if (transaction.getConnector().equals(connector)) {
            if (connector.getEndTransactionName().equals(oldValue)) {
                connector.setEndTransactionName((String) newValue);
                try {
                    ConvertigoPlugin.getDefault().getProjectExplorerView().refreshTreeObject(this);
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not refresh in tree Connector \"" + databaseObject.getName() + "\" !");
                }
            }
        }
    } else if (databaseObject instanceof JsonIndex && connector.equals(databaseObject.getParent())) {
        CouchDbManager.syncDocument(connector);
    }
    // Case of this connector rename : update all transaction schemas
    if (treeObject.equals(this)) {
        String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME;
        String oldPath = path + "/" + (String) oldValue;
        String newPath = path + "/" + (String) newValue;
        IFolder folder = getProjectTreeObject().getFolder(oldPath);
        try {
            folder.getParent().refreshLocal(IResource.DEPTH_ONE, null);
            if (folder.exists()) {
                // rename folder (xsd/internal/connector)
                folder.move(new Path((String) newValue), true, null);
                // make replacements in schema file
                List<Replacement> replacements = new ArrayList<Replacement>();
                replacements.add(new Replacement((String) oldValue + "__", (String) newValue + "__"));
                IFolder newFolder = folder.getParent().getFolder(new Path((String) newValue));
                for (Transaction transaction : getObject().getTransactionsList()) {
                    IFile file = newFolder.getFile(new Path(transaction.getName() + ".xsd"));
                    if (file.exists()) {
                        String filePath = file.getLocation().makeAbsolute().toString();
                        try {
                            ProjectUtils.makeReplacementsInFile(replacements, filePath);
                        } catch (Exception e) {
                            ConvertigoPlugin.logWarning(e, "Could rename \"" + oldValue + "\" to \"" + newValue + "\" in schema file \"" + filePath + "\" !");
                        }
                    }
                }
                // refresh folder
                folder.refreshLocal(IResource.DEPTH_ONE, null);
                Engine.theApp.schemaManager.clearCache(getProjectTreeObject().getName());
            }
        } catch (Exception e) {
            ConvertigoPlugin.logWarning(e, "Could not rename folder from \"" + oldPath + "\" to \"" + newPath + "\" !");
        }
        if (connector instanceof CouchDbConnector) {
            CouchDbManager.syncDocument(connector);
            try {
                ConvertigoPlugin.getDefault().getProjectExplorerView().reloadTreeObject(this);
            } catch (Exception e) {
                ConvertigoPlugin.logWarning(e, "Could not reload connector \"" + connector.getName() + "\" in tree !");
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Connector(com.twinsoft.convertigo.beans.core.Connector) SapJcoConnector(com.twinsoft.convertigo.beans.connectors.SapJcoConnector) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) Replacement(com.twinsoft.convertigo.engine.util.Replacement) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JsonIndex(com.twinsoft.convertigo.beans.couchdb.JsonIndex) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 Transaction (com.twinsoft.convertigo.beans.core.Transaction)2 Replacement (com.twinsoft.convertigo.engine.util.Replacement)2 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 PartInitException (org.eclipse.ui.PartInitException)2 CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)1 SapJcoConnector (com.twinsoft.convertigo.beans.connectors.SapJcoConnector)1 Connector (com.twinsoft.convertigo.beans.core.Connector)1 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)1 Variable (com.twinsoft.convertigo.beans.core.Variable)1 JsonIndex (com.twinsoft.convertigo.beans.couchdb.JsonIndex)1 AbstractHttpTransaction (com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction)1 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)1 SqlTransaction (com.twinsoft.convertigo.beans.transactions.SqlTransaction)1 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)1 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)1 JScriptEditorInput (com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1