Search in sources :

Example 1 with CouchDbConnector

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

the class DatabaseObjectDeleteAction method delete.

private void delete(DatabaseObject databaseObject, boolean deleteProjectOnDisk) throws EngineException, CoreException {
    if (databaseObject instanceof Connector) {
        if (((Connector) databaseObject).isDefault) {
            throw new EngineException("Cannot delete the default connector!");
        }
        String dirPath, projectName;
        File dir;
        projectName = databaseObject.getParent().getName();
        MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        messageBox.setText("Also delete linked resources?");
        // Delete soap templates for this connector
        dirPath = Engine.projectDir(projectName) + "/soap-templates/" + databaseObject.getName();
        dir = new File(dirPath);
        if (dir.exists()) {
            messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
            if (messageBox.open() == SWT.YES) {
                try {
                    DatabaseObjectsManager.deleteDir(dir);
                } catch (IOException e) {
                    ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
                }
            }
        }
        // Delete directory corresponding to connector under Traces directory
        dirPath = Engine.projectDir(projectName) + "/Traces/" + databaseObject.getName();
        dir = new File(dirPath);
        if (dir.exists()) {
            messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
            if (messageBox.open() == SWT.YES) {
                try {
                    DatabaseObjectsManager.deleteDir(dir);
                } catch (IOException e) {
                    ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
                }
            }
        }
    } else if (databaseObject instanceof Transaction) {
        if (((Transaction) databaseObject).isDefault) {
            throw new EngineException("Cannot delete the default transaction!");
        }
    } else if (databaseObject instanceof ScreenClass) {
        if ((databaseObject.getParent()) instanceof Project) {
            throw new EngineException("Cannot delete the root screen class!");
        }
    } else if (databaseObject instanceof Statement) {
        if ((databaseObject instanceof ThenStatement) || (databaseObject instanceof ElseStatement)) {
            throw new EngineException("Cannot delete this statement!");
        }
    } else if (databaseObject instanceof Step) {
        if ((databaseObject instanceof ThenStep) || (databaseObject instanceof ElseStep)) {
            throw new EngineException("Cannot delete this step!");
        }
    } else if (databaseObject instanceof MobilePlatform) {
        MobilePlatform mobilePlatform = (MobilePlatform) databaseObject;
        File resourceFolder = mobilePlatform.getResourceFolder();
        if (resourceFolder.exists()) {
            MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
            messageBox.setMessage("Do you want to delete the whole resource folder \"" + mobilePlatform.getRelativeResourcePath() + "\"?");
            messageBox.setText("Delete the \"" + resourceFolder.getName() + "\" folder?");
            if (messageBox.open() == SWT.YES) {
                FileUtils.deleteQuietly(resourceFolder);
            }
        }
    } else if (databaseObject instanceof PageComponent) {
        if (((PageComponent) databaseObject).isRoot) {
            throw new EngineException("Cannot delete the root page!");
        }
    }
    String dboQName = databaseObject.getQName();
    if (databaseObject instanceof Project) {
        // Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName());
        if (deleteProjectOnDisk) {
            Engine.theApp.databaseObjectsManager.deleteProjectAndCar(databaseObject.getName(), DeleteProjectOption.unloadOnly);
        } else {
            Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName(), DeleteProjectOption.unloadOnly);
        }
        ConvertigoPlugin.getDefault().deleteProjectPluginResource(deleteProjectOnDisk, databaseObject.getName());
    } else {
        databaseObject.delete();
    }
    if (databaseObject instanceof CouchDbConnector) {
        CouchDbConnector couchDbConnector = (CouchDbConnector) databaseObject;
        String db = couchDbConnector.getDatabaseName();
        if (!db.isEmpty()) {
            MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
            messageBox.setMessage("Do you want to delete the \"" + db + "\" database from the CouchDb server?");
            messageBox.setText("Delete the database?");
            if (messageBox.open() == SWT.YES) {
                couchDbConnector.getCouchClient().deleteDatabase(db);
            }
        }
    }
    ConvertigoPlugin.logDebug("The object \"" + dboQName + "\" has been deleted from the database repository!");
}
Also used : CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) EngineException(com.twinsoft.convertigo.engine.EngineException) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) IOException(java.io.IOException) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) SimpleStep(com.twinsoft.convertigo.beans.steps.SimpleStep) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) MessageBox(org.eclipse.swt.widgets.MessageBox) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Project(com.twinsoft.convertigo.beans.core.Project) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) File(java.io.File)

Example 2 with CouchDbConnector

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

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

the class DesignDocumentTreeObject method renameDocument.

private void renameDocument(String oldName, String newName) {
    if (oldName != null && newName != null) {
        try {
            CouchDbConnector couchDbConnector = getObject().getConnector();
            CouchClient couchClient = couchDbConnector.getCouchClient();
            String db = couchDbConnector.getDatabaseName();
            // delete old document
            couchClient.deleteDocument(db, CouchKey._design.key() + oldName, (Map<String, String>) null);
            // create new document
            JSONObject jso = getObject().getJSONObject();
            CouchKey._id.put(jso, CouchKey._design.key() + newName);
            CouchKey._rev.remove(jso);
            lastRev = CouchDbManager.syncDocument(couchClient, db, jso.toString());
        } catch (Exception e) {
            ConvertigoPlugin.logException(e, "Coudn't rename document \"" + oldName + "\" to \"" + newName + "\" in the CouchDb database", false);
        }
    }
}
Also used : CouchClient(com.twinsoft.convertigo.engine.providers.couchdb.CouchClient) JSONObject(org.codehaus.jettison.json.JSONObject) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 5 with CouchDbConnector

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

the class ViewExecuteSelectedAction method run.

@Override
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();
            if ((treeObject != null) && (treeObject instanceof DesignDocumentViewTreeObject)) {
                DesignDocumentViewTreeObject viewTreeObject = (DesignDocumentViewTreeObject) treeObject;
                DesignDocumentTreeObject ddto = (DesignDocumentTreeObject) viewTreeObject.getTreeObjectOwner();
                ConnectorTreeObject cto = (ConnectorTreeObject) ddto.getOwnerDatabaseObjectTreeObject();
                ProjectTreeObject projectTreeObject = cto.getProjectTreeObject();
                CouchDbConnector connector = (CouchDbConnector) cto.getObject();
                cto.openConnectorEditor();
                ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                if (connectorEditor != null) {
                    // activate connector's editor
                    getActivePage().activate(connectorEditor);
                    // set transaction's parameters
                    Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
                    ((GetViewTransaction) transaction).setViewname(viewTreeObject.getDocViewName());
                    Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
                    view_reduce.setValueOrNull(viewTreeObject.hasReduce() ? isReduceRequested() : false);
                    // execute view transaction
                    connectorEditor.getDocument(CouchDbConnector.internalView, isStubRequested());
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to execute the selected view!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Variable(com.twinsoft.convertigo.beans.core.Variable) DesignDocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject) DesignDocumentViewTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentViewTreeObject) Cursor(org.eclipse.swt.graphics.Cursor) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) Shell(org.eclipse.swt.widgets.Shell) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DesignDocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject) DesignDocumentViewTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentViewTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Display(org.eclipse.swt.widgets.Display)

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