Example usage for org.eclipse.jface.databinding.swt WidgetProperties enabled

List of usage examples for org.eclipse.jface.databinding.swt WidgetProperties enabled

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt WidgetProperties enabled.

Prototype

public static IWidgetValueProperty enabled() 

Source Link

Document

Returns a value property for observing the enablement state of a Control , Menu (since 1.5), MenuItem (since 1.5), ScrollBar (since 1.5) or ToolItem (since 1.5).

Usage

From source file:org.eclipse.emf.cdo.security.internal.ui.editor.AbstractDetailsPage.java

License:Open Source License

protected Text text(Composite parent, FormToolkit toolkit, String label, EAttribute attribute) {
    toolkit.createLabel(parent, label);//from  w  ww .jav a  2  s  .co m
    Text result = toolkit
            .createText(createDecorationComposite(parent, toolkit, layoutData(parent, SWT.FILL, false, 1)), ""); //$NON-NLS-1$
    getContext().bindValue(observeText(result),
            EMFEditObservables.observeDetailValue(getRealm(), getEditingDomain(), getValue(), attribute));
    getContext().bindValue(WidgetProperties.enabled().observe(result), getValue(), null,
            ObjectWritableConverter.createUpdateValueStrategy(attribute));

    addRevertDecoration(result, attribute);
    return result;
}

From source file:org.eclipse.emf.cdo.security.internal.ui.editor.AbstractDetailsPage.java

License:Open Source License

protected Button checkbox(Composite parent, FormToolkit toolkit, String label, EAttribute attribute) {
    Button result = toolkit.createButton(
            createDecorationComposite(parent, toolkit, layoutData(parent, SWT.LEFT, false, 2)), label,
            SWT.CHECK);//from   w ww.  ja v a  2  s.  com
    getContext().bindValue(WidgetProperties.enabled().observe(result),
            EMFEditObservables.observeDetailValue(getRealm(), getEditingDomain(), getValue(), attribute));
    getContext().bindValue(WidgetProperties.enabled().observe(result), getValue(), null,
            ObjectWritableConverter.createUpdateValueStrategy(attribute));

    addRevertDecoration(result, attribute);
    return result;
}

From source file:org.eclipse.emf.cdo.security.internal.ui.editor.AbstractDetailsPage.java

License:Open Source License

protected Button button(Composite parent, FormToolkit toolkit, String label,
        SelectionListener selectionListener) {
    Button result = toolkit.createButton(parent, label, SWT.PUSH);
    result.setLayoutData(layoutData(parent, SWT.LEFT, false, 2));

    getContext().bindValue(WidgetProperties.enabled().observe(result), getValue(), null,
            ObjectWritableConverter.createUpdateValueStrategy());

    result.addSelectionListener(selectionListener);
    return result;
}

From source file:org.eclipse.emf.cdo.security.internal.ui.editor.AbstractDetailsPage.java

License:Open Source License

protected ComboViewer combo(Composite parent, FormToolkit toolkit, String label, EAttribute attribute) {
    toolkit.createLabel(parent, label);/*from  w w w  . ja v a  2s . c om*/
    ComboViewer result = new ComboViewer(
            createDecorationComposite(parent, toolkit, layoutData(parent, SWT.LEFT, false, 1)),
            SWT.READ_ONLY | SWT.DROP_DOWN);
    result.setLabelProvider(new AdapterFactoryLabelProvider(getAdapterFactory()));
    result.setContentProvider(new ArrayContentProvider());
    result.setInput(attribute.getEAttributeType().getInstanceClass().getEnumConstants());

    getContext().bindValue(ViewersObservables.observeSingleSelection(result),
            EMFEditObservables.observeDetailValue(getRealm(), getEditingDomain(), getValue(), attribute));
    getContext().bindValue(WidgetProperties.enabled().observe(result.getControl()), getValue(), null,
            ObjectWritableConverter.createUpdateValueStrategy(attribute));

    addRevertDecoration(result.getControl(), attribute);
    return result;
}

From source file:org.eclipse.emf.cdo.security.internal.ui.util.OneToManyBlock.java

License:Open Source License

public void createControl(Composite parent, FormToolkit toolkit) {
    final EReference reference = getConfiguration().getModelReference();
    final EClass itemType = getConfiguration().getItemType();

    parent.setLayout(new GridLayout(2, false));

    Composite tableParent;//from www . j  a v a 2  s  .co m
    TableColumnLayout tableLayout = null;
    if (isTable()) {
        tableParent = toolkit.createComposite(parent);
        tableLayout = new TableColumnLayout();
        tableParent.setLayout(tableLayout);
    } else {
        tableParent = parent;
    }

    Table table = toolkit.createTable(tableParent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE);
    viewer = new TableViewer(table);

    if (isTable()) {
        tableParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        configureColumns(viewer, tableLayout);
    } else {
        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        AdapterFactoryLabelProvider labels = new TableLabelProvider(adapterFactory);
        labels.setFireLabelUpdateNotifications(true); // Needed to support the data-binding input
        viewer.setLabelProvider(labels);
    }

    viewer.setContentProvider(new ObservableListContentProvider());
    SecurityUIUtil.applySupportedElementFilter(viewer, itemType);
    if (itemType != reference.getEReferenceType()) {
        applyTypeFilter(viewer, itemType);
    }

    if (getConfiguration().getItemFilter() != null) {
        viewer.addFilter(getViewerFilter(getConfiguration().getItemFilter()));
    }

    viewer.setInput(value);
    hookUnsupportedModelContentValidation(value);

    if (!reference.isContainment()) {
        configureDropSupport(viewer);
    }

    context.bindValue(WidgetProperties.enabled().observe(viewer.getControl()), input, null,
            ObjectWritableConverter.createUpdateValueStrategy());

    Composite buttons = toolkit.createComposite(parent);
    FillLayout fill = new FillLayout(SWT.VERTICAL);
    fill.spacing = 5;
    buttons.setLayout(fill);
    buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));

    Button newButton = null;
    Button addButton = null;
    Button removeButton = null;

    newButton = toolkit.createButton(buttons, Messages.OneToManyBlock_0, SWT.PUSH);
    if (!reference.isContainment()) {
        addButton = toolkit.createButton(buttons, Messages.OneToManyBlock_1, SWT.PUSH);
    }

    removeButton = toolkit.createButton(buttons, Messages.OneToManyBlock_2, SWT.PUSH);

    final IObservableValue<?> selection = ViewersObservables.observeSingleSelection(viewer);

    context.bindValue(WidgetProperties.enabled().observe(newButton), input, null,
            ObjectWritableConverter.createUpdateValueStrategy());
    if (addButton != null) {
        context.bindValue(WidgetProperties.enabled().observe(addButton), input, null,
                ObjectWritableConverter.createUpdateValueStrategy());
    }

    context.bindValue(WidgetProperties.enabled().observe(removeButton), selection, null,
            ObjectWritableConverter.createUpdateValueStrategy());

    newButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Realm realm = ((SecurityItem) input.getValue()).getRealm();

            Object owner;
            if (reference.isContainment()) {
                owner = input.getValue();
            } else {
                owner = SecurityUIUtil.getDirectory(realm, itemType);
            }

            if (owner != null) {
                // Create a new object in the appropriate owner and add it to the
                // reference list if that's not the containment
                Object child = EcoreUtil.create(itemType);

                CommandParameter param;
                Command addToReference;

                if (reference.isContainment()) {
                    param = new CommandParameter(owner, reference, child);
                    addToReference = IdentityCommand.INSTANCE;
                } else {
                    param = new CommandParameter(owner, SecurityPackage.Literals.DIRECTORY__ITEMS, child);
                    addToReference = AddCommand.create(domain, input.getValue(), reference,
                            Collections.singleton(child));
                }

                Command command = CreateChildCommand.create(domain, owner, param, Collections.singleton(owner));
                command = command.chain(addToReference);

                if (getNewObjectConfigurator() != null) {
                    command = command.chain(getNewObjectConfigurator().createConfigureCommand(child));
                }

                if (execute(command)) {
                    viewer.setSelection(new StructuredSelection(child));
                    viewer.getControl().setFocus();
                    viewer.refresh(child);
                }
            }
        }
    });

    if (addButton != null) {
        addButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                Realm realm = ((SecurityItem) input.getValue()).getRealm();
                Directory directory = SecurityUIUtil.getDirectory(realm, itemType);
                if (directory != null) {
                    // Get the available items not already in our input's reference list
                    List<?> available = new ArrayList<Object>(
                            EcoreUtil.getObjectsByType(directory.getItems(), itemType));
                    available.removeAll(value);
                    SecurityUIUtil.applySupportedElementFilter(available, itemType);

                    String label = NLS.bind(Messages.OneToManyBlock_3,
                            SecurityEditPlugin.INSTANCE.getString(String.format("_UI_%s_%s_feature", //$NON-NLS-1$
                                    reference.getEContainingClass().getName(), reference.getName())));

                    FeatureEditorDialog dlg = new FeatureEditorDialog(viewer.getControl().getShell(),
                            new TableLabelProvider(adapterFactory), input.getValue(),
                            reference.getEContainingClass(), Collections.EMPTY_LIST, label, available, false,
                            true, true);

                    if (dlg.open() == Window.OK && !dlg.getResult().isEmpty()) {
                        Command command = AddCommand.create(domain, input.getValue(), reference,
                                dlg.getResult());
                        if (execute(command)) {
                            viewer.setSelection(new StructuredSelection(dlg.getResult()));
                            viewer.getControl().setFocus();
                        }
                    }
                }
            }
        });
    }

    final SelectionListenerAction<EObject> removeAction = new SelectionListenerAction<EObject>(
            Messages.OneToManyBlock_2, SharedIcons.getDescriptor("etool16/delete.gif")) //$NON-NLS-1$
    {
        @Override
        public void run() {
            Object selected = selection.getValue();
            if (selected != null) {
                Command command;

                if (reference.isContainment()) {
                    command = DeleteCommand.create(domain, selection.getValue());
                } else {
                    command = RemoveCommand.create(domain, input.getValue(), reference, selection.getValue());
                }

                execute(command);
            }
        }

        @Override
        protected boolean updateSelection(IStructuredSelection selection) {
            return super.updateSelection(selection) && SecurityUIUtil.isEditable(input.getValue());
        }

        @Override
        protected Class<EObject> getType() {
            return EObject.class;
        }
    };

    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (removeAction.isEnabled()) {
                removeAction.run();
            }
        }
    });

    viewer.addSelectionChangedListener(removeAction);

    new ActionBarsHelper(editorActionBars).addGlobalAction(ActionFactory.DELETE.getId(), removeAction)
            .install(viewer);
}

From source file:org.eclipse.emf.ecp.edit.internal.swt.reference.LinkControl.java

License:Open Source License

@Override
public Binding bindValue() {

    final IObservableValue value = WidgetProperties.text().observe(hyperlink);
    getDataBindingContext().bindValue(value, getModelValue(), createValueExtractingUpdateStrategy(),
            new UpdateValueStrategy() {
                @Override//www.  jav  a2s  .c o m
                public Object convert(Object value) {
                    updateChangeListener((EObject) value);
                    return "<a>" + getLinkText(value) + "</a>"; //$NON-NLS-1$ //$NON-NLS-2$
                }
            });

    final IObservableValue tooltipValue = WidgetProperties.tooltipText().observe(hyperlink);
    getDataBindingContext().bindValue(tooltipValue, getModelValue(), createValueExtractingUpdateStrategy(),
            new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return getLinkText(value);
                }
            });

    final IObservableValue imageValue = WidgetProperties.image().observe(imageHyperlink);
    getDataBindingContext().bindValue(imageValue, getModelValue(),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return getImage(value);
                }
            });

    final IObservableValue deleteButtonEnablement = WidgetProperties.enabled().observe(getDeleteButton());
    getDataBindingContext().bindValue(deleteButtonEnablement, getModelValue(),
            createValueExtractingUpdateStrategy(), new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return value != null;
                }
            });

    return null;
}

From source file:org.eclipse.emf.ecp.view.internal.core.swt.renderer.LinkControlSWTRenderer.java

License:Open Source License

@Override
protected Binding[] createBindings(Control control) throws DatabindingFailedException {

    final IObservableValue value = WidgetProperties.text().observe(hyperlink);
    final Binding binding = getDataBindingContext().bindValue(value, getModelValue(),
            createValueExtractingUpdateStrategy(), new UpdateValueStrategy() {
                @Override/*from w w w  .j ava2  s. c om*/
                public Object convert(Object value) {
                    updateChangeListener((EObject) value);
                    return "<a>" + getText(value) + "</a>"; //$NON-NLS-1$ //$NON-NLS-2$
                }
            });

    final IObservableValue tooltipValue = WidgetProperties.tooltipText().observe(hyperlink);
    final Binding tooltipBinding = getDataBindingContext().bindValue(tooltipValue, getModelValue(),
            createValueExtractingUpdateStrategy(), new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return getText(value);
                }
            });

    final IObservableValue imageValue = WidgetProperties.image().observe(imageHyperlink);
    final Binding imageBinding = getDataBindingContext().bindValue(imageValue, getModelValue(),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return getImage(value);
                }
            });

    final IObservableValue deleteButtonEnablement = WidgetProperties.enabled().observe(deleteReferenceButton);
    final Binding deleteBinding = getDataBindingContext().bindValue(deleteButtonEnablement, getModelValue(),
            createValueExtractingUpdateStrategy(), new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return value != null;
                }
            });

    return new Binding[] { binding, tooltipBinding, imageBinding, deleteBinding };
}

From source file:org.eclipse.incquery.tooling.ui.wizards.NewEiqGenmodelPage.java

License:Open Source License

protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    ///*w  ww.ja  v a 2 s  .  c  o m*/
    IObservableValue observeSelectionBtnInitializeGeneratorModelObserveWidget = WidgetProperties.selection()
            .observe(btnInitializeGeneratorModel);
    IObservableValue enabledReferencedGenmodelsObserveValue = PojoProperties.value("enabled")
            .observe(referencedGenmodels);
    bindingContext.bindValue(observeSelectionBtnInitializeGeneratorModelObserveWidget,
            enabledReferencedGenmodelsObserveValue, null, null);
    //
    IObservableValue observeEnabledAddGenmodelObserveWidget = WidgetProperties.enabled().observe(addGenmodel);
    IObservableValue observeSelectionBtnInitializeGeneratorModelObserveWidget_1 = WidgetProperties.selection()
            .observe(btnInitializeGeneratorModel);
    bindingContext.bindValue(observeEnabledAddGenmodelObserveWidget,
            observeSelectionBtnInitializeGeneratorModelObserveWidget_1, null, null);
    //
    return bindingContext;
}

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionPage.java

License:Open Source License

/**
 * Creates the {@link Composite} container that will display widgets to
 * select an {@link IDockerImage}, name it and specify the command to run.
 * // w w  w.ja v  a  2 s  .  c  o  m
 * @param container
 *            the parent {@link Composite}
 */
private void createImageSettingsSection(final Composite container) {
    // Image selection name
    final Label imageSelectionLabel = new Label(container, SWT.NONE);
    imageSelectionLabel.setText(WizardMessages.getString("ImageRunSelectionPage.imageName")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    final Combo imageSelectionCombo = new Combo(container, SWT.BORDER);
    final ComboViewer imageSelectionComboViewer = new ComboViewer(imageSelectionCombo);
    imageSelectionCombo.setToolTipText(WizardMessages.getString("ImageRunSelectionPage.selectTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(imageSelectionCombo);
    new ControlDecoration(imageSelectionCombo, SWT.TOP | SWT.LEFT);
    new ContentProposalAdapter(imageSelectionCombo, new ComboContentAdapter() {
        @Override
        public void insertControlContents(Control control, String text, int cursorPosition) {
            final Combo combo = (Combo) control;
            final Point selection = combo.getSelection();
            combo.setText(text);
            selection.x = text.length();
            selection.y = selection.x;
            combo.setSelection(selection);
        }
    }, getImageNameContentProposalProvider(imageSelectionCombo), null, null);
    // image search
    final Button searchImageButton = new Button(container, SWT.NONE);
    searchImageButton.setText(WizardMessages.getString("ImageRunSelectionPage.search")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(searchImageButton);
    searchImageButton.addSelectionListener(onSearchImage());
    // link to pull image
    final Label fillerLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(fillerLabel);
    final Link pullImageLink = new Link(container, SWT.NONE);
    pullImageLink.setText(WizardMessages.getString("ImageRunSelectionPage.pullImage")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(COLUMNS - 1, 1)
            .applyTo(pullImageLink);
    pullImageLink.addSelectionListener(onPullImage());
    dbc.bindValue(WidgetProperties.enabled().observe(pullImageLink),
            BeanProperties
                    .value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NEEDS_PULLING)
                    .observe(model));
    // bind combo with model (for values and selection)
    imageSelectionComboViewer.setContentProvider(new ObservableListContentProvider());
    dbc.bindList(WidgetProperties.items().observe(imageSelectionCombo), BeanProperties
            .list(ImageRunSelectionModel.class, ImageRunSelectionModel.IMAGE_NAMES).observe(model));
    dbc.bindValue(WidgetProperties.selection().observe(imageSelectionCombo), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NAME).observe(model));
    // Container name (optional)
    final Label containerNameLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    containerNameLabel.setText(WizardMessages.getString("ImageRunSelectionPage.containerName")); //$NON-NLS-1$
    final Text containerNameText = new Text(container, SWT.BORDER);
    containerNameText.setToolTipText(WizardMessages.getString("ImageRunSelectionPage.containerTooltip")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(containerNameText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(new Label(container, SWT.NONE));
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(containerNameText), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.CONTAINER_NAME).observe(model));

    // EntryPoint (optional)
    final Label entrypointLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    entrypointLabel.setText(WizardMessages.getString("ImageRunSelectionPage.entrypoint")); //$NON-NLS-1$
    // TODO: include SWT.SEARCH | SWT.ICON_SEARCH to support value reset
    final Text entrypointText = new Text(container, SWT.BORDER);

    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(entrypointText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(new Label(container, SWT.NONE));
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(entrypointText), BeanProperties
            .value(ImageRunSelectionModel.class, ImageRunSelectionModel.ENTRYPOINT).observe(model));

    // Command (optional)
    final Label commandLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    commandLabel.setText(WizardMessages.getString("ImageRunSelectionPage.command")); //$NON-NLS-1$
    final Text commandText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1)
            .applyTo(commandText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1)
            .applyTo(new Label(container, SWT.NONE));
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(commandText),
            BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.COMMAND).observe(model));
}

From source file:org.goko.base.commandpanel.controller.CommandPanelController.java

License:Open Source License

public void bindEnableControlWithAction(Control widget, String actionId) throws GkException {
    getDataModel().setActionEnabled(actionId, false);
    // Let's do the binding
    IObservableValue modelObservable = Observables.observeMapEntry(getDataModel().getActionState(), actionId,
            Boolean.class);
    IObservableValue controlObservable = WidgetProperties.enabled().observe(widget);
    getBindingContext().bindValue(controlObservable, modelObservable);

    // If supported, let's report to the action definition
    if (controllerService.isControllerAction(actionId)) {
        IGkControllerAction action = controllerService.getControllerAction(actionId);
        getDataModel().setActionEnabled(action.getId(), action.canExecute());
    }//from  w ww.  ja v a  2  s .  c o m
}