Search in sources :

Example 21 with StepTreeObject

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();
    }
}
Also used : JScriptEditorInput(com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) SimpleStep(com.twinsoft.convertigo.beans.steps.SimpleStep) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) MultipleDeletionDialog(com.twinsoft.convertigo.eclipse.dialogs.MultipleDeletionDialog) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) IEditorReference(org.eclipse.ui.IEditorReference) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) Job(org.eclipse.core.runtime.jobs.Job) HashSet(java.util.HashSet) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) Sequence(com.twinsoft.convertigo.beans.core.Sequence) IEditorPart(org.eclipse.ui.IEditorPart) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) Project(com.twinsoft.convertigo.beans.core.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeObjectListener(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectListener) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) IEditorInput(org.eclipse.ui.IEditorInput) Display(org.eclipse.swt.widgets.Display)

Example 22 with StepTreeObject

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();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) Step(com.twinsoft.convertigo.beans.core.Step) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent) Cursor(org.eclipse.swt.graphics.Cursor) Display(org.eclipse.swt.widgets.Display)

Example 23 with StepTreeObject

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();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent) Cursor(org.eclipse.swt.graphics.Cursor) Display(org.eclipse.swt.widgets.Display)

Aggregations

StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)23 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)22 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)22 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)20 Cursor (org.eclipse.swt.graphics.Cursor)19 Display (org.eclipse.swt.widgets.Display)19 Shell (org.eclipse.swt.widgets.Shell)19 Sequence (com.twinsoft.convertigo.beans.core.Sequence)18 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)16 Step (com.twinsoft.convertigo.beans.core.Step)15 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)15 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)15 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)15 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)9 TreePath (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath)8 EngineException (com.twinsoft.convertigo.engine.EngineException)6 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)5 AttributeStep (com.twinsoft.convertigo.beans.steps.AttributeStep)4 IfExistStep (com.twinsoft.convertigo.beans.steps.IfExistStep)3 XMLAttributeStep (com.twinsoft.convertigo.beans.steps.XMLAttributeStep)3