use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class ClipboardAction method paste.
public void paste(String source, Shell shell, ProjectExplorerView explorerView, TreeObject selectedTreeObject, boolean isDND) throws ConvertigoException, IOException, ParserConfigurationException, SAXException, CoreException {
if ((explorerView != null) && (selectedTreeObject != null)) {
TreeObject targetTreeObject = null;
Object targetObject = null;
if (selectedTreeObject instanceof FolderTreeObject) {
if (selectedTreeObject.getParent() instanceof IDesignTreeObject) {
selectedTreeObject = selectedTreeObject.getParent();
}
}
if (selectedTreeObject instanceof IPropertyTreeObject) {
targetTreeObject = selectedTreeObject;
targetObject = selectedTreeObject;
} else if (selectedTreeObject instanceof IDesignTreeObject) {
targetTreeObject = selectedTreeObject;
targetObject = selectedTreeObject;
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_DOCUMENT) {
targetTreeObject = ((IDesignTreeObject) selectedTreeObject).getTreeObjectOwner();
targetObject = (DatabaseObject) targetTreeObject.getObject();
}
} else {
// case of folder, retrieve owner object
targetTreeObject = explorerView.getFirstSelectedDatabaseObjectTreeObject(selectedTreeObject);
targetObject = (DatabaseObject) targetTreeObject.getObject();
// i.e. without having to select the parent database object.
if (clipboardManager.objectsType == ProjectExplorerView.getTreeObjectType(new TreePath(targetTreeObject))) {
// it must be different from the currently selected object.
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_SCREEN_CLASS) {
CustomDialog customDialog = new CustomDialog(shell, "Paste a Screenclass", "Do you want to paste the Screenclass as a sibling or as an inherited ScreenClass?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As an iherited", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
int response = customDialog.open();
if (response == 0)
targetObject = ((DatabaseObject) targetObject).getParent();
else if (response == 2)
return;
} else if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STATEMENT_WITH_EXPRESSIONS) {
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_FUNCTION) {
targetObject = ((DatabaseObject) targetObject).getParent();
} else {
CustomDialog customDialog = new CustomDialog(shell, "Paste a statement", "Do you want to paste the statement as a sibling or a child statement?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As a child", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
int response = customDialog.open();
if (response == 0) {
targetObject = ((DatabaseObject) targetObject).getParent();
} else if (response == 2) {
return;
}
}
} else if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_MOBILE_UICOMPONENT) {
if (!clipboardManager.isCut) {
CustomDialog customDialog = new CustomDialog(shell, "Paste a Component", "Do you want to paste the Component as a sibling or as a child component?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As a child", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
int response = customDialog.open();
if (response == 0) {
targetObject = ((DatabaseObject) targetObject).getParent();
} else if (response == 2) {
return;
}
}
} else if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP_WITH_EXPRESSIONS || clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP) {
targetObject = pasteStep(shell, source, (DatabaseObject) targetObject);
if (targetObject == null)
return;
} else if (isDND && clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_SEQUENCE) {
// Do not change target to parent
} else {
targetObject = ((DatabaseObject) targetObject).getParent();
}
targetTreeObject = explorerView.findTreeObjectByUserObject(((DatabaseObject) targetObject));
} else {
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP_WITH_EXPRESSIONS || clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP) {
targetObject = pasteStep(shell, source, (DatabaseObject) targetObject);
if (targetObject == null)
return;
}
}
}
if (clipboardManager.isCut) {
TreeParent targetTreeParent = null;
String targetPath = targetTreeObject.getPath();
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
targetTreeParent = ((DatabaseObjectTreeObject) targetTreeObject).getOwnerDatabaseObjectTreeObject();
} else if (targetTreeObject instanceof IPropertyTreeObject) {
targetTreeParent = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
} else if (targetTreeObject instanceof IDesignTreeObject) {
targetTreeParent = ((IDesignTreeObject) targetTreeObject).getTreeObjectOwner();
}
for (int i = 0; i < clipboardManager.objects.length; i++) {
// Cut & paste
clipboardManager.cutAndPaste(clipboardManager.objects[i], targetTreeObject);
// Updating the tree
// Report 4.5: fix #401
// explorerView.reloadTreeObject(clipboardManager.parentTreeNodeOfCutObjects[i]);
TreeObject parentTreeNodeOfCutObjects = clipboardManager.parentTreeNodeOfCutObjects[i];
parentTreeNodeOfCutObjects.getProjectTreeObject().hasBeenModified(true);
if (!(parentTreeNodeOfCutObjects instanceof IDesignTreeObject)) {
explorerView.reloadTreeObject(parentTreeNodeOfCutObjects);
}
}
if (targetTreeObject != null) {
if (targetTreeObject.getParent() == null)
targetTreeObject = explorerView.findTreeObjectByPath(targetTreeParent, targetPath);
if (targetTreeObject != null)
// Report 4.5: fix #401
targetTreeObject.getProjectTreeObject().hasBeenModified(true);
}
clipboardManager.reset();
} else if (source != null) {
// Paste
clipboardManager.paste(source, targetObject, true);
// Case of project copy
if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_PROJECT) {
Object[] pastedObjects = clipboardManager.pastedObjects;
for (int i = 0; i < pastedObjects.length; i++) {
Object object = pastedObjects[i];
if ((object != null) && (object instanceof Project)) {
Project project = (Project) object;
String oldName = project.getName();
try {
Project importedProject = importProjectTempArchive(oldName, explorerView);
if (importedProject != null) {
String newName = importedProject.getName();
explorerView.importProjectTreeObject(newName, true, oldName);
} else
throw new EngineException("Unable to import project temporary archive");
} catch (Exception e) {
throw new EngineException("Unable to paste project", e);
}
}
}
}
}
// Updating the tree
if (targetTreeObject != null) {
TreeObject treeObjectToReload = targetTreeObject;
TreeObject treeObjectToSelect = targetTreeObject;
if (targetTreeObject instanceof IPropertyTreeObject) {
treeObjectToSelect = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
treeObjectToReload = treeObjectToSelect;
if (treeObjectToReload instanceof DatabaseObjectTreeObject) {
treeObjectToReload = treeObjectToReload.getParent();
if (treeObjectToReload instanceof FolderTreeObject)
treeObjectToReload = treeObjectToReload.getParent();
}
}
if (targetTreeObject instanceof IDesignTreeObject) {
treeObjectToSelect = ((IDesignTreeObject) targetTreeObject).getTreeObjectOwner();
treeObjectToReload = treeObjectToSelect;
if (treeObjectToReload instanceof DatabaseObjectTreeObject) {
treeObjectToReload = treeObjectToReload.getParent();
if (treeObjectToReload instanceof FolderTreeObject)
treeObjectToReload = treeObjectToReload.getParent();
}
}
if (treeObjectToReload != null) {
// explorerView.reloadTreeObject(targetTreeObject);
// explorerView.setSelectedTreeObject(targetTreeObject);
explorerView.objectChanged(new CompositeEvent(treeObjectToReload.getObject(), treeObjectToSelect.getPath()));
}
}
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class ClipboardAction method makeProjectTempArchive.
private void makeProjectTempArchive(ProjectTreeObject projectTreeObject) throws EngineException {
Project project = projectTreeObject.getObject();
try {
File exportDirectory = new File(Engine.USER_WORKSPACE_PATH + "/temp");
if (!exportDirectory.exists())
exportDirectory.mkdir();
String exportDirectoryPath = exportDirectory.getCanonicalPath();
CarUtils.makeArchive(exportDirectoryPath, project);
} catch (Exception e) {
throw new EngineException("Unable to make a project copy archive", e);
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class ClipboardAction method importProjectTempArchive.
private Project importProjectTempArchive(String projectName, ProjectExplorerView explorerView) throws EngineException {
try {
// Get an available target project name
int index = 1;
String targetProjectName = projectName;
while (explorerView.getProjectRootObject(targetProjectName) != null) {
targetProjectName = projectName + index++;
}
// Get the original temporary project archive
File importDirectory = new File(Engine.USER_WORKSPACE_PATH + "/temp");
if (!importDirectory.exists())
importDirectory.mkdir();
String importDirectoryPath, importArchiveFilename;
importDirectoryPath = importDirectory.getCanonicalPath();
importArchiveFilename = importDirectoryPath + "/" + projectName + ".car";
// Deploy archive to target project
Project importedProject = Engine.theApp.databaseObjectsManager.deployProject(importArchiveFilename, targetProjectName, true, true);
// Try to delete archive
try {
new File(importArchiveFilename).delete();
} catch (Exception e) {
}
return importedProject;
} catch (Exception e) {
throw new EngineException("Unable to import project archive", e);
}
}
use of com.twinsoft.convertigo.engine.EngineException 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.engine.EngineException in project convertigo by convertigo.
the class ReferencesView method getRequiredRequestables.
private void getRequiredRequestables(Step step, Project projectSelected, ProjectExplorerView projectExplorerView, AbstractParentNode parentNode, List<String> transactionList, List<String> sequenceList) {
try {
if (step instanceof SequenceStep) {
SequenceStep sequenceStep = (SequenceStep) step;
String sourceProjectName = sequenceStep.getProjectName();
if (!sourceProjectName.equals(projectSelected.getName())) {
Project project;
project = getProject(sourceProjectName, projectExplorerView);
ProjectNode projectNode = new ProjectNode(parentNode, sourceProjectName, project);
Sequence sourceSequence = null;
String sourceSequenceName = sequenceStep.getSequenceName();
try {
if (project != null)
sourceSequence = project.getSequenceByName(sourceSequenceName);
} catch (EngineException e) {
sourceSequence = null;
}
projectNode.addChild(new SequenceNode(projectNode, sourceSequenceName, sourceSequence));
if (!sequenceList.contains(sourceProjectName + sourceSequenceName)) {
sequenceList.add(sourceProjectName + sourceSequenceName);
parentNode.addChild(projectNode);
}
}
} else if (step instanceof TransactionStep) {
TransactionStep transactionStep = (TransactionStep) step;
String sourceProjectName = transactionStep.getProjectName();
if (!sourceProjectName.equals(projectSelected.getName())) {
Project project;
project = getProject(sourceProjectName, projectExplorerView);
ProjectNode projectNode = new ProjectNode(parentNode, sourceProjectName, project);
if (project != null) {
Connector connector = project.getConnectorByName(transactionStep.getConnectorName());
ConnectorNode connectorNode = null;
connectorNode = getConnectorNode(projectNode, connector);
projectNode.addChild(connectorNode);
Transaction sourceTransaction = null;
String sourceTransactionName = transactionStep.getTransactionName();
try {
if (connector != null)
sourceTransaction = connector.getTransactionByName(sourceTransactionName);
} catch (Exception e) {
sourceTransaction = null;
}
connectorNode.addChild(new TransactionNode(connectorNode, sourceTransactionName, sourceTransaction));
if (!transactionList.contains(project.getName() + connector.getName() + sourceTransactionName)) {
transactionList.add(project.getName() + connector.getName() + sourceTransactionName);
parentNode.addChild(projectNode);
}
}
}
} else if (isStepContainer(step)) {
List<Step> steps = getStepList(step);
if (steps != null) {
for (Step s : steps) {
getRequiredRequestables(s, projectSelected, projectExplorerView, parentNode, transactionList, sequenceList);
}
}
}
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Unable to load the project", true);
}
}
Aggregations