use of org.eclipse.sapphire.ui.forms.swt.SwtResourceCache in project liferay-ide by liferay.
the class PossibleValuesRadioButtonsGroupBinding method initialize.
@Override
@SuppressWarnings("unchecked")
protected void initialize(PropertyEditorPresentation propertyEditorPresentation, Control control) {
super.initialize(propertyEditorPresentation, control);
final PossibleValuesService possibleValuesService = propertyEditorPresentation.property().service(PossibleValuesService.class);
_possibleValues = new ArrayList<>(possibleValuesService.values());
_buttonsGroup = (RadioButtonsGroup) control;
final Property property = propertyEditorPresentation.property();
String auxTextProviderName = propertyEditorPresentation.part().getRenderingHint("possible.values.aux.text.provider", (String) null);
PossibleValuesAuxTextProvider auxTextProvider = null;
if (auxTextProviderName != null) {
try {
Bundle bundle = ProjectUI.getDefault().getBundle();
Class<PossibleValuesAuxTextProvider> providerClass = (Class<PossibleValuesAuxTextProvider>) bundle.loadClass(auxTextProviderName);
auxTextProvider = providerClass.newInstance();
} catch (Exception e) {
}
}
for (String possibleValue : _possibleValues) {
final ValueLabelService labelService = property.service(ValueLabelService.class);
final String possibleValueText = labelService.provide(possibleValue);
String auxText = propertyEditorPresentation.part().getRenderingHint(PropertyEditorDef.HINT_AUX_TEXT + "." + possibleValue, null);
if ((auxText == null) && (auxTextProvider != null)) {
auxText = auxTextProvider.getAuxText(element(), property.definition(), possibleValue);
}
ValueImageService imageService = property.service(ValueImageService.class);
ImageData imageData = imageService.provide(possibleValue);
SwtResourceCache resources = presentation().resources();
Image image = resources.image(imageData);
final Button button = this._buttonsGroup.addRadioButton(possibleValueText, auxText, image);
button.setData(possibleValue);
}
_buttonsGroup.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent event) {
updateModel();
updateTargetAttributes();
}
});
}
Aggregations