Example usage for org.eclipse.jface.databinding.fieldassist ControlDecorationUpdater ControlDecorationUpdater

List of usage examples for org.eclipse.jface.databinding.fieldassist ControlDecorationUpdater ControlDecorationUpdater

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.fieldassist ControlDecorationUpdater ControlDecorationUpdater.

Prototype

ControlDecorationUpdater

Source Link

Usage

From source file:net.sf.jasperreports.eclipse.ui.validator.ValidatorUtil.java

License:Open Source License

public static void controlDecorator(Binding binding, final Button okButton) {
    ControlDecorationSupport.create(binding, SWT.TOP | SWT.LEFT, null, new ControlDecorationUpdater() {
        @Override/* w  ww.  jav a 2s.  c om*/
        protected void update(ControlDecoration decoration, IStatus status) {
            super.update(decoration, status);
            if (okButton != null)
                okButton.setEnabled(status.isOK());
        }
    });
}

From source file:org.eclipse.jface.examples.databinding.snippets.Snippet033CrossValidationControlDecoration.java

License:Open Source License

private void bindUI() {
    IObservableValue<Date> startDateObservable = WidgetProperties.dateTimeSelection().observe(startDate);
    IObservableValue<Date> endDateObservable = WidgetProperties.dateTimeSelection().observe(endDate);

    ControlDecorationSupport.create(new DateRangeValidator(startDateObservable, endDateObservable,
            "Start date must be on or before end date"), SWT.LEFT | SWT.CENTER);

    // Customize the decoration's description text and image
    ControlDecorationUpdater decorationUpdater = new ControlDecorationUpdater() {
        @Override//from  w w  w .  j av a  2 s  .  c  o  m
        protected String getDescriptionText(IStatus status) {
            return "ERROR: " + super.getDescriptionText(status);
        }

        @Override
        protected Image getImage(IStatus status) {
            return status.isOK() ? null : Display.getCurrent().getSystemImage(SWT.ICON_ERROR);
        }
    };
    ControlDecorationSupport.create(
            new DateRangeValidator(Observables.constantObservableValue(new Date()), startDateObservable,
                    "Choose a starting date later than today"),
            SWT.LEFT | SWT.TOP, (Composite) null, decorationUpdater);
}

From source file:org.eclipse.rcptt.ctx.filesystem.ui.FilesystemContextEditor.java

License:Open Source License

private void createRootControls(final FormToolkit toolkit, final Composite client) {
    Composite panel = toolkit.createComposite(client);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(panel);
    GridLayoutFactory.fillDefaults().numColumns(3).spacing(10, 10).applyTo(panel);

    Label rootLabel = toolkit.createLabel(panel, "Root path:");
    rootLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    rootLabel.setBackground(null);/*  ww  w .ja  va 2  s  . co m*/

    Text rootText = toolkit.createText(panel, "", SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).hint(1, SWT.DEFAULT).applyTo(rootText);
    Binding rootBinding = dbc.bindValue(SWTObservables.observeText(rootText, SWT.Modify), EMFObservables
            .observeValue(getContextElement(), FilesystemPackage.Literals.FILESYSTEM_CONTEXT__PATH),
            rootStrategy, rootStrategy);
    ControlDecorationSupport.create(rootBinding, SWT.TOP | SWT.LEFT, panel, new ControlDecorationUpdater() {
        @Override
        protected void update(ControlDecoration decoration, IStatus status) {
            decoration.setMarginWidth(2);
            super.update(decoration, status);
        }
    });

    Button browseButton = toolkit.createButton(panel, "Browse...", SWT.PUSH);
    browseButton.addSelectionListener(new OneSelectionListener() {
        @Override
        public void selected(SelectionEvent e) {
            AutLaunch launch = LaunchUtils.selectAutLaunch(client.getShell());
            if (launch == null)
                return;

            DirectoryDialog dialog = new DirectoryDialog(client.getShell());
            String result = dialog.open();
            if (result != null) {
                getContextElement().setPath(makeRootPath(result, launch));
            }
        }
    });
}

From source file:org.eclipse.rcptt.ui.verification.WidgetVerificationEditor.java

License:Open Source License

protected Control createWidgetControls(Composite parent, FormToolkit toolkit, IWorkbenchSite site,
        final EditorHeader header) {
    this.header = header;

    Composite box = toolkit.createComposite(parent);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(box);
    GridLayoutFactory.fillDefaults().numColumns(3).applyTo(box);

    Label label = toolkit.createLabel(box, "Widget:");
    label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    label.setBackground(null);//from  w w w. j  a  v  a 2  s.  c o m

    selectorText = new StyledText(box, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).hint(1, SWT.DEFAULT).applyTo(selectorText);
    selectorText.setFont(JFaceResources.getTextFont());
    new EclStyledTextHighlighter().install(selectorText);
    Binding selectorBinding = dbc.bindValue(SWTObservables.observeText(selectorText, SWT.Modify),
            EMFObservables.observeValue(getWidgetVerification(),
                    ScenarioPackage.Literals.WIDGET_VERIFICATION__SELECTOR),
            selectorStrategy, selectorStrategy);
    ControlDecorationSupport.create(selectorBinding, SWT.TOP | SWT.LEFT, box, new ControlDecorationUpdater() {
        @Override
        protected void update(ControlDecoration decoration, IStatus status) {
            decoration.setMarginWidth(2);
            super.update(decoration, status);
        }
    });

    final Button button = toolkit.createButton(box, "Pick...", SWT.NONE);
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            AutLaunch launch = LaunchUtils.selectAutLaunch();
            if (launch == null)
                return;
            VerificationType type = VerificationTypeManager.getInstance()
                    .getTypeByVerification(getWidgetVerification());
            String selector = WidgetPicker.activate(null, (BaseAutLaunch) launch, type);
            if (selector != null) {
                selectorText.setText(selector);
                header.getRecordButton().notifyListeners(SWT.Selection, new Event());
            }
        }
    });
    return box;
}

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

License:Open Source License

private void createMinutesAndSecondsControls(final FormToolkit toolkit, final Composite client) {
    Label introLabel = toolkit.createLabel(client, "Test case execution time should be less than:");
    introLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    introLabel.setBackground(null);//w w w .  j  a va 2 s . c  om
    GridDataFactory.fillDefaults().span(4, 1).applyTo(introLabel);

    Text minutesText = toolkit.createText(client, "00" /* for computeSize */, SWT.BORDER | SWT.RIGHT);
    GridDataFactory.fillDefaults().hint(minutesText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x, SWT.DEFAULT)
            .indent(32, 0).applyTo(minutesText);

    Binding minutesBinding = dbc.bindValue(SWTObservables.observeText(minutesText, SWT.Modify),
            EMFObservables.observeValue(getVerification(), TimePackage.Literals.TIME_VERIFICATION__MINUTES),
            minutesStrategy, new EMFUpdateValueStrategy());
    ControlDecorationSupport.create(minutesBinding, SWT.TOP | SWT.LEFT, client, new ControlDecorationUpdater() {
        @Override
        protected void update(ControlDecoration decoration, IStatus status) {
            decoration.setMarginWidth(2);
            super.update(decoration, status);
        }
    });

    Label minutesLabel = toolkit.createLabel(client, "minute(s) and");
    minutesLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    minutesLabel.setBackground(null);

    Text secondsText = toolkit.createText(client, "00" /* for computeSize */, SWT.BORDER | SWT.RIGHT);
    GridDataFactory.fillDefaults().hint(secondsText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x, SWT.DEFAULT)
            .applyTo(secondsText);
    Binding secondsBinding = dbc.bindValue(SWTObservables.observeText(secondsText, SWT.Modify),
            EMFObservables.observeValue(getVerification(), TimePackage.Literals.TIME_VERIFICATION__SECONDS),
            secondsStrategy, new EMFUpdateValueStrategy());
    ControlDecorationSupport.create(secondsBinding, SWT.TOP | SWT.LEFT, client, new ControlDecorationUpdater() {
        @Override
        protected void update(ControlDecoration decoration, IStatus status) {
            decoration.setMarginWidth(2);
            super.update(decoration, status);
        }
    });

    Label secondsLabel = toolkit.createLabel(client, "second(s)");
    secondsLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    secondsLabel.setBackground(null);
}

From source file:org.jboss.mapper.eclipse.internal.wizards.FirstPage.java

License:Open Source License

void createPage(final Composite parent) {

    final Composite page = new Composite(parent, SWT.NONE);
    setControl(page);//from www.  j  a  va  2  s  .co m
    page.setLayout(GridLayoutFactory.swtDefaults().spacing(0, 5).numColumns(3).create());

    // Create project widgets
    Label label = new Label(page, SWT.NONE);
    label.setText("Project:");
    label.setToolTipText("The project that will contain the mapping file.");
    final ComboViewer projectViewer = new ComboViewer(new Combo(page, SWT.READ_ONLY));
    projectViewer.getCombo().setLayoutData(
            GridDataFactory.swtDefaults().grab(true, false).span(2, 1).align(SWT.FILL, SWT.CENTER).create());
    projectViewer.getCombo().setToolTipText(label.getToolTipText());
    projectViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(final Object element) {
            return ((IProject) element).getName();
        }
    });

    // Create ID widgets
    label = new Label(page, SWT.NONE);
    label.setText("ID:");
    label.setToolTipText("The transformation ID that will be shown in the Fuse editor");
    final Text idText = new Text(page, SWT.BORDER);
    idText.setLayoutData(
            GridDataFactory.swtDefaults().span(2, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).create());
    idText.setToolTipText(label.getToolTipText());

    // Create file path widgets
    label = new Label(page, SWT.NONE);
    label.setText("Dozer File path: ");
    label.setToolTipText("The path to the Dozer transformation file.");
    final Text pathText = new Text(page, SWT.BORDER);
    pathText.setLayoutData(
            GridDataFactory.swtDefaults().span(2, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).create());
    pathText.setToolTipText(label.getToolTipText());

    // Create camel file path widgets
    label = new Label(page, SWT.NONE);
    label.setText("Camel File path: ");
    label.setToolTipText("Path to the Camel configuration file.");
    final Text camelFilePathText = new Text(page, SWT.BORDER);
    camelFilePathText.setLayoutData(
            GridDataFactory.swtDefaults().span(1, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).create());
    camelFilePathText.setToolTipText(label.getToolTipText());

    final Button camelPathButton = new Button(page, SWT.NONE);
    camelPathButton.setText("...");
    camelPathButton.setToolTipText("Browse to select an available Camel file.");
    camelPathButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            final IResource res = Util.selectResourceFromWorkspace(getShell(), ".xml", model.getProject());
            if (res != null) {
                final IPath respath = JavaUtil.getJavaPathForResource(res);
                final String path = respath.makeRelative().toString();
                model.setCamelFilePath(path);
                camelFilePathText.setText(path);
                camelFilePathText.notifyListeners(SWT.Modify, new Event());
            }
        }
    });

    // Create source widgets
    Group group = new Group(page, SWT.SHADOW_ETCHED_IN);
    Label fileLabel = new Label(group, SWT.NONE);
    final Text sourcePathText = new Text(group, SWT.BORDER);
    final Button sourcePathButton = new Button(group, SWT.NONE);
    Label typeLabel = new Label(group, SWT.NONE);
    final ComboViewer sourceTypeViewer = new ComboViewer(new Combo(group, SWT.READ_ONLY));
    createFileControls(group, fileLabel, "Source", sourcePathText, sourcePathButton, typeLabel,
            sourceTypeViewer);

    // Create target widgets
    group = new Group(page, SWT.SHADOW_ETCHED_IN);
    fileLabel = new Label(group, SWT.NONE);
    final Text targetPathText = new Text(group, SWT.BORDER);
    final Button targetPathButton = new Button(group, SWT.NONE);
    typeLabel = new Label(group, SWT.NONE);
    final ComboViewer targetTypeViewer = new ComboViewer(new Combo(group, SWT.READ_ONLY));
    createFileControls(group, fileLabel, "Target", targetPathText, targetPathButton, typeLabel,
            targetTypeViewer);

    // Bind project widget to UI model
    projectViewer.setContentProvider(new ObservableListContentProvider());
    IObservableValue widgetValue = ViewerProperties.singleSelection().observe(projectViewer);
    IObservableValue modelValue = BeanProperties.value(Model.class, "project").observe(model);
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null) {
                sourcePathButton.setEnabled(false);
                targetPathButton.setEnabled(false);
                return ValidationStatus.error("A project must be selected");
            }
            sourcePathButton.setEnabled(true);
            targetPathButton.setEnabled(true);
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT);
    projectViewer.setInput(Properties.selfList(IProject.class).observe(model.projects));

    // Bind transformation ID widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(idText);
    modelValue = BeanProperties.value(Model.class, "id").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null || value.toString().trim().isEmpty()) {
                return ValidationStatus.error("A transformation ID must be supplied");
            }
            final String id = value.toString().trim();
            final StringCharacterIterator iter = new StringCharacterIterator(id);
            for (char chr = iter.first(); chr != StringCharacterIterator.DONE; chr = iter.next()) {
                if (!Character.isJavaIdentifierPart(chr)) {
                    return ValidationStatus.error("The transformation ID may only contain letters, "
                            + "digits, currency symbols, or underscores");
                }
            }
            if (model.camelConfigBuilder != null) {
                for (final String endpointId : model.camelConfigBuilder.getTransformEndpointIds()) {
                    if (id.equalsIgnoreCase(endpointId)) {
                        return ValidationStatus.error("A transformation with the supplied ID already exists");
                    }
                }
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT);

    // Bind file path widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(pathText);
    modelValue = BeanProperties.value(Model.class, "filePath").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null || value.toString().trim().isEmpty()) {
                return ValidationStatus.error("The transformation file path must be supplied");
            }
            if (!(value.toString().trim().isEmpty())) {
                final IFile file = model.getProject().getFile(Util.RESOURCES_PATH + (String) value);
                if (file.exists()) {
                    return ValidationStatus.warning("A transformation file with that name already exists.");
                }
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT);

    // Bind camel file path widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(camelFilePathText);
    modelValue = BeanProperties.value(Model.class, "camelFilePath").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null || value.toString().trim().isEmpty()) {
                return ValidationStatus.error("The Camel file path must be supplied");
            }
            if (!(value.toString().trim().isEmpty())) {
                File testFile = null;
                final String path = (String) value;
                testFile = new File(model.getProject().getFile(path).getLocationURI());
                if (!testFile.exists()) {
                    testFile = new File(
                            model.getProject().getFile(Util.RESOURCES_PATH + path).getLocationURI());
                    if (!testFile.exists()) {
                        return ValidationStatus.error("The Camel file path must be a valid file location");
                    }
                }
                try {
                    CamelConfigBuilder.loadConfig(testFile);
                } catch (final Exception e) {
                    return ValidationStatus.error("The Camel file path must refer to a valid Camel file");
                }
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null),
            SWT.LEFT | SWT.TOP);

    final ControlDecorationUpdater sourceUpdator = new ControlDecorationUpdater();
    final ControlDecorationUpdater targetUpdator = new ControlDecorationUpdater();

    // Bind source file path widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(sourcePathText);
    modelValue = BeanProperties.value(Model.class, "sourceFilePath").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            final String path = value == null ? null : value.toString().trim();
            if (path == null || path.isEmpty()) {
                return ValidationStatus
                        .error("A source file path must be supplied for the supplied target file path");
            }
            if (model.getProject().findMember(path) == null) {
                return ValidationStatus.error("Unable to find a source file with the supplied path");
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT, null,
            sourceUpdator);

    // Bind target file path widget to UI model
    widgetValue = WidgetProperties.text(SWT.Modify).observe(targetPathText);
    modelValue = BeanProperties.value(Model.class, "targetFilePath").observe(model);
    strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            final String path = value == null ? null : value.toString().trim();
            if (path == null || path.isEmpty()) {
                return ValidationStatus
                        .error("A target file path must be supplied for the supplied source file path");
            }
            if (model.getProject().findMember(path) == null) {
                return ValidationStatus.error("Unable to find a target file with the supplied path");
            }
            return ValidationStatus.ok();
        }
    });
    ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), SWT.LEFT, null,
            targetUpdator);

    // Bind source type widget to UI model
    sourceTypeViewer.setContentProvider(new ObservableListContentProvider());
    widgetValue = ViewerProperties.singleSelection().observe(sourceTypeViewer);
    modelValue = BeanProperties.value(Model.class, "sourceType").observe(model);
    context.bindValue(widgetValue, modelValue);
    sourceTypeViewer.setInput(Properties.selfList(ModelType.class).observe(Arrays.asList(ModelType.values())));

    // Bind target type widget to UI model
    targetTypeViewer.setContentProvider(new ObservableListContentProvider());
    widgetValue = ViewerProperties.singleSelection().observe(targetTypeViewer);
    modelValue = BeanProperties.value(Model.class, "targetType").observe(model);
    context.bindValue(widgetValue, modelValue);
    targetTypeViewer.setInput(Properties.selfList(ModelType.class).observe(Arrays.asList(ModelType.values())));

    // Set focus to appropriate control
    page.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(final PaintEvent event) {
            if (model.getProject() == null) {
                projectViewer.getCombo().setFocus();
            } else {
                idText.setFocus();
            }
            page.removePaintListener(this);
        }
    });

    for (final Object observable : context.getValidationStatusProviders()) {
        ((Binding) observable).getTarget().addChangeListener(new IChangeListener() {

            @Override
            public void handleChange(final ChangeEvent event) {
                validatePage();
            }
        });
    }

    if (model.getProject() == null) {
        validatePage();
    } else {
        projectViewer.setSelection(new StructuredSelection(model.getProject()));
    }
}

From source file:org.jboss.tools.openshift.internal.ui.wizard.connection.OAuthDetailView.java

License:Open Source License

@Override
public Composite createControls(Composite parent, Object context, DataBindingContext dbc) {
    Composite composite = setControl(new Composite(parent, SWT.None));
    GridLayoutFactory.fillDefaults().numColumns(2).spacing(10, 10).applyTo(composite);

    StyledText tokenRequestLink = StyledTextUtils.emulateLinkWidget(MSG_TOKEN,
            new StyledText(composite, SWT.WRAP));
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).applyTo(tokenRequestLink);
    if (authDetails != null) {
        authDetails.getRequestTokenLink();
    }//  w w w  . j a  v  a 2  s  . c o m
    StyledTextUtils.emulateLinkAction(tokenRequestLink,
            r -> onRetrieveLinkClicked(tokenRequestLink.getShell(), dbc));
    tokenRequestLink.setCursor(new Cursor(tokenRequestLink.getShell().getDisplay(), SWT.CURSOR_HAND));

    //token
    Label authTypeLabel = new Label(composite, SWT.NONE);
    authTypeLabel.setText("Token");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(authTypeLabel);
    this.tokenText = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(tokenText);
    ControlDecorationSupport.create(connectionValidator, SWT.LEFT | SWT.TOP, null,
            new ControlDecorationUpdater());

    this.rememberTokenCheckbox = new Button(composite, SWT.CHECK);
    rememberTokenCheckbox.setText("&Save token (could trigger secure storage login)");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).grab(true, false)
            .applyTo(rememberTokenCheckbox);

    return composite;
}