FormData data;
customPropertyFields = new ArrayList<CustomPropertyField>();
TabbedPropertySheetWidgetFactory factory = getWidgetFactory();
if (workParent != null) {
workParent.dispose();
}
workParent = factory.createFlatFormComposite(parent);
customServiceTasks = ExtensionUtil.getCustomServiceTasks(ActivitiUiUtil.getProjectFromDiagram(getDiagram()));
final ServiceTask serviceTask = getServiceTask();
if (serviceTask != null) {
CustomServiceTask targetTask = null;
for (final CustomServiceTask customServiceTask : customServiceTasks) {
if (customServiceTask.getId().equals(serviceTask.getExtensionId())) {
targetTask = customServiceTask;
break;
}
}
if (targetTask != null) {
final List<Class<CustomServiceTask>> classHierarchy = new ArrayList<Class<CustomServiceTask>>();
final List<FieldInfo> fieldInfoObjects = new ArrayList<FieldInfo>();
Class clazz = targetTask.getClass();
classHierarchy.add(clazz);
boolean hierarchyOpen = true;
while (hierarchyOpen) {
clazz = clazz.getSuperclass();
if (CustomServiceTask.class.isAssignableFrom(clazz)) {
classHierarchy.add(clazz);
} else {
hierarchyOpen = false;
}
}
for (final Class<CustomServiceTask> currentClass : classHierarchy) {
for (final Field field : currentClass.getDeclaredFields()) {
if (field.isAnnotationPresent(Property.class)) {
fieldInfoObjects.add(new FieldInfo(field));
}
}
}
// Sort the list so the fields are in the correct order
Collections.sort(fieldInfoObjects);
Control previousAnchor = workParent;
final CLabel labelNodeName = factory.createCLabel(workParent, targetTask.getName(), SWT.NONE);
labelNodeName.setFont(boldFont);
data = new FormData();
data.top = new FormAttachment(previousAnchor, VSPACE);
labelNodeName.setLayoutData(data);
previousAnchor = labelNodeName;
if (targetTask.getClass().isAnnotationPresent(Help.class)) {
final Help helpAnnotation = targetTask.getClass().getAnnotation(Help.class);
final CLabel labelShort = factory.createCLabel(workParent, helpAnnotation.displayHelpShort(), SWT.WRAP);
data = new FormData();
data.top = new FormAttachment(previousAnchor, VSPACE);
labelShort.setLayoutData(data);
labelShort.setFont(italicFont);
previousAnchor = labelShort;
final CLabel labelLong = factory.createCLabel(workParent, helpAnnotation.displayHelpLong(), SWT.WRAP);
data = new FormData();
data.top = new FormAttachment(previousAnchor);
data.left = new FormAttachment(workParent, HSPACE, SWT.LEFT);
data.right = new FormAttachment(100, -HSPACE);
labelLong.setLayoutData(data);
previousAnchor = labelLong;
}
for (final FieldInfo fieldInfo : fieldInfoObjects) {
final Property property = fieldInfo.getPropertyAnnotation();
Control createdControl = null;
CustomPropertyField createdCustomPropertyField = null;
switch (property.type()) {
case TEXT:
createdCustomPropertyField = new CustomPropertyTextField(this, serviceTask, fieldInfo.getField());
createdControl = createdCustomPropertyField.render(workParent, factory, listener);
data = new FormData();
data.top = new FormAttachment(previousAnchor, VSPACE);
data.left = new FormAttachment(0, LABEL_COLUMN_WIDTH);
data.right = new FormAttachment(100, -HELP_COLUMN_WIDTH);
createdControl.setLayoutData(data);
break;
case MULTILINE_TEXT:
createdCustomPropertyField = new CustomPropertyMultilineTextField(this, serviceTask, fieldInfo.getField());
createdControl = createdCustomPropertyField.render(workParent, factory, listener);
data = new FormData();
data.top = new FormAttachment(previousAnchor, VSPACE);
data.left = new FormAttachment(0, LABEL_COLUMN_WIDTH);
data.right = new FormAttachment(100, -HELP_COLUMN_WIDTH);
data.height = 80;
createdControl.setLayoutData(data);
break;
case PERIOD:
createdCustomPropertyField = new CustomPropertyPeriodField(this, serviceTask, fieldInfo.getField());
createdControl = createdCustomPropertyField.render(workParent, factory, listener);
data = new FormData();
data.top = new FormAttachment(previousAnchor, VSPACE);
data.left = new FormAttachment(0, LABEL_COLUMN_WIDTH);
data.right = new FormAttachment(100, -HELP_COLUMN_WIDTH);
createdControl.setLayoutData(data);
break;
case BOOLEAN_CHOICE:
createdCustomPropertyField = new CustomPropertyBooleanChoiceField(this, serviceTask, fieldInfo.getField());
createdControl = createdCustomPropertyField.render(workParent, factory, listener);
data = new FormData();
data.top = new FormAttachment(previousAnchor, VSPACE);
data.left = new FormAttachment(0, LABEL_COLUMN_WIDTH);
data.right = new FormAttachment(100, -HELP_COLUMN_WIDTH);
createdControl.setLayoutData(data);
break;
case COMBOBOX_CHOICE:
createdCustomPropertyField = new CustomPropertyComboboxChoiceField(this, serviceTask, fieldInfo.getField());
createdControl = createdCustomPropertyField.render(workParent, factory, listener);
data = new FormData();
data.top = new FormAttachment(previousAnchor, VSPACE);
data.left = new FormAttachment(0, LABEL_COLUMN_WIDTH);
data.right = new FormAttachment(100, -HELP_COLUMN_WIDTH);
createdControl.setLayoutData(data);
break;
case RADIO_CHOICE:
createdCustomPropertyField = new CustomPropertyRadioChoiceField(this, serviceTask, fieldInfo.getField());
createdControl = createdCustomPropertyField.render(workParent, factory, listener);
data = new FormData();
data.top = new FormAttachment(previousAnchor, VSPACE);
data.left = new FormAttachment(0, LABEL_COLUMN_WIDTH);
data.right = new FormAttachment(100, -HELP_COLUMN_WIDTH);
createdControl.setLayoutData(data);
break;
case DATE_PICKER:
createdCustomPropertyField = new CustomPropertyDatePickerField(this, serviceTask, fieldInfo.getField());
createdControl = createdCustomPropertyField.render(workParent, factory, listener);
data = new FormData();
data.top = new FormAttachment(previousAnchor, VSPACE);
data.left = new FormAttachment(0, LABEL_COLUMN_WIDTH);
data.right = new FormAttachment(100, -HELP_COLUMN_WIDTH);
createdControl.setLayoutData(data);
break;
}
customPropertyFields.add(createdCustomPropertyField);
previousAnchor = createdControl;
// Create a label for the field
String displayName = property.displayName();
if (StringUtils.isBlank(property.displayName())) {
displayName = fieldInfo.getFieldName();
}
if (property.required()) {
displayName += PROPERTY_REQUIRED_DISPLAY;
}
displayName += ": ";
final CLabel propertyLabel = factory.createCLabel(workParent, displayName); //$NON-NLS-1$
data = new FormData();
data.top = new FormAttachment(createdControl, 0, SWT.TOP);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(createdControl, -HSPACE);
propertyLabel.setLayoutData(data);
// Create a help button for the field
final Help help = fieldInfo.getHelpAnnotation();
if (help != null) {
final Button propertyHelp = factory.createButton(workParent, "", SWT.BUTTON1);
propertyHelp.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_LCL_LINKTO_HELP));
// create a tooltip
final ToolTip tooltip = new FormToolTip(propertyHelp, String.format("Help for field %s",
property.displayName().equals("") ? fieldInfo.getFieldName() : property.displayName()), help.displayHelpShort(), help.displayHelpLong());