final ValueSource<ISourceContainer> valueSourceThis = this;
elements.getConfigureButton().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (preparedAction != null) {
ISourceContainer value = preparedAction.run(elements.getShell());
if (value != null) {
setCurrentValue(value);
}
updater.reportChanged(valueSourceThis);
updater.update();
updateAction();
}
}
});
}
public void update(Updater updater) {
if (getValue() != null && !getValue().getType().equals(selectedTypeValue.getValue())) {
setCurrentValue(null);
updater.reportChanged(this);
}
updateAction();
}
private void updateAction() {
preparedAction = SourceNameMapperContainerDialog.prepareConfigureAction(
selectedTypeValue.getValue(), getValue(), director);
elements.getConfigureButton().setEnabled(preparedAction != null);
}
};
updater.addSource(rootScope, containerFactoryButtonValue);
updater.addConsumer(rootScope, containerFactoryButtonValue);
updater.addDependency(containerFactoryButtonValue, selectedTypeValue);
// Represents printer that shows type and name of the created container.
ValueConsumer showContainerTypeValue = new ValueConsumer() {
public void update(Updater updater) {
ISourceContainer container = containerFactoryButtonValue.getValue();
String status;
Image image;
String name;
boolean enabled;
if (container == null) {
status = Messages.SourceNameMapperContainerDialog_NOTHING_CONFIGURED;
name = ""; //$NON-NLS-1$
image = null;
enabled = false;
} else {
status = Messages.SourceNameMapperContainerDialog_CONFIGURED_CONTAINER;
ISourceContainerType type = container.getType();
name = container.getName();
image = DebugUITools.getSourceContainerImage(type.getId());
enabled = true;
}
ContainerStatusGroup group = elements.getContainerStatusGroup();
group.getStatusLabel().setText(status);
group.getTypeImageLabel().setImage(image);
group.getContainerNameLabel().setText(name);
group.setEnabled(enabled);
group.layout();
}
};
updater.addConsumer(rootScope, showContainerTypeValue);
updater.addDependency(showContainerTypeValue, containerFactoryButtonValue);
// Represents possible warning about unsupported container.
ValueProcessor<String> unsupportedContainerWarning = createProcessor(new Gettable<String>() {
@Override
public String getValue() {
ISourceContainer container = containerFactoryButtonValue.getValue();
if (container == null) {
return null;
}
if (ReverseSourceLookup.isGoodTargetContainer(container)) {
return null;
}
return Messages.SourceNameMapperContainerDialogLogic_TARGET_CONTAINER_NOT_SUPPORTED0;
}
});
updater.addSource(rootScope, unsupportedContainerWarning);
updater.addConsumer(rootScope, unsupportedContainerWarning);
updater.addDependency(unsupportedContainerWarning, containerFactoryButtonValue);
warningSources.add(unsupportedContainerWarning);
// Represents expression that constructs dialog window result.
final ValueProcessor<? extends Optional<Result>> resultValue =
new ExpressionProcessor<Result>(
Arrays.<ValueSource<? extends Optional<?>>>asList(prefixValue) ) {
@Override
protected Optional<Result> calculateNormal() {
final String prefix = prefixValue.getValue().getNormal();
final ISourceContainer container = containerFactoryButtonValue.getValue();
if (container == null) {
return createErrorOptional(
new Message(Messages.SourceNameMapperContainerDialog_CONFIGURE_TARGET_CONTAINER,
MessagePriority.BLOCKING_INFO));
}