Search in sources :

Example 6 with CompositeEvent

use of com.twinsoft.convertigo.eclipse.editors.CompositeEvent in project convertigo by convertigo.

the class TransactionCreateHandlerAction method run.

@Override
public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    Statement lastStatement = null;
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            if (treeObject != null) {
                Transaction transaction = null;
                if (treeObject instanceof TransactionTreeObject) {
                    transaction = (Transaction) treeObject.getObject();
                } else if (treeObject instanceof ObjectsFolderTreeObject) {
                    transaction = (Transaction) treeObject.getParent().getObject();
                }
                if (transaction != null) {
                    CreateHandlerDialog createHandlerDialog = new CreateHandlerDialog(shell, transaction);
                    createHandlerDialog.open();
                    if (createHandlerDialog.getReturnCode() != Window.CANCEL) {
                        List<?> result = createHandlerDialog.result;
                        if (result != null) {
                            int len = result.size();
                            if (len > 0) {
                                if (transaction instanceof HtmlTransaction) {
                                    HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
                                    Statement statement = null;
                                    for (int i = 0; i < len; i++) {
                                        statement = (Statement) result.get(i);
                                        htmlTransaction.addStatement(statement);
                                    }
                                    lastStatement = statement;
                                } else {
                                    String handler = null;
                                    for (int i = 0; i < len; i++) {
                                        handler = (String) result.get(i);
                                        transaction.handlers += handler;
                                        transaction.hasChanged = true;
                                    }
                                    // Update the opened handlers editor if any
                                    JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
                                    if (jsinput != null) {
                                        jsinput.reload();
                                    }
                                }
                                // Reload transaction in tree and select last created Statement.
                                try {
                                    ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
                                    projectExplorerView.reloadDatabaseObject(transaction);
                                    if (transaction instanceof HtmlTransaction) {
                                        if (lastStatement != null) {
                                            projectExplorerView.objectSelected(new CompositeEvent(lastStatement));
                                        }
                                    } else {
                                        projectExplorerView.objectSelected(new CompositeEvent(transaction));
                                    }
                                } catch (IOException e) {
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create new handler for transaction!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : JScriptEditorInput(com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Statement(com.twinsoft.convertigo.beans.core.Statement) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) CreateHandlerDialog(com.twinsoft.convertigo.eclipse.dialogs.CreateHandlerDialog) IOException(java.io.IOException) Cursor(org.eclipse.swt.graphics.Cursor) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) Shell(org.eclipse.swt.widgets.Shell) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 7 with CompositeEvent

use of com.twinsoft.convertigo.eclipse.editors.CompositeEvent in project convertigo by convertigo.

the class VariableGenerateFromXmlAndLinkAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            Object databaseObject = treeObject.getObject();
            if ((databaseObject != null) && ((databaseObject instanceof StepVariable))) {
                StepVariable stepVariable = (StepVariable) databaseObject;
                RequestableStep requestableStep = (RequestableStep) stepVariable.getParent();
                if (requestableStep != null) {
                    DatabaseObjectTreeObject parentDboTreeObject = ((DatabaseObjectTreeObject) treeObject).getParentDatabaseObjectTreeObject().getParentDatabaseObjectTreeObject();
                    RequestableObject requestableObject = null;
                    if (requestableStep instanceof SequenceStep) {
                        requestableObject = ((SequenceStep) requestableStep).getTargetSequence();
                    } else if (requestableStep instanceof TransactionStep) {
                        requestableObject = ((TransactionStep) requestableStep).getTargetTransaction();
                    }
                    if ((requestableObject != null) && (requestableObject instanceof IVariableContainer)) {
                        String variableName = stepVariable.getName();
                        IVariableContainer container = (IVariableContainer) requestableObject;
                        RequestableVariable variable = (RequestableVariable) container.getVariable(variableName);
                        // generate dom model
                        Document document = null;
                        try {
                            String description = variable.getDescription();
                            document = XMLUtils.parseDOMFromString(description);
                        } catch (Exception e) {
                        }
                        if (document != null) {
                            Element root = document.getDocumentElement();
                            if (root != null) {
                                // create step's structure from dom
                                DatabaseObject parentObject = requestableStep.getParent();
                                Step step = StepUtils.createStepFromXmlDomModel(parentObject, root);
                                // add step's structure to parent of requestableStep
                                if (parentObject instanceof Sequence) {
                                    Sequence parentSequence = (Sequence) parentObject;
                                    parentSequence.addStep(step);
                                    parentSequence.insertAtOrder(step, requestableStep.priority);
                                } else {
                                    StepWithExpressions parentSwe = (StepWithExpressions) parentObject;
                                    parentSwe.addStep(step);
                                    parentSwe.insertAtOrder(step, requestableStep.priority);
                                }
                                // set source definition of variable
                                XMLVector<String> sourceDefinition = new XMLVector<String>();
                                sourceDefinition.add(String.valueOf(step.priority));
                                sourceDefinition.add(".");
                                stepVariable.setSourceDefinition(sourceDefinition);
                                stepVariable.hasChanged = true;
                                // Reload parent dbo in tree
                                explorerView.reloadTreeObject(parentDboTreeObject);
                                // Select variable dbo in tree
                                explorerView.objectSelected(new CompositeEvent(databaseObject));
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to generate and link variable!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Element(org.w3c.dom.Element) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) Step(com.twinsoft.convertigo.beans.core.Step) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) Cursor(org.eclipse.swt.graphics.Cursor) Document(org.w3c.dom.Document) Shell(org.eclipse.swt.widgets.Shell) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) IVariableContainer(com.twinsoft.convertigo.beans.core.IVariableContainer) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) 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) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) Display(org.eclipse.swt.widgets.Display)

Example 8 with CompositeEvent

use of com.twinsoft.convertigo.eclipse.editors.CompositeEvent in project convertigo by convertigo.

the class MobileComponentCreateAction method postCreate.

public void postCreate(TreeObject parentTreeObject, DatabaseObject createdDatabaseObject) throws Exception {
    ProjectExplorerView explorerView = getProjectExplorerView();
    explorerView.reloadTreeObject(parentTreeObject);
    explorerView.objectSelected(new CompositeEvent(createdDatabaseObject));
/* No more needed since #20 correction : see DatabaseObjectTreeObject:setParent(TreeParent parent)
		TreeObject selectedTreeObject = explorerView.getFirstSelectedTreeObject();
		if ((selectedTreeObject != null) && (selectedTreeObject.getObject().equals(createdDatabaseObject)))
			explorerView.fireTreeObjectAdded(new TreeObjectEvent(selectedTreeObject));*/
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent)

Example 9 with CompositeEvent

use of com.twinsoft.convertigo.eclipse.editors.CompositeEvent in project convertigo by convertigo.

the class SequenceImportFromXsdAction 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 databaseObjectTreeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
            DatabaseObject databaseObject = databaseObjectTreeObject.getObject();
            SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) ((databaseObject instanceof Sequence) ? databaseObjectTreeObject : databaseObjectTreeObject.getParentDatabaseObjectTreeObject());
            Sequence sequence = (databaseObject instanceof Sequence) ? (Sequence) databaseObject : ((StepWithExpressions) databaseObject).getSequence();
            FileDialog fileDialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
            fileDialog.setText("Import schema file");
            fileDialog.setFilterExtensions(new String[] { "*.xsd" });
            fileDialog.setFilterNames(new String[] { "Schema files" });
            fileDialog.setFilterPath(Engine.PROJECTS_PATH);
            String filePath = fileDialog.open();
            if (filePath != null) {
                filePath = filePath.replaceAll("\\\\", "/");
                XmlSchemaCollection collection = new XmlSchemaCollection();
                collection.setBaseUri(filePath);
                XmlSchema xmlSchema = SchemaUtils.loadSchema(new File(filePath), collection);
                SchemaMeta.setCollection(xmlSchema, collection);
                SchemaObjectsDialog dlg = new SchemaObjectsDialog(shell, sequence, xmlSchema);
                if (dlg.open() == Window.OK) {
                    if (dlg.result instanceof Throwable) {
                        throw (Throwable) dlg.result;
                    } else {
                        Step step = (Step) dlg.result;
                        if (step != null) {
                            if (databaseObject instanceof Sequence) {
                                sequence.addStep(step);
                                sequence.hasChanged = true;
                            } else {
                                StepWithExpressions swe = (StepWithExpressions) databaseObject;
                                swe.addStep(step);
                                swe.hasChanged = true;
                            }
                            sequence.hasChanged = true;
                            // Reload sequence in tree without updating its schema for faster reload
                            ConvertigoPlugin.logDebug("Reload sequence: start");
                            explorerView.reloadTreeObject(sequenceTreeObject);
                            ConvertigoPlugin.logDebug("Reload sequence: end");
                            // Select target dbo in tree
                            explorerView.objectSelected(new CompositeEvent(databaseObject));
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to import step from xsd!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) SchemaObjectsDialog(com.twinsoft.convertigo.eclipse.dialogs.SchemaObjectsDialog) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Step(com.twinsoft.convertigo.beans.core.Step) Cursor(org.eclipse.swt.graphics.Cursor) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) Shell(org.eclipse.swt.widgets.Shell) XmlSchema(org.apache.ws.commons.schema.XmlSchema) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 10 with CompositeEvent

use of com.twinsoft.convertigo.eclipse.editors.CompositeEvent in project convertigo by convertigo.

the class DatabaseObjectFindDialog method findDatabaseObject.

protected void findDatabaseObject() {
    Pattern pattern = null;
    String substring = "";
    try {
        pattern = bRegExp ? (bMatchCase ? Pattern.compile(objectTextSubstring) : Pattern.compile(objectTextSubstring, Pattern.CASE_INSENSITIVE)) : null;
    } catch (Exception pex) {
        ConvertigoPlugin.errorMessageBox(pex.getClass().getName() + ":\n" + pex.getMessage());
        return;
    }
    substring = bMatchCase ? objectTextSubstring : objectTextSubstring.toLowerCase();
    while (true) {
        Enumeration<DatabaseObjectTreeObject> enumDatabaseObjects = Collections.enumeration(vDatabaseObjects);
        while (enumDatabaseObjects.hasMoreElements()) {
            DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) enumDatabaseObjects.nextElement();
            DatabaseObject databaseObject = databaseObjectTreeObject.getObject();
            boolean bContinue = false;
            switch(objectType) {
                case // *
                0:
                    bContinue = true;
                    break;
                case // Mobile Component
                1:
                    bContinue = databaseObject.getDatabaseType().equals("MobileComponent");
                    break;
                case // Screen class
                2:
                    bContinue = databaseObject.getDatabaseType().equals("ScreenClass");
                    break;
                case // Criteria
                3:
                    bContinue = databaseObject.getDatabaseType().equals("Criteria");
                    break;
                case // Extraction rule
                4:
                    bContinue = databaseObject.getDatabaseType().equals("ExtractionRule");
                    break;
                case // Sheet
                5:
                    bContinue = databaseObject.getDatabaseType().equals("Sheet");
                    break;
                case // Transaction
                6:
                    bContinue = databaseObject.getDatabaseType().equals("Transaction");
                    break;
                case // Statement
                7:
                    bContinue = databaseObject.getDatabaseType().equals("Statement");
                    break;
                case // Sequence
                8:
                    bContinue = databaseObject.getDatabaseType().equals("Sequence");
                    break;
                case // Step
                9:
                    bContinue = databaseObject.getDatabaseType().equals("Step");
                    break;
            }
            if (bContinue) {
                String text = databaseObjectTreeObject.toString();
                try {
                    text = YamlConverter.toYaml(databaseObject.toXml(XMLUtils.createDom()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                boolean bFound = false;
                if (bRegExp) {
                    Matcher matcher = pattern.matcher(text);
                    bFound = matcher.find();
                } else {
                    text = bMatchCase ? text : text.toLowerCase();
                    bFound = text.indexOf(substring) != -1;
                }
                if (bFound) {
                    // Object found !!!
                    // System.out.println(text);
                    ConvertigoPlugin.getDefault().getProjectExplorerView().objectSelected(new CompositeEvent(databaseObject));
                    vDatabaseObjects.remove(databaseObjectTreeObject);
                    return;
                }
            }
        }
        TreeObject treeSelected = firstSelected == null ? ConvertigoPlugin.projectManager.currentProjectTreeObject : firstSelected;
        MessageBox messageBox = new MessageBox(getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL);
        String message = "End of the search for " + treeSelected.toString() + " object.\nDo you want to retry the search from the beginning?";
        messageBox.setMessage(message);
        int ret = messageBox.open();
        if (ret == SWT.YES) {
            ConvertigoPlugin.getDefault().getProjectExplorerView().setSelectedTreeObject(treeSelected);
            vDatabaseObjects.clear();
            getDatabaseObjects(null);
        } else {
            return;
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) Matcher(java.util.regex.Matcher) 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) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

CompositeEvent (com.twinsoft.convertigo.eclipse.editors.CompositeEvent)33 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)19 Shell (org.eclipse.swt.widgets.Shell)18 Cursor (org.eclipse.swt.graphics.Cursor)17 Display (org.eclipse.swt.widgets.Display)17 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)10 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)10 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)10 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)9 FolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject)9 WizardDialog (org.eclipse.jface.wizard.WizardDialog)7 HtmlScreenClass (com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass)5 DesignDocumentTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject)5 ProjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject)5 Transaction (com.twinsoft.convertigo.beans.core.Transaction)4 NewObjectWizard (com.twinsoft.convertigo.eclipse.wizards.new_object.NewObjectWizard)4 File (java.io.File)4 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)3 Sequence (com.twinsoft.convertigo.beans.core.Sequence)3 Step (com.twinsoft.convertigo.beans.core.Step)3