Search in sources :

Example 1 with JsonIndex

use of com.twinsoft.convertigo.beans.couchdb.JsonIndex 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) {
                CouchDbManager.syncDocument(couchDbConnector);
            }
        }
        if (databaseObject instanceof JsonIndex) {
            JsonIndex jsonIndex = (JsonIndex) databaseObject;
            if (jsonIndex.bNew && jsonIndex.getConnector() != null) {
                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 2 with JsonIndex

use of com.twinsoft.convertigo.beans.couchdb.JsonIndex in project convertigo by convertigo.

the class ConnectorTreeObject 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();
            Connector connector = this.getObject();
            // A transaction has been removed
            if (databaseObject instanceof Transaction) {
                if (connector.getEndTransactionName().equals(databaseObject.getName())) {
                    connector.setEndTransactionName("");
                    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) {
                CouchDbManager.syncDocument(connector);
            }
        }
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) SapJcoConnector(com.twinsoft.convertigo.beans.connectors.SapJcoConnector) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JsonIndex(com.twinsoft.convertigo.beans.couchdb.JsonIndex) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

Example 3 with JsonIndex

use of com.twinsoft.convertigo.beans.couchdb.JsonIndex in project convertigo by convertigo.

the class ConnectorTreeObject 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();
    Connector connector = getObject();
    if (treeObject instanceof DatabaseObjectTreeObject) {
        // If a bean name has changed
        if (propertyName.equals("name")) {
            handlesBeanNameChanged(treeObjectEvent);
        } else if (treeObject.equals(this)) {
            // if this connector has changed
            if (connector instanceof SapJcoConnector) {
                try {
                    ((SapJcoConnector) connector).getSapJCoProvider().updateDestination();
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not update SAP destination !");
                }
            } else if (connector instanceof CouchDbConnector) {
                if (propertyName.equals("https") || propertyName.equals("port") || propertyName.equals("server") || propertyName.equals("couchUsername") || propertyName.equals("couchPassword")) {
                    ((CouchDbConnector) connector).release();
                    CouchDbManager.syncDocument(connector);
                    try {
                        ConvertigoPlugin.getDefault().getProjectExplorerView().reloadTreeObject(this);
                    } catch (Exception e) {
                        ConvertigoPlugin.logWarning(e, "Could not reload connector \"" + connector.getName() + "\" in tree !");
                    }
                } else if (propertyName.equals("databaseName")) {
                    CouchDbManager.syncDocument(connector);
                    try {
                        ConvertigoPlugin.getDefault().getProjectExplorerView().reloadTreeObject(this);
                    } catch (Exception e) {
                        ConvertigoPlugin.logWarning(e, "Could not reload connector \"" + connector.getName() + "\" in tree !");
                    }
                }
            }
        } else if (connector instanceof CouchDbConnector) {
            DatabaseObject dbo = ((DatabaseObjectTreeObject) treeObject).getObject();
            if (dbo instanceof JsonIndex && connector.equals(dbo.getParent()) && (propertyName.equals("fields") || propertyName.equals("ascending") || propertyName.equals("name"))) {
                CouchDbManager.syncDocument(getObject());
            }
        }
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) SapJcoConnector(com.twinsoft.convertigo.beans.connectors.SapJcoConnector) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) SapJcoConnector(com.twinsoft.convertigo.beans.connectors.SapJcoConnector) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JsonIndex(com.twinsoft.convertigo.beans.couchdb.JsonIndex) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

Example 4 with JsonIndex

use of com.twinsoft.convertigo.beans.couchdb.JsonIndex 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

CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)4 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)4 JsonIndex (com.twinsoft.convertigo.beans.couchdb.JsonIndex)4 SapJcoConnector (com.twinsoft.convertigo.beans.connectors.SapJcoConnector)3 Connector (com.twinsoft.convertigo.beans.core.Connector)3 CoreException (org.eclipse.core.runtime.CoreException)3 PartInitException (org.eclipse.ui.PartInitException)3 Transaction (com.twinsoft.convertigo.beans.core.Transaction)2 Replacement (com.twinsoft.convertigo.engine.util.Replacement)1 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 Path (org.eclipse.core.runtime.Path)1