Search in sources :

Example 6 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class TreeDropAdapter method performDrop.

private void performDrop(Object data, final ProjectExplorerView explorerView, TreeObject targetTreeObject) throws EngineException, IOException {
    boolean needReload = false;
    final DatabaseObject dbo;
    if (data instanceof String) {
        String source = data.toString();
        if (targetTreeObject instanceof ObjectsFolderTreeObject) {
            ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) targetTreeObject;
            dbo = (DatabaseObject) folderTreeObject.getParent().getObject();
            switch(folderTreeObject.folderType) {
                case ObjectsFolderTreeObject.FOLDER_TYPE_CRITERIAS:
                    if (dbo instanceof HtmlScreenClass) {
                        // Creates a XPath criteria for this screen class
                        if (!dbo.equals(((HtmlConnector) dbo.getConnector()).getDefaultScreenClass())) {
                            ((HtmlScreenClass) dbo).addCriteria(createXPath(source));
                            needReload = true;
                        }
                    }
                    break;
                case ObjectsFolderTreeObject.FOLDER_TYPE_INHERITED_SCREEN_CLASSES:
                    if (dbo instanceof HtmlScreenClass) {
                        // Creates an inherited screen class with an XPath criteria for this screen class
                        HtmlScreenClass newSc = createHtmlScreenClass(dbo.priority + 1);
                        ((HtmlScreenClass) dbo).addInheritedScreenClass(newSc);
                        newSc.addCriteria(createXPath(source));
                        needReload = true;
                    }
                    break;
                case ObjectsFolderTreeObject.FOLDER_TYPE_EXTRACTION_RULES:
                    if (dbo instanceof HtmlScreenClass) {
                        NewObjectWizard newObjectWizard = new NewObjectWizard(dbo, "com.twinsoft.convertigo.beans.core.ExtractionRule", source, null);
                        WizardDialog wzdlg = new WizardDialog(Display.getDefault().getActiveShell(), newObjectWizard);
                        wzdlg.setPageSize(850, 650);
                        wzdlg.open();
                        needReload = true;
                    }
                    break;
                default:
                    break;
            }
            if (needReload)
                reloadTreeObject(explorerView, folderTreeObject.getParent());
        } else if (targetTreeObject instanceof DatabaseObjectTreeObject) {
            DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) targetTreeObject;
            dbo = (DatabaseObject) targetTreeObject.getObject();
            if (databaseObjectTreeObject instanceof ScreenClassTreeObject) {
                if (dbo instanceof HtmlScreenClass) {
                    // Creates an inherited screen class with an XPath criteria for this screen class
                    HtmlScreenClass newSc = createHtmlScreenClass(dbo.priority + 1);
                    ((HtmlScreenClass) dbo).addInheritedScreenClass(newSc);
                    newSc.addCriteria(createXPath(source));
                    needReload = true;
                }
            } else if (dbo instanceof IXPathable) {
                // Set XPath property
                if (dbo instanceof XpathableStatement)
                    ((XpathableStatement) dbo).setPureXpath(source);
                else
                    ((IXPathable) dbo).setXpath(source);
                ((DatabaseObject) dbo).hasChanged = true;
                needReload = true;
            }
            if (needReload)
                reloadTreeObject(explorerView, databaseObjectTreeObject);
        } else if (targetTreeObject instanceof IPropertyTreeObject) {
            IPropertyTreeObject pto = null;
            if (detail == DND.DROP_MOVE) {
                // Set XPath property
                if (targetTreeObject instanceof IXPathable) {
                    ((IXPathable) targetTreeObject).setXpath("." + source);
                    needReload = true;
                } else // Add new row with xpath
                if (targetTreeObject instanceof PropertyTableTreeObject) {
                    // // See Ticket #679 : Drag and drop without Control
                    // PropertyTableTreeObject description = (PropertyTableTreeObject)targetTreeObject;
                    // pto = description.addNewRow();
                    // needReload = true;
                    // if ((pto != null) && (pto instanceof IXPathable)) {
                    // ((IXPathable)pto).setXpath("."+source);
                    // }
                    String label = ((PropertyTableTreeObject) targetTreeObject).getRowDefaultLabel().toLowerCase();
                    throw new EngineException("Please hold on the 'Ctrl' key while dragging to create a new " + label);
                }
            } else if (detail == DND.DROP_COPY) {
                // Add new row with xpath
                if (targetTreeObject instanceof PropertyTableTreeObject) {
                    PropertyTableTreeObject description = (PropertyTableTreeObject) targetTreeObject;
                    pto = description.addNewRow();
                    needReload = true;
                    if ((pto != null) && (pto instanceof IXPathable)) {
                        ((IXPathable) pto).setXpath("." + source);
                    }
                } else // Add new column with xpath
                if (targetTreeObject instanceof PropertyTableRowTreeObject) {
                    PropertyTableRowTreeObject row = (PropertyTableRowTreeObject) targetTreeObject;
                    pto = row.addNewColumn();
                    needReload = true;
                    if ((pto != null) && (pto instanceof IXPathable)) {
                        ((IXPathable) pto).setXpath("." + source);
                    }
                }
            }
            if (needReload) {
                pto = (pto == null) ? (IPropertyTreeObject) targetTreeObject : pto;
                targetTreeObject = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
                if (targetTreeObject instanceof DatabaseObjectTreeObject) {
                    // reloadTreeObject(explorerView, targetTreeObject);
                    TreeParent treeParent = targetTreeObject.getParent();
                    if (treeParent instanceof FolderTreeObject)
                        treeParent = treeParent.getParent();
                    explorerView.objectChanged(new CompositeEvent(treeParent.getObject(), pto.getPath()));
                }
            }
        }
    } else if (data instanceof StepSource) {
        if (targetTreeObject instanceof DatabaseObjectTreeObject) {
            final DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) targetTreeObject;
            dbo = (DatabaseObject) targetTreeObject.getObject();
            final Set<PropertyDescriptor> propertyDescriptors = new TreeSet<PropertyDescriptor>(new Comparator<PropertyDescriptor>() {

                @Override
                public int compare(PropertyDescriptor o1, PropertyDescriptor o2) {
                    return o1.getDisplayName().compareTo(o2.getDisplayName());
                }
            });
            propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.smartType));
            propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.sourceDefinition));
            propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.sourcesDefinition));
            if (!propertyDescriptors.isEmpty()) {
                // Retrieve Source definition
                final XMLVector<String> sourceDefinition = new XMLVector<String>(2);
                sourceDefinition.add(((StepSource) data).getPriority());
                sourceDefinition.add(((StepSource) data).getXpath());
                SelectionListener selectionListener = new SelectionListener() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        PropertyDescriptor propertyDescriptor = (e == null) ? propertyDescriptors.iterator().next() : (PropertyDescriptor) e.widget.getData();
                        String propertyName = propertyDescriptor.getName();
                        if (propertyDescriptor.getPropertyType().isAssignableFrom(SmartType.class)) {
                            SmartType smartType = new SmartType();
                            smartType.setMode(Mode.SOURCE);
                            smartType.setSourceDefinition(sourceDefinition);
                            databaseObjectTreeObject.setPropertyValue(propertyDescriptor.getName(), smartType);
                        } else if (propertyName.equals("sourceDefinition")) {
                            // Use setPropertyValue in order to set object's value and fire necessary events
                            databaseObjectTreeObject.setPropertyValue(propertyDescriptor.getName(), sourceDefinition);
                        } else if (propertyName.equals("sourcesDefinition")) {
                            try {
                                XMLVector<XMLVector<Object>> sourcesDefinition = GenericUtils.cast(propertyDescriptor.getReadMethod().invoke(dbo));
                                // make a copy to make a property change
                                sourcesDefinition = new XMLVector<XMLVector<Object>>(sourcesDefinition);
                                XMLVector<Object> row = new XMLVector<Object>();
                                row.add("");
                                row.add(sourceDefinition);
                                row.add("");
                                sourcesDefinition.add(row);
                                databaseObjectTreeObject.setPropertyValue(propertyName, sourcesDefinition);
                            } catch (Exception ex) {
                                ConvertigoPlugin.logError("failed to add to sourcesDefinition of " + dbo.getName());
                            }
                        }
                        // Properties view needs to be refreshed
                        refreshPropertiesView(explorerView, databaseObjectTreeObject);
                    }

                    @Override
                    public void widgetDefaultSelected(SelectionEvent e) {
                    }
                };
                if (propertyDescriptors.size() == 1) {
                    selectionListener.widgetSelected(null);
                } else {
                    Shell shell = ConvertigoPlugin.getMainShell();
                    Menu dropMenu = new Menu(shell, SWT.POP_UP);
                    shell.setMenu(dropMenu);
                    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
                        MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
                        itemCheck.setText(propertyDescriptor.getDisplayName());
                        itemCheck.setData(propertyDescriptor);
                        itemCheck.addSelectionListener(selectionListener);
                    }
                    dropMenu.setVisible(true);
                }
            }
        }
    } else if (data instanceof PaletteSource) {
        try {
            if (targetTreeObject instanceof ObjectsFolderTreeObject) {
                ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) targetTreeObject;
                targetTreeObject = folderTreeObject.getParent();
            }
            if (targetTreeObject instanceof DatabaseObjectTreeObject) {
                DatabaseObject parent = (DatabaseObject) targetTreeObject.getObject();
                String xmlData = ((PaletteSource) data).getXmlData();
                Document document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(xmlData)));
                Element rootElement = document.getDocumentElement();
                NodeList nodeList = rootElement.getChildNodes();
                int len = nodeList.getLength();
                Node node;
                // Special objects move from palette
                if (detail == DND.DROP_MOVE) {
                    for (int i = 0; i < len; i++) {
                        node = (Node) nodeList.item(i);
                        if (node.getNodeType() != Node.TEXT_NODE) {
                            if (paste(node, parent, true) == null) {
                                throw new Exception();
                            }
                        }
                    }
                    reloadTreeObject(explorerView, targetTreeObject);
                }
            } else {
                throw new Exception();
            }
        } catch (Exception ex) {
            ConvertigoPlugin.logError("failed to add from palette");
        }
    } else if (data instanceof MobileSource) {
        try {
            String jsonString = ((MobileSource) data).getJsonString();
            if (targetTreeObject instanceof MobileUIComponentTreeObject) {
                Shell shell = ConvertigoPlugin.getMainShell();
                Menu dropMenu = new Menu(shell, SWT.POP_UP);
                shell.setMenu(dropMenu);
                MobileUIComponentTreeObject mcto = GenericUtils.cast(targetTreeObject);
                for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
                    if (descriptor instanceof MobileSmartSourcePropertyDescriptor) {
                        MobileSmartSourcePropertyDescriptor cspd = GenericUtils.cast(descriptor);
                        if (!cspd.isReadOnly()) {
                            String propertyName = (String) cspd.getId();
                            String propertyLabel = (String) cspd.getDisplayName();
                            MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
                            itemCheck.setText(propertyLabel);
                            itemCheck.addSelectionListener(new SelectionListener() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType cst = new com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType();
                                    cst.setMode(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType.Mode.SOURCE);
                                    cst.setSmartValue(jsonString);
                                    mcto.setPropertyValue(propertyName, cst);
                                    refreshPropertiesView(explorerView, mcto);
                                }

                                @Override
                                public void widgetDefaultSelected(SelectionEvent e) {
                                }
                            });
                        }
                    }
                }
                dropMenu.setVisible(true);
            }
            if (targetTreeObject instanceof NgxUIComponentTreeObject) {
                Shell shell = ConvertigoPlugin.getMainShell();
                Menu dropMenu = new Menu(shell, SWT.POP_UP);
                shell.setMenu(dropMenu);
                NgxUIComponentTreeObject mcto = GenericUtils.cast(targetTreeObject);
                for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
                    if (descriptor instanceof NgxSmartSourcePropertyDescriptor) {
                        NgxSmartSourcePropertyDescriptor cspd = GenericUtils.cast(descriptor);
                        if (!cspd.isReadOnly()) {
                            String propertyName = (String) cspd.getId();
                            String propertyLabel = (String) cspd.getDisplayName();
                            MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
                            itemCheck.setText(propertyLabel);
                            itemCheck.addSelectionListener(new SelectionListener() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType cst = new com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType();
                                    cst.setMode(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode.SOURCE);
                                    cst.setSmartValue(jsonString);
                                    mcto.setPropertyValue(propertyName, cst);
                                    refreshPropertiesView(explorerView, mcto);
                                }

                                @Override
                                public void widgetDefaultSelected(SelectionEvent e) {
                                }
                            });
                        }
                    }
                }
                dropMenu.setVisible(true);
            } else {
                throw new Exception();
            }
        } catch (Exception ex) {
            ConvertigoPlugin.logError("failed to add mobile source");
        }
    }
}
Also used : PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) InputSource(org.xml.sax.InputSource) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Node(org.w3c.dom.Node) EngineException(com.twinsoft.convertigo.engine.EngineException) Document(org.w3c.dom.Document) Comparator(java.util.Comparator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass) IXPathable(com.twinsoft.convertigo.beans.core.IXPathable) NodeList(org.w3c.dom.NodeList) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) SelectionListener(org.eclipse.swt.events.SelectionListener) Set(java.util.Set) TreeSet(java.util.TreeSet) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) Element(org.w3c.dom.Element) NgxSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NewObjectWizard(com.twinsoft.convertigo.eclipse.wizards.new_object.NewObjectWizard) Shell(org.eclipse.swt.widgets.Shell) StringReader(java.io.StringReader) Menu(org.eclipse.swt.widgets.Menu) SmartType(com.twinsoft.convertigo.beans.steps.SmartType) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) XpathableStatement(com.twinsoft.convertigo.beans.statements.XpathableStatement) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) PropertyDescriptor(java.beans.PropertyDescriptor) NgxSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) MenuItem(org.eclipse.swt.widgets.MenuItem) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) WizardDialog(org.eclipse.jface.wizard.WizardDialog) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Example 7 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class ConnectorEditorPart method createCompositeDesign.

/**
 * This method initializes compositeDesign
 */
private void createCompositeDesign() {
    if (Engine.hasXulRunner() && connector instanceof HtmlConnector) {
        try {
            compositeDesign = new HtmlConnectorDesignComposite(connector, tabFolderOutputDesign, SWT.NONE);
        } catch (MaxCvsExceededException e) {
            String message = "You have reached the maximum allowed number of simultaneous HTML connectors; check your license keys.\n\n" + "Notice: according to your license key, the maximum allowed number of simultaneous HTML connectors is 2. " + "As you have more than 2 HTML connectors open, you will not be able to open another one nor run any transaction on this connector.\n\n" + "Please close unnecessary connectors.";
            ConvertigoPlugin.logError(message, true);
            compositeDesign = new Composite(tabFolderOutputDesign, SWT.NONE);
            labelNoDesign = new Label(compositeDesign, SWT.NONE | SWT.WRAP);
            labelNoDesign.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 10, 300, 200));
            labelNoDesign.setFont(new Font(null, "Tahoma", 10, 0));
            labelNoDesign.setText("\n" + message);
            Control[] children = tabFolderOutputDesign.getChildren();
            if ((children.length >= 2) && (children[1] instanceof HtmlConnectorDesignComposite))
                children[1].moveBelow(null);
        } catch (KeyExpiredException e) {
            String message = "Your HTML license key has expired; check your license keys.\n\n" + "Notice: according to your license key, your trial period has expired. " + "You will not be able to open an HTML connector nor run any transaction on this connector.\n\n";
            ConvertigoPlugin.logError(message, true);
            compositeDesign = new Composite(tabFolderOutputDesign, SWT.NONE);
            labelNoDesign = new Label(compositeDesign, SWT.NONE | SWT.WRAP);
            labelNoDesign.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 10, 300, 200));
            labelNoDesign.setFont(new Font(null, "Tahoma", 10, 0));
            labelNoDesign.setText("\n" + message);
            Control[] children = tabFolderOutputDesign.getChildren();
            if ((children.length >= 2) && (children[1] instanceof HtmlConnectorDesignComposite))
                children[1].moveBelow(null);
        }
    } else if (connector instanceof SapJcoConnector) {
        try {
            compositeDesign = new SapJcoConnectorDesignComposite(connector, tabFolderOutputDesign, SWT.NONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (connector instanceof SqlConnector) {
        try {
            compositeDesign = new SqlConnectorDesignComposite(connector, tabFolderOutputDesign, SWT.NONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        compositeDesign = new Composite(tabFolderOutputDesign, SWT.NONE);
        labelNoDesign = new Label(compositeDesign, SWT.NONE | SWT.WRAP);
        labelNoDesign.setFont(new Font(null, "Tahoma", 10, 0));
        labelNoDesign.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 10, 300, 200));
        labelNoDesign.setText("This connector does not provide any design tool");
    }
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) Font(org.eclipse.swt.graphics.Font) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException) IOException(java.io.IOException) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) SapJcoConnector(com.twinsoft.convertigo.beans.connectors.SapJcoConnector) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException)

Example 8 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class ScSourceEditorComposite method getInitalInput.

private Object getInitalInput() {
    TVRoot tvRoot = new TVRoot();
    HtmlConnector connector = (HtmlConnector) sourceScreenClass.getConnector();
    ScreenClass defaultScreenClass = connector.getDefaultScreenClass();
    TVScreenClass tvScreenClass = new TVScreenClass(defaultScreenClass.getName());
    tvRoot.addScreenClass(tvScreenClass);
    if (requestableSource.equals(defaultScreenClass.getName())) {
        selectedTVObject = tvScreenClass;
    }
    List<ScreenClass> screenClasses = defaultScreenClass.getInheritedScreenClasses();
    for (ScreenClass screenClass : screenClasses) {
        getInHeritedScreenClass(screenClass, tvScreenClass);
    }
    return tvRoot;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass)

Example 9 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class ComponentInfoWizardPage method fillTree.

public void fillTree(Class<? extends DatabaseObject> beanClass) {
    treeItemName = null;
    tree.removeAll();
    if (parentObject instanceof Transaction) {
        Connector connector = (Connector) ((Transaction) parentObject).getParent();
        boolean isScreenClassAware = connector instanceof IScreenClassContainer<?>;
        if (beanClass.equals(ScEntryHandlerStatement.class) || beanClass.equals(ScExitHandlerStatement.class)) {
            if (isScreenClassAware) {
                if (connector instanceof HtmlConnector) {
                    HtmlConnector htmlConnector = (HtmlConnector) connector;
                    ScreenClass defaultScreenClass = htmlConnector.getDefaultScreenClass();
                    TreeItem branch = new TreeItem(tree, SWT.NONE);
                    branch.setText(defaultScreenClass.getName());
                    List<ScreenClass> screenClasses = defaultScreenClass.getInheritedScreenClasses();
                    for (ScreenClass screenClass : screenClasses) {
                        getInHeritedScreenClass(screenClass, branch);
                    }
                } else if (connector instanceof JavelinConnector) {
                    JavelinConnector javelinConnector = (JavelinConnector) connector;
                    ScreenClass defaultScreenClass = javelinConnector.getDefaultScreenClass();
                    TreeItem branch = new TreeItem(tree, SWT.NONE);
                    branch.setText(defaultScreenClass.getName());
                    List<ScreenClass> screenClasses = defaultScreenClass.getInheritedScreenClasses();
                    for (ScreenClass screenClass : screenClasses) {
                        getInHeritedScreenClass(screenClass, branch);
                    }
                }
                tree.setVisible(true);
            }
        } else if (beanClass.equals(HandlerStatement.class)) {
            TreeItem branch;
            branch = new TreeItem(tree, SWT.NONE);
            branch.setText(HandlerStatement.EVENT_TRANSACTION_STARTED);
            branch = new TreeItem(tree, SWT.NONE);
            branch.setText(HandlerStatement.EVENT_XML_GENERATED);
            tree.setVisible(true);
        } else
            tree.setVisible(false);
    }
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) TreeItem(org.eclipse.swt.widgets.TreeItem) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) IScreenClassContainer(com.twinsoft.convertigo.beans.core.IScreenClassContainer) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) List(java.util.List)

Example 10 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector 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)

Aggregations

HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)42 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)14 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)13 EngineException (com.twinsoft.convertigo.engine.EngineException)13 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)12 Connector (com.twinsoft.convertigo.beans.core.Connector)12 Transaction (com.twinsoft.convertigo.beans.core.Transaction)10 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)8 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)8 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)7 Statement (com.twinsoft.convertigo.beans.core.Statement)7 Document (org.w3c.dom.Document)7 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)6 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)6 List (java.util.List)6 HtmlScreenClass (com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass)5 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)5 IOException (java.io.IOException)5 TransformerException (javax.xml.transform.TransformerException)5