use of org.talend.designer.core.model.FakeElement in project tdi-studio-se by Talend.
the class GenericConnWizardPage method createControl.
@Override
public void createControl(final Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
container.setLayout(new FormLayout());
setControl(container);
baseElement = new FakeElement(form.getName());
baseElement.setReadOnly(!isRepositoryObjectEditable);
dynamicComposite = new DynamicComposite(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS, EComponentCategory.BASIC, baseElement, true, container.getBackground(), form, false);
dynamicComposite.setLayoutData(createMainFormData(addContextFields));
dynamicComposite.setWizardPropertyChangeListener(this);
dynamicComposite.setConnectionItem(connectionItem);
addCheckListener(dynamicComposite.getChecker());
if (addContextFields) {
Composite contextParentComp = new Composite(container, SWT.NONE);
contextParentComp.setLayoutData(createFooterFormData(dynamicComposite));
contextParentComp.setLayout(new GridLayout());
ContextComposite contextComp = addContextFields(contextParentComp);
contextComp.addPropertyChangeListener(dynamicComposite);
contextComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
}
use of org.talend.designer.core.model.FakeElement in project tdi-studio-se by Talend.
the class TextController method createControl.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createControl()
*/
@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
this.curParameter = param;
this.paramFieldType = param.getFieldType();
FormData data;
final DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new SelectAllTextControlCreator());
if (param.isRequired()) {
FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
}
if (canAddRepositoryDecoration(param)) {
FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
//$NON-NLS-1$
decoration.setDescription(Messages.getString("TextController.decoration.description"));
dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
}
Control cLayout = dField.getLayoutControl();
Text labelText = (Text) dField.getControl();
labelText.setData(PARAMETER_NAME, param.getName());
editionControlHelper.register(param.getName(), labelText);
cLayout.setBackground(subComposite.getBackground());
if (elem instanceof Node) {
labelText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
}
if (!isReadOnly()) {
if (param.isRepositoryValueUsed() && !(elem instanceof org.talend.designer.core.ui.editor.process.Process || elem instanceof StatsAndLogsElement || elem instanceof ImplicitContextLoadElement)) {
addRepositoryPropertyListener(labelText);
}
if (param.isRequired()) {
labelText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
checkTextError(param, labelText, labelText.getText());
}
});
}
boolean editable = !param.isReadOnly() && (elem instanceof FakeElement || !param.isRepositoryValueUsed());
labelText.setEditable(editable);
} else {
labelText.setEditable(false);
}
addDragAndDropTarget(labelText);
CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
data = new FormData();
if (lastControl != null) {
data.left = new FormAttachment(lastControl, 0);
} else {
data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
}
data.top = new FormAttachment(0, top);
labelLabel.setLayoutData(data);
// *********************
data = new FormData();
int currentLabelWidth = STANDARD_LABEL_WIDTH;
GC gc = new GC(labelLabel);
Point labelSize = gc.stringExtent(param.getDisplayName());
gc.dispose();
if ((labelSize.x + (ITabbedPropertyConstants.HSPACE * 2)) > currentLabelWidth) {
currentLabelWidth = labelSize.x + (ITabbedPropertyConstants.HSPACE * 2);
}
if (numInRow == 1) {
if (lastControl != null) {
data.left = new FormAttachment(lastControl, currentLabelWidth);
} else {
data.left = new FormAttachment(0, currentLabelWidth);
}
} else {
data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
}
data.right = new FormAttachment((numInRow * MAX_PERCENT) / nbInRow, 0);
data.top = new FormAttachment(0, top);
cLayout.setLayoutData(data);
// **********************
hashCurControls.put(param.getName(), labelText);
Point initialSize = cLayout.computeSize(SWT.DEFAULT, SWT.DEFAULT);
// curRowSize = initialSize.y + ITabbedPropertyConstants.VSPACE;
dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
if (isInWizard()) {
labelLabel.setAlignment(SWT.RIGHT);
if (lastControl != null) {
data.right = new FormAttachment(lastControl, 0);
} else {
data.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
}
data.left = new FormAttachment((((nbInRow - numInRow) * MAX_PERCENT) / nbInRow), currentLabelWidth + ITabbedPropertyConstants.HSPACE);
data = (FormData) labelLabel.getLayoutData();
data.right = new FormAttachment(cLayout, 0);
data.left = new FormAttachment((((nbInRow - numInRow) * MAX_PERCENT) / nbInRow), 0);
return labelLabel;
}
return cLayout;
}
use of org.talend.designer.core.model.FakeElement 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.designer.core.model.FakeElement in project tdi-studio-se by Talend.
the class ComponentsUtils method getParametersFromForm.
/**
* DOC ycbai Comment method "loadParametersFromForm".
* <p>
* Get element parameters of <code>element</code> from <code>form</code>.
*
* @param node optional, used if there is a component setting up the properties
* @param element
* @param category
* @param form
* @return parameters list
*/
private static List<ElementParameter> getParametersFromForm(IElement element, boolean isInitializing, EComponentCategory category, ComponentProperties rootProperty, Properties compProperties, String parentPropertiesPath, Form form, Widget parentWidget, AtomicInteger lastRowNum) {
List<ElementParameter> elementParameters = new ArrayList<>();
List<String> parameterNames = new ArrayList<>();
EComponentCategory compCategory = category;
if (compCategory == null) {
compCategory = EComponentCategory.BASIC;
}
AtomicInteger lastRN = lastRowNum;
if (lastRN == null) {
lastRN = new AtomicInteger();
}
if (form == null) {
return elementParameters;
}
Properties componentProperties = compProperties;
if (componentProperties == null) {
componentProperties = form.getProperties();
}
if (element instanceof INode) {
INode node = (INode) element;
// Set the properties only one time to get the top-level properties object
if (node.getComponentProperties() == null) {
node.setComponentProperties(rootProperty);
}
}
// Have to initialize for the messages
Collection<Widget> formWidgets = form.getWidgets();
for (Widget widget : formWidgets) {
NamedThing widgetProperty = widget.getContent();
String propertiesPath = getPropertiesPath(parentPropertiesPath, null);
if (widgetProperty instanceof Form) {
Form subForm = (Form) widgetProperty;
Properties subProperties = subForm.getProperties();
// Reset properties path
if (!isSameComponentProperties(componentProperties, widgetProperty)) {
propertiesPath = getPropertiesPath(parentPropertiesPath, subProperties.getName());
}
elementParameters.addAll(getParametersFromForm(element, isInitializing, compCategory, rootProperty, subProperties, propertiesPath, subForm, widget, lastRN));
continue;
}
GenericElementParameter param = new GenericElementParameter(element, rootProperty, form, widget, getComponentService());
String parameterName = propertiesPath.concat(param.getName());
param.setName(parameterName);
param.setCategory(compCategory);
param.setShow(parentWidget == null ? !widget.isHidden() : !parentWidget.isHidden() && !widget.isHidden());
int rowNum = 0;
if (widget.getOrder() != 1) {
rowNum = lastRN.get();
} else {
rowNum = widget.getRow();
if (parentWidget != null) {
rowNum += parentWidget.getRow();
}
rowNum = rowNum + lastRN.get();
}
param.setNumRow(rowNum);
lastRN.set(rowNum);
// handle form...
EParameterFieldType fieldType = getFieldType(widget, widgetProperty);
param.setFieldType(fieldType != null ? fieldType : EParameterFieldType.TEXT);
if (widgetProperty instanceof SchemaProperty) {
boolean found = false;
// set a default connector
param.setContext(EConnectionType.FLOW_MAIN.getName());
for (Connector connector : rootProperty.getPossibleConnectors(true)) {
if (!(((SchemaProperty) widgetProperty).getValue() instanceof Schema)) {
continue;
}
if (connector instanceof PropertyPathConnector) {
//$NON-NLS-1$
String linkedSchema = ((PropertyPathConnector) connector).getPropertyPath() + ".schema";
if (parameterName.equals(linkedSchema)) {
found = true;
param.setContext(connector.getName());
IElementParameterDefaultValue defaultValue = new ElementParameterDefaultValue();
Schema schema = ((SchemaProperty) widgetProperty).getValue();
defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
param.getDefaultValues().add(defaultValue);
}
}
}
if (!found) {
// compatibility.
for (Connector connector : rootProperty.getPossibleConnectors(false)) {
if (!(((SchemaProperty) widgetProperty).getValue() instanceof Schema)) {
continue;
}
if (connector instanceof PropertyPathConnector) {
//$NON-NLS-1$
String linkedSchema = ((PropertyPathConnector) connector).getPropertyPath() + ".schema";
if (parameterName.equals(linkedSchema)) {
if (GenericNodeConnector.INPUT_CONNECTOR.equals(connector.getName())) {
param.setContext(EConnectionType.FLOW_MAIN.getName());
} else {
param.setContext(connector.getName());
}
IElementParameterDefaultValue defaultValue = new ElementParameterDefaultValue();
Schema schema = ((SchemaProperty) widgetProperty).getValue();
defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
param.getDefaultValues().add(defaultValue);
}
}
}
}
}
if (widgetProperty instanceof PresentationItem) {
param.setValue(widgetProperty.getDisplayName());
} else if (widgetProperty instanceof Property) {
Property property = (Property) widgetProperty;
param.setRequired(property.isRequired());
param.setValue(getParameterValue(element, property, fieldType));
boolean isNameProperty = IGenericConstants.NAME_PROPERTY.equals(param.getParameterName());
if (EParameterFieldType.NAME_SELECTION_AREA.equals(fieldType) || EParameterFieldType.JSON_TABLE.equals(fieldType) || EParameterFieldType.CLOSED_LIST.equals(fieldType) || EParameterFieldType.CHECK.equals(fieldType) || isNameProperty) {
// Disable context support for those filed types and name parameter.
param.setSupportContext(false);
} else {
param.setSupportContext(isSupportContext(property));
}
property.setTaggedValue(IComponentConstants.SUPPORT_CONTEXT, param.isSupportContext());
Object cmTV = property.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE);
param.setReadOnly(Boolean.valueOf(String.valueOf(cmTV)));
boolean isDynamic = Boolean.valueOf(String.valueOf(property.getTaggedValue(IGenericConstants.IS_DYNAMIC)));
param.setContextMode(isDynamic);
List<?> values = property.getPossibleValues();
if (values != null || EParameterFieldType.CLOSED_LIST.equals(fieldType)) {
if (values == null) {
values = Collections.emptyList();
}
param.setPossibleValues(values);
List<String> possVals = new ArrayList<>();
List<String> possValsDisplay = new ArrayList<>();
for (Object obj : values) {
String value = null;
String valueDisplay = null;
if (obj instanceof NamedThing) {
NamedThing nal = (NamedThing) obj;
value = nal.getName();
valueDisplay = nal.getDisplayName();
} else {
value = String.valueOf(obj);
valueDisplay = String.valueOf(obj);
}
String pvDisplayName = property.getPossibleValuesDisplayName(obj);
if (StringUtils.isNotBlank(pvDisplayName) && !"null".equals(pvDisplayName)) {
//$NON-NLS-1$
valueDisplay = pvDisplayName;
}
possVals.add(value);
possValsDisplay.add(valueDisplay);
}
param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
param.setListItemsDisplayCodeName(possValsDisplay.toArray(new String[0]));
param.setListItemsValue(possVals.toArray(new String[0]));
}
} else if (fieldType != null && fieldType.equals(EParameterFieldType.TABLE) && widgetProperty instanceof Properties) {
Properties table = (Properties) widgetProperty;
Form mainForm = table.getForm(Form.MAIN);
param.setDisplayName(mainForm.getTitle());
//$NON-NLS-1$
List<ElementParameter> parameters = getParametersFromForm(new FakeElement("table"), mainForm);
// table is always empty by default
param.setSupportContext(false);
List<String> codeNames = new ArrayList<>();
List<String> possValsDisplay = new ArrayList<>();
for (ElementParameter curParam : parameters) {
curParam.setFilter(null);
curParam.setContext(null);
curParam.setShowIf(null);
curParam.setNotShowIf(null);
curParam.setReadOnlyIf(null);
curParam.setNotReadOnlyIf(null);
curParam.setNoContextAssist(false);
curParam.setRaw(false);
curParam.setReadOnly(false);
fillDefaultValsForListType(curParam);
codeNames.add(curParam.getName());
possValsDisplay.add(curParam.getDisplayName());
}
param.setListItemsDisplayName(possValsDisplay.toArray(new String[0]));
param.setListItemsDisplayCodeName(codeNames.toArray(new String[0]));
param.setListItemsValue(parameters.toArray(new ElementParameter[0]));
String[] listItemsShowIf = new String[parameters.size()];
String[] listItemsNotShowIf = new String[parameters.size()];
param.setListItemsShowIf(listItemsShowIf);
param.setListItemsNotShowIf(listItemsNotShowIf);
param.setValue(GenericTableUtils.getTableValues(table, param));
param.setBasedOnSchema(Boolean.valueOf(String.valueOf(widget.getConfigurationValue(Widget.HIDE_TOOLBAR_WIDGET_CONF))));
}
if (!param.isReadOnly()) {
param.setReadOnly(widget.isReadonly() || element.isReadOnly());
}
// For issue TUP-16139
if (EParameterFieldType.COMPONENT_REFERENCE.equals(fieldType) && param.getNumRow() == 2 && EComponentCategory.BASIC.equals(compCategory)) {
param.setNumRow(1);
}
param.setSerialized(true);
param.setDynamicSettings(true);
// Avoid adding duplicate prameter.
if (!parameterNames.contains(parameterName)) {
elementParameters.add(param);
parameterNames.add(parameterName);
}
}
return elementParameters;
}
use of org.talend.designer.core.model.FakeElement in project tdi-studio-se by Talend.
the class FileController method createControl.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createControl()
*/
@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
this.setDragAndDropActionBool();
this.curParameter = param;
FormData data;
CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
data = new FormData();
if (lastControl != null) {
data.left = new FormAttachment(lastControl, 0);
} else {
data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
}
data.top = new FormAttachment(0, top);
labelLabel.setLayoutData(data);
if (numInRow != 1) {
labelLabel.setAlignment(SWT.RIGHT);
}
//$NON-NLS-1$
Button btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
data = new FormData();
data.left = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), -STANDARD_BUTTON_WIDTH);
data.right = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), 0);
data.top = new FormAttachment(labelLabel, 0, SWT.CENTER);
data.height = STANDARD_HEIGHT - 2;
btnEdit.setLayoutData(data);
btnEdit.setData(NAME, FILE);
btnEdit.setData(PARAMETER_NAME, param.getName());
btnEdit.setEnabled(dragAndDropActionBool == true || !param.isReadOnly());
btnEdit.addSelectionListener(listenerSelection);
DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new SelectAllTextControlCreator());
if (param.isRequired()) {
FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
}
if (canAddRepositoryDecoration(param)) {
FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
//$NON-NLS-1$
decoration.setDescription(Messages.getString("FileController.decoration.description"));
dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
}
Control cLayout = dField.getLayoutControl();
Text filePathText = (Text) dField.getControl();
filePathText.setData(PARAMETER_NAME, param.getName());
cLayout.setBackground(subComposite.getBackground());
editionControlHelper.register(param.getName(), filePathText);
if (!elem.isReadOnly()) {
if (param.isRepositoryValueUsed() && dragAndDropActionBool == false) {
addRepositoryPropertyListener(filePathText);
}
filePathText.setEditable(dragAndDropActionBool == true || !param.isRepositoryValueUsed() && !(elem instanceof FakeElement) || !param.isReadOnly() && elem instanceof FakeElement);
} else {
filePathText.setEditable(dragAndDropActionBool == true || false);
}
addDragAndDropTarget(filePathText);
if (elem instanceof Node) {
filePathText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
}
hashCurControls.put(param.getName(), filePathText);
// **************************
data = new FormData();
int currentLabelWidth = STANDARD_LABEL_WIDTH;
GC gc = new GC(labelLabel);
Point labelSize = gc.stringExtent(param.getDisplayName());
gc.dispose();
if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
}
if (numInRow == 1) {
if (lastControl != null) {
data.left = new FormAttachment(lastControl, currentLabelWidth);
} else {
data.left = new FormAttachment(0, currentLabelWidth);
}
} else {
data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
}
data.right = new FormAttachment(btnEdit, 0);
data.top = new FormAttachment(labelLabel, 0, SWT.CENTER);
cLayout.setLayoutData(data);
Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
if (isInWizard()) {
labelLabel.setAlignment(SWT.RIGHT);
if (lastControl != null) {
data.right = new FormAttachment(lastControl, -STANDARD_BUTTON_WIDTH);
} else {
data.right = new FormAttachment(100, -STANDARD_BUTTON_WIDTH - ITabbedPropertyConstants.HSPACE);
}
data.left = new FormAttachment((((nbInRow - numInRow) * MAX_PERCENT) / nbInRow), currentLabelWidth + ITabbedPropertyConstants.HSPACE);
data = (FormData) labelLabel.getLayoutData();
data.right = new FormAttachment(cLayout, 0);
data.left = new FormAttachment((((nbInRow - numInRow) * MAX_PERCENT) / nbInRow), 0);
return labelLabel;
}
return btnEdit;
}
Aggregations