use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject in project convertigo by convertigo.
the class DatabaseObjectDeleteAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
treeNodesToUpdate = new ArrayList<>();
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject[] selectedTreeObjects = explorerView.getSelectedTreeObjects();
if (selectedTreeObjects != null) {
Collection<DatabaseObjectTreeObject> treeObjects = new HashSet<>(selectedTreeObjects.length);
for (TreeObject t : Arrays.asList(selectedTreeObjects)) {
if (t instanceof DatabaseObjectTreeObject) {
treeObjects.add((DatabaseObjectTreeObject) t);
}
}
;
if (treeObjects.size() > 1) {
for (DatabaseObjectTreeObject t : new ArrayList<>(treeObjects)) {
TreeObject parent = t.getParent();
while (parent != null) {
if (treeObjects.contains(parent)) {
treeObjects.remove(t);
parent = null;
} else {
parent = parent.getParent();
}
}
}
;
}
if (treeObjects.size() > 1) {
List<DatabaseObjectTreeObject> list = new ArrayList<>(treeObjects);
Collections.sort(list, new Comparator<DatabaseObjectTreeObject>() {
@Override
public int compare(DatabaseObjectTreeObject o1, DatabaseObjectTreeObject o2) {
if (o1 instanceof ProjectTreeObject) {
if (o2 instanceof ProjectTreeObject) {
return o1.getName().compareTo(o2.getName());
}
return -1;
} else if (o2 instanceof ProjectTreeObject) {
return 1;
}
return o1.getName().compareTo(o2.getName());
}
});
treeObjects = list;
}
MultipleDeletionDialog dialog = new MultipleDeletionDialog(shell, "Object Deletion", treeObjects.size() != 1);
for (DatabaseObjectTreeObject treeObject : treeObjects) {
String message = java.text.MessageFormat.format("Do you really want to delete the {0} \"{1}\" and all its sub-objects?", treeObject instanceof ProjectTreeObject ? "project" : "object", treeObject.getName());
if (treeObject instanceof ProjectTreeObject) {
message += "\nProject location: " + ((Project) treeObject.getObject()).getDirPath();
dialog.setToggle("Delete project content on disk (cannot be undone)", false);
} else {
dialog.removeToggle();
}
if (!dialog.shouldBeDeleted(message)) {
continue;
}
try {
if (treeObject instanceof ProjectTreeObject) {
((ProjectTreeObject) treeObject).closeAllEditors();
} else if (treeObject instanceof SequenceTreeObject) {
((ProjectTreeObject) ((SequenceTreeObject) treeObject).getParent().getParent()).closeSequenceEditors((Sequence) treeObject.getObject());
} else if (treeObject instanceof ConnectorTreeObject) {
((ProjectTreeObject) ((ConnectorTreeObject) treeObject).getParent().getParent()).closeConnectorEditors((Connector) treeObject.getObject());
} else if (treeObject instanceof StepTreeObject) {
// We close the editor linked with the SimpleStep (=SequenceJsStep)
if (treeObject.getObject() instanceof SimpleStep) {
boolean find = false;
SimpleStep simpleStep = (SimpleStep) treeObject.getObject();
IWorkbenchPage page = this.getActivePage();
IEditorReference[] editors = page.getEditorReferences();
int _i = 0;
while (find != true && _i < editors.length) {
IEditorReference editor = editors[_i];
IEditorInput input = editor.getEditorInput();
if (input instanceof JScriptEditorInput) {
if (simpleStep.equals(((JScriptEditorInput) input).getDatabaseObject())) {
find = true;
IEditorPart editorPart = page.findEditor(input);
if (editorPart != null) {
page.activate(editorPart);
page.closeEditor(editorPart, false);
}
}
}
++_i;
}
}
} else if (treeObject instanceof MobileComponentTreeObject) {
((MobileComponentTreeObject) treeObject).closeAllEditors(false);
}
if (treeObject instanceof ProjectTreeObject) {
explorerView.removeProjectTreeObject(treeObject);
final Project project = (Project) treeObject.getObject();
Job rmProject = new Job("Remove '" + project.getName() + "' project") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
delete(project, dialog.getToggleState());
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to delete the '" + project.getName() + "' project.");
return new MultiStatus(ConvertigoPlugin.PLUGIN_UNIQUE_ID, IStatus.ERROR, "Failed to remove the '" + project.getName() + "' project.", e);
}
return Status.OK_STATUS;
}
};
rmProject.schedule();
} else {
delete(treeObject);
// prevents treeObject and its childs to receive further TreeObjectEvents
if (treeObject instanceof TreeObjectListener) {
explorerView.removeTreeObjectListener(treeObject);
}
treeObject.removeAllChildren();
}
explorerView.fireTreeObjectRemoved(new TreeObjectEvent(treeObject));
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to delete the current selected object.");
}
}
;
// Updating the tree and the properties panel
Enumeration<DatabaseObjectTreeObject> enumeration = Collections.enumeration(treeNodesToUpdate);
DatabaseObjectTreeObject parentTreeObject;
while (enumeration.hasMoreElements()) {
parentTreeObject = enumeration.nextElement();
if (parentTreeObject != null) {
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(parentTreeObject);
}
}
// Refresh tree to show potential 'broken' steps
explorerView.refreshTree();
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to delete object!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject in project convertigo by convertigo.
the class EnableStepAction 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) {
DatabaseObjectTreeObject treeObject = null;
Step step = null;
TreeObject[] treeObjects = explorerView.getSelectedTreeObjects();
for (int i = treeObjects.length - 1; i >= 0; i--) {
treeObject = (DatabaseObjectTreeObject) treeObjects[i];
if (treeObject instanceof StepTreeObject) {
StepTreeObject stepTreeObject = (StepTreeObject) treeObject;
step = (Step) stepTreeObject.getObject();
step.setEnabled(true);
stepTreeObject.setEnabled(true);
stepTreeObject.hasBeenModified(true);
TreeObjectEvent treeObjectEvent = new TreeObjectEvent(stepTreeObject, "isEnable", false, true);
explorerView.fireTreeObjectPropertyChanged(treeObjectEvent);
}
}
explorerView.refreshSelectedTreeObjects();
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to enable step!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject in project convertigo by convertigo.
the class OutputStepAction 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) {
DatabaseObjectTreeObject treeObject = null;
TreeObject[] treeObjects = explorerView.getSelectedTreeObjects();
for (int i = treeObjects.length - 1; i >= 0; i--) {
treeObject = (DatabaseObjectTreeObject) treeObjects[i];
if (treeObject instanceof StepTreeObject) {
StepTreeObject stepTreeObject = (StepTreeObject) treeObject;
output((Step) stepTreeObject.getObject());
stepTreeObject.hasBeenModified(true);
// Updating the tree
explorerView.refreshTreeObject(stepTreeObject);
TreeObjectEvent treeObjectEvent = new TreeObjectEvent(stepTreeObject, "output", !output, output);
explorerView.fireTreeObjectPropertyChanged(treeObjectEvent);
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to output step!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations