Example usage for org.eclipse.jface.databinding.swt SWTObservables observeSelection

List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeSelection

Introduction

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

Prototype

@Deprecated
public static ISWTObservableValue observeSelection(Control control) 

Source Link

Document

Returns an observable observing the selection attribute of the provided control.

Usage

From source file:org.eclipse.rcptt.internal.launching.ext.ui.wizards.NewAUTPage.java

License:Open Source License

private void createControlArch(final Composite parent) {
    Label archLabel = new Label(parent, SWT.NONE);
    archLabel.setText("Architecture:");

    Composite archGroup = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true).applyTo(archGroup);
    GridDataFactory.fillDefaults().span(1, 1).grab(true, false).applyTo(archGroup);
    Button b32 = new Button(archGroup, SWT.RADIO);
    Button b64 = new Button(archGroup, SWT.RADIO);
    b32.setText("32bit");
    b64.setText("64bit");

    dbc.bindValue(SWTObservables.observeEnabled(b32), archEnabled);
    dbc.bindValue(SWTObservables.observeEnabled(b64), archEnabled);
    dbc.bindValue(SWTObservables.observeSelection(b64), platformArchitecture64);
    dbc.bindValue(SWTObservables.observeSelection(b32), platformArchitecture32);

    final Link archLink = new Link(parent, SWT.UNDERLINE_LINK);
    archLink.setText("There is no appropriate JVM configured. <a>Configure JVM...</a>");
    GridDataFactory.fillDefaults().span(3, 1).grab(true, false).applyTo(archLink);
    archLink.addSelectionListener(new SelectionAdapter() {
        @Override//  w  w  w .  j  a v a2  s  .  c o m
        public void widgetSelected(SelectionEvent e) {
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, JREsPreferencePage.ID,
                    new String[] { JREsPreferencePage.ID }, null);
            if (dialog.open() == PreferenceDialog.OK) {
                validatePlatform();
            }
        }
    });

    ISWTObservableValue archLinkObservable = SWTObservables.observeVisible(archLink);
    archLinkObservable.addChangeListener(new IChangeListener() {
        public void handleChange(ChangeEvent event) {
            // Hides container as well (like "display: none")
            GridData data = (GridData) archLink.getLayoutData();
            data.exclude = !archLink.getVisible();
            parent.layout(false);
        }
    });
    dbc.bindValue(archLinkObservable, architectureError);
}

From source file:org.eclipse.rcptt.internal.launching.ext.ui.wizards.NewAUTPage.java

License:Open Source License

private void createControlAutolaunch(Composite parent) {
    Button autolaunch = new Button(parent, SWT.CHECK);
    GridDataFactory.fillDefaults().span(3, 1).grab(true, false).applyTo(autolaunch);
    autolaunch.setText("to del");
    autolaunch.setSelection(true);/*  w  w  w.  j  a v a2 s. c  om*/

    dbc.bindValue(SWTObservables.observeSelection(autolaunch), autolaunchValue);
    dbc.bindValue(SWTObservables.observeText(autolaunch), autolaunchLabel);
}

From source file:org.eclipse.rcptt.ui.report.ReportMainPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(panel);

    // Report name
    Label l = new Label(panel, SWT.NONE);
    l.setText(Messages.ReportMainPage_NameLabel);
    final Text reportName = new Text(panel, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(reportName);

    final ControlDecoration controlDecoration = new ControlDecoration(reportName, SWT.LEFT | SWT.TOP);
    controlDecoration.setDescriptionText(""); //$NON-NLS-1$
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
    controlDecoration.setImage(fieldDecoration.getImage());
    controlDecoration.hide();//from ww  w. j a v  a 2  s . c o m

    dbc.bindValue(SWTObservables.observeText(reportName, SWT.Modify), this.reportName);

    this.reportName.addValueChangeListener(new IValueChangeListener() {
        public void handleValueChange(ValueChangeEvent event) {
            String name = (String) event.getObservableValue().getValue();
            if (name.trim().length() == 0) {
                controlDecoration.show();
                controlDecoration.showHoverText(Messages.ReportMainPage_EmptyReportNameMsg);
                validate();
                return;
            }
            controlDecoration.hide();
            validate();
        }
    });
    // Output format:
    l = new Label(panel, SWT.NONE);
    l.setText(Messages.ReportMainPage_FormatLabel);
    Combo reportFormat = new Combo(panel, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.swtDefaults().grab(false, false).applyTo(reportFormat);
    dbc.bindList(SWTObservables.observeItems(reportFormat), this.reports, new UpdateListStrategy() {
        @Override
        public Object convert(Object value) {
            return convertReport(value);
        }
    }, new UpdateListStrategy() {
        @Override
        public Object convert(Object value) {
            return ((ReportRenderer) value).getName();
        }
    });
    dbc.bindValue(SWTObservables.observeSelection(reportFormat), this.reportFormat, new UpdateValueStrategy() {
        @Override
        public Object convert(Object value) {
            return convertReport(value);
        }
    }, new UpdateValueStrategy() {
        @Override
        public Object convert(Object value) {
            if (value != null) {
                return ((ReportRenderer) value).getName();
            }
            return null;
        }
    });
    ReportRenderer defaultRenderer = null;
    for (int i = 0; i < reports.size(); i++) {
        ReportRenderer rr = (ReportRenderer) reports.get(i);
        if (rr.getExtension().equals("html")) { //$NON-NLS-1$
            defaultRenderer = rr;
            break;
        }
    }
    if (defaultRenderer != null) {
        this.reportFormat.setValue(defaultRenderer);
    } else {
        this.reportFormat.setValue(reports.get(0));
    }

    // Output location

    l = new Label(panel, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(l);
    Composite sPanel = new Composite(panel, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(sPanel);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(sPanel);
    l = new Label(sPanel, SWT.NONE);
    l.setText(Messages.ReportMainPage_OutputLabel);
    l = new Label(sPanel, SWT.HORIZONTAL | SWT.SEPARATOR);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(l);

    // Generate to workspace
    createGenerateWorkspace(panel);

    // Generate to file system
    createGenerateToFilesystem(panel);

    setControl(panel);
    IDialogSettings ds = getDialogSettings();
    if (ds != null) {
        String loc = ds.get("report.dialog.workspace.location"); //$NON-NLS-1$
        if (loc != null) {
            workspaceLocation.setValue(loc);
        }
    }
    if (initialWorkspaceLocation != null) {
        workspaceLocation.setValue(initialWorkspaceLocation);
    }
    validate();
}

From source file:org.eclipse.rcptt.ui.report.ReportMainPage.java

License:Open Source License

private void createGenerateWorkspace(Composite panel) {
    Button generateToWorkspace = new Button(panel, SWT.RADIO);
    GridDataFactory.swtDefaults().span(2, 1).applyTo(generateToWorkspace);
    generateToWorkspace.setText(Messages.ReportMainPage_GenerateInWorkspaceButton);

    Composite sPanelWorkspace = new Composite(panel, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(3).extendedMargins(20, 0, 0, 0).applyTo(sPanelWorkspace);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(sPanelWorkspace);

    Label sWorkspaceLanel = new Label(sPanelWorkspace, SWT.NONE);
    sWorkspaceLanel.setText(Messages.ReportMainPage_LocationLabel);
    Text workspaceLocation = new Text(sPanelWorkspace, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(workspaceLocation);

    final ControlDecoration controlDecoration = new ControlDecoration(workspaceLocation, SWT.LEFT | SWT.TOP);
    controlDecoration.setDescriptionText(""); //$NON-NLS-1$
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
    controlDecoration.setImage(fieldDecoration.getImage());
    controlDecoration.hide();/*from www. java 2  s.c om*/

    Button browseWorkspace = new Button(sPanelWorkspace, SWT.PUSH);
    browseWorkspace.setText(Messages.ReportMainPage_BrowseButton);

    browseWorkspace.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FolderSelectionDialog dialog = new FolderSelectionDialog(getShell(), new WorkbenchLabelProvider(),
                    new WorkbenchContentProvider()) {
                @Override
                protected TreeViewer createTreeViewer(Composite parent) {
                    TreeViewer viewer = super.createTreeViewer(parent);
                    viewer.setFilters(new ViewerFilter[] { new ViewerFilter() {
                        @Override
                        public boolean select(Viewer viewer, Object parentElement, Object element) {
                            if (element instanceof IResource) {
                                if (((IResource) element).getType() == IResource.FILE) {
                                    return false;
                                }
                            }
                            return true;
                        }

                    } });
                    return viewer;
                }
            };
            dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
            dialog.setAllowMultiple(false);
            dialog.setMessage(Messages.ReportMainPage_SelectLocationDialogText);
            dialog.setBlockOnOpen(true);
            if (dialog.open() == ResourceSelectionDialog.OK) {
                Object[] result = dialog.getResult();
                if (result.length == 1) {
                    ReportMainPage.this.workspaceLocation
                            .setValue(((IResource) result[0]).getFullPath().toString());
                }
            }
        }
    });
    setButtonLayoutData(browseWorkspace);

    dbc.bindValue(SWTObservables.observeEnabled(browseWorkspace), this.generateToWorkspace);
    dbc.bindValue(SWTObservables.observeEnabled(workspaceLocation), this.generateToWorkspace);

    dbc.bindValue(SWTObservables.observeEnabled(sWorkspaceLanel), this.generateToWorkspace);

    dbc.bindValue(SWTObservables.observeSelection(generateToWorkspace), this.generateToWorkspace);

    dbc.bindValue(SWTObservables.observeText(workspaceLocation, SWT.Modify), this.workspaceLocation);
    this.workspaceLocation.addValueChangeListener(new IValueChangeListener() {
        public void handleValueChange(ValueChangeEvent event) {
            if (!isValidWorkspaceLocation()) {
                controlDecoration.show();
                controlDecoration.showHoverText(Messages.ReportMainPage_IncorrectLocationMsg);
                validate();
                return;
            }
            controlDecoration.hide();
            validate();
        }
    });
    this.generateToWorkspace.addValueChangeListener(new IValueChangeListener() {
        public void handleValueChange(ValueChangeEvent event) {
            validate();
        }
    });
}

From source file:org.eclipse.rcptt.ui.resources.viewers.WorkspaceContextEditor.java

License:Open Source License

private void createOptionsControls(Composite parent, FormToolkit toolkit) {

    Button clearWorkspace = toolkit.createButton(parent, "Clear workspace", SWT.CHECK);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(clearWorkspace);

    ignoreByClearPatternLabel = new Label(parent, SWT.NONE);
    ignoreByClearPatternLabel//from   w  w w  .  ja va2s.  com
            .setText("Do not clear following folders or files (use comma as separator, * = any string):");
    ignoreByClearPatternLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    ignoreByClearPatternLabel.setBackground(null);
    GridDataFactory.fillDefaults().span(2, 1).hint(100, SWT.DEFAULT).applyTo(ignoreByClearPatternLabel);

    ignoreByClearPattern = toolkit.createText(parent, "", SWT.BORDER);
    ignoreByClearPattern.setBackground(null);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).hint(100, SWT.DEFAULT)
            .applyTo(ignoreByClearPattern);

    dbc.bindValue(SWTObservables.observeSelection(clearWorkspace),
            EMFObservables.observeValue(getContextElement(),
                    WorkspacePackage.Literals.WORKSPACE_CONTEXT__CLEAR_WORKSPACE),
            new ClearWorkspaceChangeListener(), new ClearWorkspaceChangeListener());

    dbc.bindValue(SWTObservables.observeText(ignoreByClearPattern, SWT.Modify), EMFObservables.observeValue(
            getContextElement(), WorkspacePackage.Literals.WORKSPACE_CONTEXT__IGNORED_BY_CLEAR_PATTERN));
}

From source file:org.eclipse.rcptt.ui.wizards.plain.DestinationsBox.java

License:Open Source License

public Composite create(Composite tab) {
    this.shell = tab.getShell();
    Composite cp = new Composite(tab, SWT.NONE);

    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(cp);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(cp);

    Button clipboardRadio = new Button(cp, SWT.RADIO);
    clipboardRadio.setText(getClipboardTitle());
    clipboardRadio.setSelection(true);//from   w w  w  . java 2  s . c  o  m
    GridDataFactory.fillDefaults().span(2, 1).applyTo(clipboardRadio);

    Button filesystemRadio = new Button(cp, SWT.RADIO);
    filesystemRadio.setText(getFileTitle());
    GridDataFactory.fillDefaults().span(2, 1).applyTo(filesystemRadio);
    Text filesystemPath = new Text(cp, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(filesystemPath);
    Button browseFilesystem = new Button(cp, SWT.PUSH);
    browseFilesystem.setText("Browse...");
    browseFilesystem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            handleBrowseFilesystem();
        }
    });
    GridDataFactory.swtDefaults().applyTo(browseFilesystem);
    SWTFactory.setButtonDimensionHint(browseFilesystem);

    dbc.bindValue(SWTObservables.observeSelection(filesystemRadio), fsSelected,
            new SelectionToModel(Selection.Filesystem), null);
    dbc.bindValue(SWTObservables.observeSelection(clipboardRadio), fsSelected,
            new SelectionToModel(Selection.Clipboard), null);

    dbc.bindValue(SWTObservables.observeEnabled(browseFilesystem), fsSelected, null,
            new ModelToSelection(Selection.Filesystem));
    dbc.bindValue(SWTObservables.observeEnabled(filesystemPath), fsSelected, null,
            new ModelToSelection(Selection.Filesystem));

    dbc.bindValue(SWTObservables.observeText(filesystemPath, SWT.Modify), filesystemPathValue);
    return cp;
}

From source file:org.eclipse.rcptt.verifications.text.ui.TextVerificationEditor.java

License:Open Source License

private void createControls(final FormToolkit toolkit, final Composite client) {
    Label introLabel = toolkit.createLabel(client, "Text should be:");
    introLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    introLabel.setBackground(null);//from ww  w. j  ava 2s.  c  o  m

    // --

    final StyledText text = new StyledText(client, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    text.setFont(JFaceResources.getTextFont());
    GridDataFactory.fillDefaults().grab(true, true).hint(1, 1).applyTo(text);
    final Button ignoreStylingCheckbox = toolkit.createButton(client, "Ignore text styling and colors",
            SWT.CHECK);

    dbc.bindValue(SWTObservables.observeText(text, SWT.Modify),
            EMFObservables.observeValue(getVerification(), TextPackage.Literals.TEXT_VERIFICATION__TEXT));

    IObservableList observableStyles = EMFObservables.observeList(getVerification(),
            TextPackage.Literals.TEXT_VERIFICATION__STYLES);
    observableStyles.addListChangeListener(new IListChangeListener() {
        @Override
        public void handleListChange(ListChangeEvent event) {
            updateStyling(text, ignoreStylingCheckbox);
        }
    });

    // --

    final Binding binding = dbc.bindValue(SWTObservables.observeSelection(ignoreStylingCheckbox), EMFObservables
            .observeValue(getVerification(), TextPackage.Literals.TEXT_VERIFICATION__IGNORE_STYLING));
    binding.getModel().addChangeListener(new IChangeListener() {
        @Override
        public void handleChange(ChangeEvent event) {
            updateStyling(text, ignoreStylingCheckbox);
        }
    });

    updateStyling(text, ignoreStylingCheckbox);
}

From source file:org.eclipse.rcptt.verifications.time.ui.TimeVerificationEditor.java

License:Open Source License

private void createIncludeContextsControls(FormToolkit toolkit, Composite client) {
    final Button includeContextsCheckbox = toolkit.createButton(client,
            "Take into account the time spent executing contexts", SWT.CHECK);
    GridDataFactory.fillDefaults().span(4, 1).applyTo(includeContextsCheckbox);

    dbc.bindValue(SWTObservables.observeSelection(includeContextsCheckbox), EMFObservables
            .observeValue(getVerification(), TimePackage.Literals.TIME_VERIFICATION__INCLUDE_CONTEXTS));
}

From source file:org.eclipse.rcptt.verifications.tree.ui.TreeVerificationEditor.java

License:Open Source License

private void createPropertiesControls(final FormToolkit toolkit, final Composite parent) {

    GridDataFactory align = GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER);

    Label verifyStyleLabel = toolkit.createLabel(parent, "Verify styles:");
    verifyStyleLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    verifyStyleLabel.setBackground(null);
    align.applyTo(verifyStyleLabel);//from w  w  w  . ja v  a2 s .c  om

    verifyStyleCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    int selectedStyleInd = 0;
    dbc.bindValue(SWTObservables.observeSelection(verifyStyleCombo), EMFObservables.observeValue(
            getVerificationElement(), TreePackage.Literals.VERIFY_TREE_DATA__ENABLE_VERIFY_STYLE));
    for (VerifyStyleType type : VerifyStyleType.values()) {
        verifyStyleCombo.add(type.getLiteral());
        if (type.getValue() == getVerificationElement().getVerifyStyle().getValue()) {
            selectedStyleInd = verifyStyleCombo.getItemCount() - 1;
        }
    }
    verifyStyleCombo.select(selectedStyleInd);
    verifyStyleCombo.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            getVerificationElement().setVerifyStyle(VerifyStyleType.get(verifyStyleCombo.getText()));
            widgetObservable.updateOutputFormat();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    align.applyTo(verifyStyleCombo);

    Button unverifiedChildrenCheck = new Button(parent, SWT.CHECK);
    unverifiedChildrenCheck.setText("Allow uncaptured children");
    unverifiedChildrenCheck
            .setToolTipText("Tree items from verification without chirdren, may contain children in UI. "
                    + "This might happen when tree was not fully expanded during capturing.");
    dbc.bindValue(SWTObservables.observeSelection(unverifiedChildrenCheck), EMFObservables.observeValue(
            getVerificationElement(), TreePackage.Literals.VERIFY_TREE_DATA__ALLOW_UNCAPTURED_CHILDREN));
    align.applyTo(unverifiedChildrenCheck);

    // Button missingColumnsCheck = new Button(parent, SWT.CHECK);
    // missingColumnsCheck.setText("Allow missing columns");
    // missingColumnsCheck.setToolTipText("This verification may contain columns, which are not present in UI");
    // dbc.bindValue(SWTObservables.observeSelection(missingColumnsCheck),
    // EMFObservables.observeValue(getVerificationElement(),
    // TreePackage.Literals.VERIFY_TREE_DATA__ALLOW_MISSING_COLUMNS));

    Button verifyIconsCheck = new Button(parent, SWT.CHECK);
    verifyIconsCheck.setText("Verify icons");

    dbc.bindValue(SWTObservables.observeSelection(verifyIconsCheck), EMFObservables
            .observeValue(getVerificationElement(), TreePackage.Literals.VERIFY_TREE_DATA__VERIFY_ICONS));
    verifyIconsCheck.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            widgetObservable.updateOutputFormat();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    align.applyTo(verifyIconsCheck);
}

From source file:org.eclipse.reqcycle.repository.data.ui.dialog.AddTypeDialog.java

License:Open Source License

@Override
protected void doInitDataBindings(DataBindingContext bindingContext) {
    //Create the Select Observable for our enum type  
    SelectObservableValue typeRadioObservable = new SelectObservableValue(TYPE.class);

    //bind the requirement radio button selection to the right enum value  
    IObservableValue btnRequirementObserverSelection = SWTObservables.observeSelection(btnReqRadio);
    typeRadioObservable.addOption(TYPE.REQUIREMENT, btnRequirementObserverSelection);

    //bind the enumeration radio button selection to the right enum value 
    IObservableValue btnEnumerationObserverSelection = SWTObservables.observeSelection(btnEnumRadio);
    typeRadioObservable.addOption(TYPE.ENUMERATION, btnEnumerationObserverSelection);

    bindingContext.bindValue(typeRadioObservable, PojoObservables.observeValue(bean, "type"));
}