use of org.eclipse.core.databinding.observable.value.ValueChangeEvent in project n4js by eclipse.
the class N4JSNewClassifierWizardPage method setupBindings.
/**
* Setup additional non-component contained bindings
*/
protected void setupBindings() {
DataBindingContext dataBindingContext = this.getDataBindingContext();
@SuppressWarnings("unchecked") IObservableValue<String> moduleSpecifierValue = BeanProperties.value(WorkspaceWizardModel.class, WorkspaceWizardModel.MODULE_SPECIFIER_PROPERTY).observe(getModel());
@SuppressWarnings("unchecked") IObservableValue<Boolean> suffixVisibilityValue = BeanProperties.value(SuffixText.class, SuffixText.SUFFIX_VISIBILITY_PROPERTY).observe(workspaceWizardControl.getModuleSpecifierText());
// // Only show the suffix on input values ending with a '/' character or empty module specifiers.
dataBindingContext.bindValue(suffixVisibilityValue, moduleSpecifierValue, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(m -> {
String moduleSpecifier = (String) m;
return (moduleSpecifier.isEmpty() || moduleSpecifier.charAt(moduleSpecifier.length() - 1) == IPath.SEPARATOR);
}));
// // interface name to module specifier suffix binding
@SuppressWarnings("unchecked") IObservableValue<String> interfaceNameModelValue = BeanProperties.value(N4JSInterfaceWizardModel.class, N4JSClassifierWizardModel.NAME_PROPERTY).observe(getModel());
@SuppressWarnings("unchecked") IObservableValue<String> greySuffixValue = BeanProperties.value(SuffixText.class, SuffixText.SUFFIX_PROPERTY).observe(workspaceWizardControl.getModuleSpecifierText());
dataBindingContext.bindValue(greySuffixValue, interfaceNameModelValue, noUpdateValueStrategy(), new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
// // Enable n4js <-> Definition value(external) is selected
@SuppressWarnings("unchecked") IObservableValue<Boolean> externalValue = BeanProperties.value(DefinitionFileModel.class, N4JSClassifierWizardModel.DEFINITION_FILE_PROPERTY).observe(getModel());
@SuppressWarnings("unchecked") IObservableValue<Boolean> n4jsEnabled = WidgetProperties.enabled().observe(otherClassifierModifiersComponent.getN4jsAnnotationBox());
dataBindingContext.bindValue(n4jsEnabled, externalValue, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(input -> getModel().isDefinitionFile() && AccessModifier.PRIVATE != getModel().getAccessModifier()));
// One way binding of the access modifiers to the enabled state of internal checkbox
@SuppressWarnings("unchecked") IObservableValue<Boolean> internalEnabledValue = WidgetProperties.enabled().observe(accessModifierComponent.getInternalAnnotationBox());
@SuppressWarnings("unchecked") IObservableValue<AccessModifier> accessModifierSelectObservable = BeanProperties.value(N4JSInterfaceWizardModel.class, N4JSClassifierWizardModel.ACCESS_MODIFIER_PROPERTY).observe(getModel());
dataBindingContext.bindValue(internalEnabledValue, accessModifierSelectObservable, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(object -> {
if (object instanceof AccessModifier) {
return isInternalAccessModifierEnabled((AccessModifier) object);
}
return false;
}));
// N4JS annotation checkbox disabled when access modifier is private
@SuppressWarnings("unchecked") IObservableValue<Boolean> n4jsEnabledValue = WidgetProperties.enabled().observe(otherClassifierModifiersComponent.getN4jsAnnotationBox());
dataBindingContext.bindValue(n4jsEnabledValue, accessModifierSelectObservable, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(object -> {
if (object instanceof AccessModifier) {
return ((AccessModifier) object != AccessModifier.PRIVATE) && getModel().isDefinitionFile();
}
return false;
}));
// Refresh wizard state on validation change
@SuppressWarnings("unchecked") IObservableValue<ValidationResult> observableValidationValue = BeanProperties.value(WorkspaceWizardModelValidator.VALIDATION_RESULT).observe(getValidator());
observableValidationValue.addValueChangeListener(new IValueChangeListener<ValidationResult>() {
@Override
public void handleValueChange(ValueChangeEvent<? extends ValidationResult> event) {
onValidationChange(event.diff.getNewValue());
}
});
}
use of org.eclipse.core.databinding.observable.value.ValueChangeEvent in project jbosstools-openshift by jbosstools.
the class PortForwardingWizardPage method doCreateControls.
@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(parent);
Composite container = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(container);
Composite tableContainer = new Composite(container, SWT.NONE);
final TableViewer viewer = createTable(tableContainer, dbc);
GridDataFactory.fillDefaults().span(1, 3).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
final Button startButton = new Button(container, SWT.PUSH);
startButton.setText("Start All");
GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).align(SWT.FILL, SWT.TOP).applyTo(startButton);
startButton.addSelectionListener(onStartPortForwarding(viewer));
final Button stopButton = new Button(container, SWT.PUSH);
stopButton.setText("Stop All");
GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).align(SWT.FILL, SWT.TOP).applyTo(stopButton);
stopButton.addSelectionListener(onStopPortForwarding(viewer));
final Button findFreesPortButton = new Button(container, SWT.CHECK);
findFreesPortButton.setText("Find free local ports for remote ports");
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(findFreesPortButton);
final IObservableValue findFreePortsButtonObservable = BeanProperties.value(PortForwardingWizardModel.PROPERTY_USE_FREE_PORTS).observe(wizardModel);
final IObservableValue findFreePortsButtonSelection = WidgetProperties.selection().observe(findFreesPortButton);
dbc.bindValue(findFreePortsButtonSelection, findFreePortsButtonObservable);
DataBindingUtils.addDisposableValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
refreshViewerInput(viewer);
}
}, findFreePortsButtonObservable, viewer.getTable());
// enabling/disabling controls
IObservableValue portForwardingStartedObservable = BeanProperties.value(PortForwardingWizardModel.PROPERTY_PORT_FORWARDING).observe(wizardModel);
IObservableValue portForwardingAllowedObservable = BeanProperties.value(PortForwardingWizardModel.PROPERTY_PORT_FORWARDING_ALLOWED).observe(wizardModel);
IObservableValue freePortSearchAllowedObservable = BeanProperties.value(PortForwardingWizardModel.PROPERTY_FREE_PORT_SEARCH_ALLOWED).observe(wizardModel);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(startButton)).notUpdating(portForwardingAllowedObservable).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(stopButton)).notUpdating(portForwardingStartedObservable).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(findFreesPortButton)).notUpdating(freePortSearchAllowedObservable).in(dbc);
}
use of org.eclipse.core.databinding.observable.value.ValueChangeEvent in project jbosstools-openshift by jbosstools.
the class ConnectionValidatorsTest method testOAuthAuthenticationValidatorInUI.
@Test
public void testOAuthAuthenticationValidatorInUI() {
Connection connection1 = mockConnection(HOST1, null, TOKEN1);
mockConnection(HOST2, null, TOKEN2);
ConnectionWizardPageModel pageModel = mockConnectionWizardPageModel(connection1);
Mockito.when(pageModel.getHost()).thenReturn(HOST2);
IValueChangeListener<Object> l = new IValueChangeListener<Object>() {
@Override
public void handleValueChange(ValueChangeEvent<? extends Object> event) {
}
};
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Composite composite = new Composite(shell, SWT.NONE);
try {
OAuthDetailView view = new OAuthDetailView(null, pageModel, l, null, null);
DataBindingContext dbc = new DataBindingContext();
view.createControls(shell, null, dbc);
view.onVisible(null, dbc);
view.getTokenTextControl().setText(TOKEN2);
MultiValidator v = findValidator(dbc);
Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
view.getTokenTextControl().setText(TOKEN3);
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
} finally {
composite.dispose();
}
}
use of org.eclipse.core.databinding.observable.value.ValueChangeEvent in project jbosstools-openshift by jbosstools.
the class ApplicationSourceListPage method createServerTemplateControls.
private IObservableValue createServerTemplateControls(TabFolder tabFolder, TabFolderTraverseListener tabFolderTraverseListener, IObservableValue uploadTemplate, DataBindingContext dbc) {
TabItem serverTemplatesTab = new TabItem(tabFolder, SWT.NONE);
serverTemplatesTab.setText("Server application source");
Composite parent = new Composite(tabFolder, SWT.NONE);
GridLayoutFactory.fillDefaults().margins(10, 6).spacing(2, 2).applyTo(parent);
serverTemplatesTab.setControl(parent);
// filter text
final Text txtTemplateFilter = UIUtils.createSearchText(parent);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(txtTemplateFilter);
IObservableValue eclipseProjectObservable = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_ECLIPSE_PROJECT).observe(model);
DataBindingUtils.addDisposableValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
filterTemplates(txtTemplateFilter, (org.eclipse.core.resources.IProject) event.getObservableValue().getValue());
}
}, eclipseProjectObservable, txtTemplateFilter);
filterTemplates(txtTemplateFilter, model.getEclipseProject());
// the list of templates
this.templatesViewer = createServerTemplatesViewer(parent, txtTemplateFilter);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(400, 180).applyTo(templatesViewer.getControl());
IObservableValue selectedViewerServerTemplate = ViewerProperties.singleSelection().observe(templatesViewer);
ValueBindingBuilder.bind(selectedViewerServerTemplate).converting(new ObservableTreeItem2ModelConverter(IApplicationSource.class)).to(BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_SERVER_APP_SOURCE).observe(model)).converting(new Model2ObservableTreeItemConverter(ApplicationSourceTreeItems.INSTANCE)).in(dbc);
templatesViewer.addDoubleClickListener(onServerTemplateDoubleClicked());
txtTemplateFilter.addModifyListener(onFilterTextTyped(templatesViewer));
tabFolderTraverseListener.bindTabControls(tabFolder.getItemCount() - 1, txtTemplateFilter, templatesViewer.getTree());
return selectedViewerServerTemplate;
}
use of org.eclipse.core.databinding.observable.value.ValueChangeEvent in project jbosstools-openshift by jbosstools.
the class ApplicationSourceListPage method createEclipseProjectControls.
private IObservableValue createEclipseProjectControls(Composite parent, DataBindingContext dbc) {
IObservableValue eclipseProjectObservable = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_ECLIPSE_PROJECT).observe(model);
SelectProjectComponentBuilder builder = new SelectProjectComponentBuilder();
builder.setTextLabel("Use existing workspace project:").setRequired(false).setEclipseProjectObservable(eclipseProjectObservable).setSelectionListener(onBrowseProjects()).setButtonIndent(0).build(parent, dbc);
Link gitLabel = new Link(parent, SWT.NONE);
gitLabel.setText("The project needs to be <a>shared with Git</a> and have a remote repository accessible by OpenShift");
gitLabel.addSelectionListener(onClickEGitLink());
GridDataFactory.fillDefaults().span(3, 1).applyTo(gitLabel);
DataBindingUtils.addDisposableValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
org.eclipse.core.resources.IProject p = (org.eclipse.core.resources.IProject) event.getObservableValue().getValue();
toggleEgitLink(gitLabel, p);
}
}, eclipseProjectObservable, gitLabel);
toggleEgitLink(gitLabel, model.getEclipseProject());
return builder.getProjectNameTextObservable();
}
Aggregations