use of org.talend.core.model.process.IElement in project tdi-studio-se by Talend.
the class PropertiesTableToolbarEditorView method createAddAllPushButton.
/*
* (non-Javadoc)
*
* @see org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView#createAddAllPushButton()
*/
@Override
protected AddAllPushButton createAddAllPushButton() {
final PropertiesTableEditorModel tableEditorModel = (PropertiesTableEditorModel) getExtendedTableViewer().getExtendedControlModel();
if (!TableController.isNeedAddAllButton(tableEditorModel.getElemParameter())) {
return null;
}
return new AddAllPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {
@Override
public boolean getEnabledState() {
return super.getEnabledState() && (model == null || !model.getElemParameter().isBasedOnSubjobStarts());
}
@Override
protected List<Object> getObjectToAdd() {
if (!tableEditorModel.isButtonEnabled()) {
MessageDialog.openInformation(tableEditorModel.getTableViewer().getControl().getShell(), "Information", "All output columns have been added already");
return new ArrayList<Object>();
}
IElement element = tableEditorModel.getElement();
if (element != null && element instanceof INode) {
List<ColumnInfo> tableInputs = null;
IElementParameter param = tableEditorModel.getElemParameter();
String componentName = ((INode) element).getComponent().getName();
// prompt the dialog when clicking the button of "Add All".
if ("tStewardshipTaskOutput".equalsIgnoreCase(componentName)) {
//$NON-NLS-1$
if ("EXTRA_INFO".equals(param.getName())) {
//$NON-NLS-1$
tableInputs = promptForDefaultValue(tableEditorModel.getTableViewer().getControl().getShell(), param);
} else {
tableInputs = new ArrayList<ColumnInfo>();
}
} else {
// diplay a dialog for setting default values. see 0005416: When click Add All in a table, add
// the
// possibility to setup the default parameters value.
tableInputs = promptForDefaultValue(tableEditorModel.getTableViewer().getControl().getShell(), param);
}
if (tableInputs == null) {
return new ArrayList<Object>();
}
// default name //$NON-NLS-1$
String paramColumnsName = "COLUMN";
// default name //$NON-NLS-1$
String paramSizeName = "SIZE";
for (Object object : param.getListItemsValue()) {
if (object instanceof IElementParameter) {
IElementParameter tableParameter = (IElementParameter) object;
if (tableParameter.getFieldType().equals(EParameterFieldType.COLUMN_LIST)) {
paramColumnsName = tableParameter.getName();
}
if (tableParameter.getContext() != null && tableParameter.getContext().equals("LENGTH")) {
//$NON-NLS-1$
paramSizeName = tableParameter.getName();
}
}
}
INode node = (INode) element;
if (node.getMetadataList() != null && !node.getMetadataList().isEmpty()) {
IMetadataTable metadata = node.getMetadataList().get(0);
if (metadata.getListColumns() != null && !metadata.getListColumns().isEmpty()) {
List<Object> objects = new ArrayList<Object>();
for (IMetadataColumn column : metadata.getListColumns()) {
if (tableEditorModel.exist(column.getLabel())) {
continue;
}
Object entry = tableEditorModel.createNewEntry();
if (!(entry instanceof Map)) {
continue;
}
Map mapObject = (Map) entry;
if (mapObject.containsKey(paramColumnsName)) {
mapObject.put(paramColumnsName, column.getLabel());
}
if (mapObject.containsKey(paramSizeName)) {
if (column.getLength() != null) {
mapObject.put(paramSizeName, Integer.toString(column.getLength()));
}
}
// set default values
for (ColumnInfo col : tableInputs) {
Object defaultValue = col.defaultValue;
Object found = findDefaultName(column.getLabel(), col);
if (found != null && !"".equals(found)) {
defaultValue = found;
}
mapObject.put(col.parameter.getName(), defaultValue);
}
objects.add(entry);
}
return objects;
}
}
}
return Collections.EMPTY_LIST;
}
private List<ColumnInfo> promptForDefaultValue(Shell shell, IElementParameter param) {
List<ColumnInfo> tableInputs = new ArrayList<ColumnInfo>();
Object[] listItemsValue = param.getListItemsValue();
String[] displayNames = param.getListItemsDisplayName();
for (int i = 0; i < listItemsValue.length; i++) {
if (listItemsValue[i] instanceof IElementParameter) {
IElementParameter colParam = (IElementParameter) listItemsValue[i];
if (colParam.getFieldType().equals(EParameterFieldType.COLUMN_LIST)) {
continue;
}
ColumnInfo row = new ColumnInfo();
row.name = displayNames[i];
row.parameter = colParam;
tableInputs.add(row);
}
}
PromptDefaultValueDialog dialog = new PromptDefaultValueDialog(shell, tableInputs);
if (dialog.open() == Window.OK) {
return tableInputs;
} else {
return null;
}
}
};
}
use of org.talend.core.model.process.IElement in project tdi-studio-se by Talend.
the class GenericTableUtilsTest method testGetTableValues.
@Test
public void testGetTableValues() {
MyTestTable tableProperties = new MyTestTable("tableProp");
List<String> columnValues = new ArrayList<String>();
columnValues.add("Text1");
columnValues.add("Text2");
tableProperties.column1.setValue(columnValues);
columnValues = new ArrayList<String>();
columnValues.add("true");
columnValues.add("false");
tableProperties.column2.setValue(columnValues);
columnValues = new ArrayList<String>();
columnValues.add("Value1");
columnValues.add("Value3");
tableProperties.column3.setValue(columnValues);
IElement elem = new FakeElement("test");
IElementParameter tableParam = new ElementParameter(elem);
tableParam.setName("myTable");
IElementParameter column1 = new ElementParameter(elem);
column1.setName("column1");
column1.setFieldType(EParameterFieldType.TEXT);
IElementParameter column2 = new ElementParameter(elem);
column2.setName("column2");
column2.setFieldType(EParameterFieldType.CHECK);
IElementParameter column3 = new ElementParameter(elem);
column3.setName("column3");
column3.setFieldType(EParameterFieldType.CLOSED_LIST);
List<String> values = new ArrayList<>();
values.add("Value1");
values.add("Value2");
values.add("Value3");
column3.setListItemsValue(values.toArray());
List<String> codeNames = new ArrayList<>();
codeNames.add("column1");
codeNames.add("column2");
codeNames.add("column3");
tableParam.setListItemsDisplayCodeName(codeNames.toArray(new String[0]));
List<IElementParameter> childParams = new ArrayList<>();
childParams.add(column1);
childParams.add(column2);
childParams.add(column3);
tableParam.setListItemsValue(childParams.toArray());
List<Map<String, Object>> table = GenericTableUtils.getTableValues(tableProperties, tableParam);
assertEquals(2, table.size());
Map<String, Object> line1 = table.get(0);
Map<String, Object> line2 = table.get(1);
assertEquals("Text1", line1.get("column1"));
assertEquals(Boolean.TRUE, line1.get("column2"));
assertEquals("Value1", line1.get("column3"));
assertEquals("Text2", line2.get("column1"));
assertEquals(Boolean.FALSE, line2.get("column2"));
assertEquals("Value3", line2.get("column3"));
}
use of org.talend.core.model.process.IElement in project tdi-studio-se by Talend.
the class ExpressionTest method createMockParameter.
private ElementParameter createMockParameter(String paraName, boolean isShow, String showIf) {
ElementParameter param = mock(ElementParameter.class);
IElement testElement = mock(IElement.class);
when(param.getName()).thenReturn(paraName);
if (isShow) {
when(param.isShow(anyList())).thenReturn(isShow);
when(param.isShow(anyString(), anyString(), anyList())).thenReturn(isShow);
} else {
when(param.getShowIf()).thenReturn(showIf);
}
when(param.getElement()).thenReturn(testElement);
when(param.getElement().getElementName()).thenReturn("testComponent");
return param;
}
use of org.talend.core.model.process.IElement in project tdi-studio-se by Talend.
the class AbstractPreferenceComposite method addButtonListeners.
private void addButtonListeners() {
reloadBtn.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
onReloadButtonClick();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
saveBtn.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
onSaveButtonClick();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
if (hasRunJobNode(false) && needApplyToChildren()) {
applyToChildrenJob.addSelectionListener(new SelectionListener() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
// zli for bug 12335
final ProgressDialog progress = new ProgressDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()) {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorReference[] editorReferences = activePage.getEditorReferences();
CorePlugin defaultPlugin = CorePlugin.getDefault();
IDesignerCoreService designerCoreService = defaultPlugin.getDesignerCoreService();
List<IProcess2> openedProcessList = designerCoreService.getOpenedProcess(RepositoryUpdateManager.getEditors());
List<String> activeProcessId = new ArrayList<String>();
for (IProcess process : openedProcessList) {
activeProcessId.add(process.getId());
}
final int rate = 1 / openedProcessList.size() - activeProcessId.size();
for (INode runjobNode : tRunJobNodes) {
String id = (String) runjobNode.getElementParameter(EParameterName.PROCESS_TYPE_PROCESS.getName()).getValue();
String version = (String) runjobNode.getElementParameter(EParameterName.PROCESS_TYPE_VERSION.getName()).getValue();
if ("".equals(id) || id == null) {
//$NON-NLS-1$
MessageDialog.openWarning(getShell(), //$NON-NLS-1$
Messages.getString("AbstractPreferenceComposite.warning", runjobNode.getUniqueName()), Messages.getString("AbstractPreferenceComposite.jobAssigned", //$NON-NLS-1$
runjobNode.getUniqueName()));
return;
}
if (activeProcessId.contains(id)) {
IEditorPart activeEditorPart = activePage.getActiveEditor();
for (IEditorReference editorReference : editorReferences) {
IEditorPart editorPart = editorReference.getEditor(false);
if ((editorPart != activeEditorPart) && (editorPart instanceof MultiPageTalendEditor)) {
IElement element = ((MultiPageTalendEditor) editorPart).getProcess();
StatsAndLogsViewHelper.applySettings(elem, element, AbstractPreferenceComposite.this);
}
}
} else {
try {
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1 * UpdatesConstants.SCALE, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask(UpdatesConstants.EMPTY, 1 * rate);
IRepositoryViewObject lastVersion = DesignerPlugin.getDefault().getProxyRepositoryFactory().getLastVersion(id);
if (lastVersion != null) {
Item item = lastVersion.getProperty().getItem();
IProcess processFromItem = designerCoreService.getProcessFromItem(item);
if (processFromItem instanceof Process) {
Process process = (Process) processFromItem;
StatsAndLogsViewHelper.applySettings(elem, process, AbstractPreferenceComposite.this);
IProxyRepositoryFactory factory = defaultPlugin.getProxyRepositoryFactory();
Property property = factory.getUptodateProperty(process.getProperty());
process.setProperty(property);
subMonitor.subTask(RepositoryUpdateManager.getUpdateJobInfor(process.getProperty()));
ProcessType processType = process.saveXmlFile();
Item item2 = process.getProperty().getItem();
if (item2 instanceof JobletProcessItem) {
((JobletProcessItem) item2).setJobletProcess((JobletProcess) processType);
} else {
((ProcessItem) item2).setProcess(processType);
}
factory.save(item2);
subMonitor.done();
}
}
} catch (PersistenceException e1) {
e1.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
}
applySettingsToSubJob(id, version);
}
}
};
try {
progress.executeProcess();
} catch (InvocationTargetException e1) {
e1.printStackTrace();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
/**
* yzhang Comment method "applySettingsToSubJob".
*
* @param id
* @param version
*/
private void applySettingsToSubJob(String id, String version) {
final ProcessItem processItem = ItemCacheManager.getProcessItem(id, version);
if (processItem == null) {
return;
}
ProcessType processType = processItem.getProcess();
EList<ElementParameterType> parameters = processType.getParameters().getElementParameter();
StatsAndLogsViewHelper.applySettings(parameters, elem);
List<NodeType> nodes = findRunJobNode(processType.getNode());
for (NodeType nodeType : nodes) {
EList<ElementParameterType> list = nodeType.getElementParameter();
ElementParameterType idParam = getElementParameterType(list, //$NON-NLS-1$
PROCESS + ":" + EParameterName.PROCESS_TYPE_PROCESS.getName());
ElementParameterType versionParam = getElementParameterType(list, //$NON-NLS-1$
PROCESS + ":" + EParameterName.PROCESS_TYPE_VERSION.getName());
String subId = idParam.getValue();
String subVersion = versionParam.getValue();
applySettingsToSubJob(subId, subVersion);
}
}
});
}
}
use of org.talend.core.model.process.IElement in project tdi-studio-se by Talend.
the class AbstractElementPropertySectionController method addRepositoryPropertyListener.
public void addRepositoryPropertyListener(Control control) {
boolean flag = false;
if (this.curParameter != null) {
final EComponentCategory category = this.curParameter.getCategory();
final IElement element = this.curParameter.getElement();
if (element instanceof FakeElement || AbstractPreferenceComposite.inUseProjectSettingMode(element, category, EParameterName.STATANDLOG_USE_PROJECT_SETTINGS) || AbstractPreferenceComposite.inUseProjectSettingMode(element, category, EParameterName.IMPLICITCONTEXT_USE_PROJECT_SETTINGS)) {
// don't add the listener.
flag = true;
}
}
if (!flag) {
control.addMouseListener(listenerSelection);
}
}
Aggregations