use of com.twinsoft.convertigo.engine.ConvertigoException 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.ConvertigoException in project convertigo by convertigo.
the class ProjectTreeObject method rename_.
@Override
protected void rename_(String newName, boolean bDialog) throws ConvertigoException, CoreException {
Project project = getObject();
String oldName = project.getName();
// First verify if an object with the same name exists
if (Engine.theApp.databaseObjectsManager.existsProject(newName)) {
throw new ConvertigoException("The project \"" + newName + "\" already exist!");
}
// save only objects which have changed
save(bDialog);
Engine.theApp.databaseObjectsManager.renameProject(project, newName, true);
// delete old resources plugin
ConvertigoPlugin.getDefault().deleteProjectPluginResource(oldName);
// create new resources plugin
ConvertigoPlugin.getDefault().createProjectPluginResource(newName, project.getDirPath());
}
use of com.twinsoft.convertigo.engine.ConvertigoException in project convertigo by convertigo.
the class OperationImportParametersFromVariablesAction 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 UrlMappingOperation)) {
UrlMappingOperation operation = (UrlMappingOperation) databaseObject;
String targetRequestable = operation.getTargetRequestable();
if (!targetRequestable.isEmpty()) {
StringTokenizer st = new StringTokenizer(targetRequestable, ".");
int count = st.countTokens();
String projectName = st.nextToken();
String sequenceName = count == 2 ? st.nextToken() : "";
String connectorName = count == 3 ? st.nextToken() : "";
String transactionName = count == 3 ? st.nextToken() : "";
Project project = Engine.theApp.databaseObjectsManager.getProjectByName(projectName);
RequestableObject requestableObject = null;
if (sequenceName.isEmpty()) {
requestableObject = project.getConnectorByName(connectorName).getTransactionByName(transactionName);
} else {
requestableObject = project.getSequenceByName(sequenceName);
}
if (requestableObject != null && requestableObject instanceof IVariableContainer) {
IVariableContainer variableContainer = (IVariableContainer) requestableObject;
for (Variable variable : variableContainer.getVariables()) {
String variableName = variable.getName();
Object variableValue = variable.getValueOrNull();
UrlMappingParameter parameter = null;
try {
parameter = operation.getParameterByName(variableName);
} catch (Exception e) {
}
if (parameter == null) {
if (operation instanceof PostOperation || operation instanceof PutOperation)
parameter = new FormParameter();
else
parameter = new QueryParameter();
parameter.setName(variableName);
parameter.setComment(variable.getComment());
parameter.setArray(false);
parameter.setExposed(((RequestableVariable) variable).isWsdl());
parameter.setMultiValued(variable.isMultiValued());
parameter.setRequired(variable.isRequired());
parameter.setValueOrNull(!variable.isMultiValued() ? variableValue : null);
parameter.setMappedVariableName(variableName);
parameter.bNew = true;
parameter.hasChanged = true;
operation.add(parameter);
operation.hasChanged = true;
}
}
if (operation.hasChanged) {
explorerView.reloadTreeObject(treeObject);
StructuredSelection structuredSelection = new StructuredSelection(treeObject);
ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
}
}
} else {
throw new ConvertigoException("Operation has no target requestable : please select one first.");
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to import variables as new parameters in operation!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.engine.ConvertigoException in project convertigo by convertigo.
the class DatabaseObjectTreeObject method rename_.
protected void rename_(String newName, boolean bDialog) throws ConvertigoException, CoreException {
// Verify if an object with the same name exists
TreeObject siblingTreeObject = this;
while ((siblingTreeObject = siblingTreeObject.getPreviousSibling()) != null) {
if (siblingTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject siblingDatabaseObjectTreeObject = (DatabaseObjectTreeObject) siblingTreeObject;
if (!siblingDatabaseObjectTreeObject.isInherited) {
DatabaseObject databaseObjectTmp = siblingDatabaseObjectTreeObject.getObject();
String databaseObjectName = databaseObjectTmp.getName();
if (databaseObjectName.equalsIgnoreCase(newName)) {
throw new ConvertigoException("Another object with the same name already exists (case insensitive).");
}
}
}
}
siblingTreeObject = this;
while ((siblingTreeObject = siblingTreeObject.getNextSibling()) != null) {
if (siblingTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject siblingDatabaseObjectTreeObject = (DatabaseObjectTreeObject) siblingTreeObject;
if (!siblingDatabaseObjectTreeObject.isInherited) {
DatabaseObject databaseObjectTmp = siblingDatabaseObjectTreeObject.getObject();
String databaseObjectName = databaseObjectTmp.getName();
if (databaseObjectName.equalsIgnoreCase(newName)) {
throw new ConvertigoException("Another object with the same name already exists (case insensitive).");
}
}
}
}
DatabaseObject databaseObject = getObject();
databaseObject.setName(newName);
databaseObject.hasChanged = true;
hasBeenModified(true);
}
use of com.twinsoft.convertigo.engine.ConvertigoException in project convertigo by convertigo.
the class DatabaseObjectTreeObject method rename.
public boolean rename(String newName, boolean bDialog) {
try {
if (!StringUtils.isNormalized(newName)) {
throw new ConvertigoException("The name \"" + newName + "\" must be normalized.\nDon't start with number and don't use non ASCII caracters.");
}
DatabaseObject databaseObject = getObject();
String oldName = databaseObject.getName();
if (newName.equals(oldName)) {
return true;
}
if (newName.equalsIgnoreCase(oldName)) {
throw new ConvertigoException("The rename operation is case insensitive.");
}
rename_(newName, bDialog);
} catch (ConvertigoException e) {
ConvertigoPlugin.logException(e, "Unable to change the object name.", bDialog);
return false;
} catch (CoreException e) {
ConvertigoPlugin.logException(e, "Unable to change the object name.", bDialog);
return false;
}
return true;
}
Aggregations