Search in sources :

Example 56 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class NodeTest method testGetNodeConnectorsShowIf2FlowConnector.

@Test
public void testGetNodeConnectorsShowIf2FlowConnector() {
    Process process = new Process(new FakePropertyImpl());
    IComponent sourceCom = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
    Node node = new Node(sourceCom, process);
    // create node connector for test
    List<INodeConnector> listConnector = new ArrayList<>();
    NodeConnector connector1 = new NodeConnector(node);
    connector1.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    connector1.setName(EConnectionType.FLOW_MAIN.getName());
    connector1.setMaxLinkOutput(1);
    listConnector.add(connector1);
    connector1.setShowIf("SHOW_FLOW_CONNECTOR == 'true'");
    NodeConnector connector2 = new NodeConnector(node);
    connector2.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    connector2.setName(EConnectionType.FLOW_MAIN.getName());
    connector2.setMaxLinkInput(-1);
    connector2.setMaxLinkOutput(-1);
    connector2.setShowIf("SHOW_FLOW_CONNECTOR == 'false'");
    listConnector.add(connector2);
    node.setListConnector(listConnector);
    // create a test param with default value 'false'
    IElementParameter param = addShowIfParam(node);
    Assert.assertTrue(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) == connector2);
    Assert.assertTrue(node.getConnectorFromType(EConnectionType.FLOW_MAIN) == connector2);
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 1);
    // make connector show if to 'true'
    param.setValue(true);
    Assert.assertTrue(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) == connector1);
    Assert.assertTrue(node.getConnectorFromType(EConnectionType.FLOW_MAIN) == connector1);
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 1);
    // connector with same name should have the same current input/output
    connector1.setCurLinkNbInput(10);
    connector1.setCurLinkNbOutput(100);
    Assert.assertEquals(connector1.getCurLinkNbInput(), 10);
    Assert.assertEquals(connector1.getCurLinkNbOutput(), 100);
    Assert.assertEquals(connector2.getCurLinkNbInput(), 10);
    Assert.assertEquals(connector2.getCurLinkNbOutput(), 100);
}
Also used : FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) Test(org.junit.Test)

Example 57 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class NodeTest method addShowIfParam.

private IElementParameter addShowIfParam(Node node) {
    IElementParameter param = new ElementParameter(node);
    param.setName("SHOW_FLOW_CONNECTOR");
    param.setCategory(EComponentCategory.TECHNICAL);
    param.setFieldType(EParameterFieldType.CHECK);
    param.setDisplayName("show flow  connector");
    param.setNumRow(99);
    param.setShow(false);
    param.setValue(false);
    node.addElementParameter(param);
    return param;
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 58 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class RepositoryUpdateTest method testRepositoryValue.

private void testRepositoryValue(INode node, String parameter, Object expectedValue) {
    IElementParameter param = node.getElementParameter(parameter);
    assertTrue(param.isRepositoryValueUsed());
    assertEquals(expectedValue, param.getValue());
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter)

Example 59 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class SQLPatternComposite method getAllSqlPatterns.

private List<SQLPatternInfor> getAllSqlPatterns(List<Map> tableInput, boolean modifySQL) {
    IElementParameter elementParam = element.getElementParameter(EParameterName.SQLPATTERN_DB_NAME.getName());
    if (elementParam == null) {
        return Collections.EMPTY_LIST;
    }
    // String dbName = (String) elementParam.getValue();
    List<SQLPatternInfor> patternInfor = new ArrayList<SQLPatternInfor>();
    try {
        List<IRepositoryViewObject> list = null;
        if (isItemIndexChecked() && modifySQL) {
            List<Relation> relations = new ArrayList<Relation>();
            IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
            List<IRepositoryViewObject> updateList = new ArrayList<IRepositoryViewObject>();
            for (Map map : tableInput) {
                String id = (String) map.get(SQLPatternUtils.SQLPATTERNLIST);
                relations.addAll(RelationshipItemBuilder.getInstance().getItemsRelatedTo(id, ItemCacheManager.LATEST_VERSION, RelationshipItemBuilder.SQLPATTERN_RELATION));
            }
            for (Relation relation : relations) {
                try {
                    IRepositoryViewObject obj = factory.getLastVersion(relation.getId());
                    if (obj != null) {
                        updateList.add(obj);
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }
            list = updateList;
        } else {
            list = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getAll(ERepositoryObjectType.SQLPATTERNS, false);
            // add reference sql pattern
            addReferencedSQLTemplate(list, ProjectManager.getInstance().getCurrentProject());
        }
        for (IRepositoryViewObject repositoryObject : list) {
            Item item = repositoryObject.getProperty().getItem();
            if (item instanceof SQLPatternItem) {
                SQLPatternItem sqlitem = (SQLPatternItem) repositoryObject.getProperty().getItem();
                // disable this test as there is now only Generic ELT components
                // if (item.getEltName().equals(dbName)) {
                patternInfor.add(new SQLPatternInfor(sqlitem.getProperty().getId() + SQLPatternUtils.ID_SEPARATOR + sqlitem.getProperty().getLabel(), sqlitem.getProperty().getLabel()));
            // }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return patternInfor;
}
Also used : ArrayList(java.util.ArrayList) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) PartInitException(org.eclipse.ui.PartInitException) PersistenceException(org.talend.commons.exception.PersistenceException) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) TableItem(org.eclipse.swt.widgets.TableItem) Relation(org.talend.core.model.relationship.Relation) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) Map(java.util.Map) HashMap(java.util.HashMap) BidiMap(org.apache.commons.collections.BidiMap) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 60 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class SQLPatternComposite method createCodeControl.

/**
     * DOC bqian Comment method "createCodeControl".
     * 
     * @param panel
     * @param
     */
private void createCodeControl(Composite panel, Control reference) {
    codeText = new Text(panel, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    codeText.setEditable(false);
    FormData fd = new FormData();
    fd.left = new FormAttachment(10, 0);
    fd.right = new FormAttachment(90, 0);
    fd.top = new FormAttachment(reference, 2);
    fd.bottom = new FormAttachment(95, 0);
    codeText.setLayoutData(fd);
    codeText.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            if (tableViewer.getTable().getSelection().length == 0) {
                return;
            }
            TableItem item = tableViewer.getTable().getSelection()[0];
            if (item == null || item.getText() == null) {
                return;
            }
            String sqlpatternName = item.getText();
            SQLPatternItem patternItem = SQLPatternUtils.getSQLPatternItem(SQLPatternComposite.this.element, sqlpatternName);
            if (patternItem.isSystem()) {
                boolean answer = //$NON-NLS-1$
                MessageDialog.openQuestion(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.forbidModification"));
                if (!answer) {
                    return;
                }
                IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                IElementParameter parameter = element.getElementParameter(EParameterName.SQLPATTERN_DB_NAME.getName());
                String dbName = (String) parameter.getValue();
                //$NON-NLS-1$
                String path = dbName + "/" + RepositoryConstants.USER_DEFINED;
                repositoryService.createSqlpattern(path, true);
            } else if (sqlPatternAndProject.get(patternItem) != null) {
                MessageDialog.openInformation(getShell(), "Information", "Forbid modification on sql template from reference project");
            } else {
                boolean answer = //$NON-NLS-1$
                MessageDialog.openQuestion(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.TOS"), //$NON-NLS-1$
                Messages.getString("SQLPatternComposite.modifySQLPattern"));
                if (!answer) {
                    return;
                }
                IRepositoryService repositoryService = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                repositoryService.openSQLPatternEditor(patternItem, false);
            }
        }

        @Override
        public void mouseDown(MouseEvent e) {
        // do nothing
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            mouseUp(e);
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) TableItem(org.eclipse.swt.widgets.TableItem) IElementParameter(org.talend.core.model.process.IElementParameter) Text(org.eclipse.swt.widgets.Text) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) FormAttachment(org.eclipse.swt.layout.FormAttachment) IRepositoryService(org.talend.repository.model.IRepositoryService)

Aggregations

IElementParameter (org.talend.core.model.process.IElementParameter)439 ArrayList (java.util.ArrayList)165 List (java.util.List)112 Node (org.talend.designer.core.ui.editor.nodes.Node)108 Map (java.util.Map)99 INode (org.talend.core.model.process.INode)94 HashMap (java.util.HashMap)87 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)73 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)69 Point (org.eclipse.swt.graphics.Point)57 ElementParameter (org.talend.designer.core.model.components.ElementParameter)48 ConnectionItem (org.talend.core.model.properties.ConnectionItem)45 IConnection (org.talend.core.model.process.IConnection)40 PersistenceException (org.talend.commons.exception.PersistenceException)39 Item (org.talend.core.model.properties.Item)38 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)37 IComponent (org.talend.core.model.components.IComponent)36 CCombo (org.eclipse.swt.custom.CCombo)33 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)29 Connection (org.talend.core.model.metadata.builder.connection.Connection)28