Author Message
MichaelDailous_deprecated
Joined: Nov 11, 2013
Messages: 171
Offline
In creating a PDC, I have a need to allow the user to select variables that meet a set of criteria. For example, only list complex variables that have fieldA and fieldB, don't show any other complex variables or simple variables. Something similar to how the InvokeLocal input/output variable selectors work.

Is this possible within a PDC?

Thank you,
Michael
RossYakulis
Joined: Nov 6, 2013
Messages: 2652
Offline
Yes but more complicated. Stay tuned for a code sample probably tomorrow morning.
RossYakulis
Joined: Nov 6, 2013
Messages: 2652
Offline

Normally you would write:

addVariablePropertyDescriptors(list,
new PropDescData(FlowItem.PROP_RESULT_VAR, "Result Variable","The variable that receives the result."),
new PropDescData(FlowItem.PROP_RESULT_VARFIELD, "Result Variable Field", "The variable field that receives the result."),
null);


Which ends up calling



protected final void addVariablePropertyDescriptors(List<IPropertyDescriptor> list, PropDescData var, PropDescData field,
PropDescData constant, boolean constLast) {
if (var == null || field == null) {
throw new IllegalArgumentException("Variable descriptor data is not valid.");
}

// add constant if it is supposed to be first.
if (constant != null && !constLast) {
addTextPropertyDescriptor(list, constant.propId, constant.display, constant.description);
}

// store the data for the variable/field/constant so we can handle get/set property later on
addVarPropIdHolder(new VarPropIdHolder(var, field, constant));

// add variable
String[] variables = getProjectVariables();
addEnumPropertyDescriptor(list, var.propId, variables, var.display, var.description);

// add field for complex variables
String varName = getFlowItem().getProperty(var.propId);
String[] fields = getVariableFields(varName);
addEnumPropertyDescriptor(list, field.propId, fields, field.display, field.description);

// add const
if (constant != null && constLast) {
addTextPropertyDescriptor(list, constant.propId, constant.display, constant.description);
}
}



You would need to copy the above and instead of using getProjectVariables, substuite your own method. As an example, the following method return variables that match the input field list.



protected String[] getVariableWithMatchingFields(String[] fields) {
CallFlowEditor cfe = (CallFlowEditor) getMultiPageEditor();
Collection c = cfe.getProjectVariables();
ArrayList<String> vars = new ArrayList<String>();
for (Iterator iter = c.iterator(); iter.hasNext();) {
IVariableInfo var = (IVariableInfo) iter.next();
if (var.isComplex() == true) {
String[] temp = ((IComplexVariableInfo) var).getFieldNames();
boolean match = true;
if (temp.length == fields.length) {
for (int i = 0; i < temp.length; i++) {
if (temp[i].equalsIgnoreCase(fields[i]) == false) {
match = false;
break;
}
}
} else {
match = false;
}
if (match == true) {
vars.add(var.getName());
}
}
}
return (vars.toArray(new String[0]));
}

MichaelDailous_deprecated
Joined: Nov 11, 2013
Messages: 171
Offline
Thanks Ross. That's close to what I need and definitely points me in the right direction. I'm not adding the variable fields portion of the property descriptors, so using the addEnumPropertyDescriptor suites my needs.

Thanks again. :)
Michael
Go to:   
Mobile view