Search in sources :

Example 86 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence 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 87 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.

the class OpenFlowViewerAction method 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();
            if ((treeObject != null) && (treeObject instanceof SequenceTreeObject)) {
                SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) treeObject;
                Sequence sequence = sequenceTreeObject.getObject();
                ConvertigoPlugin.getDefault().openFlowViewerEditor(sequence);
            }
        }
    } catch (NoSuchElementException e) {
        ConvertigoPlugin.logException(e, "No previous XML file found");
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to execute the selected sequence!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Cursor(org.eclipse.swt.graphics.Cursor) NoSuchElementException(java.util.NoSuchElementException) Display(org.eclipse.swt.widgets.Display)

Example 88 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.

the class MobilePickerContentProvider method addSequences.

private void addSequences(Map<String, Set<String>> map, TVObject tvs, Object object, boolean isReferenced) {
    if (object != null) {
        if (object instanceof Project) {
            Project project = (Project) object;
            for (Sequence s : project.getSequencesList()) {
                String label = isReferenced ? s.getQName() : s.getName();
                SourceData sd = null;
                try {
                    sd = Filter.Sequence.toSourceData(new JSONObject().put("sequence", s.getQName()));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                tvs.add(new TVObject(label, s, sd));
                Set<String> infos = map.get(s.getQName());
                if (infos != null) {
                    for (String info : infos) {
                        try {
                            JSONObject jsonInfo = new JSONObject(info);
                            if (jsonInfo.has("marker")) {
                                String marker = jsonInfo.getString("marker");
                                if (!marker.isEmpty()) {
                                    sd = Filter.Sequence.toSourceData(new JSONObject().put("sequence", s.getQName()).put("marker", marker));
                                    tvs.add(new TVObject(label + "#" + marker, s, sd, jsonInfo));
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SourceData(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.SourceData)

Example 89 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.

the class MobileSmartSource method getDatabaseObject.

public DatabaseObject getDatabaseObject(String rootDboName) {
    List<String> sourceData = getSources();
    String sourceInput = sourceData.size() > 0 ? sourceData.get(0) : null;
    if (sourceInput != null) {
        if (Filter.Action.equals(getFilter())) {
            Matcher m = actionPattern.matcher(sourceInput);
            if (m.find()) {
                String stack = m.group(1);
                try {
                    String p = stack.replaceFirst("stack\\[", "").replaceFirst("\\]", "");
                    // ignore quotes
                    p = p.substring(1, p.length() - 1);
                    long priority = Long.valueOf(p, 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Shared.equals(getFilter())) {
            Matcher m = sharedPattern.matcher(sourceInput);
            if (m.find()) {
                String shared = m.group(1);
                try {
                    long priority = Long.valueOf(shared.replaceFirst("params", ""), 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Iteration.equals(getFilter())) {
            Matcher m = directivePattern.matcher(sourceInput);
            if (m.find()) {
                String item = m.group(1);
                try {
                    long priority = Long.valueOf(item.replaceFirst("item", ""), 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Form.equals(getFilter())) {
            Matcher m = formPattern.matcher(sourceInput);
            if (m.find()) {
                String form = m.group(1);
                try {
                    long priority = Long.valueOf(form.replaceFirst("form", ""), 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Global.equals(getFilter())) {
            Matcher m = globalPattern.matcher(sourceInput);
            if (m.find()) {
                try {
                    String projectName = getProjectName();
                    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                    DatabaseObject dbo = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
                    return dbo;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Database.equals(getFilter())) {
            Matcher m = cafPattern.matcher(sourceInput);
            if (m.find()) {
                try {
                    String name = m.group(1);
                    name = name.replaceFirst("fs://", "");
                    name = name.replaceFirst("\\.view", "");
                    name = name.replaceFirst("\\.get", "");
                    int i = name.indexOf('#');
                    if (i != -1) {
                        name = name.substring(0, i);
                    }
                    int index = name.indexOf('.');
                    String projectName = index != -1 ? name.substring(0, index) : getProjectName();
                    String dbName = index != -1 ? name.substring(index + 1) : name;
                    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                    FullSyncConnector connector = (FullSyncConnector) project.getConnectorByName(dbName);
                    String documentName = getParameters().get("ddoc");
                    DesignDocument ddoc = (DesignDocument) connector.getDocumentByName(documentName);
                    return ddoc;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Sequence.equals(getFilter())) {
            Matcher m = cafPattern.matcher(sourceInput);
            if (m.find()) {
                try {
                    String name = m.group(1);
                    int i = name.indexOf('#');
                    if (i != -1) {
                        name = name.substring(0, i);
                    }
                    int index = name.indexOf('.');
                    String projectName = index != -1 ? name.substring(0, index) : getProjectName();
                    projectName = projectName.isEmpty() ? getProjectName() : projectName;
                    String sequenceName = index != -1 ? name.substring(index + 1) : name;
                    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                    Sequence sequence = project.getSequenceByName(sequenceName);
                    return sequence;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return null;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Matcher(java.util.regex.Matcher) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) Sequence(com.twinsoft.convertigo.beans.core.Sequence) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) JSONException(org.codehaus.jettison.json.JSONException)

Example 90 with Sequence

use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.

the class SequenceStep method getTargetSequence.

public Sequence getTargetSequence() throws EngineException {
    Project p = getTargetProject(projectName);
    if (p == null) {
        throw new EngineException("There is no project named \"" + projectName + "\" found.");
    }
    List<Sequence> v = p.getSequencesList();
    Sequence targetSequence = (sequenceName.equals("") ? (v.isEmpty() ? null : (Sequence) v.get(0)) : p.getSequenceByName(sequenceName));
    return targetSequence;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) EngineException(com.twinsoft.convertigo.engine.EngineException) Sequence(com.twinsoft.convertigo.beans.core.Sequence) GenericSequence(com.twinsoft.convertigo.beans.sequences.GenericSequence)

Aggregations

Sequence (com.twinsoft.convertigo.beans.core.Sequence)94 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)47 EngineException (com.twinsoft.convertigo.engine.EngineException)42 Step (com.twinsoft.convertigo.beans.core.Step)38 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)37 Project (com.twinsoft.convertigo.beans.core.Project)34 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)34 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)32 Transaction (com.twinsoft.convertigo.beans.core.Transaction)29 Cursor (org.eclipse.swt.graphics.Cursor)29 Display (org.eclipse.swt.widgets.Display)29 Shell (org.eclipse.swt.widgets.Shell)29 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)27 Connector (com.twinsoft.convertigo.beans.core.Connector)21 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)20 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)19 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)18 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)17 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)17 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)16