Search in sources :

Example 1 with HandlerStatement

use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.

the class CreateHandlerDialogComposite method generateStatementHandler.

public void generateStatementHandler() throws EngineException {
    String normalizedScreenClassName, handlerName = "";
    if (jCheckBoxTransactionStarted.getSelection()) {
        handlerName = "on" + Transaction.EVENT_TRANSACTION_STARTED;
        if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
            HandlerStatement statement = new HandlerStatement(HandlerStatement.EVENT_TRANSACTION_STARTED, "");
            addElement(statement, handlerName);
        } else
            Beep();
    }
    if (jCheckBoxXmlGenerated.getSelection()) {
        handlerName = "on" + Transaction.EVENT_XML_GENERATED;
        if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
            HandlerStatement statement = new HandlerStatement(HandlerStatement.EVENT_XML_GENERATED, "");
            addElement(statement, handlerName);
        } else
            Beep();
    }
    if (jCheckBoxTransactionDefaultHandlerEntry.getSelection()) {
        handlerName = "onTransactionDefaultHandlerEntry";
        if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
            ScEntryDefaultHandlerStatement statement = new ScEntryDefaultHandlerStatement();
            addElement(statement, handlerName);
        } else
            Beep();
    }
    if (jCheckBoxTransactionDefaultHandlerExit.getSelection()) {
        handlerName = "onTransactionDefaultHandlerExit";
        if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
            ScExitDefaultHandlerStatement statement = new ScExitDefaultHandlerStatement();
            addElement(statement, handlerName);
        } else
            Beep();
    }
    if (jCheckBoxEntry.getSelection() || jCheckBoxExit.getSelection()) {
        TreeItem[] treeItems = tree.getSelection();
        for (int i = 0; i < treeItems.length; i++) {
            String selectedScreenClass = treeItems[i].getText();
            normalizedScreenClassName = StringUtils.normalize(selectedScreenClass);
            if (jCheckBoxEntry.getSelection()) {
                handlerName = "on" + normalizedScreenClassName + "Entry";
                if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
                    ScEntryHandlerStatement statement = new ScEntryHandlerStatement(normalizedScreenClassName);
                    addElement(statement, handlerName);
                } else
                    Beep();
            }
            if (jCheckBoxExit.getSelection()) {
                handlerName = "on" + normalizedScreenClassName + "Exit";
                if (((HtmlTransaction) transaction).getHandlerStatement(handlerName) == null) {
                    ScExitHandlerStatement statement = new ScExitHandlerStatement(normalizedScreenClassName);
                    addElement(statement, handlerName);
                } else
                    Beep();
            }
        }
    }
}
Also used : ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) TreeItem(org.eclipse.swt.widgets.TreeItem) ScExitDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitDefaultHandlerStatement) ScExitDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitDefaultHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScEntryDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryDefaultHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) ScEntryDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryDefaultHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement)

Example 2 with HandlerStatement

use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.

the class NewObjectWizard method doFinish.

private void doFinish(IProgressMonitor monitor) throws CoreException {
    String dboName, name;
    boolean bContinue = true;
    int index = 0;
    try {
        int total = 0;
        Class<?> c = getCreatedBeanClass();
        if (c != null) {
            total = 4;
            if (c.equals(WebServiceReference.class)) {
                total += ImportWsReference.getTotalTaskNumber();
            }
        }
        monitor.beginTask("Creating new object", total);
        newBean = getCreatedBean();
        if (newBean != null) {
            monitor.setTaskName("Object created");
            monitor.worked(1);
            dboName = newBean.getName();
            if (!StringUtils.isNormalized(dboName))
                throw new EngineException("Bean name is not normalized : \"" + dboName + "\".");
            // Verify if a child object with same name exist and change name
            while (bContinue) {
                if (index == 0)
                    name = dboName;
                else
                    name = dboName + index;
                newBean.setName(name);
                newBean.hasChanged = true;
                newBean.bNew = true;
                try {
                    new WalkHelper() {

                        boolean root = true;

                        boolean find = false;

                        @Override
                        protected boolean before(DatabaseObject dbo, Class<? extends DatabaseObject> dboClass) {
                            boolean isInstance = dboClass.isInstance(newBean);
                            find |= isInstance;
                            return isInstance;
                        }

                        @Override
                        protected void walk(DatabaseObject dbo) throws Exception {
                            if (root) {
                                root = false;
                                super.walk(dbo);
                                if (!find) {
                                    throw new EngineException("You cannot add to a " + newBean.getClass().getSimpleName() + " a database object of type " + parentObject.getClass().getSimpleName());
                                }
                            } else {
                                if (newBean.getName().equalsIgnoreCase(dbo.getName())) {
                                    throw new ObjectWithSameNameException("Unable to add the object because an object with the same name already exists in target.");
                                }
                            }
                        }
                    }.init(parentObject);
                    bContinue = false;
                } catch (ObjectWithSameNameException owsne) {
                    if ((parentObject instanceof HtmlTransaction) && (newBean instanceof Statement)) {
                        throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
                    }
                    // Silently ignore
                    index++;
                } catch (EngineException ee) {
                    throw ee;
                } catch (Exception e) {
                    throw new EngineException("Exception in create", e);
                }
            }
            // Now add bean to target
            try {
                boolean hasChanged = parentObject.hasChanged;
                if ((newBean instanceof Statement) && (parentObject instanceof Transaction)) {
                    newBean.priority = 0;
                }
                if (newBean instanceof ScreenClass)
                    newBean.priority = parentObject.priority + 1;
                if (newBean instanceof Criteria) {
                    Connector connector = parentObject.getConnector();
                    if (parentObject.equals(((IScreenClassContainer<?>) connector).getDefaultScreenClass()))
                        throw new EngineException("You cannot add a new criterion on default screenclass.");
                }
                parentObject.add(newBean);
                monitor.setTaskName("Object added");
                monitor.worked(1);
                if (newBean instanceof HTTPStatement) {
                    HTTPStatement httpStatement = (HTTPStatement) newBean;
                    HtmlConnector connector = (HtmlConnector) httpStatement.getParentTransaction().getParent();
                    httpStatement.setMethod("GET");
                    httpStatement.setHost(connector.getServer());
                    httpStatement.setPort(connector.getPort());
                    httpStatement.setHttps(connector.isHttps());
                }
                if (newBean instanceof ContinueWithSiteClipperStatement) {
                    Project project = newBean.getProject();
                    if (project != null) {
                        String[] connectorWithSiteClipperConnector = ContinueWithSiteClipperStatement.getSiteClippersConnectorNames(project);
                        if (connectorWithSiteClipperConnector.length > 0) {
                            ((ContinueWithSiteClipperStatement) newBean).setSiteClipperConnectorName(connectorWithSiteClipperConnector[0]);
                        }
                    }
                }
                if (newBean instanceof Connector) {
                    Project project = (Project) parentObject;
                    if (project.getDefaultConnector() == null)
                        project.setDefaultConnector((Connector) newBean);
                    Connector.setupConnector(newBean);
                }
                if (newBean instanceof PageComponent) {
                    ApplicationComponent application = (ApplicationComponent) parentObject;
                    if (application.getRootPage() == null)
                        application.setRootPage((PageComponent) newBean);
                }
                if (newBean instanceof SequenceStep) {
                    Project project = newBean.getProject();
                    ((SequenceStep) newBean).setSourceSequence(project.getName() + TransactionStep.SOURCE_SEPARATOR + project.getSequencesList().get(0));
                }
                if (newBean instanceof TransactionStep) {
                    Project project = newBean.getProject();
                    Connector connector = project.getDefaultConnector();
                    Transaction transaction = connector.getDefaultTransaction();
                    ((TransactionStep) newBean).setSourceTransaction(project.getName() + TransactionStep.SOURCE_SEPARATOR + connector.getName() + TransactionStep.SOURCE_SEPARATOR + transaction.getName());
                }
                if (newBean instanceof IThenElseContainer) {
                    ThenStep thenStep = new ThenStep();
                    ((IThenElseContainer) newBean).addStep(thenStep);
                    ElseStep elseStep = new ElseStep();
                    ((IThenElseContainer) newBean).addStep(elseStep);
                }
                if (newBean instanceof IThenElseStatementContainer) {
                    ThenStatement thenStatement = new ThenStatement();
                    ((IThenElseStatementContainer) newBean).addStatement(thenStatement);
                    ElseStatement elseStatement = new ElseStatement();
                    ((IThenElseStatementContainer) newBean).addStatement(elseStatement);
                }
                if (newBean instanceof Sheet) {
                    InputStream is = null;
                    try {
                        String sheetName = newBean.getName() + ".xsl";
                        is = new FileInputStream(new File(Engine.XSL_PATH + "/customsheet.xsl"));
                        String projectName = ((DatabaseObject) parentObject).getProject().getName();
                        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
                        final IFile file = project.getFile(sheetName);
                        if (!file.exists())
                            file.create(is, true, null);
                        ((Sheet) newBean).setUrl(sheetName);
                    } catch (Exception e) {
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }
                }
                if (newBean instanceof TestCase) {
                    TestCase testCase = (TestCase) newBean;
                    testCase.importRequestableVariables((RequestableObject) testCase.getParent());
                }
                if (newBean instanceof RequestableHttpVariable) {
                    RequestableHttpVariable variable = (RequestableHttpVariable) newBean;
                    AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) variable.getParent();
                    HttpMethodType httpMethodType = httpTransaction.getHttpVerb();
                    boolean isVarPost = httpMethodType.equals(HttpMethodType.PUT) || httpMethodType.equals(HttpMethodType.POST);
                    variable.setHttpMethod(isVarPost ? HttpMethodType.POST.name() : HttpMethodType.GET.name());
                    if (!(httpTransaction instanceof HtmlTransaction)) {
                        variable.setHttpName(variable.getName());
                    }
                }
                if (newBean instanceof WebServiceReference) {
                    try {
                        Project project = (Project) parentObject;
                        WebServiceReference webServiceReference = (WebServiceReference) newBean;
                        ImportWsReference wsr = new ImportWsReference(webServiceReference);
                        wsr.importInto(project);
                    } catch (Exception e) {
                        if (newBean != null) {
                            parentObject.remove(newBean);
                            parentObject.hasChanged = hasChanged;
                        }
                        throw new Exception(e);
                    }
                }
                if (newBean instanceof RestServiceReference) {
                    try {
                        Project project = (Project) parentObject;
                        RestServiceReference restServiceReference = (RestServiceReference) newBean;
                        ImportWsReference wsr = new ImportWsReference(restServiceReference);
                        wsr.importInto(project);
                    } catch (Exception e) {
                        if (newBean != null) {
                            parentObject.remove(newBean);
                            parentObject.hasChanged = hasChanged;
                        }
                        throw new Exception(e);
                    }
                }
                if (newBean instanceof SqlTransaction) {
                    SqlTransaction sqlTransaction = (SqlTransaction) newBean;
                    sqlTransaction.setSqlQuery(sqlQueriesWizardPage.getSQLQueries());
                    sqlTransaction.initializeQueries(true);
                }
                if (newBean instanceof SapJcoLogonTransaction) {
                    SapJcoLogonTransaction sapLogonTransaction = (SapJcoLogonTransaction) newBean;
                    sapLogonTransaction.addCredentialsVariables();
                }
                if (newBean instanceof AbstractCouchDbTransaction) {
                    AbstractCouchDbTransaction abstractCouchDbTransaction = (AbstractCouchDbTransaction) newBean;
                    List<CouchVariable> selectedVariables = objectInfoPage.getSelectedParameters();
                    abstractCouchDbTransaction.createVariables(selectedVariables);
                }
                ConvertigoPlugin.logInfo("New object class '" + this.className + "' named '" + newBean.getName() + "' has been added");
                monitor.setTaskName("Object setted up");
                monitor.worked(1);
                bContinue = false;
            } catch (com.twinsoft.convertigo.engine.ObjectWithSameNameException owsne) {
                if (newBean instanceof HandlerStatement) {
                    throw owsne;
                }
            }
        } else {
            throw new Exception("Could not instantiate bean!");
        }
    } catch (Exception e) {
        String message = "Unable to create a new object from class '" + this.className + "'.";
        ConvertigoPlugin.logException(e, message);
        if (objectExplorerPage != null) {
            objectExplorerPage.doCancel();
        }
    }
}
Also used : RestServiceReference(com.twinsoft.convertigo.beans.references.RestServiceReference) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) IThenElseContainer(com.twinsoft.convertigo.beans.steps.IThenElseContainer) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) HttpMethodType(com.twinsoft.convertigo.engine.enums.HttpMethodType) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) EngineException(com.twinsoft.convertigo.engine.EngineException) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) FileInputStream(java.io.FileInputStream) IProject(org.eclipse.core.resources.IProject) Project(com.twinsoft.convertigo.beans.core.Project) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) SapJcoLogonTransaction(com.twinsoft.convertigo.beans.transactions.SapJcoLogonTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CouchVariable(com.twinsoft.convertigo.beans.transactions.couchdb.CouchVariable) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) IFile(org.eclipse.core.resources.IFile) SapJcoLogonTransaction(com.twinsoft.convertigo.beans.transactions.SapJcoLogonTransaction) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) ImportWsReference(com.twinsoft.convertigo.engine.util.ImportWsReference) IThenElseStatementContainer(com.twinsoft.convertigo.beans.statements.IThenElseStatementContainer) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) IProject(org.eclipse.core.resources.IProject) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) TestCase(com.twinsoft.convertigo.beans.core.TestCase) WebServiceReference(com.twinsoft.convertigo.beans.references.WebServiceReference) Sheet(com.twinsoft.convertigo.beans.core.Sheet) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Example 3 with HandlerStatement

use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.

the class ProjectExplorerView method edit.

private void edit(TreeObject treeObject) {
    final Tree tree = viewer.getTree();
    final TreeEditor editor = new TreeEditor(tree);
    final Color black = getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK);
    TreeItem[] items = tree.getSelection();
    if (items.length > 0) {
        final TreeItem item = items[0];
        final TreeObject theTreeObject = treeObject;
        if (treeObject instanceof ProjectTreeObject) {
            if (((ProjectTreeObject) treeObject).getModified()) {
                // Project need to be saved to avoid xsd/wsdl modification errors - Fix ticket #2265
                ConvertigoPlugin.warningMessageBox("Please save project before renaming it.");
                return;
            }
        }
        if (treeObject.getObject() instanceof HandlerStatement) {
            return;
        }
        if ((item != null) && lastItem.length > 0 && (item == lastItem[0])) {
            boolean isCarbon = SWT.getPlatform().equals("carbon");
            final Composite composite = new Composite(tree, SWT.NONE);
            if (!isCarbon) {
                composite.setBackground(black);
            }
            final Text text = new Text(composite, SWT.NONE);
            final int inset = isCarbon ? 0 : 1;
            composite.addListener(SWT.Resize, new Listener() {

                public void handleEvent(Event e) {
                    Rectangle rect = composite.getClientArea();
                    text.setBounds(rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height - inset * 2);
                }
            });
            Listener textListener = new Listener() {

                public void handleEvent(final Event e) {
                    MobileBuilder mba = null;
                    MobileBuilder mbo = null;
                    IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
                    if (editorPart != null) {
                        IEditorInput input = editorPart.getEditorInput();
                        if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
                            com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                            mba = editorInput.getApplication().getProject().getMobileBuilder();
                        }
                        if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
                            com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                            mba = editorInput.getApplication().getProject().getMobileBuilder();
                        }
                    }
                    if (theTreeObject instanceof DatabaseObjectTreeObject) {
                        mbo = ((DatabaseObjectTreeObject) theTreeObject).getObject().getProject().getMobileBuilder();
                    }
                    String newName = null;
                    String oldName = null;
                    boolean needRefresh = false;
                    boolean needProjectReload = false;
                    if (theTreeObject instanceof DatabaseObjectTreeObject) {
                        oldName = ((DatabaseObject) ((DatabaseObjectTreeObject) theTreeObject).getObject()).getName();
                    } else if (theTreeObject instanceof TraceTreeObject) {
                        oldName = ((TraceTreeObject) theTreeObject).getName();
                    } else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
                        oldName = ((DesignDocumentViewTreeObject) theTreeObject).getName();
                    } else if (theTreeObject instanceof DesignDocumentFunctionTreeObject) {
                        oldName = ((DesignDocumentFunctionTreeObject) theTreeObject).getName();
                    }
                    switch(e.type) {
                        case SWT.FocusOut:
                            editingTextCtrl = null;
                            composite.dispose();
                            break;
                        case SWT.Verify:
                            String newText = text.getText();
                            String leftText = newText.substring(0, e.start);
                            String rightText = newText.substring(e.end, newText.length());
                            GC gc = new GC(text);
                            Point size = gc.textExtent(leftText + e.text + rightText);
                            gc.dispose();
                            size = text.computeSize(size.x, SWT.DEFAULT);
                            editor.horizontalAlignment = SWT.LEFT;
                            Rectangle itemRect = item.getBounds(), rect = tree.getClientArea();
                            editor.minimumWidth = Math.max(size.x, itemRect.width) + inset * 2;
                            int left = itemRect.x, right = rect.x + rect.width;
                            editor.minimumWidth = Math.min(editor.minimumWidth, right - left);
                            editor.minimumHeight = size.y + inset * 2;
                            editor.layout();
                            break;
                        case SWT.Traverse:
                            switch(e.detail) {
                                case SWT.TRAVERSE_RETURN:
                                    Engine.logStudio.info("---------------------- Rename started ----------------------");
                                    if (mba != null) {
                                        mba.prepareBatchBuild();
                                    }
                                    newName = text.getText();
                                    // Save and close editors
                                    if (theTreeObject instanceof IClosableTreeObject) {
                                        ((IClosableTreeObject) theTreeObject).closeAllEditors(true);
                                    }
                                    if (theTreeObject instanceof DatabaseObjectTreeObject) {
                                        DatabaseObjectTreeObject dbObjectTreeObject = (DatabaseObjectTreeObject) theTreeObject;
                                        if (dbObjectTreeObject.rename(newName, Boolean.TRUE)) {
                                            item.setText(newName);
                                            needRefresh = true;
                                            if (theTreeObject instanceof ProjectTreeObject) {
                                                needProjectReload = true;
                                            }
                                        }
                                    } else if (theTreeObject instanceof TraceTreeObject) {
                                        TraceTreeObject traceTreeObject = (TraceTreeObject) theTreeObject;
                                        traceTreeObject.rename(newName);
                                        if (traceTreeObject.hasChanged) {
                                            item.setText(newName);
                                            traceTreeObject.hasChanged = false;
                                            needRefresh = true;
                                        }
                                    } else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
                                        DesignDocumentViewTreeObject ddvto = (DesignDocumentViewTreeObject) theTreeObject;
                                        if (ddvto.rename(newName, Boolean.TRUE)) {
                                            item.setText(newName);
                                            needRefresh = true;
                                        }
                                    } else if (theTreeObject instanceof DesignDocumentFunctionTreeObject) {
                                        DesignDocumentFunctionTreeObject ddfto = (DesignDocumentFunctionTreeObject) theTreeObject;
                                        if (ddfto.rename(newName, Boolean.TRUE)) {
                                            item.setText(newName);
                                            needRefresh = true;
                                        }
                                    }
                                // FALL THROUGH
                                case SWT.TRAVERSE_ESCAPE:
                                    editingTextCtrl = null;
                                    composite.dispose();
                                    e.doit = false;
                            }
                            break;
                    }
                    if (needRefresh) {
                        boolean updateDlg = false;
                        boolean updateReferences = false;
                        int update = 0;
                        // Updates references to object if needed
                        if ((theTreeObject instanceof ProjectTreeObject) || (theTreeObject instanceof SequenceTreeObject) || (theTreeObject instanceof ConnectorTreeObject) || (theTreeObject instanceof TransactionTreeObject) || (theTreeObject instanceof VariableTreeObject2) || (theTreeObject instanceof IDesignTreeObject) || (theTreeObject instanceof MobilePageComponentTreeObject) || (theTreeObject instanceof MobileUIComponentTreeObject) || (theTreeObject instanceof NgxPageComponentTreeObject) || (theTreeObject instanceof NgxUIComponentTreeObject)) {
                            String objectType = "";
                            if (theTreeObject instanceof ProjectTreeObject) {
                                objectType = "project";
                                updateDlg = true;
                            } else if (theTreeObject instanceof SequenceTreeObject) {
                                objectType = "sequence";
                                updateDlg = true;
                            } else if (theTreeObject instanceof ConnectorTreeObject) {
                                objectType = "connector";
                                updateDlg = true;
                            } else if (theTreeObject instanceof TransactionTreeObject) {
                                objectType = "transaction";
                                updateDlg = true;
                            } else if (theTreeObject instanceof VariableTreeObject2) {
                                objectType = "variable";
                                updateDlg = ((DatabaseObject) theTreeObject.getObject()) instanceof RequestableVariable ? true : false;
                            } else if (theTreeObject instanceof DesignDocumentTreeObject) {
                                objectType = "document";
                                updateDlg = true;
                            } else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
                                objectType = "view";
                                updateDlg = true;
                            } else if (theTreeObject instanceof DesignDocumentFilterTreeObject) {
                                objectType = "filter";
                                updateDlg = true;
                            } else if (theTreeObject instanceof DesignDocumentUpdateTreeObject) {
                                objectType = "update";
                                updateDlg = true;
                            } else if (theTreeObject instanceof DesignDocumentValidateTreeObject) {
                                objectType = "validate";
                                updateDlg = true;
                            } else if (theTreeObject instanceof MobilePageComponentTreeObject) {
                                objectType = "page";
                                updateDlg = true;
                            } else if (theTreeObject instanceof NgxPageComponentTreeObject) {
                                objectType = "page";
                                updateDlg = true;
                            } else if (theTreeObject instanceof MobileUIComponentTreeObject) {
                                DatabaseObject dbo = (DatabaseObject) theTreeObject.getObject();
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) {
                                    objectType = "menu";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UIActionStack) {
                                    objectType = "shared action";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) {
                                    objectType = "shared component";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UIStackVariable) {
                                    objectType = "variable";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UICompVariable) {
                                    objectType = "variable";
                                    updateDlg = true;
                                }
                            } else if (theTreeObject instanceof NgxUIComponentTreeObject) {
                                DatabaseObject dbo = (DatabaseObject) theTreeObject.getObject();
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu) {
                                    objectType = "menu";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UIActionStack) {
                                    objectType = "shared action";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) {
                                    objectType = "shared component";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UIStackVariable) {
                                    objectType = "variable";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UICompVariable) {
                                    objectType = "variable";
                                    updateDlg = true;
                                }
                            }
                            if (updateDlg) {
                                Shell shell = Display.getDefault().getActiveShell();
                                CustomDialog customDialog = new CustomDialog(shell, "Update object references", "Do you want to update " + objectType + " references ?\n You can replace '" + oldName + "' by '" + newName + "' in all loaded projects \n or replace '" + oldName + "' by '" + newName + "' in current project only.", 670, 200, new ButtonSpec("Replace in all loaded projects", true), new ButtonSpec("Replace in current project", false), new ButtonSpec("Do not replace anywhere", false));
                                int response = customDialog.open();
                                if (response == 0) {
                                    updateReferences = true;
                                    update = TreeObjectEvent.UPDATE_ALL;
                                }
                                if (response == 1) {
                                    updateReferences = true;
                                    update = TreeObjectEvent.UPDATE_LOCAL;
                                }
                            }
                        }
                        TreeObjectEvent treeObjectEvent = null;
                        if (updateReferences) {
                            treeObjectEvent = new TreeObjectEvent(theTreeObject, "name", oldName, newName, update);
                        } else {
                            treeObjectEvent = new TreeObjectEvent(theTreeObject, "name", oldName, newName);
                        }
                        BatchOperationHelper.start();
                        ProjectExplorerView.this.refreshTree();
                        ProjectExplorerView.this.setSelectedTreeObject(theTreeObject);
                        ProjectExplorerView.this.fireTreeObjectPropertyChanged(treeObjectEvent);
                        if (updateReferences && needProjectReload) {
                            ((ProjectTreeObject) theTreeObject).save(false);
                        }
                        if (mbo != null) {
                            if (theTreeObject instanceof MobilePageComponentTreeObject) {
                                try {
                                    mbo.pageRenamed((com.twinsoft.convertigo.beans.mobile.components.PageComponent) theTreeObject.getObject(), oldName);
                                } catch (EngineException e1) {
                                    e1.printStackTrace();
                                }
                            }
                            if (theTreeObject instanceof NgxPageComponentTreeObject) {
                                try {
                                    mbo.pageRenamed((com.twinsoft.convertigo.beans.ngx.components.PageComponent) theTreeObject.getObject(), oldName);
                                } catch (EngineException e1) {
                                    e1.printStackTrace();
                                }
                            }
                        }
                        BatchOperationHelper.stop();
                        Engine.logStudio.info("---------------------- Rename ended   ----------------------");
                        StructuredSelection structuredSelection = new StructuredSelection(theTreeObject);
                        ISelectionListener listener = null;
                        // refresh properties view
                        listener = ConvertigoPlugin.getDefault().getPropertiesView();
                        if (listener != null)
                            listener.selectionChanged((IWorkbenchPart) ProjectExplorerView.this, structuredSelection);
                        // refresh references view
                        listener = ConvertigoPlugin.getDefault().getReferencesView();
                        if (listener != null)
                            listener.selectionChanged((IWorkbenchPart) ProjectExplorerView.this, structuredSelection);
                    }
                    if (needProjectReload) {
                        Engine.theApp.databaseObjectsManager.clearCache(newName);
                        reloadProject(theTreeObject);
                        refreshTree();
                    }
                }
            };
            text.addListener(SWT.FocusOut, textListener);
            text.addListener(SWT.Traverse, textListener);
            text.addListener(SWT.Verify, textListener);
            editor.setEditor(composite, item);
            if (theTreeObject instanceof DatabaseObjectTreeObject) {
                text.setText(((DatabaseObjectTreeObject) theTreeObject).getName());
            } else if (theTreeObject instanceof TraceTreeObject) {
                text.setText(((TraceTreeObject) theTreeObject).getName());
            } else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
                text.setText(((DesignDocumentViewTreeObject) theTreeObject).getName());
            } else if (theTreeObject instanceof DesignDocumentFunctionTreeObject) {
                text.setText(((DesignDocumentFunctionTreeObject) theTreeObject).getName());
            }
            text.selectAll();
            text.setFocus();
            editingTextCtrl = text;
        }
        lastItem[0] = item;
    }
}
Also used : NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) TreeItem(org.eclipse.swt.widgets.TreeItem) DesignDocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject) Rectangle(org.eclipse.swt.graphics.Rectangle) EngineException(com.twinsoft.convertigo.engine.EngineException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ISelectionListener(org.eclipse.ui.ISelectionListener) CustomDialog(com.twinsoft.convertigo.eclipse.dialogs.CustomDialog) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Tree(org.eclipse.swt.widgets.Tree) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ButtonSpec(com.twinsoft.convertigo.eclipse.dialogs.ButtonSpec) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) Color(org.eclipse.swt.graphics.Color) IClosableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IClosableTreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) MobilePageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePageComponentTreeObject) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) UrlMappingParameterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingParameterTreeObject) MobileApplicationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileApplicationTreeObject) IClosableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IClosableTreeObject) XMLRecordDescriptionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.XMLRecordDescriptionTreeObject) DesignDocumentValidateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentValidateTreeObject) UrlMappingTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingTreeObject) DesignDocumentUpdateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentUpdateTreeObject) DesignDocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject) MobileApplicationComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileApplicationComponentTreeObject) UrlMappingOperationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingOperationTreeObject) ReferenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject) HandlersDeclarationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.HandlersDeclarationTreeObject) UrlMappingResponseTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingResponseTreeObject) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) CriteriaTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.CriteriaTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) UrlAuthenticationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlAuthenticationTreeObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) MobileRouteActionComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileRouteActionComponentTreeObject) ListenerTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ListenerTreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) FullSyncListenerTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FullSyncListenerTreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) NgxApplicationComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxApplicationComponentTreeObject) MobileRouteEventComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileRouteEventComponentTreeObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) IEditableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IEditableTreeObject) XMLTableDescriptionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.XMLTableDescriptionTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) DesignDocumentViewTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentViewTreeObject) TemplateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TemplateTreeObject) TestCaseTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TestCaseTreeObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) PropertyTableColumnTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableColumnTreeObject) DesignDocumentFilterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFilterTreeObject) VariableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject) DesignDocumentFunctionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFunctionTreeObject) MobilePlatformTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePlatformTreeObject) ExtractionRuleTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ExtractionRuleTreeObject) MobileRouteComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileRouteComponentTreeObject) SheetTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SheetTreeObject) UrlMapperTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMapperTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) MobilePageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePageComponentTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TraceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TraceTreeObject) DocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DocumentTreeObject) DesignDocumentFilterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFilterTreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) MigrationListener(com.twinsoft.convertigo.engine.MigrationListener) TreeDragListener(com.twinsoft.convertigo.eclipse.dnd.TreeDragListener) ISelectionListener(org.eclipse.ui.ISelectionListener) CompositeListener(com.twinsoft.convertigo.eclipse.editors.CompositeListener) DatabaseObjectListener(com.twinsoft.convertigo.engine.DatabaseObjectListener) Listener(org.eclipse.swt.widgets.Listener) EngineListener(com.twinsoft.convertigo.engine.EngineListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) DesignDocumentViewTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentViewTreeObject) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) Shell(org.eclipse.swt.widgets.Shell) GC(org.eclipse.swt.graphics.GC) VariableTreeObject2(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject2) DesignDocumentValidateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentValidateTreeObject) TreeEditor(org.eclipse.swt.custom.TreeEditor) Composite(org.eclipse.swt.widgets.Composite) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) Text(org.eclipse.swt.widgets.Text) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) DesignDocumentFunctionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFunctionTreeObject) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) DatabaseObjectImportedEvent(com.twinsoft.convertigo.engine.DatabaseObjectImportedEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) DatabaseObjectLoadedEvent(com.twinsoft.convertigo.engine.DatabaseObjectLoadedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Event(org.eclipse.swt.widgets.Event) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) TraceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TraceTreeObject) IEditorInput(org.eclipse.ui.IEditorInput) DesignDocumentUpdateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentUpdateTreeObject)

Example 4 with HandlerStatement

use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.

the class ChangeToScEntryHandlerStatementAction 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) {
            DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
            DatabaseObject databaseObject = treeObject.getObject();
            // For ScExitHandler statement
            if ((databaseObject != null) && (databaseObject instanceof ScExitHandlerStatement || databaseObject instanceof ScExitDefaultHandlerStatement)) {
                HandlerStatement scExitHandlerStatement = (HandlerStatement) databaseObject;
                DatabaseObjectTreeObject parentTreeObject = treeObject.getOwnerDatabaseObjectTreeObject();
                if (parentTreeObject != null) {
                    // New ScEntryHandler statement
                    HandlerStatement scEntryHandlerStatement = databaseObject instanceof ScExitHandlerStatement ? new ScEntryHandlerStatement() : new ScEntryDefaultHandlerStatement();
                    // Set properties
                    String handlerResult = scExitHandlerStatement.getHandlerResult();
                    if (ScHandlerStatement.RETURN_ACCUMULATE.equals(handlerResult)) {
                        handlerResult = ScHandlerStatement.RETURN_REDETECT;
                    }
                    scEntryHandlerStatement.setHandlerResult(handlerResult);
                    scEntryHandlerStatement.setComment(scExitHandlerStatement.getComment());
                    scEntryHandlerStatement.setEnabled(scExitHandlerStatement.isEnabled());
                    scEntryHandlerStatement.setPreventFromLoops(scExitHandlerStatement.preventFromLoops());
                    scEntryHandlerStatement.setParent(scExitHandlerStatement.getParent());
                    scEntryHandlerStatement.setReturnedValue(scExitHandlerStatement.getReturnedValue());
                    scEntryHandlerStatement.setVersion(scExitHandlerStatement.getVersion());
                    if (databaseObject instanceof ScExitHandlerStatement) {
                        ScExitHandlerStatement scExit = (ScExitHandlerStatement) scExitHandlerStatement;
                        ScEntryHandlerStatement scEntry = (ScEntryHandlerStatement) scEntryHandlerStatement;
                        scEntry.setNormalizedScreenClassName(scExit.getNormalizedScreenClassName());
                        scEntry.setName("on" + scExit.getNormalizedScreenClassName() + "Entry");
                    }
                    // Change status of ScEntryHandler statement
                    scEntryHandlerStatement.bNew = true;
                    scEntryHandlerStatement.hasChanged = true;
                    // Add new ScEntryHandler statement to parent
                    DatabaseObject parentDbo = scEntryHandlerStatement.getParent();
                    parentDbo.add(scEntryHandlerStatement);
                    for (Statement statement : scExitHandlerStatement.getStatements()) {
                        scEntryHandlerStatement.addStatement(statement);
                    }
                    // Delete ScExitHandler statement
                    scExitHandlerStatement.delete();
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    DatabaseObjectTreeObject newTreeObject = parentTreeObject.findDatabaseObjectTreeObjectChild(scEntryHandlerStatement);
                    explorerView.setSelectedTreeObject(newTreeObject);
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change screen class exit handler statement to screen class entry handler statement!");
    } 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) ScExitDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitDefaultHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) ScExitDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitDefaultHandlerStatement) ScEntryDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryDefaultHandlerStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) ScExitDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitDefaultHandlerStatement) ScEntryDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryDefaultHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) Cursor(org.eclipse.swt.graphics.Cursor) ScEntryDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryDefaultHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) Shell(org.eclipse.swt.widgets.Shell) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Display(org.eclipse.swt.widgets.Display)

Example 5 with HandlerStatement

use of com.twinsoft.convertigo.beans.statements.HandlerStatement in project convertigo by convertigo.

the class ChangeToScExitHandlerStatementAction 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) {
            DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
            DatabaseObject databaseObject = treeObject.getObject();
            // For ScEntryHandler statement
            if ((databaseObject != null) && (databaseObject instanceof ScEntryHandlerStatement || databaseObject instanceof ScEntryDefaultHandlerStatement)) {
                HandlerStatement scEntryHandlerStatement = (HandlerStatement) databaseObject;
                DatabaseObjectTreeObject parentTreeObject = treeObject.getOwnerDatabaseObjectTreeObject();
                if (parentTreeObject != null) {
                    // New ScExitHandler statement
                    HandlerStatement scExitHandlerStatement = databaseObject instanceof ScEntryHandlerStatement ? new ScExitHandlerStatement() : new ScExitDefaultHandlerStatement();
                    // Set properties
                    String handlerResult = scEntryHandlerStatement.getHandlerResult();
                    if (ScHandlerStatement.RETURN_REDETECT.equals(handlerResult)) {
                        handlerResult = ScHandlerStatement.RETURN_ACCUMULATE;
                    } else if (ScHandlerStatement.RETURN_SKIP.equals(handlerResult)) {
                        handlerResult = "";
                    }
                    scExitHandlerStatement.setHandlerResult(handlerResult);
                    scExitHandlerStatement.setComment(scEntryHandlerStatement.getComment());
                    scExitHandlerStatement.setEnabled(scEntryHandlerStatement.isEnabled());
                    scExitHandlerStatement.setPreventFromLoops(scEntryHandlerStatement.preventFromLoops());
                    scExitHandlerStatement.setParent(scEntryHandlerStatement.getParent());
                    scExitHandlerStatement.setReturnedValue(scEntryHandlerStatement.getReturnedValue());
                    scExitHandlerStatement.setVersion(scEntryHandlerStatement.getVersion());
                    if (databaseObject instanceof ScEntryHandlerStatement) {
                        ScExitHandlerStatement scExit = (ScExitHandlerStatement) scExitHandlerStatement;
                        ScEntryHandlerStatement scEntry = (ScEntryHandlerStatement) scEntryHandlerStatement;
                        scExit.setNormalizedScreenClassName(scEntry.getNormalizedScreenClassName());
                        scExit.setName("on" + scEntry.getNormalizedScreenClassName() + "Exit");
                    }
                    // Change status of scExitHanlder statement
                    scExitHandlerStatement.bNew = true;
                    scExitHandlerStatement.hasChanged = true;
                    // Add new ScExitHandler statement to parent
                    DatabaseObject parentDbo = scEntryHandlerStatement.getParent();
                    parentDbo.add(scExitHandlerStatement);
                    // Add new ScExitHandler statement in Tree
                    StatementTreeObject statementTreeObject = new StatementTreeObject(explorerView.viewer, scExitHandlerStatement);
                    parentTreeObject.addChild(statementTreeObject);
                    for (Statement statement : scEntryHandlerStatement.getStatements()) {
                        scExitHandlerStatement.addStatement(statement);
                    }
                    // Delete ScEntryHandler statement
                    scEntryHandlerStatement.delete();
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    DatabaseObjectTreeObject newTreeObject = parentTreeObject.findDatabaseObjectTreeObjectChild(scExitHandlerStatement);
                    explorerView.setSelectedTreeObject(newTreeObject);
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change screen class entry handler statement to screen class exit handler statement!");
    } 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) ScExitDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitDefaultHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) ScExitDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitDefaultHandlerStatement) ScEntryDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryDefaultHandlerStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) ScExitDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitDefaultHandlerStatement) ScEntryDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryDefaultHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) Cursor(org.eclipse.swt.graphics.Cursor) ScEntryDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryDefaultHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) Shell(org.eclipse.swt.widgets.Shell) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Display(org.eclipse.swt.widgets.Display)

Aggregations

HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)15 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)12 EngineException (com.twinsoft.convertigo.engine.EngineException)8 ScEntryHandlerStatement (com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement)5 ScExitHandlerStatement (com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement)5 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)5 Statement (com.twinsoft.convertigo.beans.core.Statement)4 ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 CoreException (org.eclipse.core.runtime.CoreException)4 Shell (org.eclipse.swt.widgets.Shell)4 Connector (com.twinsoft.convertigo.beans.core.Connector)3 Sheet (com.twinsoft.convertigo.beans.core.Sheet)3 Transaction (com.twinsoft.convertigo.beans.core.Transaction)3 ScEntryDefaultHandlerStatement (com.twinsoft.convertigo.beans.statements.ScEntryDefaultHandlerStatement)3 ScExitDefaultHandlerStatement (com.twinsoft.convertigo.beans.statements.ScExitDefaultHandlerStatement)3 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)3 WalkHelper (com.twinsoft.convertigo.engine.helpers.WalkHelper)3 Display (org.eclipse.swt.widgets.Display)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3