How to get dependent enumaration?
Hi,
i have found the solution for fetching dependent enumation.
Let me know how to pass configuration value to this function.
public List<Identifier<extends>> getValueSet(IAttribute attribute, IWorkItem workItem, IWorkItemCommon workItemCommon,IConfiguration configuration , IProgressMonitor monitor) throws TeamRepositoryException {
if (workItem == null) {
List<extends> literals= workItemCommon.resolveEnumeration(attribute, monitor).getEnumerationLiterals();
List<Identifier<extends>> identifiers= new ArrayList<Identifier<extends>>();
for (ILiteral l: literals) {
identifiers.add(l.getIdentifier2());
}
return identifiers;
}
IAttribute filterAttribute= findFilterAttribute(attribute, workItem, workItemCommon, configuration, monitor);
if (filterAttribute == null) {
throw new IllegalArgumentException(NLS.bind(Messages.getString("FilteringValueSetProvider.FILTER_ATTRIBUTE_NOT_DEFINED"), workItem.getId(), attribute.getDisplayName())); //$NON-NLS-1$
}
if (!workItem.hasAttribute(filterAttribute)) {
throw new IllegalStateException(NLS.bind(Messages.getString("FilteringValueSetProvider.FILTER_ATTRIBUTE_NOT_FOUND"), workItem.getId(), attribute.getDisplayName())); //$NON-NLS-1$
}
Object filterValue= workItem.getValue(filterAttribute);
if (filterValue instanceof Identifier<?>) {
filterValue= ((Identifier<?>) filterValue).getStringIdentifier();
}
final IEnumeration<extends> enumeration= workItemCommon.resolveEnumeration(attribute, monitor);
if (enumeration == null) {
throw new IllegalStateException(NLS.bind(Messages.getString("FilteringValueSetProvider.ENUMERATION_OF_FILTER_ATTRIBUTE_NOT_FOUND"), workItem.getId(), attribute.getDisplayName())); //$NON-NLS-1$
}
AttributeType attributeType= AttributeTypes.getAttributeType(attribute.getAttributeType());
List<String> literalIds= ValueProviderUtil.getMappedLiterals(configuration, (String) filterValue);
List<ILiteral> literals= new ArrayList<ILiteral>();
for (String literalId: literalIds) {
ILiteral lit= enumeration.findEnumerationLiteral((Identifier<extends>)attributeType.valueOf(literalId, null));
if (lit != null) {
literals.add(lit);
}
}
Collections.sort(literals, new Comparator<ILiteral>() {
public int compare(ILiteral o1, ILiteral o2) {
return enumeration.getEnumerationLiterals().indexOf(o1) - enumeration.getEnumerationLiterals().indexOf(o2);
}
});
List<Identifier<extends>> filteredValues= new ArrayList<Identifier<extends>>();
for (ILiteral lit: literals) {
filteredValues.add(lit.getIdentifier2());
}
return filteredValues;
}
i have found the solution for fetching dependent enumation.
public List<Identifier<extends>> getValueSet(IAttribute attribute, IWorkItem workItem, IWorkItemCommon workItemCommon,
if (workItem == null) {
List<extends> literals= workItemCommon.resolveEnumeration(attribute, monitor).getEnumerationLiterals();
List<Identifier<extends>> identifiers= new ArrayList<Identifier<extends>>();
for (ILiteral l: literals) {
identifiers.add(l.getIdentifier2());
}
return identifiers;
}
IAttribute filterAttribute= findFilterAttribute(attribute, workItem, workItemCommon, configuration, monitor);
if (filterAttribute == null) {
throw new IllegalArgumentException(NLS.bind(Messages.getString("FilteringValueSetProvider.FILTER_ATTRIBUTE_NOT_DEFINED"), workItem.getId(), attribute.getDisplayName())); //$NON-NLS-1$
}
if (!workItem.hasAttribute(filterAttribute)) {
throw new IllegalStateException(NLS.bind(Messages.getString("FilteringValueSetProvider.FILTER_ATTRIBUTE_NOT_FOUND"), workItem.getId(), attribute.getDisplayName())); //$NON-NLS-1$
}
Object filterValue= workItem.getValue(filterAttribute);
if (filterValue instanceof Identifier<?>) {
filterValue= ((Identifier<?>) filterValue).getStringIdentifier();
}
final IEnumeration<extends> enumeration= workItemCommon.resolveEnumeration(attribute, monitor);
if (enumeration == null) {
throw new IllegalStateException(NLS.bind(Messages.getString("FilteringValueSetProvider.ENUMERATION_OF_FILTER_ATTRIBUTE_NOT_FOUND"), workItem.getId(), attribute.getDisplayName())); //$NON-NLS-1$
}
AttributeType attributeType= AttributeTypes.getAttributeType(attribute.getAttributeType());
List<String> literalIds= ValueProviderUtil.getMappedLiterals(configuration, (String) filterValue);
List<ILiteral> literals= new ArrayList<ILiteral>();
for (String literalId: literalIds) {
ILiteral lit= enumeration.findEnumerationLiteral((Identifier<extends>)attributeType.valueOf(literalId, null));
if (lit != null) {
literals.add(lit);
}
}
Collections.sort(literals, new Comparator<ILiteral>() {
public int compare(ILiteral o1, ILiteral o2) {
return enumeration.getEnumerationLiterals().indexOf(o1) - enumeration.getEnumerationLiterals().indexOf(o2);
}
});
List<Identifier<extends>> filteredValues= new ArrayList<Identifier<extends>>();
for (ILiteral lit: literals) {
filteredValues.add(lit.getIdentifier2());
}
return filteredValues;
}
2 answers
Hi,
find the solution for calling above get value method.
IWorkItem workItem1 = null;
ProviderConfiguration providerConfiguration= ((WorkItemCommon) workItemCommon).getProviderConfiguration(attribute, monitor);
IConfiguration configuration= providerConfiguration != null ? providerConfiguration.getValueSetProviderConfiguration() : null;
List<ILiteral> test= obj.getValueSet(attribute,workItem1,workItemCommon,configuration,monitor,getEnumarationLiteral(filterid,filterValue).getStringIdentifier());
Thanks,
Pugazh
IWorkItem workItem1 = null;
ProviderConfiguration providerConfiguration= ((WorkItemCommon) workItemCommon).getProviderConfiguration(attribute, monitor);
IConfiguration configuration= providerConfiguration != null ? providerConfiguration.getValueSetProviderConfiguration() : null;
Thanks,
Pugazh