Search in sources :

Example 21 with Realm

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;
}
Also used : Group(org.eclipse.swt.widgets.Group) IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) Spinner(org.eclipse.swt.widgets.Spinner) Label(org.eclipse.swt.widgets.Label) Image(org.eclipse.swt.graphics.Image) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) Event(org.eclipse.swt.widgets.Event) Realm(org.eclipse.core.databinding.observable.Realm)

Example 22 with Realm

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);
}
Also used : PreferenceEntriesContentProvider(org.eclipse.pde.spy.preferences.viewer.PreferenceEntriesContentProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.e4.ui.dialogs.filteredtree.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PreferenceMapLabelProvider(org.eclipse.pde.spy.preferences.viewer.PreferenceMapLabelProvider) PreferenceEntryManager(org.eclipse.pde.spy.preferences.model.PreferenceEntryManager) PreferenceEntryPatternFilter(org.eclipse.pde.spy.preferences.model.PreferenceEntryPatternFilter) PreferenceEntry(org.eclipse.pde.spy.preferences.model.PreferenceEntry) ISelection(org.eclipse.jface.viewers.ISelection) FilteredTree(org.eclipse.e4.ui.dialogs.filteredtree.FilteredTree) Tree(org.eclipse.swt.widgets.Tree) PreferenceEntryViewerComparator(org.eclipse.pde.spy.preferences.viewer.PreferenceEntryViewerComparator) Realm(org.eclipse.core.databinding.observable.Realm) DisplayRealm(org.eclipse.jface.databinding.swt.DisplayRealm) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Realm (org.eclipse.core.databinding.observable.Realm)22 Test (org.junit.Test)10 CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)8 Event (org.eclipse.swt.widgets.Event)7 Listener (org.eclipse.swt.widgets.Listener)7 DisplayRealm (org.eclipse.jface.databinding.swt.DisplayRealm)6 Button (org.eclipse.swt.widgets.Button)6 Group (org.eclipse.swt.widgets.Group)6 Text (org.eclipse.swt.widgets.Text)3 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)2 IObservableMap (org.eclipse.core.databinding.observable.map.IObservableMap)2 WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)2 ComputedValue (org.eclipse.core.databinding.observable.value.ComputedValue)2 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)2 IValueChangeListener (org.eclipse.core.databinding.observable.value.IValueChangeListener)2 ValueChangeEvent (org.eclipse.core.databinding.observable.value.ValueChangeEvent)2 ThreadRealm (org.eclipse.core.tests.databinding.observable.ThreadRealm)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 GridData (org.eclipse.swt.layout.GridData)2 Control (org.eclipse.swt.widgets.Control)2