Search in sources :

Example 6 with CouchDbConnector

use of com.twinsoft.convertigo.beans.connectors.CouchDbConnector in project convertigo by convertigo.

the class ImportDesignDocumentsFromDatabaseAction 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 && databaseObject instanceof CouchDbConnector) {
                CouchDbConnector connector = (CouchDbConnector) databaseObject;
                connector.importCouchDbDesignDocuments();
                if (connector.hasChanged) {
                    explorerView.reloadTreeObject(treeObject);
                    explorerView.setSelectedTreeObject(treeObject);
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to import design documents from CouchDB database!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) Cursor(org.eclipse.swt.graphics.Cursor) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Display(org.eclipse.swt.widgets.Display)

Example 7 with CouchDbConnector

use of com.twinsoft.convertigo.beans.connectors.CouchDbConnector in project convertigo by convertigo.

the class ComponentInfoWizardPage method createControl.

public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    layout.verticalSpacing = 9;
    Label label = new Label(container, SWT.NULL);
    label.setText("&Name:");
    beanName = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    beanName.setLayoutData(gd);
    beanName.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged(false);
        }
    });
    if (parentObject instanceof CouchDbConnector || parentObject instanceof FullSyncConnector) {
        couchVariablesComposite = new CouchVariablesComposite(container, SWT.V_SCROLL);
        GridData couchVarData = new GridData(GridData.FILL_BOTH);
        couchVarData.horizontalSpan = 2;
        couchVariablesComposite.setLayoutData(couchVarData);
    } else {
        tree = new Tree(container, SWT.SINGLE | SWT.BORDER);
        tree.setHeaderVisible(false);
        GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
        gridData.verticalSpan = 20;
        gridData.horizontalSpan = 2;
        tree.setLayoutData(gridData);
        tree.addListener(SWT.Selection, new Listener() {

            public void handleEvent(final Event event) {
                TreeItem item = (TreeItem) event.item;
                treeItemName = item.getText();
                String suffix = getBeanName().endsWith(ScHandlerStatement.EVENT_ENTRY_HANDLER) ? ScHandlerStatement.EVENT_ENTRY_HANDLER : getBeanName().endsWith(ScHandlerStatement.EVENT_EXIT_HANDLER) ? ScHandlerStatement.EVENT_EXIT_HANDLER : "";
                setBeanName("on" + treeItemName + suffix);
                dialogChanged(true);
            }
        });
        tree.setVisible(false);
    }
    initialize();
    dialogChanged(true);
    setControl(container);
}
Also used : CouchVariablesComposite(com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesComposite) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) CouchVariablesComposite(com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesComposite) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeItem(org.eclipse.swt.widgets.TreeItem) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent)

Example 8 with CouchDbConnector

use of com.twinsoft.convertigo.beans.connectors.CouchDbConnector 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 9 with CouchDbConnector

use of com.twinsoft.convertigo.beans.connectors.CouchDbConnector 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)

Example 10 with CouchDbConnector

use of com.twinsoft.convertigo.beans.connectors.CouchDbConnector in project convertigo by convertigo.

the class DesignDocumentTreeObject method syncDocument.

private void syncDocument() {
    try {
        DesignDocument dd = getObject();
        JSONObject jso = dd.getJSONObject();
        if (CouchKey._id.has(jso)) {
            CouchDbConnector couchDbConnector = dd.getConnector();
            lastRev = CouchDbManager.syncDocument(couchDbConnector.getCouchClient(), couchDbConnector.getDatabaseName(), jso.toString());
        }
    } catch (Throwable t) {
        ConvertigoPlugin.logException(t, "Failed to syncDocument");
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector)

Aggregations

CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)13 Connector (com.twinsoft.convertigo.beans.core.Connector)4 Transaction (com.twinsoft.convertigo.beans.core.Transaction)4 FullSyncConnector (com.twinsoft.convertigo.beans.connectors.FullSyncConnector)3 SapJcoConnector (com.twinsoft.convertigo.beans.connectors.SapJcoConnector)3 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)3 JsonIndex (com.twinsoft.convertigo.beans.couchdb.JsonIndex)3 CouchVariablesComposite (com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesComposite)3 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3 ModifyListener (org.eclipse.swt.events.ModifyListener)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Event (org.eclipse.swt.widgets.Event)3 Label (org.eclipse.swt.widgets.Label)3 Listener (org.eclipse.swt.widgets.Listener)3 Text (org.eclipse.swt.widgets.Text)3 Tree (org.eclipse.swt.widgets.Tree)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 MobilePlatform (com.twinsoft.convertigo.beans.core.MobilePlatform)2