List of usage examples for org.eclipse.jface.databinding.viewers ObservableListContentProvider ObservableListContentProvider
public ObservableListContentProvider()
From source file:org.jboss.tools.fuse.transformation.editor.internal.wizards.StartPage.java
License:Open Source License
private void bindControls() { IObservableValue dozerPathTextValue = WidgetProperties.text(SWT.Modify).observe(_dozerPathText); IObservableValue dozerPathValue = BeanProperties.value(Model.class, "filePath").observe(model); //$NON-NLS-1$ // bind the project dropdown UpdateValueStrategy strategy = new UpdateValueStrategy(); strategy.setBeforeSetValidator(new IValidator() { @Override/*from ww w . java 2s.com*/ public IStatus validate(final Object value) { if (value == null) { return ValidationStatus.error(Messages.StartPage_errorMessageProjectMustBeSelected); } return ValidationStatus.ok(); } }); // Bind transformation ID widget to UI model IObservableValue idTextValue = WidgetProperties.text(SWT.Modify).observe(_idText); IObservableValue idValue = BeanProperties.value(Model.class, "id").observe(model); //$NON-NLS-1$ strategy = new UpdateValueStrategy(); strategy.setBeforeSetValidator(new IValidator() { @Override public IStatus validate(final Object value) { if (value == null || value.toString().trim().isEmpty()) { return ValidationStatus.error(Messages.StartPage_errorMessageIDMustBeSupplied); } 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(Messages.StartPage_errorMessageInvalidCharacters); } } CamelConfigBuilder configBuilder = new CamelConfigBuilder(); for (final String endpointId : configBuilder.getTransformEndpointIds()) { if (id.equalsIgnoreCase(endpointId)) { return ValidationStatus.error(Messages.StartPage_errorMessageIDAlreadyExists); } } return ValidationStatus.ok(); } }); _endpointIdBinding = context.bindValue(idTextValue, idValue, strategy, null); ControlDecorationSupport.create(_endpointIdBinding, decoratorPosition, _idText.getParent()); // Bind file path widget to UI 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(Messages.StartPage_errorMessageFlePathMissing); } if (!(value.toString().trim().isEmpty())) { if (CamelUtils.project() != null) { final IFile file = CamelUtils.project().getFile(MavenUtils.RESOURCES_PATH + (String) value); if (file != null && file.exists()) { return ValidationStatus.warning(Messages.StartPage_errorMessageNameFileAlreadyExists); } } } return ValidationStatus.ok(); } }); _filePathBinding = context.bindValue(dozerPathTextValue, dozerPathValue, strategy, null); ControlDecorationSupport.create(_filePathBinding, decoratorPosition, _dozerPathText.getParent()); // bind the source type string dropdown _sourceCV.setContentProvider(new ObservableListContentProvider()); IObservableValue widgetValue = ViewerProperties.singleSelection().observe(_sourceCV); IObservableValue modelValue = BeanProperties.value(Model.class, "sourceTypeStr").observe(model); //$NON-NLS-1$ strategy = new UpdateValueStrategy(); strategy.setBeforeSetValidator(new IValidator() { @Override public IStatus validate(final Object value) { getModel().setSourceFilePath(""); ((NewTransformationWizard) getWizard()).resetSourceAndTargetPages(); if (StartPage.this.getSourcePage() != null) { ((XformWizardPage) StartPage.this.getSourcePage()).clearControls(); } UIJob uiJob = new UIJob(Messages.StartPage_openErroUiJobName) { @Override public IStatus runInUIThread(IProgressMonitor monitor) { if (StartPage.this.getTargetPage() != null) { ((XformWizardPage) StartPage.this.getTargetPage()).pingBinding(); } return Status.OK_STATUS; } }; uiJob.setSystem(true); uiJob.schedule(); if (value == null || ((String) value).trim().isEmpty()) { resetFinish(); return ValidationStatus.error(Messages.StartPage_errorMessageSourceTypeMissing); } return ValidationStatus.ok(); } }); WritableList sourceList = new WritableList(); sourceList.add("Java"); //$NON-NLS-1$ sourceList.add("XML"); //$NON-NLS-1$ sourceList.add("JSON"); //$NON-NLS-1$ sourceList.add("Other"); //$NON-NLS-1$ sourceList.add(""); //$NON-NLS-1$ _sourceCV.setInput(sourceList); ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), decoratorPosition, null); // bind the source type string dropdown _targetCV.setContentProvider(new ObservableListContentProvider()); widgetValue = ViewerProperties.singleSelection().observe(_targetCV); modelValue = BeanProperties.value(Model.class, "targetTypeStr").observe(model); //$NON-NLS-1$ strategy = new UpdateValueStrategy(); strategy.setBeforeSetValidator(new IValidator() { @Override public IStatus validate(final Object value) { getModel().setTargetFilePath(""); ((NewTransformationWizard) getWizard()).resetSourceAndTargetPages(); if (StartPage.this.getTargetPage() != null) { ((XformWizardPage) StartPage.this.getTargetPage()).clearControls(); } UIJob uiJob = new UIJob(Messages.StartPage_openErroruiJobName) { @Override public IStatus runInUIThread(IProgressMonitor monitor) { if (StartPage.this.getSourcePage() != null) { ((XformWizardPage) StartPage.this.getSourcePage()).pingBinding(); } return Status.OK_STATUS; } }; uiJob.setSystem(true); uiJob.schedule(); if (value == null || ((String) value).trim().isEmpty()) { resetFinish(); return ValidationStatus.error(Messages.StartPage_errorMessageTargetTypeMissing); } return ValidationStatus.ok(); } }); WritableList targetList = new WritableList(); targetList.add("Java"); //$NON-NLS-1$ targetList.add("XML"); //$NON-NLS-1$ targetList.add("JSON"); //$NON-NLS-1$ targetList.add("Other"); //$NON-NLS-1$ targetList.add(""); //$NON-NLS-1$ _targetCV.setInput(targetList); ControlDecorationSupport.create(context.bindValue(widgetValue, modelValue, strategy, null), decoratorPosition, null); listenForValidationChanges(); }
From source file:org.jboss.tools.fuse.transformation.editor.internal.wizards.XMLPage.java
License:Open Source License
private void createPage(Composite parent) { _page = new Composite(parent, SWT.NONE); setControl(_page);//w w w . j a va 2 s . c o m GridLayout layout = new GridLayout(3, false); layout.marginRight = 5; layout.horizontalSpacing = 10; _page.setLayout(layout); Group group = new Group(_page, SWT.SHADOW_ETCHED_IN); group.setText(Messages.XMLPage_GroupTitleXMLDefintion); group.setLayout(new GridLayout(1, false)); group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 2)); _xmlSchemaOption = new Button(group, SWT.RADIO); _xmlSchemaOption.setText(Messages.XMLPage_labelXMLSchema); _xmlSchemaOption.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); _xmlSchemaOption.setSelection(true); _xmlInstanceOption = new Button(group, SWT.RADIO); _xmlInstanceOption.setText(Messages.XMLPage_labelXMLDocument); _xmlInstanceOption.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); _xmlSchemaOption.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent event) { if (isSourcePage()) { model.setSourceType(ModelType.XSD); model.setSourceFilePath(""); //$NON-NLS-1$ } else { model.setTargetType(ModelType.XSD); model.setTargetFilePath(""); //$NON-NLS-1$ } _xmlPreviewText.setText(""); //$NON-NLS-1$ _xmlRootsCombo.getCombo().removeAll(); _xmlRootsCombo.getCombo().setText(""); //$NON-NLS-1$ XMLPage.this.resetFinish(); } @Override public void widgetDefaultSelected(SelectionEvent event) { // empty } }); _xmlInstanceOption.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent event) { if (isSourcePage()) { model.setSourceType(ModelType.XML); } else { model.setTargetType(ModelType.XML); } model.setTargetFilePath(""); //$NON-NLS-1$ _xmlPreviewText.setText(""); //$NON-NLS-1$ _xmlRootsCombo.getCombo().removeAll(); _xmlRootsCombo.getCombo().setText(""); //$NON-NLS-1$ XMLPage.this.resetFinish(); } @Override public void widgetDefaultSelected(SelectionEvent event) { // empty } }); // Create file path widgets Label label; if (isSourcePage()) { label = createLabel(_page, Messages.XMLPage_labelSourceFile, Messages.XMLPage_labelSourceFileTooltip); } else { label = createLabel(_page, Messages.XMLPage_labeltargetFile, Messages.XMLPage_labelTargetFileTooltip); } _xmlFileText = new Text(_page, SWT.BORDER); _xmlFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); _xmlFileText.setToolTipText(label.getToolTipText()); final Button xmlFileBrowseButton = new Button(_page, SWT.NONE); xmlFileBrowseButton.setLayoutData(new GridData()); xmlFileBrowseButton.setText("..."); //$NON-NLS-1$ xmlFileBrowseButton.setToolTipText(Messages.XMLPage_tooltipBrowseXML); xmlFileBrowseButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent event) { String extension = "xml"; //$NON-NLS-1$ if (_xmlInstanceOption.getSelection()) { extension = "xml"; //$NON-NLS-1$ } else if (_xmlSchemaOption.getSelection()) { extension = "xsd"; //$NON-NLS-1$ } String path = selectResourceFromWorkspace(_page.getShell(), extension); if (path != null) { IResource resource = CamelUtils.project().findMember(path); if (resource != null && resource.exists()) { updateSettingsBasedOnFilePath(resource.getLocation().makeAbsolute().toOSString()); updatePreview(resource.getProjectRelativePath().toString()); } _xmlFileText.setText(path); pingBinding(); } } }); label = createLabel(_page, Messages.XMLPage_labelElementRoot, Messages.XMLPage_labelElementRootTooltip); _xmlRootsCombo = new ComboViewer(_page, SWT.DROP_DOWN | SWT.READ_ONLY); _xmlRootsCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); _xmlRootsCombo.getCombo().setToolTipText(label.getToolTipText()); _xmlRootsCombo.setContentProvider(new ObservableListContentProvider()); _xmlRootsCombo.setLabelProvider(new QNameLabelProvider()); _xmlRootsCombo.getCombo().setEnabled(false); _xmlRootsCombo.getCombo().setToolTipText(Messages.XMLPage_tooltipCombo); Group group2 = new Group(_page, SWT.SHADOW_ETCHED_IN); group2.setText(Messages.XMLPage_grouptitleXMLPreview); group2.setLayout(new FillLayout()); group2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 3)); _xmlPreviewText = new Text(group2, SWT.V_SCROLL | SWT.READ_ONLY | SWT.H_SCROLL); _xmlPreviewText.setBackground(_page.getBackground()); bindControls(); validatePage(); }
From source file:org.jboss.tools.openshift.express.internal.ui.wizard.domain.ManageDomainsWizardPage.java
License:Open Source License
@Override protected void doCreateControls(Composite parent, DataBindingContext dbc) { GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent); Group domainsGroup = new Group(parent, SWT.NONE); domainsGroup.setText("Domains"); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(domainsGroup); GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(domainsGroup); // domains table Composite tableContainer = new Composite(domainsGroup, SWT.NONE); this.viewer = createTable(tableContainer); GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true) .applyTo(tableContainer);/*w ww . j a va 2 s.c om*/ viewer.setContentProvider(new ObservableListContentProvider()); viewer.setInput(BeanProperties.list(ManageDomainsWizardPageModel.PROPERTY_DOMAINS).observe(pageModel)); loadDomains(dbc); IObservableValue viewerSingleSelection = ViewerProperties.singleSelection().observe(viewer); ValueBindingBuilder.bind(viewerSingleSelection) .to(BeanProperties.value(ManageDomainsWizardPageModel.PROPERTY_SELECTED_DOMAIN).observe(pageModel)) .in(dbc); // new domain Button newButton = new Button(domainsGroup, SWT.PUSH); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(newButton); newButton.setText("New..."); newButton.addSelectionListener(onNew(dbc)); // edit domain Button editButton = new Button(domainsGroup, SWT.PUSH); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(editButton); editButton.setText("Edit..."); editButton.addSelectionListener(onEdit(dbc)); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(editButton)).notUpdatingParticipant() .to(viewerSingleSelection).converting(new IsNotNull2BooleanConverter()).in(dbc); // remove Button removeButton = new Button(domainsGroup, SWT.PUSH); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(removeButton); removeButton.setText("Remove..."); removeButton.addSelectionListener(onRemove(dbc)); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(removeButton)).notUpdatingParticipant() .to(viewerSingleSelection).converting(new IsNotNull2BooleanConverter()).in(dbc); Composite filler = new Composite(domainsGroup, SWT.None); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(filler); // refresh Button refreshButton = new Button(domainsGroup, SWT.PUSH); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.END).applyTo(refreshButton); refreshButton.setText("Refresh..."); refreshButton.addSelectionListener(onRefresh(dbc)); }
From source file:org.jboss.tools.openshift.express.internal.ui.wizard.embed.EmbeddedCartridgesWizardPage.java
License:Open Source License
protected CheckboxTableViewer createCartridgesTableViewer(Composite tableContainer) { Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.CHECK); table.setLinesVisible(true);// w w w. j av a 2 s . c om CheckboxTableViewer tableViewer = new CheckboxTableViewer(table); new TableViewerBuilder(tableViewer, tableContainer).sorter(new EmbeddableCartridgeViewerSorter()) .comparer(new EqualityComparer()).contentProvider(new ObservableListContentProvider()) .<ICartridge>column("Embeddable Cartridge").labelProvider(new IColumnLabelProvider<ICartridge>() { @Override public String getValue(ICartridge cartridge) { return ExpressResourceLabelUtils.toString(cartridge); } }).weight(1).buildColumn().buildViewer(); return tableViewer; }
From source file:org.jboss.tools.openshift.express.internal.ui.wizard.environment.EnvironmentVariablesWizardPage.java
License:Open Source License
@Override protected void doCreateControls(Composite container, DataBindingContext dbc) { GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(container); Group envVariableGroup = new Group(container, SWT.NONE); envVariableGroup.setText(ExpressUIMessages.EnvironmentVariables); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(envVariableGroup); GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(envVariableGroup); Composite tableContainer = new Composite(envVariableGroup, SWT.NONE); this.viewer = createTable(tableContainer); GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true) .applyTo(tableContainer);//from ww w.j a v a 2 s. c om ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(viewer)) .to(BeanProperties.value(AbstractEnvironmentVariablesWizardModel.PROPERTY_SELECTED).observe(model)) .in(dbc); viewer.setComparator(new ViewerComparator()); viewer.setContentProvider(new ObservableListContentProvider()); viewer.setInput( BeanProperties.list(AbstractEnvironmentVariablesWizardModel.PROPERTY_VARIABLES).observe(model)); Button addButton = new Button(envVariableGroup, SWT.PUSH); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(addButton); addButton.setText(ExpressUIMessages.Add); addButton.addSelectionListener(onAdd()); Button editExistingButton = new Button(envVariableGroup, SWT.PUSH); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(editExistingButton); editExistingButton.setText(ExpressUIMessages.Edit); editExistingButton.addSelectionListener(onEdit()); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(editExistingButton)).notUpdatingParticipant() .to(BeanProperties.value(AbstractEnvironmentVariablesWizardModel.PROPERTY_SELECTED).observe(model)) .converting(new IsNotNull2BooleanConverter()).in(dbc); Button removeButton = new Button(envVariableGroup, SWT.PUSH); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(removeButton); removeButton.setText(ExpressUIMessages.Remove); removeButton.addSelectionListener(onRemove()); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(removeButton)).notUpdatingParticipant() .to(BeanProperties.value(AbstractEnvironmentVariablesWizardModel.PROPERTY_SELECTED).observe(model)) .converting(new IsNotNull2BooleanConverter()).in(dbc); Label filler = new Label(envVariableGroup, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, true).applyTo(filler); Button refreshButton = new Button(envVariableGroup, SWT.PUSH); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(refreshButton); refreshButton.setText(ExpressUIMessages.Refresh); refreshButton.addSelectionListener(onRefresh()); // not supported enableEnvVariableGroup(model.isSupported(), envVariableGroup); Label validationLabel = new Label(envVariableGroup, SWT.NONE); validationLabel.setVisible(false); GridDataFactory.fillDefaults().exclude(true).applyTo(validationLabel); ValueBindingBuilder .bind(WidgetProperties.enabled().observe(validationLabel)).notUpdating(BeanProperties .value(AbstractEnvironmentVariablesWizardModel.PROPERTY_SUPPORTED).observe(model)) .validatingAfterGet(new IValidator() { @Override public IStatus validate(Object value) { if (Boolean.FALSE.equals((Boolean) value)) { return ValidationStatus.warning( NLS.bind(ExpressUIMessages.ServerDoesNotSupportChanging, model.getHost())); } return ValidationStatus.ok(); } }).in(dbc); }
From source file:org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPage.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override/* ww w .j a v a 2 s . co m*/ 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(); }
From source file:org.jboss.tools.openshift.internal.ui.server.OpenShiftServerEditorSection.java
License:Open Source License
private void createConnectionContols(Composite parent, DataBindingContext dbc) { Label connectionLabel = new Label(parent, SWT.NONE); connectionLabel.setText("Connection:"); GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(connectionLabel); Combo connectionCombo = new Combo(parent, SWT.DEFAULT); ComboViewer connectionViewer = new ComboViewer(connectionCombo); connectionViewer.setContentProvider(new ObservableListContentProvider()); connectionViewer.setLabelProvider(new ConnectionColumLabelProvider()); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(connectionCombo); connectionViewer// w w w . j a v a2s . c o m .setInput(BeanProperties.list(OpenShiftServerEditorModel.PROPERTY_CONNECTIONS).observe(model)); Binding connectionBinding = ValueBindingBuilder .bind(ViewerProperties.singleSelection().observe(connectionViewer)) .validatingAfterGet(new IValidator() { @Override public IStatus validate(Object value) { if (!(value instanceof Connection)) { return ValidationStatus.cancel("Please select a connection for this server adapter."); } return ValidationStatus.ok(); } }).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_CONNECTION).observe(model)).in(dbc); ControlDecorationSupport.create(connectionBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true)); Button newConnectionButton = new Button(parent, SWT.PUSH); newConnectionButton.setText("New..."); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(100, SWT.DEFAULT) .applyTo(newConnectionButton); newConnectionButton.addSelectionListener(onNewConnection(connectionViewer)); }
From source file:org.jboss.tools.openshift.internal.ui.server.OpenShiftServerEditorSection.java
License:Open Source License
private void createProjectControls(Composite parent, DataBindingContext dbc) { Label projectLabel = new Label(parent, SWT.NONE); projectLabel.setText("Eclipse Project: "); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(projectLabel); StructuredViewer projectsViewer = new ComboViewer(parent); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false) .applyTo(projectsViewer.getControl()); projectsViewer.setContentProvider(new ObservableListContentProvider()); projectsViewer.setLabelProvider(new ColumnLabelProvider() { @Override//from w w w. j a va 2 s .c om public String getText(Object element) { if (!(element instanceof IProject)) { return null; } return ((IProject) element).getName(); } }); projectsViewer.setInput(BeanProperties.list(OpenShiftServerEditorModel.PROPERTY_PROJECTS).observe(model)); IObservableValue selectedProjectObservable = ViewerProperties.singleSelection().observe(projectsViewer); Binding selectedProjectBinding = ValueBindingBuilder.bind(selectedProjectObservable) .validatingAfterConvert(new IValidator() { @Override public IStatus validate(Object value) { if (value instanceof IProject) { return ValidationStatus.ok(); } return ValidationStatus.cancel("Please choose a project to deploy."); } }).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_DEPLOYPROJECT).observe(model)) .in(dbc); ControlDecorationSupport.create(selectedProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true)); // browse projects Button browseProjectsButton = new Button(parent, SWT.NONE); browseProjectsButton.setText("Browse..."); GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT) .applyTo(browseProjectsButton); browseProjectsButton.addSelectionListener(onBrowseProjects(model, browseProjectsButton.getShell())); }
From source file:org.jboss.tools.openshift.internal.ui.server.ServerSettingsWizardPage.java
License:Open Source License
private void createRouteControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {//from w w w . j a va 2s. c o m Group routeGroup = new Group(container, SWT.NONE); routeGroup.setText("Route"); GridDataFactory.fillDefaults().span(4, 1).align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(routeGroup); GridLayoutFactory.fillDefaults().applyTo(routeGroup); // additional nesting required because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=478618 Composite routeContainer = new Composite(routeGroup, SWT.None); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(routeContainer); GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(2).applyTo(routeContainer); Button promptRouteButton = new Button(routeContainer, SWT.CHECK); promptRouteButton.setSelection(true); promptRouteButton.setText("Prompt for route when multiple routes available to show in browser"); GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(promptRouteButton); Label routeLabel = new Label(routeContainer, SWT.NONE); routeLabel.setText("Use Route: "); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(routeLabel); StructuredViewer routesViewer = new ComboViewer(routeContainer); GridDataFactory.fillDefaults().span(1, 1).align(SWT.FILL, SWT.CENTER).grab(true, false) .applyTo(routesViewer.getControl()); routesViewer.setContentProvider(new ObservableListContentProvider()); routesViewer.setLabelProvider(new RouteLabelProvider()); routesViewer.setInput(BeanProperties.list(ServerSettingsWizardPageModel.PROPERTY_ROUTES).observe(model)); // routesViewer.setComparer(new IElementComparer() { // // @Override // public boolean equals(Object object1, Object object2) { // if (object1 instanceof IRoute) { // if (!(object2 instanceof IRoute)) { // return false; // } // // IRoute route1 = (IRoute) object1; // IRoute route2 = (IRoute) object2; // // return Objects.equals(route1.getServiceName(), route2.getServiceName()) // && Objects.equals(route1.getURL(), route2.getURL()); // } else if (object2 instanceof IRoute) { // return false; // } else { // return Objects.equals(object1, object2); // } // } // // @Override // public int hashCode(Object element) { // if (element instanceof IRoute) { // IRoute route = (IRoute) element; // return new HashCodeBuilder() // .append(route.getServiceName()) // .append(route.getURL()) // .toHashCode(); // } // return element.hashCode(); // } // }); IObservableValue<IResource> selectedRouteObservable = ViewerProperties.singleSelection() .observe(routesViewer); ValueBindingBuilder.bind(selectedRouteObservable) .to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_ROUTE).observe(model)).in(dbc); final IObservableValue<Boolean> isSelectDefaultRouteObservable = WidgetProperties.selection() .observe(promptRouteButton); final IObservableValue<Boolean> selectDefaultRouteModelObservable = BeanProperties .value(ServerSettingsWizardPageModel.PROPERTY_SELECT_DEFAULT_ROUTE).observe(model); ValueBindingBuilder.bind(isSelectDefaultRouteObservable).converting(new InvertingBooleanConverter()) .to(selectDefaultRouteModelObservable).converting(new InvertingBooleanConverter()).in(dbc); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(routesViewer.getControl())) .notUpdating(selectDefaultRouteModelObservable).in(dbc); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(routeLabel)) .notUpdating(selectDefaultRouteModelObservable).in(dbc); RouteValidator routeValidator = new RouteValidator(isSelectDefaultRouteObservable, selectedRouteObservable); dbc.addValidationStatusProvider(routeValidator); ControlDecorationSupport.create(routeValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true)); }
From source file:org.jboss.tools.openshift.internal.ui.wizard.common.AbstractProjectPage.java
License:Open Source License
private void createProjectControls(Composite parent, DataBindingContext dbc) { Label projectLabel = new Label(parent, SWT.NONE); projectLabel.setText("OpenShift project: "); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(projectLabel); StructuredViewer projectsViewer = new ComboViewer(parent); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false) .applyTo(projectsViewer.getControl()); final OpenShiftExplorerLabelProvider labelProvider = new OpenShiftExplorerLabelProvider(); projectsViewer.setContentProvider(new ObservableListContentProvider()); projectsViewer.setLabelProvider(new ObservableTreeItemLabelProvider()); projectsViewer.setInput(BeanProperties.list(IProjectPageModel.PROPERTY_PROJECT_ITEMS).observe(model)); projectsViewer.setComparator(ProjectViewerComparator.createProjectTreeSorter(labelProvider)); model.setProjectsComparator(new ProjectViewerComparator(labelProvider).asItemComparator()); IObservableValue selectedProjectObservable = ViewerProperties.singleSelection().observe(projectsViewer); Binding selectedProjectBinding = ValueBindingBuilder.bind(selectedProjectObservable) .converting(new ObservableTreeItem2ModelConverter(IProject.class)) .validatingAfterConvert(new IValidator() { @Override/* ww w .j ava 2s .c o m*/ public IStatus validate(Object value) { if (value instanceof IProject) { return ValidationStatus.ok(); } return ValidationStatus.cancel("Please choose an OpenShift project."); } }).to(BeanProperties.value(IProjectPageModel.PROPERTY_PROJECT).observe(model)) .converting(new Model2ObservableTreeItemConverter(null)).in(dbc); ControlDecorationSupport.create(selectedProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true)); IObservableValue connectionObservable = BeanProperties.value(IProjectPageModel.PROPERTY_CONNECTION) .observe(model); DataBindingUtils.addDisposableValueChangeListener(onConnectionChanged(), connectionObservable, projectsViewer.getControl()); Button newProjectButton = new Button(parent, SWT.PUSH); newProjectButton.setText("New..."); GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(newProjectButton); UIUtils.setDefaultButtonWidth(newProjectButton); newProjectButton.addSelectionListener(onNewProjectClicked()); Label filler = new Label(parent, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(3, 1) .applyTo(filler); }