/** * @param composite * @return */ private Composite createBooleanConfigurationComposite(Composite composite) { Composite booleanComposite = new Composite(composite, SWT.NONE); booleanComposite.setLayout(new GridLayout(2, false)); Label nameLabel = new Label(booleanComposite, SWT.NONE); nameLabel.setText(Messages.AddSimulationDataWizardPage_ProbabilityOfTrueLabel); Text labelText = new Text(booleanComposite, SWT.BORDER); labelText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); // ControlDecoration controlDecoration = new ControlDecoration(labelText, // SWT.LEFT|SWT.TOP); // FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault() // .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); // controlDecoration.setImage(fieldDecoration.getImage()); // controlDecoration.setDescriptionText(Messages.mustBeAPercentage); UpdateValueStrategy targetToModel = new UpdateValueStrategy(); targetToModel.setConverter( StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), true)); targetToModel.setAfterGetValidator( new ProbabilityValidator( new StringToDoubleValidator( StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), false)))); Binding provider = context.bindValue( SWTObservables.observeText(labelText, SWT.Modify), PojoObservables.observeValue(this, "probabilityOfTrue"), targetToModel, new UpdateValueStrategy() .setConverter( NumberToStringConverter.fromDouble( BonitaNumberFormat.getPercentInstance(), true))); ControlDecorationSupport.create(provider, SWT.TOP | SWT.LEFT); return booleanComposite; }
protected void bindValidator(Text field, Object obj, String property, IValidator validator) { DataBindingContext bindingContext = new DataBindingContext(); UpdateValueStrategy ttm = new UpdateValueStrategy(); ttm.setBeforeSetValidator(validator); // IObservableValue countryTxtObserveTextObserveWidget = SWTObservables.observeText(field, SWT.Modify); IObservableValue currentAddressCountryObserveValue = PojoObservables.observeValue(obj, property); Binding binding = bindingContext.bindValue( countryTxtObserveTextObserveWidget, currentAddressCountryObserveValue, ttm, null); ControlDecorationSupport.create(binding, SWT.TOP | SWT.LEFT); }
private void bindControls() { // Bind source file path widget to UI model IObservableValue widgetValue = WidgetProperties.text(SWT.Modify).observe(_javaClassText); IObservableValue modelValue = null; if (isSourcePage()) { modelValue = BeanProperties.value(Model.class, "sourceFilePath").observe(model); } else { modelValue = BeanProperties.value(Model.class, "targetFilePath").observe(model); } UpdateValueStrategy 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 transformation."); } NewTransformationWizard wizard = (NewTransformationWizard) getWizard(); try { Class<?> tempClass = wizard.getLoader().loadClass(path); if (tempClass == null) { return ValidationStatus.error( "Unable to find a source file with the supplied path"); } } catch (ClassNotFoundException e) { return ValidationStatus.error("Unable to find a source file with the supplied path"); } return ValidationStatus.ok(); } }); _binding = context.bindValue(widgetValue, modelValue, strategy, null); ControlDecorationSupport.create( _binding, decoratorPosition, _javaClassText.getParent(), new WizardControlDecorationUpdater()); listenForValidationChanges(); }
private void createNameAndDescription(Composite composite) { Label nameLabel = new Label(composite, SWT.NONE); nameLabel.setText(Messages.dataNameLabel); final Text labelText = new Text(composite, SWT.BORDER); labelText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); // Add an validator so that age can only be a number IValidator validator = new IValidator() { Set<String> existingDataNames = null; @Override public IStatus validate(Object arg0) { if (existingDataNames == null) { existingDataNames = new HashSet<String>(); if (element != null) { for (SimulationData simuData : element.getSimulationData()) { existingDataNames.add(simuData.getName()); } } } if (existingDataNames.contains(labelText.getText())) { return ValidationStatus.error("Data name already exists."); } return ValidationStatus.ok(); } }; UpdateValueStrategy strategy = new UpdateValueStrategy(); strategy.setBeforeSetValidator(validator); Binding bindingDataName = context.bindValue( SWTObservables.observeText(labelText, SWT.Modify), PojoObservables.observeValue(this, "dataName"), strategy, null); ControlDecorationSupport.create(bindingDataName, SWT.TOP | SWT.LEFT); // labelText.addModifyListener(updateButtonModifyListener) ; Label isExpressionLabel = new Label(composite, SWT.NONE); isExpressionLabel.setText(Messages.BasedOn); Composite radioBasedComposite = new Composite(composite, SWT.NONE); radioBasedComposite.setLayout(new GridLayout(2, true)); isExpressionBased = new Button(radioBasedComposite, SWT.RADIO); isExpressionBased.setText(Messages.Expression); isExpressionBased.setSelection(expressionBased); isOtherBased = new Button(radioBasedComposite, SWT.RADIO); isOtherBased.setSelection(!expressionBased); isOtherBased.setText(Messages.AddSimulationDataWizardPage_probability); context.bindValue( SWTObservables.observeSelection(isExpressionBased), PojoObservables.observeValue(this, "expressionBased")); context.bindValue( SWTObservables.observeSelection(isOtherBased), PojoObservables.observeValue(this, "expressionBased"), new UpdateValueStrategy() .setConverter( new Converter(Boolean.class, Boolean.class) { @Override public Object convert(Object fromObject) { return !(Boolean) fromObject; } }), new UpdateValueStrategy() .setConverter( new Converter(Boolean.class, Boolean.class) { @Override public Object convert(Object fromObject) { return !(Boolean) fromObject; } })); Label expressionLabel = new Label(composite, SWT.NONE); expressionLabel.setText(Messages.Expression); ExpressionViewer expressionViewer = new ExpressionViewer(composite, SWT.BORDER, null); // FIXME: Expressionviewer expressionViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); if (element != null) { expressionViewer.setInput(element); } else { expressionViewer.setInput(data.eContainer()); } expressionViewer.addFilter( new AvailableExpressionTypeFilter( new String[] { ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE, ExpressionConstants.SCRIPT_TYPE, ExpressionConstants.SIMULATION_VARIABLE_TYPE })); expressionViewer.setSelection(new StructuredSelection(dataExpression)); context.bindValue( SWTObservables.observeVisible(expressionLabel), SWTObservables.observeSelection(isExpressionBased)); context.bindValue( SWTObservables.observeVisible(expressionViewer.getControl()), SWTObservables.observeSelection(isExpressionBased)); isOtherBased.addSelectionListener(updateButtonSelectionListener); isExpressionBased.addSelectionListener(updateButtonSelectionListener); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Override protected void doCreateControls(final Composite parent, DataBindingContext dbc) { GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).applyTo(parent); // userdoc link (JBIDE-20401) this.userdocLink = new StyledText(parent, SWT.WRAP); // text set in #showHideUserdocLink GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).applyTo(userdocLink); showHideUserdocLink(); IObservableValue userdocUrlObservable = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USERDOCURL).observe(pageModel); StyledTextUtils.emulateLinkAction(userdocLink, r -> onUserdocLinkClicked(userdocUrlObservable)); userdocUrlObservable.addValueChangeListener( new IValueChangeListener() { @Override public void handleValueChange(ValueChangeEvent event) { showHideUserdocLink(); } }); IObservableValue connectionFactoryObservable = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_CONNECTION_FACTORY) .observe(pageModel); // filler Label fillerLabel = new Label(parent, SWT.NONE); GridDataFactory.fillDefaults().span(3, 3).hint(SWT.DEFAULT, 6).applyTo(fillerLabel); // existing connections combo Label connectionLabel = new Label(parent, SWT.NONE); connectionLabel.setText("Connection:"); GridDataFactory.fillDefaults() .align(SWT.LEFT, SWT.CENTER) .hint(100, SWT.DEFAULT) .applyTo(connectionLabel); Combo connectionCombo = new Combo(parent, SWT.DEFAULT); GridDataFactory.fillDefaults() .span(2, 1) .align(SWT.FILL, SWT.CENTER) .grab(true, false) .applyTo(connectionCombo); ComboViewer connectionComboViewer = new ComboViewer(connectionCombo); connectionComboViewer.setContentProvider(ArrayContentProvider.getInstance()); connectionComboViewer.setLabelProvider(new ConnectionColumLabelProvider()); connectionComboViewer.setInput(pageModel.getAllConnections()); Binding selectedConnectionBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(connectionComboViewer)) .validatingAfterGet( new IsNotNullValidator( ValidationStatus.cancel("You have to select or create a new connection."))) .to( BeanProperties.value( ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION, IConnection.class) .observe(pageModel)) .in(dbc); ControlDecorationSupport.create( selectedConnectionBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater()); // server type Label connectionFactoryLabel = new Label(parent, SWT.NONE); connectionFactoryLabel.setText("Server type:"); GridDataFactory.fillDefaults() .align(SWT.LEFT, SWT.CENTER) .hint(100, SWT.DEFAULT) .applyTo(connectionFactoryLabel); Combo connectionFactoryCombo = new Combo(parent, SWT.DEFAULT); GridDataFactory.fillDefaults() .span(2, 1) .align(SWT.FILL, SWT.CENTER) .grab(true, false) .applyTo(connectionFactoryCombo); ComboViewer connectionFactoriesViewer = new ComboViewer(connectionFactoryCombo); connectionFactoriesViewer.setContentProvider(ArrayContentProvider.getInstance()); connectionFactoriesViewer.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { if (!(element instanceof IConnectionFactory)) { return element.toString(); } else { return ((IConnectionFactory) element).getName(); } } }); connectionFactoriesViewer.setInput(pageModel.getAllConnectionFactories()); final IViewerObservableValue selectedServerType = ViewerProperties.singleSelection().observe(connectionFactoriesViewer); ValueBindingBuilder.bind(selectedServerType).to(connectionFactoryObservable).in(dbc); // server Button useDefaultServerCheckbox = new Button(parent, SWT.CHECK); useDefaultServerCheckbox.setText("Use default server"); GridDataFactory.fillDefaults() .span(3, 1) .align(SWT.FILL, SWT.FILL) .applyTo(useDefaultServerCheckbox); ValueBindingBuilder.bind(WidgetProperties.selection().observe(useDefaultServerCheckbox)) .to( BeanProperties.value( ConnectionWizardPageModel.PROPERTY_USE_DEFAULT_HOST, IConnection.class) .observe(pageModel)) .in(dbc); IObservableValue hasDefaultHostObservable = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_HAS_DEFAULT_HOST) .observe(pageModel); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(useDefaultServerCheckbox)) .notUpdating(hasDefaultHostObservable) .in(dbc); Label serverLabel = new Label(parent, SWT.NONE); serverLabel.setText("Server:"); GridDataFactory.fillDefaults() .align(SWT.LEFT, SWT.CENTER) .hint(100, SWT.DEFAULT) .applyTo(serverLabel); Combo serversCombo = new Combo(parent, SWT.BORDER); ComboViewer serversViewer = new ComboViewer(serversCombo); serversViewer.setContentProvider(new ObservableListContentProvider()); serversViewer.setInput( BeanProperties.list(ConnectionWizardPageModel.PROPERTY_ALL_HOSTS).observe(pageModel)); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.FILL) .grab(true, false) .applyTo(serversCombo); final IObservableValue serverUrlObservable = WidgetProperties.text().observe(serversCombo); serversCombo.addFocusListener(onServerFocusLost(serverUrlObservable)); ValueBindingBuilder.bind(serverUrlObservable) .converting(new TrimTrailingSlashConverter()) .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_HOST).observe(pageModel)) .in(dbc); MultiValidator serverUrlValidator = new MultiValidator() { @Override protected IStatus validate() { Object value = serverUrlObservable.getValue(); if (!(value instanceof String) || StringUtils.isEmpty((String) value)) { return ValidationStatus.cancel("Please provide an OpenShift server url."); } else if (!UrlUtils.isValid((String) value)) { return ValidationStatus.error("Please provide a valid OpenShift server url."); } return ValidationStatus.ok(); } }; ControlDecorationSupport.create( serverUrlValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater()); dbc.addValidationStatusProvider(serverUrlValidator); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(serversCombo)) .notUpdatingParticipant() .to( BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USE_DEFAULT_HOST) .observe(pageModel)) .converting(new InvertingBooleanConverter()) .in(dbc); // connect error dbc.addValidationStatusProvider( new MultiValidator() { IObservableValue observable = BeanProperties.value( ConnectionWizardPageModel.PROPERTY_CONNECTED_STATUS, IStatus.class) .observe(pageModel); @Override protected IStatus validate() { return (IStatus) observable.getValue(); } }); // connection editors Group authenticationDetailsGroup = new Group(parent, SWT.NONE); authenticationDetailsGroup.setText("Authentication"); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.FILL) .span(3, 1) .applyTo(authenticationDetailsGroup); GridLayoutFactory.fillDefaults().margins(0, 0).applyTo(authenticationDetailsGroup); // additional nesting required because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=478618 Composite authenticationDetailsContainer = new Composite(authenticationDetailsGroup, SWT.None); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.FILL) .grab(true, true) .applyTo(authenticationDetailsContainer); this.connectionEditors = new ConnectionEditorsStackedView( connectionFactoryObservable, this, authenticationDetailsContainer, dbc); connectionEditors.createControls(); // adv editors Composite advEditorContainer = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().margins(0, 0).applyTo(authenticationDetailsGroup); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.FILL) .span(3, 1) .grab(true, true) .applyTo(advEditorContainer); this.advConnectionEditors = new AdvancedConnectionEditorsStackedView( connectionFactoryObservable, pageModel, advEditorContainer, dbc); advConnectionEditors.createControls(); }
private void bindControls(final DataBindingContext context) { final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(getTargetObject()); final Realm realm = SWTObservables.getRealm(_nameText.getDisplay()); _bindingValue = new WritableValue(realm, null, CamelMailBindingType.class); org.eclipse.core.databinding.Binding binding = context.bindValue( SWTObservables.observeText(_nameText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, ScaPackage.eINSTANCE.getBinding_Name()), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator( new StringEmptyValidator( "Mail binding name should not be empty", Status.WARNING)), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); /* * we also want to bind the name field to the binding name. note that * the model to target updater is configured to NEVER update. we want * the camel binding name to be the definitive source for this field. */ binding = context.bindValue( SWTObservables.observeText(_nameText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, ScaPackage.eINSTANCE.getBinding_Name()), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator( new StringEmptyValidator( "Mail binding name should not be empty", Status.WARNING)), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeText(_hostText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__HOST), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator(new StringEmptyValidator(Messages.error_emptyHost)), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeText(_portText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__PORT), new EMFUpdateValueStrategyNullForEmptyString( "Port must be a valid numeric value or follow the pattern for escaped properties (i.e. '${propName}').", UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator( new EscapedPropertyIntegerValidator( "Port must be a valid numeric value or follow the pattern for escaped properties (i.e. '${propName}').")), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); FeaturePath path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__FETCH_SIZE); binding = context.bindValue( SWTObservables.observeText(_fetchSizeText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString( "Fetch Size must be a valid numeric value or follow the pattern for escaped properties (i.e. '${propName}').", UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator( new EscapedPropertyIntegerValidator( "Fetch Size must be a valid numeric value or follow the pattern for escaped properties (i.e. '${propName}').")), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__ACCOUNT_TYPE); binding = context.bindValue( ViewersObservables.observeSingleSelection(_accountTypeCombo), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeText(_usernameText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__USERNAME), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeText(_passwordText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__PASSWORD), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__FOLDER_NAME); binding = context.bindValue( SWTObservables.observeText(_folderNameText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString("", UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__UNSEEN); binding = context.bindValue( SWTObservables.observeSelection(_unseenCheckbox), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeSelection(_securedCheckbox), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__SECURE), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__DELETE); binding = context.bindValue( SWTObservables.observeSelection(_deleteCheckbox), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); _opSelectorComposite.bindControls(domain, context); }