final PolicyType[] types = policyModelSet.getFallBackTypes();
Map typesToTextComponents = new HashMap();
if (types != null && types.length > 0) {
for (int i = 0; i < types.length; i++) {
final PolicyType type = types[i];
String labelString = EditorMessages.getString(
RESOURCE_PREFIX + StringUtils.toLowerIgnoreLocale(
types[i].toString()) + ".fallback.label");
Label fallBackLabel = new Label(parent, SWT.NONE);
setDefaultColour(fallBackLabel);
fallBackLabel.setText(labelString);
GridData data =
new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
fallBackLabel.setLayoutData(data);
enableableControls.add(fallBackLabel);
Composite entry = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
entry.setLayout(layout);
data = new GridData(GridData.FILL_HORIZONTAL);
entry.setLayoutData(data);
setDefaultColour(entry);
final Text fallBackText = new Text(entry, SWT.BORDER);
data = new GridData(GridData.FILL_HORIZONTAL);
fallBackText.setLayoutData(data);
typesToTextComponents.put(type, fallBackText);
enableableControls.add(fallBackText);
final PolicySelectorBrowseAction browseAction =
new PolicySelectorBrowseAction(FileExtension.
getFileExtensionForPolicyType(types[i]));
Button button = new Button(entry, SWT.NONE);
button.setText("Browse...");
button.addSelectionListener(new SelectionListener() {
private void handleSelection() {
String oldText = fallBackText.getText();
String policyValue = browseAction.doBrowse(
oldText, parent, context);
// Has anything changed?
if (policyValue != null &&
!policyValue.equals(oldText)) {
fallBackText.setText(policyValue);
setFallbackPolicy(type, policyValue);
}
}
public void widgetSelected(SelectionEvent event) {
handleSelection();
}
public void widgetDefaultSelected(SelectionEvent event) {
handleSelection();
}
});
enableableControls.add(button);
}
// Initialise the fallback policies
ListProxy alternatePolicies =
(ListProxy) ((BeanProxy) context.getInteractionModel()).
getPropertyProxy(PolicyModel.ALTERNATE_POLICIES);
int size = alternatePolicies.size();
for (int i = 0; i < size; i++) {
Proxy itemProxy = alternatePolicies.getItemProxy(i);
Object modelObject = itemProxy.getModelObject();
PolicyReference ref = (PolicyReference) modelObject;
Text text = (Text) typesToTextComponents
.get(ref.getExpectedPolicyType());
text.setText(ref.getName());
}
// Register the listeners for the fallback GUI components
for (int i = 0; i < types.length; i++) {
final PolicyType type = types[i];
final Text text = (Text) typesToTextComponents.get(type);
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setFallbackPolicy(type, text.getText());
}