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

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

Introduction

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

Prototype

@Deprecated
public static ISWTObservableValue observeText(Control control, int event) 

Source Link

Document

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

Usage

From source file:com.ebmwebsourcing.petals.services.cdk.editor.CDK5JBIEndpointUIHelper.java

License:Open Source License

/**
 * Creates the UI for "provide" blocks in the JBI editor (with CDK 5 fields).
 * @param endpoint//from w w  w .  j a  v  a2  s .  co  m
 * @param toolkit
 * @param generalDetails
 * @param ise
 */
public static void createProvidesUI(final AbstractEndpoint endpoint, final FormToolkit toolkit,
        final Composite parent, final ISharedEdition ise) {

    // First: the WSDL part
    Color blueFont = parent.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE);

    // The label browser
    Label wsdlLabel = toolkit.createLabel(parent, "WSDL location:");
    wsdlLabel.setToolTipText("The relative path of the WSDL in the service unit or an URL");
    wsdlLabel.setForeground(blueFont);
    GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.TOP).indent(0, 4).applyTo(wsdlLabel);

    Composite subContainer = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(0, 0).numColumns(2).extendedMargins(0, 0, 0, 20)
            .applyTo(subContainer);
    subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final Text wsdlText = toolkit.createText(subContainer, "", SWT.SINGLE | SWT.BORDER);
    wsdlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button browseButton = toolkit.createButton(subContainer, "Browse...", SWT.PUSH);
    browseButton.setToolTipText("Select a WSDL located in the project resources");
    browseButton.addSelectionListener(new DefaultSelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            IProject project = ise.getEditedFile().getProject();
            IFolder resourceFolder = project.getFolder(PetalsConstants.LOC_RES_FOLDER);

            // FIXME: replace this dialog by one that only shows WSDLs?
            ElementTreeSelectionDialog dlg = SwtFactory.createWorkspaceFileSelectionDialog(wsdlText.getShell(),
                    resourceFolder, "WSDL Selection",
                    "Select a WSDL file located in the project's resource directory.", "wsdl");

            File file = JbiXmlUtils.getWsdlFile(ise.getEditedFile(), wsdlText.getText());

            if (file != null) {
                IFile wsdlFile = ResourceUtils.getIFile(file);
                if (wsdlFile != null)
                    dlg.setInitialElementSelections(Arrays.asList(wsdlFile));
            }

            if (dlg.open() == Window.OK) {
                IFile selectedFile = (IFile) dlg.getResult()[0];
                int rfsc = resourceFolder.getFullPath().segmentCount();
                String wsdlValue = selectedFile.getFullPath().removeFirstSegments(rfsc).toString();
                wsdlText.setText(wsdlValue);
            }
        }
    });

    // The helpers
    final WsdlParsingJobManager wsdlParsingJob = new WsdlParsingJobManager();
    wsdlText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {

            String wsdlValue = ((Text) e.widget).getText().trim();
            File f = JbiXmlUtils.getWsdlFile(ise.getEditedFile(), wsdlValue);
            final URI wsdlUri;
            if (f != null)
                wsdlUri = f.toURI();
            else if (!StringUtils.isEmpty(wsdlValue))
                wsdlUri = UriAndUrlHelper.urlToUri(wsdlValue);
            else
                wsdlUri = null;

            wsdlParsingJob.setWsdlUri(wsdlUri);
        }
    });

    Link link = new Link(subContainer, SWT.NONE);
    link.setText("<A>" + Messages.wsdlTools + "</A>");
    final AtomicBoolean tooltipVisible = new AtomicBoolean(false);
    final WSDLHelperTooltip tooltip = new WSDLHelperTooltip(link, toolkit, (Provides) endpoint, ise,
            wsdlParsingJob);
    link.addSelectionListener(new DefaultSelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            boolean visible = tooltipVisible.get();
            if (visible)
                tooltip.hide();
            else
                tooltip.show();

            tooltipVisible.set(!visible);
        }
    });

    link.addMouseTrackListener(new MouseTrackAdapter() {
        @Override
        public void mouseEnter(MouseEvent e) {
            tooltip.show();
        }

        @Override
        public void mouseExit(MouseEvent e) {
            if (!tooltipVisible.get())
                tooltip.hide();
        }
    });

    // The data-binding
    ise.getDataBindingContext().bindValue(
            SWTObservables.observeDelayedValue(200, SWTObservables.observeText(wsdlText, SWT.Modify)),
            EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
                    Cdk5Package.Literals.CDK5_PROVIDES__WSDL));

    // Then, the common widgets
    final CommonUIBean commonBean = JBIEndpointUIHelpers.createCommonEndpointUI(endpoint, toolkit, parent, ise);

    // Then, add the auto-generation button
    toolkit.createLabel(parent, "");

    // Add the button and its label
    final Button generateEdptButton = toolkit.createButton(parent, "", SWT.CHECK);
    generateEdptButton.setText("Generate the end-point at deployment time");
    generateEdptButton.setToolTipText("The end-point name will be generated by Petals on deployment");
    generateEdptButton.addSelectionListener(new DefaultSelectionListener() {
        private String oldValue;

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean selected = generateEdptButton.getSelection();
            commonBean.edptText.setEnabled(!selected);
            commonBean.edptLabel.setEnabled(!selected);

            if (selected)
                this.oldValue = commonBean.edptText.getText().trim();
            else if (StringUtils.isEmpty(this.oldValue))
                this.oldValue = commonBean.srvNameText.getText() + "Endpoint";

            String edptValue = selected ? PetalsConstants.AUTO_GENERATE : this.oldValue;
            Command cmd = SetCommand.create(ise.getEditingDomain(), endpoint,
                    JbiPackage.Literals.ABSTRACT_ENDPOINT__ENDPOINT_NAME, edptValue);
            ise.getEditingDomain().getCommandStack().execute(cmd);
        }
    });
}

From source file:com.ebmwebsourcing.petals.services.filetransfer.v24.editor.FileTransferProvidesJbiEditorContribution.java

License:Open Source License

@Override
public void addAdvancedSUContent(AbstractEndpoint endpoint, FormToolkit toolkit, Composite advancedTab,
        ISharedEdition ise) {//  ww  w  .  j av  a 2 s . c  o  m

    Composite composite = createEditorSection(advancedTab, toolkit, "File Transfer Parameters", true);
    if ("writefiles".equalsIgnoreCase(endpoint.getInterfaceName().getLocalPart())) {
        FileTransferProvideWriteControls controls = new FileTransferProvideWriteControls();
        controls.createControls(composite, true);

        IObservableValue widgetObservable = SWTObservables.observeDelayedValue(300,
                SWTObservables.observeText(controls.getDirectoryText(), SWT.Modify));
        IObservableValue iov = EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
                Filetransfer2xPackage.Literals.FILE_TRANSFER_PROVIDES__WRITE_DIRECTORY);
        ise.getDataBindingContext().bindValue(widgetObservable, iov);

        widgetObservable = ViewersObservables
                .observeSingleSelection((ISelectionProvider) controls.getCopyModeViewer());
        iov = EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
                Filetransfer2xPackage.Literals.FILE_TRANSFER_PROVIDES__COPY_MODE);
        ise.getDataBindingContext().bindValue(widgetObservable, iov);

        widgetObservable = SWTObservables.observeDelayedValue(300,
                SWTObservables.observeText(controls.getFilenameText(), SWT.Modify));
        iov = EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
                Filetransfer2xPackage.Literals.FILE_TRANSFER_PROVIDES__FILE_PATTERN);
        ise.getDataBindingContext().bindValue(widgetObservable, iov);

    } else {
        FileTransferProvideGetControls controls = new FileTransferProvideGetControls();
        controls.createControls(composite, true);

        IObservableValue widgetObservable = SWTObservables.observeDelayedValue(300,
                SWTObservables.observeText(controls.getReadText(), SWT.Modify));
        IObservableValue iov = EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
                Filetransfer2xPackage.Literals.FILE_TRANSFER_PROVIDES__READ_DIRECTORY);
        ise.getDataBindingContext().bindValue(widgetObservable, iov);

        widgetObservable = SWTObservables.observeDelayedValue(300,
                SWTObservables.observeText(controls.getBackupText(), SWT.Modify));
        iov = EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
                Filetransfer2xPackage.Literals.FILE_TRANSFER_PROVIDES__BACKUP_DIRECTORY);
        ise.getDataBindingContext().bindValue(widgetObservable, iov);
    }

    composite = createEditorSection(advancedTab, toolkit, "CDK Parameters");
    CDK5JBIEndpointUIHelper.generateDefaultCdkWidgetsForProvidesEditor(endpoint, toolkit, composite, ise);
}

From source file:com.ebmwebsourcing.petals.services.quartz.editor.QuartzConsumesEditorContribution.java

License:Open Source License

@Override
public void addAdvancedSUContent(AbstractEndpoint endpoint, FormToolkit toolkit, Composite advancedTab,
        ISharedEdition ise) {//w  w w.java2  s.co m

    Composite composite = createEditorSection(advancedTab, toolkit, "Quartz Parameters");
    QuartzControls controls = new QuartzControls();
    controls.createControls(composite, true);

    IObservableValue widgetObservable = SWTObservables.observeDelayedValue(300,
            SWTObservables.observeText(controls.getCronText(), SWT.Modify));
    IObservableValue iov = EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
            QuartzPackage.Literals.QUARTZ_CONSUMES__CRON_EXPRESSION);
    ise.getDataBindingContext().bindValue(widgetObservable, iov);

    widgetObservable = SWTObservables.observeDelayedValue(300,
            SWTObservables.observeText(controls.getMsgText(), SWT.Modify));
    iov = EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
            QuartzPackage.Literals.QUARTZ_CONSUMES__CONTENT);
    ise.getDataBindingContext().bindValue(widgetObservable, iov);

    composite = createEditorSection(advancedTab, toolkit, "CDK Parameters");
    CDK5JBIEndpointUIHelper.generateDefaultCdkWidgetsForConsumesEditor(endpoint, toolkit, composite, ise);
}

From source file:com.ebmwebsourcing.petals.services.validation.editor.ValidationProvidesEditorContribution.java

License:Open Source License

@Override
public void addMainSUContent(final AbstractEndpoint endpoint, FormToolkit toolkit, final Composite mainTab,
        ISharedEdition ise) {/*from   www.  java2 s .  c  o  m*/

    Composite composite = createCommonProvideSection(mainTab, toolkit);
    CDK5JBIEndpointUIHelper.createProvidesUI(endpoint, toolkit, composite, ise);

    composite = createEditorSection(mainTab, toolkit, "Validation Parameters", true);
    createLabel(toolkit, composite, "XML Schema *:", "Relative path to the XSD File");

    IFile jbiXmlFile = ise.getEditedFile();
    TextWithButtonComposite browser = SwtFactory.createWorkspaceFileBrowser(composite, jbiXmlFile.getParent(),
            jbiXmlFile, "XSD");
    browser.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
    ise.getDataBindingContext().bindValue(SWTObservables.observeText(browser.getText(), SWT.Modify),
            EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
                    ValidationPackage.Literals.VALIDATION_PROVIDES__SCHEMA));
}

From source file:com.ebmwebsourcing.petals.services.xslt.editor.XsltProvidesEditorContribution.java

License:Open Source License

@Override
public void addMainSUContent(final AbstractEndpoint endpoint, FormToolkit toolkit, final Composite mainTab,
        ISharedEdition ise) {/*from  w  w w  . j a va  2s.  c o  m*/

    Composite composite = createCommonProvideSection(mainTab, toolkit);
    CDK5JBIEndpointUIHelper.createProvidesUI(endpoint, toolkit, composite, ise);

    composite = createEditorSection(mainTab, toolkit, "XSLT Parameters", true);
    createLabel(toolkit, composite, "XSL Stylesheet *:", "Relative path to the XSLT File");

    IFile jbiXmlFile = ise.getEditedFile();
    TextWithButtonComposite browser = SwtFactory.createWorkspaceFileBrowser(composite, jbiXmlFile.getParent(),
            jbiXmlFile, "XSLT");
    browser.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
    ise.getDataBindingContext().bindValue(SWTObservables.observeText(browser.getText(), SWT.Modify),
            EObjectUIHelper.createCustomEmfEditObservable(ise.getEditingDomain(), endpoint,
                    XsltPackage.Literals.XSLT_PROVIDES__STYLESHEET));
}

From source file:com.googlecode.osde.internal.ui.OsdePreferenceBinder.java

License:Apache License

/**
 * Binds a <code>preferenceName<code> to the attribute of the provided <code>control</code>.
 * The supported controls are:/*  w  w w.j av a2s .  com*/
 * <ul>
 * <li>org.eclipse.swt.widgets.Button (Radio or Checkbox)</li>
 * <li>org.eclipse.swt.widgets.Combo</li>
 * <li>org.eclipse.swt.widgets.Text</li>
 * </ul>
 *
 * The supported preference types are:
 * <ul>
 * <li>java.lang.Boolean</li>
 * <li>java.lang.String</li>
 * </ul>
 *
 * @param control
 *            the SWT widget will be bound
 * @param preferenceName
 *            a key used to the preference store
 * @param type
 *            model type
 * @param targetToModel
 *            strategy to employ when the target is the source of the change
 *            and the model is the destination
 * @param modelToTarget
 *            strategy to employ when the model is the source of the change
 *            and the target is the destination
 */
public void bind(Control control, String preferenceName, Class<?> type, IConverter targetToModel,
        IConverter modelToTarget) {

    if (!ArrayUtils.contains(supportedTypes, type)) {
        throw new IllegalArgumentException("type[" + type + "] is not supported.");
    }

    IObservableValue model = new ObservableMapValue(store, preferenceName);
    IObservableValue ui = null;

    UpdateValueStrategy modelUpdater = new UpdateValueStrategy();
    UpdateValueStrategy uiUpdater = new UpdateValueStrategy();

    if (targetToModel != null) {
        modelUpdater.setConverter(targetToModel);
    }

    if (modelToTarget != null) {
        uiUpdater.setConverter(modelToTarget);
    }

    if (control instanceof Button) {
        boolean isRadio = (control.getStyle() & SWT.RADIO) != 0;
        boolean isCheck = (control.getStyle() & SWT.CHECK) != 0;
        if (isRadio || isCheck) {
            ui = SWTObservables.observeSelection(control);
        }
    } else if (control instanceof Text) {
        ui = SWTObservables.observeText(control, SWT.Modify);
    } else if (control instanceof Combo) {
        ui = SWTObservables.observeText(control);
    }

    if (ui == null) {
        logger.error(control + " is not supported yet.");
        throw new UnsupportedOperationException(control + " is not supported yet.");
    }

    propagateData(preferenceName, type);
    context.bindValue(ui, model, modelUpdater, uiUpdater);
}

From source file:com.htmlhifive.tools.jslint.dialog.CreateEngineDialog.java

License:Apache License

/**
 * ??./*from  www. j a v a2  s  . c o  m*/
 */
private void initialDataBinding() {

    DataBindingContext context = new DataBindingContext();

    // Validator
    MultiValidator validator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            StringBuilder sb = new StringBuilder();

            if ((Boolean) wvJshint.getValue() && (Boolean) wvJslint.getValue()) {
                sb.append(Messages.EM0014.getText());
            }
            String outputPath = (String) wvOutputDir.getValue();
            if (StringUtils.isEmpty(outputPath)) {
                sb.append(Messages.EM0009.format(Messages.DL0020.getText()));
            } else {
                IPath path = new Path(outputPath);
                if (!ResourcesPlugin.getWorkspace().getRoot().exists(path)) {
                    sb.append(Messages.EM0000.format(Messages.DL0020.getText()));
                }
            }

            if (StringUtils.isEmpty(sb.toString())) {
                getButton(IDialogConstants.OK_ID).setEnabled(true);
                return ValidationStatus.info(Messages.DL0027.getText());
            }

            if (getButton(IDialogConstants.OK_ID) != null) {
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            }
            return ValidationStatus.error(sb.toString());
        }
    };

    // ??
    IObservableValue obsOutputDirText = SWTObservables.observeText(textOutputDir, SWT.Modify);
    context.bindValue(obsOutputDirText, wvOutputDir, null, null);

    // JSLint???
    IObservableValue obsSelectJslint = WidgetProperties.selection().observe(btnRadioJSLint);
    context.bindValue(obsSelectJslint, wvJslint, null, null);

    // JSHint???
    IObservableValue obsSelectJsHint = WidgetProperties.selection().observe(btnRadioJSHint);
    context.bindValue(obsSelectJsHint, wvJshint);

    // ??
    context.addValidationStatusProvider(validator);
    TitleAreaDialogSupport.create(this, context);

}

From source file:com.htmlhifive.tools.jslint.dialog.CreateOptionFileDialog.java

License:Apache License

/**
 * ???./*from   ww  w  .j  a v a2s . c om*/
 */
private void initializeDataBindings() {
    DataBindingContext context = new DataBindingContext();
    // validator
    MultiValidator validator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            StringBuilder sb = new StringBuilder();
            String optionFileName = (String) wvOptionFileName.getValue();
            if (StringUtils.isEmpty(optionFileName)) {
                sb.append(Messages.EM0009.format(Messages.DL0021.getText()));
            } else if (!FilenameUtils.isExtension(optionFileName, "xml")) {
                optionFileName += ".xml";
            }
            String outputDir = (String) wvOutpuDir.getValue();

            if (StringUtils.isEmpty(outputDir)) {
                sb.append(Messages.EM0009.format(Messages.DL0020.getText()));
            } else {
                IPath path = new Path(outputDir);
                if (!ResourcesPlugin.getWorkspace().getRoot().exists(path)) {
                    sb.append(Messages.EM0000.format(Messages.DL0020.getText()));
                }
            }

            if (StringUtils.isNotEmpty(optionFileName) && StringUtils.isNotEmpty(outputDir)) {
                IPath path = new Path(outputDir + "/" + optionFileName);
                if (ResourcesPlugin.getWorkspace().getRoot().exists(path)) {
                    sb.append(Messages.EM0013.getText());
                }
            }
            if (StringUtils.isEmpty(sb.toString())) {
                getButton(IDialogConstants.OK_ID).setEnabled(true);
                return ValidationStatus.info(Messages.DL0019.getText());
            }

            if (getButton(IDialogConstants.OK_ID) != null) {
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            }
            return ValidationStatus.error(sb.toString());
        }
    };

    // 
    IObservableValue outputDir = SWTObservables.observeText(textOutputDir, SWT.Modify);
    context.bindValue(outputDir, wvOutpuDir, null, null);

    // ??
    IObservableValue optionFileName = SWTObservables.observeText(textOptionFileName, SWT.Modify);
    context.bindValue(optionFileName, wvOptionFileName, null, null);

    context.addValidationStatusProvider(validator);
    TitleAreaDialogSupport.create(this, context);

}

From source file:com.jaspersoft.studio.data.hbase.HBaseDataAdapterComposite.java

License:Open Source License

@Override
protected void bindWidgets(DataAdapter dataAdapter) {
    bindingContext.bindValue(SWTObservables.observeText(quorumField, SWT.Modify),
            PojoObservables.observeValue(dataAdapter, "zookeeperQuorum")); //$NON-NLS-1$
    bindingContext.bindValue(SWTObservables.observeText(zookeeperClientField, SWT.Modify),
            PojoObservables.observeValue(dataAdapter, "zookeeperClientPort")); //$NON-NLS-1$
}

From source file:com.jaspersoft.studio.data.hbase.HBaseThriftDataAdapterComposite.java

License:Open Source License

@Override
protected void bindWidgets(DataAdapter dataAdapter) {
    bindingContext.bindValue(SWTObservables.observeText(host, SWT.Modify),
            PojoObservables.observeValue(dataAdapter, "host")); //$NON-NLS-1$
    bindingContext.bindValue(SWTObservables.observeText(port, SWT.Modify),
            PojoObservables.observeValue(dataAdapter, "port")); //$NON-NLS-1$
}