Search in sources :

Example 1 with CreateHandlerDialog

use of com.twinsoft.convertigo.eclipse.dialogs.CreateHandlerDialog 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)

Aggregations

Statement (com.twinsoft.convertigo.beans.core.Statement)1 Transaction (com.twinsoft.convertigo.beans.core.Transaction)1 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)1 CreateHandlerDialog (com.twinsoft.convertigo.eclipse.dialogs.CreateHandlerDialog)1 CompositeEvent (com.twinsoft.convertigo.eclipse.editors.CompositeEvent)1 JScriptEditorInput (com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput)1 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)1 ObjectsFolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject)1 TransactionTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject)1 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)1 IOException (java.io.IOException)1 Cursor (org.eclipse.swt.graphics.Cursor)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1