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);
}
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;
}
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());
}
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;
}
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);
}
});
}
Aggregations