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!");
}
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());
}
}
}
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);
}
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);
}
}
}
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();
}
}
Aggregations