Search in sources :

Example 1 with TreePath

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath 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()));
            }
        }
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) EngineException(com.twinsoft.convertigo.engine.EngineException) CoreException(org.eclipse.core.runtime.CoreException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) CustomDialog(com.twinsoft.convertigo.eclipse.dialogs.CustomDialog) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) ButtonSpec(com.twinsoft.convertigo.eclipse.dialogs.ButtonSpec) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Example 2 with TreePath

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath in project convertigo by convertigo.

the class ChangeToIfFileExistThenElseStepAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#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();
            Object databaseObject = treeObject.getObject();
            if ((databaseObject != null) && (databaseObject instanceof IfFileExistStep)) {
                IfFileExistStep ifFileExistStep = (IfFileExistStep) databaseObject;
                List<Step> list = ifFileExistStep.getSteps();
                TreePath[] selectedPaths = new TreePath[list.size()];
                for (int i = 0; i < list.size(); i++) {
                    StepTreeObject stepTreeObject = (StepTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
                    selectedPaths[i] = new TreePath(stepTreeObject);
                }
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New IfFileExistThenElseStep step
                    IfFileExistThenElseStep ifFileExistThenElseStep = new IfFileExistThenElseStep(ifFileExistStep.getCondition());
                    ifFileExistThenElseStep.bNew = true;
                    ifFileExistThenElseStep.hasChanged = true;
                    // Add new IfFileExistThenElseStep step to parent
                    DatabaseObject parentDbo = ifFileExistStep.getParent();
                    parentDbo.add(ifFileExistThenElseStep);
                    // Set correct order
                    if (parentDbo instanceof StepWithExpressions)
                        ((StepWithExpressions) parentDbo).insertAtOrder(ifFileExistThenElseStep, ifFileExistStep.priority);
                    else if (parentDbo instanceof Sequence)
                        ((Sequence) parentDbo).insertAtOrder(ifFileExistThenElseStep, ifFileExistStep.priority);
                    // Add Then/Else steps
                    ThenStep thenStep = new ThenStep();
                    thenStep.bNew = true;
                    ifFileExistThenElseStep.addStep(thenStep);
                    ElseStep elseStep = new ElseStep();
                    elseStep.bNew = true;
                    ifFileExistThenElseStep.addStep(elseStep);
                    // Add new IfFileExistThenElseStep step in Tree
                    StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifFileExistThenElseStep);
                    treeParent.addChild(stepTreeObject);
                    StepTreeObject thenTreeObject = new StepTreeObject(explorerView.viewer, thenStep);
                    stepTreeObject.addChild(thenTreeObject);
                    StepTreeObject elseTreeObject = new StepTreeObject(explorerView.viewer, elseStep);
                    stepTreeObject.addChild(elseTreeObject);
                    // Cut/Paste steps under Then step
                    if (selectedPaths.length > 0) {
                        new ClipboardAction(ConvertigoPlugin.clipboardManagerDND).cut(explorerView, selectedPaths, ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP);
                        for (int i = 0; i < ConvertigoPlugin.clipboardManagerDND.objects.length; i++) {
                            ConvertigoPlugin.clipboardManagerDND.cutAndPaste(ConvertigoPlugin.clipboardManagerDND.objects[i], thenTreeObject);
                        }
                        ConvertigoPlugin.clipboardManagerDND.reset();
                    }
                    // Delete If step
                    long oldPriority = ifFileExistStep.priority;
                    ifFileExistStep.delete();
                    // Simulate move of If to IfThenElse
                    ifFileExistThenElseStep.getSequence().fireStepMoved(new StepEvent(ifFileExistThenElseStep, String.valueOf(oldPriority)));
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifFileExistThenElseStep));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to IfFileExistThenElse step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : IfFileExistStep(com.twinsoft.convertigo.beans.steps.IfFileExistStep) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IfFileExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfFileExistThenElseStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) IfFileExistStep(com.twinsoft.convertigo.beans.steps.IfFileExistStep) Step(com.twinsoft.convertigo.beans.core.Step) IfFileExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfFileExistThenElseStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) Cursor(org.eclipse.swt.graphics.Cursor) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Shell(org.eclipse.swt.widgets.Shell) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Sequence(com.twinsoft.convertigo.beans.core.Sequence) IfFileExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfFileExistThenElseStep) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) 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) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) 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) Display(org.eclipse.swt.widgets.Display)

Example 3 with TreePath

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath in project convertigo by convertigo.

the class ChangeToIfStepAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#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();
            Object databaseObject = treeObject.getObject();
            if ((databaseObject != null) && (databaseObject instanceof IfThenElseStep)) {
                IfThenElseStep ifThenElseStep = (IfThenElseStep) databaseObject;
                if (ifThenElseStep.hasThenElseSteps()) {
                    ThenStep thenStep = ifThenElseStep.getThenStep();
                    List<Step> list = thenStep.getSteps();
                    TreePath[] selectedPaths = new TreePath[list.size()];
                    for (int i = 0; i < list.size(); i++) {
                        StepTreeObject stepTreeObject = (StepTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
                        selectedPaths[i] = new TreePath(stepTreeObject);
                    }
                    TreeParent treeParent = treeObject.getParent();
                    DatabaseObjectTreeObject parentTreeObject = null;
                    if (treeParent instanceof DatabaseObjectTreeObject)
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                    else
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                    if (parentTreeObject != null) {
                        // New jIf step
                        IfStep ifStep = new IfStep(ifThenElseStep.getCondition());
                        ifStep.bNew = true;
                        ifStep.hasChanged = true;
                        // Add new jIf step to parent
                        DatabaseObject parentDbo = ifThenElseStep.getParent();
                        parentDbo.add(ifStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(ifStep, ifThenElseStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(ifStep, ifThenElseStep.priority);
                        // Add new jIf step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifStep);
                        treeParent.addChild(stepTreeObject);
                        // Cut/Paste steps under jIf step
                        if (selectedPaths.length > 0) {
                            new ClipboardAction(ConvertigoPlugin.clipboardManagerDND).cut(explorerView, selectedPaths, ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP);
                            for (int i = 0; i < ConvertigoPlugin.clipboardManagerDND.objects.length; i++) {
                                ConvertigoPlugin.clipboardManagerDND.cutAndPaste(ConvertigoPlugin.clipboardManagerDND.objects[i], stepTreeObject);
                            }
                            ConvertigoPlugin.clipboardManagerDND.reset();
                        }
                        // Delete IfThenElse step
                        long oldPriority = ifThenElseStep.priority;
                        ifThenElseStep.delete();
                        // Simulate move of IfThenElse to If
                        ifStep.getSequence().fireStepMoved(new StepEvent(ifStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifStep));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to jIf step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) 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) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Step(com.twinsoft.convertigo.beans.core.Step) IfStep(com.twinsoft.convertigo.beans.steps.IfStep) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Cursor(org.eclipse.swt.graphics.Cursor) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Shell(org.eclipse.swt.widgets.Shell) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) 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) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) 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) Display(org.eclipse.swt.widgets.Display) IfStep(com.twinsoft.convertigo.beans.steps.IfStep)

Example 4 with TreePath

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath in project convertigo by convertigo.

the class ChangeToIfThenElseStepAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#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();
            Object databaseObject = treeObject.getObject();
            if ((databaseObject != null) && (databaseObject instanceof IfStep)) {
                IfStep ifStep = (IfStep) databaseObject;
                List<Step> list = ifStep.getSteps();
                TreePath[] selectedPaths = new TreePath[list.size()];
                for (int i = 0; i < list.size(); i++) {
                    StepTreeObject stepTreeObject = (StepTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
                    selectedPaths[i] = new TreePath(stepTreeObject);
                }
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New IfThenElseStep step
                    IfThenElseStep ifThenElseStep = new IfThenElseStep(ifStep.getCondition());
                    ifThenElseStep.bNew = true;
                    ifThenElseStep.hasChanged = true;
                    // Add new IfThenElseStep step to parent
                    DatabaseObject parentDbo = ifStep.getParent();
                    parentDbo.add(ifThenElseStep);
                    // Set correct order
                    if (parentDbo instanceof StepWithExpressions)
                        ((StepWithExpressions) parentDbo).insertAtOrder(ifThenElseStep, ifStep.priority);
                    else if (parentDbo instanceof Sequence)
                        ((Sequence) parentDbo).insertAtOrder(ifThenElseStep, ifStep.priority);
                    // Add Then/Else steps
                    ThenStep thenStep = new ThenStep();
                    thenStep.bNew = true;
                    ifThenElseStep.addStep(thenStep);
                    ElseStep elseStep = new ElseStep();
                    elseStep.bNew = true;
                    ifThenElseStep.addStep(elseStep);
                    // Add new IfThenElseStep step in Tree
                    StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifThenElseStep);
                    treeParent.addChild(stepTreeObject);
                    StepTreeObject thenTreeObject = new StepTreeObject(explorerView.viewer, thenStep);
                    stepTreeObject.addChild(thenTreeObject);
                    StepTreeObject elseTreeObject = new StepTreeObject(explorerView.viewer, elseStep);
                    stepTreeObject.addChild(elseTreeObject);
                    // Cut/Paste steps under Then step
                    if (selectedPaths.length > 0) {
                        new ClipboardAction(ConvertigoPlugin.clipboardManagerDND).cut(explorerView, selectedPaths, ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP);
                        for (int i = 0; i < ConvertigoPlugin.clipboardManagerDND.objects.length; i++) {
                            ConvertigoPlugin.clipboardManagerDND.cutAndPaste(ConvertigoPlugin.clipboardManagerDND.objects[i], thenTreeObject);
                        }
                        ConvertigoPlugin.clipboardManagerDND.reset();
                    }
                    // Delete If step
                    long oldPriority = ifStep.priority;
                    ifStep.delete();
                    // Simulate move of If to IfThenElse
                    ifThenElseStep.getSequence().fireStepMoved(new StepEvent(ifThenElseStep, String.valueOf(oldPriority)));
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifThenElseStep));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to jIfThenElse step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Step(com.twinsoft.convertigo.beans.core.Step) IfStep(com.twinsoft.convertigo.beans.steps.IfStep) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) Cursor(org.eclipse.swt.graphics.Cursor) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Shell(org.eclipse.swt.widgets.Shell) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Sequence(com.twinsoft.convertigo.beans.core.Sequence) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) 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) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) 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) Display(org.eclipse.swt.widgets.Display) IfStep(com.twinsoft.convertigo.beans.steps.IfStep)

Example 5 with TreePath

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath in project convertigo by convertigo.

the class ChangeToIsInThenElseStepAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#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();
            Object databaseObject = treeObject.getObject();
            // For IsInStep
            if ((databaseObject != null) && (databaseObject instanceof IsInStep)) {
                IsInStep isIn = (IsInStep) databaseObject;
                List<Step> list = isIn.getSteps();
                TreePath[] selectedPaths = new TreePath[list.size()];
                for (int i = 0; i < list.size(); i++) {
                    StepTreeObject stepTreeObject = (StepTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
                    selectedPaths[i] = new TreePath(stepTreeObject);
                }
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New IfThenElseStep step
                    IsInThenElseStep ifThenElseStep = new IsInThenElseStep();
                    // Set properties
                    ifThenElseStep.setSourceDefinition(isIn.getSourceDefinition());
                    ifThenElseStep.setTestDefinition(isIn.getTestDefinition());
                    ifThenElseStep.setComment(isIn.getComment());
                    ifThenElseStep.setCondition(isIn.getCondition());
                    ifThenElseStep.setEnabled(isIn.isEnabled());
                    ifThenElseStep.setOutput(isIn.isOutput());
                    ifThenElseStep.setName(isIn.getName());
                    ifThenElseStep.bNew = true;
                    ifThenElseStep.hasChanged = true;
                    // Add new IfThenElseStep step to parent
                    DatabaseObject parentDbo = isIn.getParent();
                    parentDbo.add(ifThenElseStep);
                    // Set correct order
                    if (parentDbo instanceof StepWithExpressions)
                        ((StepWithExpressions) parentDbo).insertAtOrder(ifThenElseStep, isIn.priority);
                    else if (parentDbo instanceof Sequence)
                        ((Sequence) parentDbo).insertAtOrder(ifThenElseStep, isIn.priority);
                    // Add Then/Else steps
                    ThenStep thenStep = new ThenStep();
                    thenStep.bNew = true;
                    ifThenElseStep.addStep(thenStep);
                    ElseStep elseStep = new ElseStep();
                    elseStep.bNew = true;
                    ifThenElseStep.addStep(elseStep);
                    // Add new IfThenElseStep step in Tree
                    StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifThenElseStep);
                    treeParent.addChild(stepTreeObject);
                    StepTreeObject thenTreeObject = new StepTreeObject(explorerView.viewer, thenStep);
                    stepTreeObject.addChild(thenTreeObject);
                    StepTreeObject elseTreeObject = new StepTreeObject(explorerView.viewer, elseStep);
                    stepTreeObject.addChild(elseTreeObject);
                    // Cut/Paste steps under Then step
                    if (selectedPaths.length > 0) {
                        new ClipboardAction(ConvertigoPlugin.clipboardManagerDND).cut(explorerView, selectedPaths, ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP);
                        for (int i = 0; i < ConvertigoPlugin.clipboardManagerDND.objects.length; i++) {
                            ConvertigoPlugin.clipboardManagerDND.cutAndPaste(ConvertigoPlugin.clipboardManagerDND.objects[i], thenTreeObject);
                        }
                        ConvertigoPlugin.clipboardManagerDND.reset();
                    }
                    // Delete If step
                    long oldPriority = isIn.priority;
                    // Save oldName
                    String oldName = isIn.getName();
                    // Now delete
                    isIn.delete();
                    // Set name after deletion
                    ifThenElseStep.setName(oldName);
                    // Simulate move of If to IfThenElse
                    ifThenElseStep.getSequence().fireStepMoved(new StepEvent(ifThenElseStep, String.valueOf(oldPriority)));
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifThenElseStep));
                }
            }
            // For IfExistThenElse step
            if ((databaseObject != null) && (databaseObject instanceof IfExistThenElseStep)) {
                IfExistThenElseStep ifExistThenElse = (IfExistThenElseStep) databaseObject;
                if (ifExistThenElse.hasThenElseSteps()) {
                    TreeParent treeParent = treeObject.getParent();
                    DatabaseObjectTreeObject parentTreeObject = null;
                    if (treeParent instanceof DatabaseObjectTreeObject)
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                    else
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                    if (parentTreeObject != null) {
                        // New IsInThenElse step
                        IsInThenElseStep isInThenElse = new IsInThenElseStep();
                        // Set properties
                        isInThenElse.setSourceDefinition(ifExistThenElse.getSourceDefinition());
                        isInThenElse.setComment(ifExistThenElse.getComment());
                        isInThenElse.setCondition(ifExistThenElse.getCondition());
                        isInThenElse.setEnabled(ifExistThenElse.isEnabled());
                        isInThenElse.setOutput(ifExistThenElse.isOutput());
                        isInThenElse.setName(ifExistThenElse.getName());
                        isInThenElse.bNew = true;
                        isInThenElse.hasChanged = true;
                        // Add new IsInThenElse step to parent
                        DatabaseObject parentDbo = ifExistThenElse.getParent();
                        parentDbo.add(isInThenElse);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(isInThenElse, ifExistThenElse.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(isInThenElse, ifExistThenElse.priority);
                        // Add Then/Else steps
                        ThenStep thenStep = ifExistThenElse.getThenStep();
                        ElseStep elseStep = ifExistThenElse.getElseStep();
                        thenStep.bNew = true;
                        elseStep.bNew = true;
                        isInThenElse.addStep(thenStep);
                        isInThenElse.addStep(elseStep);
                        // Add new IsInThenElse step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, isInThenElse);
                        treeParent.addChild(new StepTreeObject(explorerView.viewer, isInThenElse));
                        stepTreeObject.addChild(new StepTreeObject(explorerView.viewer, thenStep));
                        stepTreeObject.addChild(new StepTreeObject(explorerView.viewer, elseStep));
                        // Delete ifExistThenElse step
                        long oldPriority = ifExistThenElse.priority;
                        // Save oldName
                        String oldName = ifExistThenElse.getName();
                        // Now delete
                        ifExistThenElse.delete();
                        // Set name after deletion
                        isInThenElse.setName(oldName);
                        // Simulate move of ifExistThenElse to IsInThenElse step
                        isInThenElse.getSequence().fireStepMoved(new StepEvent(isInThenElse, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(isInThenElse));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to IsInThenElse step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IfExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfExistThenElseStep) IsInThenElseStep(com.twinsoft.convertigo.beans.steps.IsInThenElseStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) IfExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfExistThenElseStep) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) IfExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfExistThenElseStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) IsInStep(com.twinsoft.convertigo.beans.steps.IsInStep) Step(com.twinsoft.convertigo.beans.core.Step) IsInThenElseStep(com.twinsoft.convertigo.beans.steps.IsInThenElseStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) Cursor(org.eclipse.swt.graphics.Cursor) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Shell(org.eclipse.swt.widgets.Shell) IsInStep(com.twinsoft.convertigo.beans.steps.IsInStep) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IsInThenElseStep(com.twinsoft.convertigo.beans.steps.IsInThenElseStep) StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Sequence(com.twinsoft.convertigo.beans.core.Sequence) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) 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) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) 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) Display(org.eclipse.swt.widgets.Display)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)11 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)11 TreePath (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath)11 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)11 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)11 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)10 Cursor (org.eclipse.swt.graphics.Cursor)10 Display (org.eclipse.swt.widgets.Display)10 Shell (org.eclipse.swt.widgets.Shell)10 Sequence (com.twinsoft.convertigo.beans.core.Sequence)8 Step (com.twinsoft.convertigo.beans.core.Step)8 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)8 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)8 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)8 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)8 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)4 IfExistStep (com.twinsoft.convertigo.beans.steps.IfExistStep)3 IfExistThenElseStep (com.twinsoft.convertigo.beans.steps.IfExistThenElseStep)3 IsInStep (com.twinsoft.convertigo.beans.steps.IsInStep)3 IsInThenElseStep (com.twinsoft.convertigo.beans.steps.IsInThenElseStep)3