use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class SapSchemaTypeController method estimateRowSize.
/*
* (non-Javadoc)
*
* @see org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController#
* estimateRowSize (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter)
*/
@Override
public int estimateRowSize(Composite subComposite, IElementParameter param) {
int comboSize, buttonSize;
CCombo combo = new CCombo(subComposite, SWT.BORDER);
IElementParameter schemaTypeParameter = param.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
// elem.getElementParameter(EParameterName.SCHEMA_TYPE.getName());
String[] originalList = schemaTypeParameter.getListItemsDisplayName();
combo.setItems(originalList);
comboSize = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
combo.dispose();
//$NON-NLS-1$
Button btn = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
buttonSize = btn.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
btn.dispose();
return Math.max(comboSize, buttonSize) + ITabbedPropertyConstants.VSPACE;
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class JavaCommandController method createControl.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController#createControl
* (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
* org.eclipse.swt.widgets.Control)
*/
@Override
public Control createControl(Composite subComposite, final IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
Button btnEdit;
//$NON-NLS-1$
btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
FormData data;
btnEdit.setData(NAME, JAVA_COMMAND);
btnEdit.setData(PARAMETER_NAME, param.getName());
btnEdit.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@Override
public void widgetSelected(SelectionEvent e) {
// execute Java Command
ElementParameter fullParam = (ElementParameter) param;
File jar;
URL url;
try {
List<URL> listURL = new ArrayList<URL>();
ILibraryManagerService libManager = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
IFolder javaLibFolder = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
if (talendProcessJavaProject != null) {
javaLibFolder = talendProcessJavaProject.getLibFolder();
}
}
if (javaLibFolder == null) {
return;
}
for (String jarString : fullParam.getJar().split(";")) {
IPath libPath = javaLibFolder.getLocation();
libManager.retrieve(jarString, libPath.toPortableString(), new NullProgressMonitor());
jar = libPath.append(jarString).toFile();
url = jar.toURL();
listURL.add(url);
}
URLClassLoader urlClassLoader = new URLClassLoader(listURL.toArray(new URL[0]));
Class<?> classLoaded = Class.forName(fullParam.getJavaClass(), true, urlClassLoader);
Object object = classLoaded.newInstance();
List<String> args = new ArrayList<String>();
for (String arg : fullParam.getArgs()) {
args.add(ElementParameterParser.parse(elem, arg));
}
for (Method method : classLoaded.getDeclaredMethods()) {
if (method.getName().equals(fullParam.getJavaFunction())) {
Object[] arglist = new Object[1];
arglist[0] = args.toArray(new String[0]);
method.invoke(object, arglist);
}
}
} catch (Exception e1) {
MessageBoxExceptionHandler.process(e1);
}
}
});
if (elem instanceof Node) {
btnEdit.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
}
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);
}
// **************************
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);
data.right = new FormAttachment(lastControl, currentLabelWidth + STANDARD_BUTTON_WIDTH);
} else {
data.left = new FormAttachment(0, currentLabelWidth);
data.right = new FormAttachment(0, currentLabelWidth + STANDARD_BUTTON_WIDTH);
}
} else {
data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
data.right = new FormAttachment(labelLabel, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
}
data.top = new FormAttachment(0, top);
btnEdit.setLayoutData(data);
// **************************
hashCurControls.put(param.getName(), btnEdit);
Point initialSize = btnEdit.computeSize(SWT.DEFAULT, SWT.DEFAULT);
dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
return btnEdit;
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class ProcessController method refreshCombo.
/**
*
* ggu Comment method "refreshCombo".
*
*/
private void refreshCombo(IElementParameter parentParam, final String childParamName) {
if (parentParam == null || childParamName == null) {
return;
}
IElementParameter childParameter = parentParam.getChildParameters().get(childParamName);
CCombo combo = (CCombo) hashCurControls.get(childParameter.getName());
if (combo == null || combo.isDisposed()) {
return;
}
Object value = childParameter.getValue();
if (value instanceof String) {
//$NON-NLS-1$
String strValue = "";
int nbInList = 0, nbMax = childParameter.getListItemsValue().length;
String name = (String) value;
while (strValue.equals(new String("")) && nbInList < nbMax) {
//$NON-NLS-1$
if (name.equals(childParameter.getListItemsValue()[nbInList])) {
strValue = childParameter.getListItemsDisplayName()[nbInList];
}
nbInList++;
}
String[] paramItems = getListToDisplay(childParameter);
String[] comboItems = combo.getItems();
if (!Arrays.equals(paramItems, comboItems)) {
combo.setItems(paramItems);
}
combo.setText(strValue);
combo.setVisible(true);
}
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class ModuleListController method createCommand.
public Command createCommand(SelectionEvent selectionEvent) {
Set<String> elementsName;
Control ctrl;
elementsName = hashCurControls.keySet();
for (String name : elementsName) {
Object o = hashCurControls.get(name);
if (o instanceof Control) {
ctrl = (Control) o;
if (ctrl == null) {
hashCurControls.remove(name);
return null;
}
if (ctrl.equals(selectionEvent.getSource()) && ctrl instanceof CCombo) {
boolean isDisposed = ((CCombo) ctrl).isDisposed();
if (!isDisposed && (!elem.getPropertyValue(name).equals(((CCombo) ctrl).getText()))) {
//$NON-NLS-1$
String value = new String("");
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getName().equals(name)) {
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (((CCombo) ctrl).getText().equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
}
}
if (value.equals(elem.getPropertyValue(name))) {
// anything
return null;
}
CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
return new PropertyChangeCommand(elem, name, value);
}
}
}
}
return null;
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class OpenedListController method modifyCommand.
/**
* DOC zli Comment method "modifyCommand".
*
* @param event
* @return
*/
private Command modifyCommand(ModifyEvent event) {
Set<String> elementsName;
Control ctrl;
elementsName = hashCurControls.keySet();
for (String name : elementsName) {
Object o = hashCurControls.get(name);
if (o instanceof Control) {
ctrl = (Control) o;
if (ctrl == null) {
hashCurControls.remove(name);
return null;
}
CCombo combo = (CCombo) event.getSource();
Object data = ctrl.getData(PARAMETER_NAME);
if (!(ctrl instanceof CCombo)) {
continue;
}
boolean isDisposed = ((CCombo) ctrl).isDisposed() || combo.isDisposed();
if (isDisposed) {
continue;
}
String paramName = "";
if (data != null) {
paramName = data.toString();
}
String value = "";
if (data != null && data.equals(combo.getData(PARAMETER_NAME))) {
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getFieldType().equals(EParameterFieldType.OPENED_LIST) && paramName.equals(param.getName())) {
String text = ((CCombo) ctrl).getText();
String[] listItemsDisplayName = param.getListItemsDisplayName();
boolean valueSet = false;
Object[] listItemsValue = param.getListItemsValue();
for (int j = 0; j < listItemsValue.length; j++) {
if (j < listItemsDisplayName.length && text.equals(listItemsDisplayName[j])) {
value = (String) listItemsValue[j];
valueSet = true;
break;
}
}
if (!valueSet) {
value = text;
}
// TDI-21313
if (value != null && value.equals(param.getValue())) {
return null;
}
param.setValue(value);
}
}
return new PropertyChangeCommand(elem, paramName, value);
}
}
}
return null;
}
Aggregations