Search in sources :

Example 1 with ScHandlerStatement

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

the class ReferencesView method handleTransactionSelection.

private void handleTransactionSelection(Object firstElement) {
    TransactionTreeObject transactionTreeObject = (TransactionTreeObject) firstElement;
    Transaction transaction = transactionTreeObject.getObject();
    String transactionName = transactionTreeObject.getName();
    // Get the referencing sequence steps
    String transactionProjectName = transaction.getProject().getName();
    String transactionConnectorName = transaction.getParent().getName();
    try {
        Project project = null;
        List<String> projectNames = Engine.theApp.databaseObjectsManager.getAllProjectNamesList();
        ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
        treeViewer.setInput(null);
        RootNode root = new RootNode();
        TransactionNode transactionFolder = new TransactionNode(root, transactionName, transaction);
        root.addChild(transactionFolder);
        IsUsedByNode isUsedByNode = new IsUsedByNode(transactionFolder, "Is used by");
        RequiresNode requiresNode = new RequiresNode(transactionFolder, "Requires");
        ProjectNode projectFolder = null;
        // Searching all objects are required transaction selected
        Connector connector = transaction.getConnector();
        if (connector instanceof HtmlConnector) {
            Project proj = ((HtmlConnector) connector).getProject();
            ProjectNode projectNode = new ProjectNode(requiresNode, transactionProjectName, proj);
            HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
            List<Statement> statements = htmlTransaction.getStatements();
            List<ScreenClass> screenClassList = new ArrayList<ScreenClass>();
            List<String> siteClipperConnectorNames = new ArrayList<String>();
            for (Statement statement : statements) {
                if (statement instanceof ScHandlerStatement) {
                    ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
                    String screenClassName = scHandlerStatement.getNormalizedScreenClassName();
                    ScreenClass screenClass = ((HtmlConnector) connector).getScreenClassByName(screenClassName);
                    if (screenClass != null) {
                        if (!screenClassList.contains(screenClass)) {
                            screenClassList.add(screenClass);
                            requiresNode.addChild(new ScreenClassNode(requiresNode, screenClassName, screenClass));
                        }
                    }
                }
                List<Statement> statementList = ((FunctionStatement) statement).getStatements();
                for (Statement st : statementList) {
                    if (st instanceof ContinueWithSiteClipperStatement) {
                        ContinueWithSiteClipperStatement continueWithSiteClipperStatement = (ContinueWithSiteClipperStatement) st;
                        String siteClipperconnectorName = continueWithSiteClipperStatement.getSiteClipperConnectorName();
                        if (!siteClipperConnectorNames.contains(siteClipperconnectorName)) {
                            siteClipperConnectorNames.add(siteClipperconnectorName);
                            Connector siteClipperConnector = proj.getConnectorByName(siteClipperconnectorName);
                            ConnectorNode connectorSiteClipperNode = new SiteClipperConnectorNode(projectNode, siteClipperconnectorName, siteClipperConnector);
                            projectNode.addChild(connectorSiteClipperNode);
                        }
                    }
                }
            }
            if (projectNode.hasChildren()) {
                requiresNode.addChild(projectNode);
            }
        } else if (connector instanceof JavelinConnector) {
            JavelinTransaction javelinTransaction = (JavelinTransaction) transaction;
            String handlers = javelinTransaction.handlers;
            List<JavelinScreenClass> screenClasses = ((JavelinConnector) connector).getAllScreenClasses();
            List<JavelinScreenClass> screenClassList = new ArrayList<JavelinScreenClass>();
            for (JavelinScreenClass screenClass : screenClasses) {
                if (handlers.indexOf("function on" + screenClass.getName()) != -1) {
                    if (!screenClassList.contains(screenClass)) {
                        screenClassList.add(screenClass);
                        requiresNode.addChild(new ScreenClassNode(requiresNode, screenClass.getName(), screenClass));
                    }
                }
            }
        }
        // Searching all objects are used transaction selected
        for (String projectName : projectNames) {
            project = getProject(projectName, projectExplorerView);
            if (project != null) {
                projectFolder = new ProjectNode(isUsedByNode, project.getName(), project);
                UrlMapper urlMapper = project.getUrlMapper();
                if (urlMapper != null) {
                    MapperNode mapperNode = new MapperNode(projectFolder, urlMapper.getName(), urlMapper);
                    List<UrlMapping> mappings = urlMapper.getMappingList();
                    for (UrlMapping mapping : mappings) {
                        MappingPathNode pathNode = new MappingPathNode(mapperNode, mapping.getPath(), mapping);
                        List<UrlMappingOperation> operations = mapping.getOperationList();
                        for (UrlMappingOperation operation : operations) {
                            String targetRequestable = operation.getTargetRequestable();
                            if (targetRequestable.equals(transactionProjectName + "." + transactionConnectorName + "." + transactionName)) {
                                MappingOperationNode operationNode = new MappingOperationNode(pathNode, operation.getName(), operation);
                                pathNode.addChild(operationNode);
                            }
                        }
                        if (pathNode.hasChildren()) {
                            mapperNode.addChild(pathNode);
                        }
                    }
                    if (mapperNode.hasChildren()) {
                        projectFolder.addChild(mapperNode);
                    }
                }
                List<Sequence> sequences = project.getSequencesList();
                for (Sequence sequence : sequences) {
                    List<Step> stepList = sequence.getAllSteps();
                    SequenceNode sequenceNode = new SequenceNode(projectFolder, sequence.getName(), sequence);
                    for (Step step : stepList) {
                        getTransactionReferencing(step, projectExplorerView, sequenceNode, transactionProjectName, transactionConnectorName, transactionName);
                    }
                    if (sequenceNode.hasChildren()) {
                        projectFolder.addChild(sequenceNode);
                    }
                }
                if (projectFolder.hasChildren()) {
                    isUsedByNode.addChild(projectFolder);
                }
            }
        }
        if (requiresNode.hasChildren()) {
            transactionFolder.addChild(requiresNode);
        }
        if (isUsedByNode.hasChildren()) {
            transactionFolder.addChild(isUsedByNode);
        }
        if (!transactionFolder.hasChildren()) {
            transactionFolder.addChild(new InformationNode(projectFolder, "This transaction is not used in any sequence"));
        }
        treeViewer.setInput(root);
        treeViewer.expandAll();
    } catch (EngineException e) {
        ConvertigoPlugin.logException(e, "Error while analyzing the projects hierarchy", true);
    }
}
Also used : UrlMapping(com.twinsoft.convertigo.beans.core.UrlMapping) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) RootNode(com.twinsoft.convertigo.eclipse.views.references.model.RootNode) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) ProxyHttpConnector(com.twinsoft.convertigo.beans.connectors.ProxyHttpConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) MapperNode(com.twinsoft.convertigo.eclipse.views.references.model.MapperNode) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) ArrayList(java.util.ArrayList) EngineException(com.twinsoft.convertigo.engine.EngineException) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) BranchStep(com.twinsoft.convertigo.beans.steps.BranchStep) XMLComplexStep(com.twinsoft.convertigo.beans.steps.XMLComplexStep) BlockStep(com.twinsoft.convertigo.beans.steps.BlockStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) ScreenClassNode(com.twinsoft.convertigo.eclipse.views.references.model.ScreenClassNode) InformationNode(com.twinsoft.convertigo.eclipse.views.references.model.InformationNode) List(java.util.List) ArrayList(java.util.ArrayList) SiteClipperConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.SiteClipperConnectorNode) UrlMapper(com.twinsoft.convertigo.beans.core.UrlMapper) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) MappingOperationNode(com.twinsoft.convertigo.eclipse.views.references.model.MappingOperationNode) Sequence(com.twinsoft.convertigo.beans.core.Sequence) ConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.ConnectorNode) SiteClipperConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.SiteClipperConnectorNode) HtmlConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.HtmlConnectorNode) JavelinConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.JavelinConnectorNode) CicsConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.CicsConnectorNode) SqlConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.SqlConnectorNode) ProxyHttpConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.ProxyHttpConnectorNode) HttpConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.HttpConnectorNode) SequenceNode(com.twinsoft.convertigo.eclipse.views.references.model.SequenceNode) Project(com.twinsoft.convertigo.beans.core.Project) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) MappingPathNode(com.twinsoft.convertigo.eclipse.views.references.model.MappingPathNode) TransactionNode(com.twinsoft.convertigo.eclipse.views.references.model.TransactionNode) IsUsedByNode(com.twinsoft.convertigo.eclipse.views.references.model.IsUsedByNode) RequiresNode(com.twinsoft.convertigo.eclipse.views.references.model.RequiresNode) ProjectNode(com.twinsoft.convertigo.eclipse.views.references.model.ProjectNode) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement)

Example 2 with ScHandlerStatement

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

the class ReferencesView method handleScreenClassSelection.

private void handleScreenClassSelection(Object firstElement) {
    ScreenClassTreeObject screenClassTreeObject = (ScreenClassTreeObject) firstElement;
    ScreenClass screenClass = screenClassTreeObject.getObject();
    String screenClassName = screenClassTreeObject.getName();
    // Get the referencing transactions
    Connector connector = screenClass.getConnector();
    List<Transaction> transactions = connector.getTransactionsList();
    RootNode root = new RootNode();
    ScreenClassNode screenClassFolder = new ScreenClassNode(root, screenClassName, screenClass);
    root.addChild(screenClassFolder);
    IsUsedByNode isUsedByNode = new IsUsedByNode(screenClassFolder, "Is used by");
    EntryHandlerNode entryFolder = new EntryHandlerNode(isUsedByNode, "Transaction entry handlers", null);
    ExitHandlerNode exitFolder = new ExitHandlerNode(isUsedByNode, "Transaction exit handlers", null);
    if (connector instanceof HtmlConnector) {
        for (Transaction transaction : transactions) {
            HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
            List<Statement> statements = htmlTransaction.getStatements();
            for (Statement statement : statements) {
                if (statement instanceof ScHandlerStatement) {
                    ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
                    if (scHandlerStatement.getNormalizedScreenClassName().equals(screenClassName)) {
                        if (scHandlerStatement.getName().endsWith("Entry")) {
                            entryFolder.addChild(new TransactionNode(entryFolder, transaction.getName(), scHandlerStatement));
                        } else {
                            exitFolder.addChild(new TransactionNode(exitFolder, transaction.getName(), scHandlerStatement));
                        }
                    }
                }
            }
        }
    } else if (connector instanceof JavelinConnector) {
        for (Transaction transaction : transactions) {
            JavelinTransaction javelinTransaction = (JavelinTransaction) transaction;
            if (javelinTransaction.handlers.indexOf("function on" + screenClassName + "Entry()") != -1) {
                entryFolder.addChild(new TransactionNode(entryFolder, transaction.getName(), transaction));
            }
            if (javelinTransaction.handlers.indexOf("function on" + screenClassName + "Exit()") != -1) {
                exitFolder.addChild(new TransactionNode(exitFolder, transaction.getName(), transaction));
            }
        }
    }
    if (entryFolder.hasChildren()) {
        isUsedByNode.addChild(entryFolder);
    }
    if (exitFolder.hasChildren()) {
        isUsedByNode.addChild(exitFolder);
    }
    if (!isUsedByNode.hasChildren()) {
        screenClassFolder.addChild(new InformationNode(screenClassFolder, "This screen class is not used in any transaction"));
    } else {
        screenClassFolder.addChild(isUsedByNode);
    }
    // Build the treeviewer model
    treeViewer.setInput(null);
    treeViewer.setInput(root);
    treeViewer.expandAll();
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) ProxyHttpConnector(com.twinsoft.convertigo.beans.connectors.ProxyHttpConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) RootNode(com.twinsoft.convertigo.eclipse.views.references.model.RootNode) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EntryHandlerNode(com.twinsoft.convertigo.eclipse.views.references.model.EntryHandlerNode) ExitHandlerNode(com.twinsoft.convertigo.eclipse.views.references.model.ExitHandlerNode) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) ScreenClassNode(com.twinsoft.convertigo.eclipse.views.references.model.ScreenClassNode) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) IsUsedByNode(com.twinsoft.convertigo.eclipse.views.references.model.IsUsedByNode) TransactionNode(com.twinsoft.convertigo.eclipse.views.references.model.TransactionNode) InformationNode(com.twinsoft.convertigo.eclipse.views.references.model.InformationNode) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement)

Example 3 with ScHandlerStatement

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

the class StatementTreeObject method treeObjectRemoved.

@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
    super.treeObjectRemoved(treeObjectEvent);
    // Avoid the cast between "UnloadedProjectTreeObject" and "DatabaseObjectTreeObject
    if (!(treeObjectEvent.getSource() instanceof UnloadedProjectTreeObject)) {
        DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
        DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
        Statement statement = getObject();
        boolean change = false;
        // Case this is a screen class
        if (databaseObject instanceof ScreenClass) {
            ScreenClassTreeObject sto = (ScreenClassTreeObject) treeObjectEvent.getSource();
            String screenClassName = StringUtils.normalize(databaseObject.getName());
            // ScreenClass and Statement must have the same connector!
            if (statement.getConnector().equals(sto.getConnectorTreeObject().getObject())) {
                if (statement instanceof ITriggerOwner) {
                    ITriggerOwner ito = (ITriggerOwner) statement;
                    AbstractTrigger atrigger = ito.getTrigger().getTrigger();
                    if (atrigger instanceof ScreenClassTrigger) {
                        ScreenClassTrigger sct = (ScreenClassTrigger) atrigger;
                        List<String> screenClasses = sct.getScreenClasses();
                        for (int i = 0; i < screenClasses.size(); i++) {
                            if (screenClasses.get(i).equals(screenClassName)) {
                                screenClasses.remove(i);
                                change = true;
                            }
                        }
                        // Add default root screen class if all have been removed
                        if (screenClasses.isEmpty()) {
                            IScreenClassContainer<?> iscc = (IScreenClassContainer<?>) sto.getConnectorTreeObject().getObject();
                            String defaultScreenClassName = StringUtils.normalize(iscc.getDefaultScreenClass().getName());
                            screenClasses.add(defaultScreenClassName);
                            change = true;
                        }
                        if (change)
                            ito.setTrigger(new TriggerXMLizer(sct));
                    }
                }
            }
        }
        if (change)
            try {
                hasBeenModified(true);
                ConvertigoPlugin.getDefault().getProjectExplorerView().refreshTreeObject(this);
            } catch (Exception e) {
                ConvertigoPlugin.logWarning(e, "Could not refresh in tree ScHandlerStatement \"" + statement.getName() + "\" !");
            }
    }
}
Also used : TriggerXMLizer(com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer) ScreenClassTrigger(com.twinsoft.convertigo.engine.parsers.triggers.ScreenClassTrigger) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) SimpleStatement(com.twinsoft.convertigo.beans.statements.SimpleStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) IScreenClassContainer(com.twinsoft.convertigo.beans.core.IScreenClassContainer) ITriggerOwner(com.twinsoft.convertigo.engine.parsers.triggers.ITriggerOwner) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractTrigger(com.twinsoft.convertigo.engine.parsers.triggers.AbstractTrigger) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 4 with ScHandlerStatement

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

the class StatementTreeObject method handlesBeanNameChanged.

protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
    DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
    DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    Statement statement = getObject();
    boolean change = false;
    if (databaseObject instanceof ScreenClass) {
        String oldScreenClassName = StringUtils.normalize((String) oldValue);
        String newScreenClassName = StringUtils.normalize((String) newValue);
        // ScreenClass and Statement must have the same connector!
        if (statement.getConnector().equals(databaseObject.getConnector())) {
            // Modify screenclass handlers name
            if (statement instanceof ScHandlerStatement) {
                ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
                if (scHandlerStatement.getNormalizedScreenClassName().equals(oldScreenClassName)) {
                    String handlerType = scHandlerStatement.getHandlerType();
                    String beanName = "on" + newScreenClassName + handlerType;
                    try {
                        scHandlerStatement.setName(beanName);
                        scHandlerStatement.setNormalizedScreenClassName(newScreenClassName);
                        change = true;
                    } catch (EngineException e) {
                        ConvertigoPlugin.logWarning(e, "Could not rename ScHandlerStatement from \"" + scHandlerStatement.getName() + "\" to \"" + beanName + "\" !");
                    }
                }
            }
            if (statement instanceof ITriggerOwner) {
                ITriggerOwner ito = (ITriggerOwner) statement;
                AbstractTrigger atrigger = ito.getTrigger().getTrigger();
                if (atrigger instanceof ScreenClassTrigger) {
                    ScreenClassTrigger sct = (ScreenClassTrigger) atrigger;
                    List<String> screenClasses = sct.getScreenClasses();
                    for (int i = 0; i < screenClasses.size(); i++) if (screenClasses.get(i).equals(oldScreenClassName) && (change = true))
                        screenClasses.set(i, newScreenClassName);
                    if (change)
                        ito.setTrigger(new TriggerXMLizer(sct));
                }
            }
        }
    } else // Case of connector rename
    if (databaseObject instanceof SiteClipperConnector) {
        if (statement instanceof ContinueWithSiteClipperStatement) {
            boolean isLocalProject = statement.getProject().equals(databaseObject.getProject());
            boolean isSameValue = ((ContinueWithSiteClipperStatement) statement).getSiteClipperConnectorName().equals(oldValue);
            if (isSameValue && isLocalProject) {
                ((ContinueWithSiteClipperStatement) statement).setSiteClipperConnectorName((String) newValue);
                hasBeenModified(true);
                viewer.refresh();
                // refresh editors (e.g labels in combobox)
                getDescriptors();
            }
        }
    }
    if (statement instanceof CallFunctionStatement && databaseObject.getClass().equals(FunctionStatement.class) && ((FunctionStatement) databaseObject).getParentTransaction().equals(statement.getParentTransaction())) {
        CallFunctionStatement callfunction = (CallFunctionStatement) statement;
        if (callfunction.getFunctionName().equals(oldValue) && (change = true))
            callfunction.setFunctionName(newValue.toString());
    }
    if (change)
        try {
            hasBeenModified(true);
            ConvertigoPlugin.getDefault().getProjectExplorerView().refreshTreeObject(this);
        } catch (Exception e) {
            ConvertigoPlugin.logWarning(e, "Could not refresh in tree ScHandlerStatement \"" + statement.getName() + "\" !");
        }
}
Also used : TriggerXMLizer(com.twinsoft.convertigo.engine.parsers.triggers.TriggerXMLizer) ScreenClassTrigger(com.twinsoft.convertigo.engine.parsers.triggers.ScreenClassTrigger) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) ContinueWithSiteClipperStatement(com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) SimpleStatement(com.twinsoft.convertigo.beans.statements.SimpleStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) EngineException(com.twinsoft.convertigo.engine.EngineException) ITriggerOwner(com.twinsoft.convertigo.engine.parsers.triggers.ITriggerOwner) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) CallFunctionStatement(com.twinsoft.convertigo.beans.statements.CallFunctionStatement) AbstractTrigger(com.twinsoft.convertigo.engine.parsers.triggers.AbstractTrigger) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement)

Example 5 with ScHandlerStatement

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

the class DatabaseObjectTreeObject method setPropertyValue.

public void setPropertyValue(Object id, Object value) {
    MobileBuilder mb = 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);
            mb = 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);
            mb = editorInput.getApplication().getProject().getMobileBuilder();
        }
    }
    DatabaseObject databaseObject = getObject();
    Object oldValue = getPropertyValue(id);
    String propertyName = (String) id;
    ComboBoxCellEditor editor = DynamicComboBoxPropertyDescriptor.getLast();
    if (editor != null && (!acceptSymbols() || !Integer.valueOf(editor.getItems().length - 1).equals(value))) {
        editor = null;
    }
    if (isValueInProcess || (oldValue != null && oldValue.equals(value) && editor == null)) {
        return;
    }
    try {
        isValueInProcess = true;
        java.beans.PropertyDescriptor databaseObjectPropertyDescriptor = getPropertyDescriptor(propertyName);
        TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
        if (databaseObjectPropertyDescriptor == null)
            return;
        Class<?> propertyClass = databaseObjectPropertyDescriptor.getPropertyType();
        Class<?> pec = databaseObjectPropertyDescriptor.getPropertyEditorClass();
        if (editor != null) {
            Control control = editor.getControl();
            Display display = control.getDisplay();
            final Shell shell = new Shell(control.getShell(), SWT.ON_TOP | SWT.TOOL | SWT.NO_FOCUS | SWT.APPLICATION_MODAL);
            shell.setLocation(control.toDisplay(0, 0));
            shell.setSize(control.getSize());
            shell.setLayout(new FillLayout());
            final Text text = new Text(shell, SWT.NONE);
            final String[] newValue = new String[] { null };
            String[] items = editor.getItems();
            text.setText(items[items.length - 1]);
            text.addTraverseListener(new TraverseListener() {

                @Override
                public void keyTraversed(TraverseEvent e) {
                    if (e.detail == SWT.TRAVERSE_RETURN) {
                        newValue[0] = text.getText();
                        shell.close();
                    }
                }
            });
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            }
            if (newValue[0] != null) {
                value = newValue[0];
            }
        }
        Object oriValue = value;
        boolean changed;
        do {
            changed = false;
            boolean wasSymbolError = databaseObject.isSymbolError();
            value = databaseObject.compileProperty(propertyClass, propertyName, oriValue);
            try {
                oldValue = Engine.theApp.databaseObjectsManager.getCompiledValue(oldValue);
            } catch (UndefinedSymbolsException e) {
                oldValue = e.incompletValue();
            }
            Set<String> symbolsErrors = databaseObject.getSymbolsErrors(propertyName);
            if (symbolsErrors != null) {
                boolean[] res = ConvertigoPlugin.warningGlobalSymbols(databaseObject.getProject().getName(), databaseObject.getName(), databaseObject.getDatabaseType(), propertyName, "" + databaseObject.getCompilablePropertySourceValue(propertyName), symbolsErrors, false);
                changed = res[0];
                if (changed) {
                    Engine.theApp.databaseObjectsManager.symbolsCreateUndefined(symbolsErrors);
                } else {
                    databaseObject.getProject().undefinedGlobalSymbols = true;
                    viewer.update(getProjectTreeObject(), null);
                }
            } else if (wasSymbolError) {
                Engine.theApp.databaseObjectsManager.symbolsProjectCheckUndefined(databaseObject.getProject().getName());
                viewer.update(getProjectTreeObject(), null);
            }
        } while (changed);
        if (editor != null && value instanceof String) {
            String[] items = editor.getItems();
            int len = items.length - 1;
            String strValue = (String) value;
            value = 0;
            for (int i = 0; i < len; i++) {
                if (items[i].equals(strValue)) {
                    value = i;
                    break;
                }
                ;
            }
        }
        if (pec != null && propertyClass != int.class && propertyClass != Integer.class && value instanceof Integer) {
            Object[] values = null;
            try {
                int index = (Integer) value;
                if (PropertyWithTagsEditorAdvance.class.isAssignableFrom(pec)) {
                    Method getTags = pec.getMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
                    values = (String[]) getTags.invoke(null, new Object[] { this, propertyName });
                    value = values[index];
                } else if (Enum.class.isAssignableFrom(pec)) {
                    values = (Enum[]) pec.getMethod("values").invoke(null);
                    value = index < values.length ? values[index] : values[0];
                    if (propertyClass == String.class) {
                        value = value.toString();
                    }
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                value = values.length > 0 ? values[0] : "";
                String message = "Incorrect property \"" + propertyName + "\" value for the object \"" + databaseObject.getName() + "\".";
                ConvertigoPlugin.logWarning(message);
            }
        }
        if ((EmulatorTechnologyEditor.class.equals(pec))) {
            Method getEmulatorClassNames = pec.getDeclaredMethod("getEmulatorClassNames", new Class[] { DatabaseObjectTreeObject.class });
            String[] emulatorClassNames = (String[]) getEmulatorClassNames.invoke(null, new Object[] { this });
            value = emulatorClassNames[((Integer) value).intValue()];
        }
        // Must rename bean when normalizedScreenClassName changed
        if (databaseObject instanceof ScHandlerStatement) {
            ScHandlerStatement scHandlerStatement = (ScHandlerStatement) databaseObject;
            if (propertyName.equals("normalizedScreenClassName")) {
                if (!this.rename("on" + (String) value + scHandlerStatement.getHandlerType(), Boolean.FALSE))
                    return;
            }
        } else // Must rename bean when handlerType changed
        if ((databaseObject instanceof HandlerStatement) && !(databaseObject instanceof ScDefaultHandlerStatement)) {
            // HandlerStatement handlerStatement = (HandlerStatement)databaseObject;
            if (propertyName.equals("handlerType")) {
                if (!this.rename("on" + (String) value, Boolean.FALSE))
                    return;
            }
        }
        // Set property's nillable value
        if (Boolean.TRUE.equals(databaseObjectPropertyDescriptor.getValue("nillable"))) {
            try {
                PropertyDescriptor pd = findPropertyDescriptor(propertyName);
                if ((pd != null) && (pd instanceof DataOrNullPropertyDescriptor)) {
                    Boolean isNull = ((DataOrNullPropertyDescriptor) pd).isNullProperty();
                    ((INillableProperty) databaseObject).setNullProperty(propertyName, isNull);
                    if (isNull) {
                        // Overrides fake editor value to real bean's one
                        if (value instanceof String)
                            value = "";
                        if (value instanceof XMLVector)
                            value = new XMLVector<Object>();
                    }
                }
            } catch (Exception e) {
                String message = "Error while trying to set 'isNull' attribute of property \"" + propertyName + "\" for the object \"" + databaseObject.getName() + "\".";
                ConvertigoPlugin.logException(e, message);
            }
        }
        // Check XML name property value if needed
        if (Boolean.TRUE.equals(databaseObjectPropertyDescriptor.getValue(DatabaseObject.PROPERTY_XMLNAME))) {
            if (value instanceof String) {
                String sValue = value.toString();
                if (!XMLUtils.checkName(sValue)) {
                    String message = "The property \"" + propertyName + "\" value for the object \"" + databaseObject.getName() + "\" is not a valid XML name: " + sValue;
                    ConvertigoPlugin.logWarning(message);
                    return;
                }
            }
        }
        Method setter = databaseObjectPropertyDescriptor.getWriteMethod();
        Object[] args = { value };
        setter.invoke(databaseObject, args);
        hasBeenModified(true);
        // Set treeObject isEnabled attribute value (Fix #1129)
        if (propertyName.equals("isEnabled") || propertyName.equals("isEnable")) {
            setEnabled(value.equals(true));
        }
        viewer.update(this, null);
        // update property view and display the new value for zone editor
        if (pec != null) {
            PropertySheet propertySheet = ConvertigoPlugin.getDefault().getPropertiesView();
            if (propertySheet != null && pec.getName().contains("ZoneEditor")) {
                Tree tree = (Tree) propertySheet.getCurrentPage().getControl();
                TreeItem[] treeItems = tree.getSelection();
                for (int i = 0; i < treeItems.length; i++) {
                    TreeItem treeItem = treeItems[i];
                    if (treeItem.getText().equals(databaseObjectPropertyDescriptor.getDisplayName())) {
                        PropertySheetEntry propEntry = (PropertySheetEntry) treeItem.getData();
                        propEntry.getEditor(tree).setValue(value);
                        propEntry.setValues(args);
                    }
                }
                tree.update();
            }
        }
        Engine.logStudio.info("---------------------- SetPropertyValue started: " + propertyName + "----------------------");
        if (mb != null) {
            mb.prepareBatchBuild();
        }
        BatchOperationHelper.start();
        TreeObjectEvent treeObjectEvent = new TreeObjectEvent(this, propertyName, oldValue, value);
        ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent);
        BatchOperationHelper.stop();
    } catch (Exception e) {
        String message = "Error while trying to set property \"" + propertyName + "\" value for the object \"" + databaseObject.getName() + "\".";
        ConvertigoPlugin.logException(e, message);
    } finally {
        BatchOperationHelper.cancel();
        Engine.logStudio.info("---------------------- SetPropertyValue ended:   " + propertyName + "----------------------");
        isValueInProcess = false;
    }
}
Also used : TraverseEvent(org.eclipse.swt.events.TraverseEvent) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) INillableProperty(com.twinsoft.convertigo.beans.core.INillableProperty) PropertySheetEntry(org.eclipse.ui.views.properties.PropertySheetEntry) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Tree(org.eclipse.swt.widgets.Tree) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent) ScDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScDefaultHandlerStatement) UndefinedSymbolsException(com.twinsoft.convertigo.engine.UndefinedSymbolsException) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) FillLayout(org.eclipse.swt.layout.FillLayout) Method(java.lang.reflect.Method) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DataOrNullPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.DataOrNullPropertyDescriptor) PropertySheet(org.eclipse.ui.views.properties.PropertySheet) ScDefaultHandlerStatement(com.twinsoft.convertigo.beans.statements.ScDefaultHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) Control(org.eclipse.swt.widgets.Control) Shell(org.eclipse.swt.widgets.Shell) InfoPropertyDescriptor(com.twinsoft.convertigo.eclipse.views.projectexplorer.InfoPropertyDescriptor) DynamicComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.DynamicComboBoxPropertyDescriptor) PropertyDescriptor(org.eclipse.ui.views.properties.PropertyDescriptor) StringComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) ScriptablePropertyDescriptor(com.twinsoft.convertigo.eclipse.views.projectexplorer.ScriptablePropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) DynamicInfoPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.DynamicInfoPropertyDescriptor) DataOrNullPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.DataOrNullPropertyDescriptor) TraverseListener(org.eclipse.swt.events.TraverseListener) EmulatorTechnologyEditor(com.twinsoft.convertigo.eclipse.property_editors.EmulatorTechnologyEditor) Text(org.eclipse.swt.widgets.Text) IEditorPart(org.eclipse.ui.IEditorPart) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) UndefinedSymbolsException(com.twinsoft.convertigo.engine.UndefinedSymbolsException) IEditorInput(org.eclipse.ui.IEditorInput) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) Display(org.eclipse.swt.widgets.Display)

Aggregations

ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)7 FunctionStatement (com.twinsoft.convertigo.beans.statements.FunctionStatement)5 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)5 EngineException (com.twinsoft.convertigo.engine.EngineException)5 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)4 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)4 Statement (com.twinsoft.convertigo.beans.core.Statement)4 ContinueWithSiteClipperStatement (com.twinsoft.convertigo.beans.statements.ContinueWithSiteClipperStatement)4 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)3 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)3 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)2 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)2 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)2 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)2 ProxyHttpConnector (com.twinsoft.convertigo.beans.connectors.ProxyHttpConnector)2 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)2 Connector (com.twinsoft.convertigo.beans.core.Connector)2 Transaction (com.twinsoft.convertigo.beans.core.Transaction)2 JavelinScreenClass (com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass)2 CallFunctionStatement (com.twinsoft.convertigo.beans.statements.CallFunctionStatement)2