use of org.eclipse.core.databinding.observable.Realm in project KLighD by kieler.
the class CopiesBlock method createContents.
/**
* Creates the 'Copies' block contents.
* The bindings are used to bind observable GUI elements to print setting in the given options.
*
* @param parent
* the parent {@link Composite} to use
* @param bindings
* the {@link DataBindingContext} managing the employed
* {@link org.eclipse.core.databinding.Binding Bindings}
* @param options
* the {@link PrintOptions} to be used
* @return the created {@link Group}
*/
public static Group createContents(final Composite parent, final DataBindingContext bindings, final PrintOptions options) {
final int columns = 2;
final Realm realm = bindings.getValidationRealm();
// create group
final Group result = DialogUtil.group(parent, KlighdUIPrintingMessages.PrintDialog_Copies);
DialogUtil.layout(result, columns);
// number of copies (label & spinner)
DialogUtil.label(result, KlighdUIPrintingMessages.PrintDialog_NumberOfCopies);
final Spinner copiesSpinner = DialogUtil.spinner(result, 1, Integer.MAX_VALUE);
final IObservableValue<Object> copiesValue = BeanProperties.value(options.getClass().asSubclass(PrintOptions.class), PrintOptions.PROPERTY_COPIES).observe(realm, options);
ISWTObservableValue<Object> copiesObservation = WidgetProperties.selection().observe(copiesSpinner);
bindings.bindValue(copiesObservation, copiesValue);
final Image collateOnImage = COLLATE_ON.createImage();
final Image collateOffImage = COLLATE_OFF.createImage();
// collate (imagelabel & checkbox)
final Label collateImageLabel = new Label(result, SWT.CENTER | SWT.SHADOW_NONE);
DialogUtil.layoutAlignRight(collateImageLabel);
final Button collateCheck = DialogUtil.check(result, KlighdUIPrintingMessages.PrintDialog_Collate);
collateImageLabel.setImage(collateCheck.getSelection() ? collateOnImage : collateOffImage);
final IObservableValue<Object> collateValue = BeanProperties.value(options.getClass().asSubclass(PrintOptions.class), PrintOptions.PROPERTY_COLLATE).observe(realm, options);
ISWTObservableValue<Object> collateObservation = WidgetProperties.selection().observe((Widget) collateCheck);
bindings.bindValue(collateObservation, collateValue);
collateValue.addValueChangeListener(new IValueChangeListener<Object>() {
public void handleValueChange(final ValueChangeEvent<? extends Object> event) {
// set image according to collate state
if (((Boolean) event.getObservableValue().getValue()).booleanValue()) {
collateImageLabel.setImage(collateOnImage);
} else {
collateImageLabel.setImage(collateOffImage);
}
}
});
result.addListener(SWT.Dispose, new Listener() {
public void handleEvent(final Event event) {
collateOnImage.dispose();
collateOffImage.dispose();
// while the SWTObservableValues are disposed while disposing the corresponding widgets
// the Beans-based ones should be disposed explicitly
copiesValue.dispose();
collateValue.dispose();
}
});
if (Klighd.IS_MACOSX) {
// I deactivated 'copies' block as this information can be changed in the native dialog
// but (on OSX) it is not delivered back within the returned PrinterData.
// Thus, 'copies' cannot be updated properly.
// This, however, seems not to hold for windows and linux.
result.setToolTipText(KlighdUIPrintingMessages.KlighdPrintDialog_Copies_OSXToolTip);
for (final Control con : result.getChildren()) {
con.setEnabled(false);
}
}
return result;
}
use of org.eclipse.core.databinding.observable.Realm in project eclipse.pde by eclipse-pde.
the class PreferenceSpyPart method postConstruct.
@SuppressWarnings("unchecked")
@PostConstruct
public void postConstruct(Composite parent, final ESelectionService selectionService, EModelService modelService, MWindow window) {
preferenceEntryManager = new PreferenceEntryManager();
PreferenceEntryPatternFilter patternFilter = new PreferenceEntryPatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
filteredTree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter);
Tree table = filteredTree.getViewer().getTree();
table.setHeaderVisible(true);
table.setLinesVisible(true);
filteredTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
ArrayList<PreferenceEntry> preferenceEntries = new ArrayList<PreferenceEntry>(((IStructuredSelection) selection).toList());
selectionService.setSelection(preferenceEntries);
}
}
});
createColumn(Fields.nodePath, Messages.PreferenceSpyPart_Nodepath, 300);
createColumn(Fields.key, Messages.PreferenceSpyPart_Key, 300);
createColumn(Fields.oldValue, Messages.PreferenceSpyPart_Old_Value, 150);
createColumn(Fields.newValue, Messages.PreferenceSpyPart_New_Value, 150);
filteredTree.getViewer().setComparator(new PreferenceEntryViewerComparator());
FontDescriptor fontDescriptor = getBoldFontDescriptor();
Realm realm = DisplayRealm.getRealm(filteredTree.getViewer().getControl().getDisplay());
PreferenceEntriesContentProvider contentProvider = new PreferenceEntriesContentProvider(BeanProperties.set("preferenceEntries", PreferenceNodeEntry.class).setFactory(realm), null);
contentProvider.setHierarchicalLayout(hierarchicalLayoutPreference);
filteredTree.getViewer().setContentProvider(contentProvider);
filteredTree.getViewer().setLabelProvider(new PreferenceMapLabelProvider(fontDescriptor, Properties.observeEach(contentProvider.getKnownElements(), BeanProperties.values(PreferenceEntry.class, "nodePath", "key", "oldValue", "newValue"))));
filteredTree.getViewer().setInput(preferenceEntryManager);
}
Aggregations