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:org.bonitasoft.studio.common.properties.DescriptionPropertySectionContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection page) {

    composite.setLayout(new RowLayout());
    Text text = widgetFactory.createText(composite, element.getDocumentation(),
            SWT.BORDER | SWT.MULTI | SWT.WRAP);
    RowData rd = new RowData();
    rd.width = 300;/*  ww w. j a v a2  s  .  c  om*/
    rd.height = 60;
    text.setLayoutData(rd);

    context = new EMFDataBindingContext();
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new InputLengthValidator(Messages.GeneralSection_Description, 254));
    //   context.bindValue(SWTObservables.observeDelayedValue(400, SWTObservables.observeText(text, SWT.Modify)), EMFEditObservables.observeValue(editingDomain, element, ProcessPackage.Literals.ELEMENT__DOCUMENTATION),strategy,null);
    ControlDecorationSupport.create(
            context.bindValue(
                    SWTObservables.observeDelayedValue(400, SWTObservables.observeText(text, SWT.Modify)),
                    EMFEditObservables.observeValue(editingDomain, element,
                            ProcessPackage.Literals.ELEMENT__DOCUMENTATION),
                    strategy, null),
            SWT.LEFT | SWT.TOP);

}

From source file:org.bonitasoft.studio.condition.ui.expression.ComparisonExpressionEditor.java

License:Open Source License

@Override
public void bindExpression(EMFDataBindingContext dataBindingContext, EObject context,
        Expression inputExpression, ViewerFilter[] viewerTypeFilters, ExpressionViewer expressionViewer) {
    this.inputExpression = inputExpression;
    final IObservableValue contentModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__CONTENT);
    final IObservableValue nameModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__NAME);
    final IObservableValue dependenciesModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS);
    final IObservableValue autoDepsModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__AUTOMATIC_DEPENDENCIES);
    final IObservableValue returnTypeModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE);
    final ISWTObservableValue observeText = SWTObservables
            .observeText(comparisonEditor.getViewer().getControl(), SWT.Modify);
    dataBindingContext.bindValue(observeText, contentModelObservable);
    observeText.addValueChangeListener(new IValueChangeListener() {

        @Override//w  w  w  .j a v a2 s.  com
        public void handleValueChange(ValueChangeEvent event) {
            if (ComparisonExpressionEditor.this.inputExpression.isAutomaticDependencies()) {
                updateDependencies();
            }
        }
    });
    dataBindingContext.bindValue(observeText, nameModelObservable);
    dataBindingContext.bindValue(ViewersObservables.observeInput(dependenciesViewer),
            dependenciesModelObservable);

    UpdateValueStrategy opposite = new UpdateValueStrategy();
    opposite.setConverter(new Converter(Boolean.class, Boolean.class) {

        @Override
        public Object convert(Object fromObject) {
            return !((Boolean) fromObject);
        }
    });

    dataBindingContext.bindValue(SWTObservables.observeSelection(automaticResolutionButton),
            autoDepsModelObservable);
    dataBindingContext.bindValue(SWTObservables.observeSelection(automaticResolutionButton),
            SWTObservables.observeEnabled(addDependencyButton), opposite,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
    dependencySection.setExpanded(!automaticResolutionButton.getSelection());

    addDependencyButton.setEnabled(!inputExpression.isAutomaticDependencies());
    ControlDecorationSupport.create(dataBindingContext.bindValue(
            ViewersObservables.observeSingleSelection(typeCombo), returnTypeModelObservable), SWT.LEFT);
    typeCombo.getCombo().setEnabled(!inputExpression.isReturnTypeFixed());

    final ExpressionContentProvider provider = new ExpressionContentProvider();
    provider.setContext(context);

    final Set<Expression> filteredExpressions = new HashSet<Expression>();
    Expression[] expressions = provider.getExpressions();
    EObject input = provider.getContext();
    if (expressions != null) {
        filteredExpressions.addAll(Arrays.asList(expressions));
        if (input != null && viewerTypeFilters != null) {
            for (Expression exp : expressions) {
                for (ViewerFilter filter : viewerTypeFilters) {
                    if (filter != null && !filter.select(comparisonEditor.getViewer(), input, exp)) {
                        filteredExpressions.remove(exp);
                    }
                }
            }
        }
    }

    addDependencyButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectDependencyDialog dialog = new SelectDependencyDialog(Display.getDefault().getActiveShell(),
                    filteredExpressions,
                    ComparisonExpressionEditor.this.inputExpression.getReferencedElements());
            dialog.open();
        }
    });
}

From source file:org.bonitasoft.studio.configuration.ui.wizard.page.RunConfigurationWizardPage.java

License:Open Source License

@Override
public void updatePage(AbstractProcess process, Configuration configuration) {
    this.process = process;
    if (context != null) {
        context.dispose();/*  w  w w  .  ja  v a2s . c  om*/
    }
    if (pageSupport != null) {
        pageSupport.dispose();
    }
    context = new EMFDataBindingContext();
    UpdateValueStrategy targetStrategy = new UpdateValueStrategy();
    targetStrategy.setBeforeSetValidator(userNameValidator);
    context.bindValue(SWTObservables.observeText(usernameText, SWT.Modify),
            EMFObservables.observeValue(configuration, ConfigurationPackage.Literals.CONFIGURATION__USERNAME),
            targetStrategy, null);
    context.bindValue(SWTObservables.observeText(passwordText, SWT.Modify),
            EMFObservables.observeValue(configuration, ConfigurationPackage.Literals.CONFIGURATION__PASSWORD));

    UpdateValueStrategy targetAnonymousStrategy = new UpdateValueStrategy();
    targetAnonymousStrategy.setBeforeSetValidator(anonymousUserNameValidator);
    context.bindValue(SWTObservables.observeText(anonymousUsernameText, SWT.Modify),
            EMFObservables.observeValue(configuration,
                    ConfigurationPackage.Literals.CONFIGURATION__ANONYMOUS_USER_NAME),
            targetAnonymousStrategy, null);
    context.bindValue(SWTObservables.observeText(anonymousPasswordText, SWT.Modify), EMFObservables
            .observeValue(configuration, ConfigurationPackage.Literals.CONFIGURATION__ANONYMOUS_PASSWORD));

    pageSupport = WizardPageSupport.create(this, context);

}

From source file:org.bonitasoft.studio.connector.model.definition.dialog.NewCategoryDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite/*w  ww.  j a  va  2  s. c  o  m*/
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(250, SWT.DEFAULT).create());
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 10).create());

    context = new DataBindingContext();

    final Label nameLabel = new Label(mainComposite, SWT.NONE);
    nameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    nameLabel.setText(Messages.categoryId);

    final Text idText = new Text(mainComposite, SWT.BORDER);
    idText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    UpdateValueStrategy idStrategy = new UpdateValueStrategy();
    idStrategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value == null || value.toString().isEmpty()) {
                return ValidationStatus.error(Messages.idIsEmpty);
            }

            if (existingCatIds.contains(value.toString().toLowerCase())) {
                return ValidationStatus.error(Messages.idAlreadyExists);
            }
            return Status.OK_STATUS;
        }
    });

    ControlDecorationSupport.create(context.bindValue(SWTObservables.observeText(idText, SWT.Modify),
            EMFObservables.observeValue(category, ConnectorDefinitionPackage.Literals.CATEGORY__ID), idStrategy,
            null), SWT.LEFT);

    final Label displayNameLabel = new Label(mainComposite, SWT.NONE);
    displayNameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    displayNameLabel.setText(Messages.displayName);

    final Text displayNameText = new Text(mainComposite, SWT.BORDER);
    displayNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    context.bindValue(SWTObservables.observeText(displayNameText, SWT.Modify),
            PojoProperties.value(NewCategoryDialog.class, "displayName").observe(this));

    final Label parentCategoryLabel = new Label(mainComposite, SWT.NONE);
    parentCategoryLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    parentCategoryLabel.setText(Messages.parentCategoryLabel);

    final Combo parentCategoryCombo = new Combo(mainComposite, SWT.BORDER | SWT.READ_ONLY);
    parentCategoryCombo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    Set<String> categories = new HashSet<String>(existingCatIds);
    categories.add("");
    parentCategoryCombo.setItems(categories.toArray(new String[] {}));

    UpdateValueStrategy str = new UpdateValueStrategy();
    str.setConverter(new Converter(String.class, String.class) {

        @Override
        public Object convert(Object fromObject) {
            if (fromObject.toString().isEmpty()) {
                return null;
            }
            return fromObject;
        }
    });
    context.bindValue(SWTObservables.observeText(parentCategoryCombo), EMFObservables.observeValue(category,
            ConnectorDefinitionPackage.Literals.CATEGORY__PARENT_CATEGORY_ID), str, null);

    final Label iconLabel = new Label(mainComposite, SWT.NONE);
    iconLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    iconLabel.setText(Messages.iconLabel);

    final Composite iconComposite = new Composite(mainComposite, SWT.NONE);
    iconComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    iconComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create());

    final Label icon = new Label(iconComposite, SWT.NONE);
    icon.setLayoutData(GridDataFactory.fillDefaults().create());

    final Button iconButton = new Button(iconComposite, SWT.PUSH);
    iconButton.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.FILL).create());
    iconButton.setText("...");
    iconButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.SINGLE);
            dialog.setFilterExtensions(new String[] { "*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.ico" });
            dialog.setFilterPath(System.getProperty("user.home"));
            String res = dialog.open();
            if (res != null) {
                try {
                    FileInputStream is = new FileInputStream(res);
                    iconFile = new File(res);
                    category.setIcon(iconFile.getName());
                    if (iconImage != null) {
                        iconImage.dispose();
                    }
                    iconImage = new Image(Display.getDefault(), new ImageData(is).scaledTo(16, 16));
                    icon.setImage(iconImage);
                    icon.getParent().layout(true, true);
                    is.close();
                } catch (Exception ex) {
                    BonitaStudioLog.error(ex);
                }
            }
        }
    });
    DialogSupport.create(this, context);
    return mainComposite;
}

From source file:org.bonitasoft.studio.connector.model.definition.dialog.SelectPageWidgetDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite//from  w  ww  . j a  va  2s . co  m
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(400, SWT.DEFAULT).create());
    mainComposite
            .setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 10).spacing(15, 5).create());

    context = new DataBindingContext();
    if (component == null) {
        component = ConnectorDefinitionFactory.eINSTANCE.createText();
    }
    final Label idLabel = new Label(mainComposite, SWT.NONE);
    idLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    idLabel.setText(Messages.widgetId + "*");

    final Text idText = new Text(mainComposite, SWT.BORDER);
    idText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    idTextObservable = SWTObservables.observeText(idText, SWT.Modify);
    bindComponentId(idText);

    final Label widgetTypeLabel = new Label(mainComposite, SWT.NONE);
    widgetTypeLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    widgetTypeLabel.setText(Messages.widgetType);

    final ComboViewer typeViewer = new ComboViewer(mainComposite, SWT.BORDER | SWT.READ_ONLY);
    typeViewer.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    typeViewer.setContentProvider(new ArrayContentProvider());
    typeViewer.setLabelProvider(new WidgetLabelProvider());
    typeViewer.setInput(widgetTypes);

    typeViewer.setSelection(new StructuredSelection(component.eClass()));

    final Label inputLabel = new Label(mainComposite, SWT.NONE);
    inputLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    inputLabel.setText(Messages.input + " *");

    final ComboViewer inputViewer = new ComboViewer(mainComposite, SWT.BORDER | SWT.READ_ONLY);
    inputViewer.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    inputViewer.setContentProvider(new ArrayContentProvider());
    inputViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Input input = (Input) element;
            return super.getText(input.getName() + " (" + input.getType() + ")");
        }
    });
    inputViewer.setInput(inputs);
    inputSelectionObservable = ViewersObservables.observeSingleSelection(inputViewer);
    bindComponentInput(inputViewer);

    final Label displayNameLabel = new Label(mainComposite, SWT.NONE);
    displayNameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    displayNameLabel.setText(Messages.displayName);

    final Text displayNameText = new Text(mainComposite, SWT.BORDER);
    displayNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    context.bindValue(SWTObservables.observeText(displayNameText, SWT.Modify),
            PojoProperties.value(SelectPageWidgetDialog.class, "displayName").observe(this));

    final Label descriptionLabel = new Label(mainComposite, SWT.NONE);
    descriptionLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());
    descriptionLabel.setText(Messages.description);

    final Text descriptionText = new Text(mainComposite, SWT.BORDER | SWT.MULTI);
    descriptionText
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 60).create());

    context.bindValue(SWTObservables.observeText(descriptionText, SWT.Modify),
            PojoProperties.value(SelectPageWidgetDialog.class, "description").observe(this));

    section = new Section(parent, Section.NO_TITLE);
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(2, 1).create());
    section.setClient(createSectionClient(component));
    section.setExpanded(isExpanded(component));

    typeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            EClass eClass = (EClass) ((IStructuredSelection) event.getSelection()).getFirstElement();
            String id = null;
            if (component != null) {
                id = component.getId();
            }
            String input = null;
            if (component instanceof WidgetComponent) {
                input = ((WidgetComponent) component).getInputName();
            }
            component = (Component) ConnectorDefinitionFactory.eINSTANCE.create(eClass);
            component.setId(id);
            if (component instanceof WidgetComponent) {
                ((WidgetComponent) component).setInputName(input);
            }
            bindComponentId(idText);
            bindComponentInput(inputViewer);

            section.setClient(createSectionClient(component));
            section.setExpanded(isExpanded(component));
            Shell shell = section.getShell();
            Point defaultSize = shell.getSize();
            Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
            shell.setSize(defaultSize.x, size.y);
            shell.layout(true, true);
        }
    });

    dialogSupport = DialogSupport.create(this, context);

    return mainComposite;
}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.DefinitionInformationWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    context = new EMFDataBindingContext();

    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).create());

    final Label definitionIdLabel = new Label(mainComposite, SWT.NONE);
    definitionIdLabel.setText(Messages.definitionIdLabel + " *");
    definitionIdLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Composite idComposite = new Composite(mainComposite, SWT.NONE);
    idComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
    idComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(0, 0).create());

    final Text idText = new Text(idComposite, SWT.BORDER);
    idText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final Label definitionVersionLabel = new Label(idComposite, SWT.NONE);
    definitionVersionLabel.setText(Messages.versionLabel + " *");
    definitionVersionLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Text versionText = new Text(idComposite, SWT.BORDER);
    versionText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final UpdateValueStrategy versionStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    versionStrategy.setAfterGetValidator(new EmptyInputValidator(Messages.versionLabel));
    versionStrategy.setBeforeSetValidator(new IValidator() {

        @Override//from  w w  w.  j av  a2 s  . c om
        public IStatus validate(Object value) {
            if (!FileUtil.isValidName(
                    NamingUtils.toConnectorDefinitionFilename(definition.getId(), value.toString(), true))) {
                return ValidationStatus.error(Messages.invalidFileName);
            }

            return Status.OK_STATUS;
        }
    });

    final ISWTObservableValue observableIdText = SWTObservables.observeText(idText, SWT.Modify);
    final ISWTObservableValue observableVersionText = SWTObservables.observeText(versionText, SWT.Modify);
    final MultiValidator definitionValidator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            if (observableIdText.getValue().toString().contains(" ")) {
                return ValidationStatus.error(Messages.whitespaceInDefinitionIDNotAllowed);
            }
            if (observableVersionText.getValue().toString().contains(" ")) {
                return ValidationStatus.error(Messages.whitespaceInDefinitionIDNotAllowed);
            }

            String defID = NamingUtils.toConnectorDefinitionFilename(observableIdText.getValue().toString(),
                    observableVersionText.getValue().toString(), false);
            for (ConnectorDefinition def : existingDefinitions) {
                String existingId = NamingUtils.toConnectorDefinitionFilename(def.getId(), def.getVersion(),
                        false);
                if (defID.equals(existingId)) {
                    return ValidationStatus.error(Messages.definitionAlreadyExists);
                }
            }
            return ValidationStatus.ok();
        }
    };

    context.addValidationStatusProvider(definitionValidator);

    final UpdateValueStrategy idStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    idStrategy.setAfterGetValidator(new EmptyInputValidator(Messages.definitionIdLabel));
    idStrategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (!FileUtil.isValidName(NamingUtils.toConnectorDefinitionFilename(value.toString(),
                    definition.getVersion(), true))) {
                return ValidationStatus.error(Messages.invalidFileName);
            }
            return Status.OK_STATUS;
        }
    });

    context.bindValue(definitionValidator.observeValidatedValue(observableIdText), EMFObservables.observeValue(
            definition, ConnectorDefinitionPackage.Literals.CONNECTOR_DEFINITION__ID), idStrategy, null);
    context.bindValue(definitionValidator.observeValidatedValue(observableVersionText), EMFObservables
            .observeValue(definition, ConnectorDefinitionPackage.Literals.CONNECTOR_DEFINITION__VERSION),
            versionStrategy, null);

    final Label displayNameLabel = new Label(mainComposite, SWT.NONE);
    displayNameLabel.setText(Messages.displayName);
    displayNameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Text displayNameText = new Text(mainComposite, SWT.BORDER);
    displayNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

    context.bindValue(SWTObservables.observeText(displayNameText, SWT.Modify),
            PojoProperties.value(DefinitionInformationWizardPage.class, "displayName").observe(this));

    final Label descriptionNameLabel = new Label(mainComposite, SWT.NONE);
    descriptionNameLabel.setText(Messages.description);
    descriptionNameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());

    final Text descriptionText = new Text(mainComposite, SWT.BORDER | SWT.MULTI | SWT.WRAP);
    descriptionText.setLayoutData(
            GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 60).span(2, 1).create());
    UpdateValueStrategy descStrategy = new UpdateValueStrategy();
    descStrategy.setBeforeSetValidator(new InputLengthValidator(Messages.description, 255));
    context.bindValue(SWTObservables.observeText(descriptionText, SWT.Modify),
            PojoProperties.value(DefinitionInformationWizardPage.class, "definitionDescription").observe(this),
            descStrategy, null);

    final Label iconLabel = new Label(mainComposite, SWT.NONE);
    iconLabel.setText(Messages.iconLabel);
    iconLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Composite iconComposite = new Composite(mainComposite, SWT.NONE);
    iconComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
    iconComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create());

    final Label icon = new Label(iconComposite, SWT.NONE);
    icon.setLayoutData(GridDataFactory.fillDefaults().create());

    if (definition.getIcon() == null || definition.getIcon().isEmpty()) {
        iconImage = defaultImage;
    } else {
        iconImage = messageProvider.getDefinitionIcon(definition);
    }
    icon.setImage(iconImage);

    final Button iconButton = new Button(iconComposite, SWT.PUSH);
    iconButton.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.FILL).create());
    iconButton.setText("...");
    iconButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.SINGLE);
            dialog.setFilterExtensions(new String[] { "*.jpg;*.jpeg;*.gif;*.png;*.bmp;" });
            dialog.setFilterPath(System.getProperty("user.home"));
            String res = dialog.open();
            if (res != null) {
                try {
                    FileInputStream is = new FileInputStream(res);
                    iconImageFile = new File(res);
                    setIconName(iconImageFile.getName());
                    if (iconImage != null) {
                        iconImage.dispose();
                    }
                    iconImage = new Image(Display.getDefault(), new ImageData(is).scaledTo(16, 16));
                    icon.setImage(iconImage);
                    icon.getParent().layout(true, true);
                    is.close();
                } catch (Exception ex) {
                    BonitaStudioLog.error(ex);
                }
            }
        }
    });

    createCategoryViewer(mainComposite);

    createDependenciesViewer(mainComposite);

    updateButtons(new StructuredSelection());

    pageSupport = WizardPageSupport.create(this, context);
    setControl(mainComposite);
}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.PageWidgetsWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    context = new EMFDataBindingContext();
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).create());

    final Label pageIdLabel = new Label(mainComposite, SWT.NONE);
    pageIdLabel.setText(Messages.pageId + " *");
    pageIdLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Text idText = new Text(mainComposite, SWT.BORDER);
    idText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    UpdateValueStrategy idStrategy = new UpdateValueStrategy();
    idStrategy.setBeforeSetValidator(new IValidator() {

        @Override/*w w  w . j  av  a 2 s .  c  o m*/
        public IStatus validate(Object value) {
            if (value == null || value.toString().isEmpty()) {
                return ValidationStatus.error(Messages.idIsEmpty);
            } else if (value.toString().contains(" ")) {
                return ValidationStatus.error(Messages.noWhiteSpaceInPageID);
            } else if (!FileUtil.isValidName(value.toString())) {
                return ValidationStatus.error(Messages.idIsInvalid);
            }
            for (Page p : definition.getPage()) {
                if (!p.equals(originalPage) && p.getId().equals(value.toString())) {
                    return ValidationStatus.error(Messages.idAlreadyExists);
                }
            }
            return Status.OK_STATUS;
        }
    });

    context.bindValue(SWTObservables.observeText(idText, SWT.Modify),
            EMFObservables.observeValue(page, ConnectorDefinitionPackage.Literals.PAGE__ID), idStrategy, null);

    final Label displayNameLabel = new Label(mainComposite, SWT.NONE);
    displayNameLabel.setText(Messages.displayName);
    displayNameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Text displayNameText = new Text(mainComposite, SWT.BORDER);
    displayNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    IObservableValue displayNameObs = PojoProperties.value(PageWidgetsWizardPage.class, "displayName")
            .observe(this);
    context.bindValue(SWTObservables.observeText(displayNameText, SWT.Modify), displayNameObs);

    final Label descriptionLabel = new Label(mainComposite, SWT.NONE);
    descriptionLabel.setText(Messages.pageDescLabel);
    descriptionLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());

    final Text descriptionText = new Text(mainComposite, SWT.BORDER | SWT.MULTI | SWT.WRAP);
    descriptionText
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 60).create());

    IObservableValue descObs = PojoProperties.value(PageWidgetsWizardPage.class, "pageDescription")
            .observe(this);
    context.bindValue(SWTObservables.observeText(descriptionText, SWT.Modify), descObs);

    final Label inputsLabel = new Label(mainComposite, SWT.NONE);
    inputsLabel.setText(Messages.widgets);
    inputsLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());

    createWidgetViewer(mainComposite);
    updateButtons(new StructuredSelection());

    pageSupport = WizardPageSupport.create(this, context);
    setControl(mainComposite);
}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.SaveConnectorConfigurationWizardPage.java

License:Open Source License

@Override
protected void doCreateControl(Composite composite) {
    super.doCreateControl(composite);
    final Composite saveComposite = new Composite(composite, SWT.NONE);
    saveComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    saveComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 10).create());

    final Label nameLabel = new Label(saveComposite, SWT.NONE);
    nameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    nameLabel.setText(Messages.name + " *");

    final Text nameText = new Text(saveComposite, SWT.BORDER);
    nameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    UpdateValueStrategy targetToModel = new UpdateValueStrategy();
    targetToModel.setBeforeSetValidator(new IValidator() {

        @Override/*from www.  j  a  v  a 2s. c om*/
        public IStatus validate(Object newText) {
            if (newText == null || newText.toString().isEmpty()) {
                return ValidationStatus.error(Messages.nameIsEmpty);
            }

            if (configurationStore.getChild(
                    newText + "." + configurationStore.getCompatibleExtensions().iterator().next()) != null) {
                return ValidationStatus.error(Messages.nameAlreadyExists);
            }
            return Status.OK_STATUS;
        }
    });
    context.bindValue(SWTObservables.observeText(nameText, SWT.Modify),
            PojoProperties.value(SaveConnectorConfigurationWizardPage.class, "confName").observe(this),
            targetToModel, null);

}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.SelectNameAndDescWizardPage.java

License:Open Source License

/**
 * @param parent/*from w  ww.  j  a  v a  2s.  c  o m*/
 * @param context
 * @return
 */
protected Composite doCreateControl(Composite parent, EMFDataBindingContext context) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());

    Label nameLabel = new Label(composite, SWT.NONE);
    nameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    nameLabel.setText(Messages.dataNameLabel);

    final Text nameText = new Text(composite, SWT.BORDER);
    nameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    Label descLabel = new Label(composite, SWT.NONE);
    descLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());
    descLabel.setText(Messages.dataDescriptionLabel);

    final Text descText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP);
    descText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 50).create());

    UpdateValueStrategy nameStrategy = new UpdateValueStrategy();
    nameStrategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value == null || value.toString().isEmpty()) {
                return ValidationStatus.error(Messages.nameIsEmpty);
            }
            if (container != null) {
                for (EStructuralFeature feature : featureToCheckForUniqueID) {
                    List<?> otherConnectors = (List<?>) container.eGet(feature);
                    for (Object c : otherConnectors) {
                        if (!c.equals(originalConnector) && ((Connector) c).getName().equals(value)) {
                            return ValidationStatus.error(Messages.nameAlreadyExists);
                        }
                    }
                }
            }
            return Status.OK_STATUS;
        }
    });

    context.bindValue(SWTObservables.observeText(nameText, SWT.Modify),
            EMFObservables.observeValue(connector, ProcessPackage.Literals.ELEMENT__NAME), nameStrategy, null);
    UpdateValueStrategy descStrategy = new UpdateValueStrategy();
    descStrategy.setBeforeSetValidator(new InputLengthValidator(Messages.dataDescriptionLabel, 255));
    context.bindValue(SWTObservables.observeText(descText, SWT.Modify),
            EMFObservables.observeValue(connector, ProcessPackage.Literals.ELEMENT__DOCUMENTATION),
            descStrategy, null);

    return composite;
}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.support.InputNameEditingSupport.java

License:Open Source License

@Override
protected IObservableValue doCreateCellEditorObservable(CellEditor editor) {
    return SWTObservables.observeText(editor.getControl(), SWT.Modify);
}