Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@

package org.activiti.designer.property.extension.field;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.activiti.bpmn.model.ServiceTask;
import org.activiti.designer.integration.servicetask.PropertyType;
import org.activiti.designer.integration.servicetask.annotation.PropertyItems;
import org.activiti.designer.integration.servicetask.annotation.PropertyItemsDataSource;
import org.activiti.designer.integration.servicetask.validator.RequiredFieldValidator;
import org.activiti.designer.property.PropertyCustomServiceTaskSection;
import org.eclipse.swt.SWT;
Expand All @@ -40,6 +49,7 @@ public class CustomPropertyComboboxChoiceField extends AbstractCustomPropertyFie

private CCombo comboControl;
private PropertyItems propertyItemsAnnotation;
private PropertyItemsDataSource propertyItemsDataSource;

private Map<String, String> values;

Expand Down Expand Up @@ -102,6 +112,77 @@ public Composite render(final Composite parent, final TabbedPropertySheetWidgetF
}
}
}

/*
* Load values from the annotation data source and append them to the values and labels.
*
* If necessary, initialize both variables.
*/
if(propertyItemsDataSource == null) {
propertyItemsDataSource = getField().getAnnotation(PropertyItemsDataSource.class);
if(propertyItemsDataSource != null) {

String filename = propertyItemsDataSource.filename();
if(filename != null) {

FileReader fr = null;
BufferedReader br = null;
try {
File file = new File(filename);
if(!file.isFile()) {
throw new IllegalArgumentException("Unable to find file: "+file.getAbsolutePath());
}
fr = new FileReader(file);
br = new BufferedReader(fr);

List<String> valueList = new ArrayList<String>();
String line = null;
while((line=br.readLine()) != null) {
valueList.add(line);
}

if(values == null) {
values = new HashMap<String, String>();
}

List<String> labelList = new ArrayList<String>();

if(labels != null) {
labelList.addAll(Arrays.asList(labels));
}

for(int i = 0; i < valueList.size(); i+=2) {
values.put(valueList.get(i+1), valueList.get(i));
labelList.add(valueList.get(i));
}

labels = labelList.toArray(new String[labelList.size()]);
} catch (FileNotFoundException e) {
e.printStackTrace();
throw new IllegalArgumentException("Unable to find file "+filename);
} catch (IOException e) {
throw new IllegalArgumentException("Unable to read file "+filename);
} finally {
if(br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fr != null) {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} else {
throw new IllegalArgumentException("The filename is mandatory");
}
}
}

comboControl = factory.createCCombo(result, SWT.DROP_DOWN);
comboControl.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
@Target(ElementType.FIELD)
public @interface PropertyItems {

public static final String[] DEFAULT_VALUE = new String[] {};

/**
* The items.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
*
*/
package org.activiti.designer.integration.servicetask.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author André Macedo
* @version 1
* @since 5.16.0
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface PropertyItemsDataSource {
abstract String filename();
}