Search in sources :

Example 26 with CompositeEvent

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

the class JavelinConnectorComposite method fireHandlerChanged.

private void fireHandlerChanged(String newScreenClassHandler) {
    JavelinTransaction transaction = (JavelinTransaction) connector.getLearningTransaction();
    transaction.handlers += handlers;
    transaction.hasChanged = true;
    ConvertigoPlugin.logDebug2("(JavelinConnectorComposite) added new handler to transaction '" + transaction.getName() + "'");
    fireObjectChanged(new CompositeEvent(transaction, newScreenClassHandler));
}
Also used : JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent)

Example 27 with CompositeEvent

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

the class UpdateXSDTypesAction method run.

public void run() {
    final 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();
            ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
            MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL);
            String message = "Do you really want to extract the schema?\nWarning: the previous one will be replaced.";
            messageBox.setMessage(message);
            if (messageBox.open() == SWT.YES) {
                RequestableObject requestable = (RequestableObject) treeObject.getObject();
                String requestableName = StringUtils.normalize(requestable.getName(), true);
                Document document = null;
                String result = null;
                if (!(requestableName.equals(requestable.getName()))) {
                    throw new Exception("Requestable name should be normalized");
                }
                if (requestable instanceof Transaction) {
                    Connector connector = (Connector) requestable.getParent();
                    String connectorName = StringUtils.normalize(connector.getName(), true);
                    if (!(connectorName.equals(connector.getName()))) {
                        throw new Exception("Connector name should be normalized");
                    }
                    if (connector.getDefaultTransaction() == null) {
                        throw new Exception("Connector must have a default transaction");
                    }
                    if (requestable instanceof HtmlTransaction) {
                        if (extract) {
                            ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                            if (connectorEditor == null) {
                                ConvertigoPlugin.infoMessageBox("Please open connector first.");
                                return;
                            }
                            document = connectorEditor.getLastGeneratedDocument();
                            if (document == null) {
                                ConvertigoPlugin.infoMessageBox("You should first generate the document data before trying to extract the XSD types.");
                                return;
                            }
                            result = requestable.generateXsdTypes(document, extract);
                        } else {
                            HtmlTransaction defaultTransaction = (HtmlTransaction) connector.getDefaultTransaction();
                            String defaultTransactionName = StringUtils.normalize(defaultTransaction.getName(), true);
                            if (!(defaultTransactionName.equals(defaultTransaction.getName()))) {
                                throw new Exception("Default transaction name should be normalized");
                            }
                            String defaultXsdTypes = defaultTransaction.generateXsdTypes(null, false);
                            if (requestable.equals(defaultTransaction))
                                result = defaultXsdTypes;
                            else {
                                TransactionXSDTypesDialog dlg = new TransactionXSDTypesDialog(shell, requestable);
                                if (dlg.open() == Window.OK) {
                                    result = dlg.result;
                                    result += defaultXsdTypes;
                                }
                            }
                        }
                    } else {
                        if (extract) {
                            ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                            if (connectorEditor == null) {
                                ConvertigoPlugin.infoMessageBox("Please open connector first.");
                                return;
                            }
                            document = connectorEditor.getLastGeneratedDocument();
                            if (document == null) {
                                ConvertigoPlugin.infoMessageBox("You should first generate the document data before trying to extract the XSD types.");
                                return;
                            }
                            String prefix = requestable.getXsdTypePrefix();
                            document.getDocumentElement().setAttribute("transaction", prefix + requestableName);
                        }
                        if (requestable instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
                            XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
                                if (!xmlQName.isEmpty()) {
                                    ConvertigoPlugin.infoMessageBox("You should first unset 'Assigned element QName' property.");
                                    return;
                                }
                                if (!reqn.equals("")) {
                                    ConvertigoPlugin.infoMessageBox("You should first unset 'Schema of XML response root element' property.");
                                    return;
                                }
                            }
                        }
                        result = requestable.generateXsdTypes(document, extract);
                    }
                }
                if ((result != null) && (!result.equals(""))) {
                    String xsdTypes = result;
                    if (requestable instanceof Transaction) {
                        if (requestable instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
                            XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (!extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
                                // ignore
                                ;
                            } else
                                ((Transaction) requestable).writeSchemaToFile(xsdTypes);
                        } else
                            ((Transaction) requestable).writeSchemaToFile(xsdTypes);
                    }
                    requestable.hasChanged = true;
                    Engine.theApp.schemaManager.clearCache(requestable.getProject().getName());
                    explorerView.refreshFirstSelectedTreeObject();
                    explorerView.objectSelected(new CompositeEvent(requestable));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to update schema!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) Cursor(org.eclipse.swt.graphics.Cursor) Document(org.w3c.dom.Document) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) MessageBox(org.eclipse.swt.widgets.MessageBox) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) Shell(org.eclipse.swt.widgets.Shell) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) TransactionXSDTypesDialog(com.twinsoft.convertigo.eclipse.dialogs.TransactionXSDTypesDialog) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 28 with CompositeEvent

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

the class ProjectImportWsReference 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();
            if (treeObject != null) {
                ProjectTreeObject projectTreeObject = null;
                RemoteFileReference reference = null;
                HttpConnector httpConnector = null;
                // Create a new  WS reference
                if (treeObject instanceof ProjectTreeObject) {
                    projectTreeObject = (ProjectTreeObject) treeObject;
                    if (wsType == TYPE_SOAP) {
                        reference = new WebServiceReference();
                        reference.bNew = true;
                    }
                    if (wsType == TYPE_REST) {
                        reference = new RestServiceReference();
                        reference.bNew = true;
                    }
                } else // Update an existing WS reference
                if (treeObject instanceof ReferenceTreeObject) {
                /* For further use
						ReferenceTreeObject referenceTreeObject = (ReferenceTreeObject)treeObject;
						webServiceReference = (WebServiceReference) referenceTreeObject.getObject();
						projectTreeObject = referenceTreeObject.getProjectTreeObject();*/
                }
                if (reference != null) {
                    WsReferenceImportDialog wsReferenceImportDialog = null;
                    if (wsType == TYPE_SOAP) {
                        wsReferenceImportDialog = new WsReferenceImportDialog(shell, WsSoapReferenceImportDialogComposite.class, "SOAP Web Service reference");
                    }
                    if (wsType == TYPE_REST) {
                        wsReferenceImportDialog = new WsReferenceImportDialog(shell, WsRestReferenceImportDialogComposite.class, "REST Web Service reference");
                    }
                    wsReferenceImportDialog.setProject(projectTreeObject.getObject());
                    wsReferenceImportDialog.setReference(reference);
                    wsReferenceImportDialog.open();
                    if (wsReferenceImportDialog.getReturnCode() != Window.CANCEL) {
                        httpConnector = wsReferenceImportDialog.getHttpConnector();
                    }
                    Project project = projectTreeObject.getObject();
                    Engine.theApp.schemaManager.clearCache(project.getName());
                    // Reload project in tree
                    explorerView.reloadTreeObject(projectTreeObject);
                    if (httpConnector != null && httpConnector.getParent() != null) {
                        explorerView.objectSelected(new CompositeEvent(httpConnector));
                    } else if (reference != null && reference.getParent() != null) {
                        if (reference.hasChanged)
                            projectTreeObject.hasBeenModified(true);
                        explorerView.objectSelected(new CompositeEvent(reference));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to " + (updateMode ? "update" : "import") + " from remote WS definition!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) WsReferenceImportDialog(com.twinsoft.convertigo.eclipse.dialogs.WsReferenceImportDialog) WsRestReferenceImportDialogComposite(com.twinsoft.convertigo.eclipse.dialogs.WsRestReferenceImportDialogComposite) Cursor(org.eclipse.swt.graphics.Cursor) WsSoapReferenceImportDialogComposite(com.twinsoft.convertigo.eclipse.dialogs.WsSoapReferenceImportDialogComposite) Project(com.twinsoft.convertigo.beans.core.Project) Shell(org.eclipse.swt.widgets.Shell) ReferenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ReferenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) RemoteFileReference(com.twinsoft.convertigo.beans.references.RemoteFileReference) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Example 29 with CompositeEvent

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

the class SequenceImportFromXmlAction 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();
            // Open a file dialog to search a XML file
            FileDialog fileDialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
            fileDialog.setText("Import XML file");
            fileDialog.setFilterExtensions(new String[] { "*.xml" });
            fileDialog.setFilterNames(new String[] { "XML" });
            fileDialog.setFilterPath(Engine.PROJECTS_PATH);
            String filePath = fileDialog.open();
            if (filePath != null) {
                // Get XML content from the file
                File xmlFile = new File(filePath);
                Charset charset = XMLUtils.getEncoding(xmlFile);
                String xmlContent = FileUtils.readFileToString(xmlFile, charset.name());
                // Open and add XML content to the dialog area
                XmlStructureDialog dlg = new XmlStructureDialog(shell, sequence, xmlContent);
                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);
                            } else {
                                StepWithExpressions swe = (StepWithExpressions) databaseObject;
                                swe.addStep(step);
                            }
                            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 xml!");
    } 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) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) Charset(java.nio.charset.Charset) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Step(com.twinsoft.convertigo.beans.core.Step) Cursor(org.eclipse.swt.graphics.Cursor) XmlStructureDialog(com.twinsoft.convertigo.eclipse.dialogs.XmlStructureDialog) Shell(org.eclipse.swt.widgets.Shell) 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 30 with CompositeEvent

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

the class DatabaseObjectCreateAction 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)

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