Search in sources :

Example 6 with ValueChangeEvent

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());
        }
    });
}
Also used : N4JSInterfaceWizardModel(org.eclipse.n4js.ui.wizard.interfaces.N4JSInterfaceWizardModel) OtherClassifierModifiersComponent(org.eclipse.n4js.ui.wizard.components.OtherClassifierModifiersComponent) WizardPreview(org.eclipse.n4js.ui.wizard.workspace.WizardPreviewProvider.WizardPreview) IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) AccessModifierComponent(org.eclipse.n4js.ui.wizard.components.AccessModifierComponent) WorkspaceWizardGenerator(org.eclipse.n4js.ui.wizard.generator.WorkspaceWizardGenerator) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) WizardComponentDataConverters(org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) AccessModifier(org.eclipse.n4js.ui.wizard.model.AccessModifier) DefinitionFileModel(org.eclipse.n4js.ui.wizard.model.DefinitionFileModel) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) SuffixText(org.eclipse.n4js.ui.wizard.workspace.SuffixText) ModuleSpecifierSelectionDialog(org.eclipse.n4js.ui.dialog.ModuleSpecifierSelectionDialog) N4JSGlobals(org.eclipse.n4js.N4JSGlobals) IPath(org.eclipse.core.runtime.IPath) Composite(org.eclipse.swt.widgets.Composite) WorkspaceWizardModelValidator(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator) NameComponent(org.eclipse.n4js.ui.wizard.components.NameComponent) ValidationResult(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator.ValidationResult) Shell(org.eclipse.swt.widgets.Shell) Display(org.eclipse.swt.widgets.Display) WorkspaceWizardModel(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModel) ContentBlock(org.eclipse.n4js.ui.wizard.generator.ContentBlock) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) Path(org.eclipse.core.runtime.Path) PreviewableWizardPage(org.eclipse.n4js.ui.wizard.workspace.PreviewableWizardPage) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) N4JSInterfaceWizardModel(org.eclipse.n4js.ui.wizard.interfaces.N4JSInterfaceWizardModel) WorkspaceWizardModel(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModel) SuffixText(org.eclipse.n4js.ui.wizard.workspace.SuffixText) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) ValidationResult(org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardModelValidator.ValidationResult) AccessModifier(org.eclipse.n4js.ui.wizard.model.AccessModifier) DefinitionFileModel(org.eclipse.n4js.ui.wizard.model.DefinitionFileModel)

Example 7 with ValueChangeEvent

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);
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 8 with ValueChangeEvent

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();
    }
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) OAuthDetailView(org.jboss.tools.openshift.internal.ui.wizard.connection.OAuthDetailView) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel) Connection(org.jboss.tools.openshift.core.connection.Connection) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) Test(org.junit.Test)

Example 9 with ValueChangeEvent

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;
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) TabItem(org.eclipse.swt.widgets.TabItem) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) Composite(org.eclipse.swt.widgets.Composite) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) Text(org.eclipse.swt.widgets.Text) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 10 with ValueChangeEvent

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();
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) SelectProjectComponentBuilder(org.jboss.tools.openshift.internal.common.ui.SelectProjectComponentBuilder) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) Link(org.eclipse.swt.widgets.Link)

Aggregations

IValueChangeListener (org.eclipse.core.databinding.observable.value.IValueChangeListener)11 ValueChangeEvent (org.eclipse.core.databinding.observable.value.ValueChangeEvent)11 Composite (org.eclipse.swt.widgets.Composite)6 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)5 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)3 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)3 Shell (org.eclipse.swt.widgets.Shell)3 IStatus (org.eclipse.core.runtime.IStatus)2 Button (org.eclipse.swt.widgets.Button)2 Connection (org.jboss.tools.openshift.core.connection.Connection)2 ConnectionWizardPageModel (org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel)2 Iterator (java.util.Iterator)1 Binding (org.eclipse.core.databinding.Binding)1 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)1 ValidationStatusProvider (org.eclipse.core.databinding.ValidationStatusProvider)1 BeanProperties (org.eclipse.core.databinding.beans.BeanProperties)1 ChangeEvent (org.eclipse.core.databinding.observable.ChangeEvent)1 IChangeListener (org.eclipse.core.databinding.observable.IChangeListener)1 IObservable (org.eclipse.core.databinding.observable.IObservable)1 IStaleListener (org.eclipse.core.databinding.observable.IStaleListener)1