Search in sources :

Example 16 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy in project linuxtools by eclipse.

the class PackageVMPage method createControl.

@Override
public void createControl(Composite parent) {
    ScrolledComposite scrollTop = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    scrollTop.setExpandVertical(true);
    scrollTop.setExpandHorizontal(true);
    final Composite container = new Composite(scrollTop, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(3).margins(6, 6).applyTo(container);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true, false).applyTo(container);
    // Box name
    final Label boxNameLabel = new Label(container, SWT.NONE);
    boxNameLabel.setText(// $NON-NLS-1$
    WizardMessages.getString("ImagePull.name.label"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(boxNameLabel);
    final Text boxNameText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(boxNameText);
    boxNameText.setToolTipText(// $NON-NLS-1$
    WizardMessages.getString("ImagePull.name.tooltip"));
    // Name binding
    final IObservableValue<String> boxNameObservable = BeanProperties.value(PackageVMPageModel.class, PackageVMPageModel.BOX_NAME).observe(model);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(boxNameText), boxNameObservable, new UpdateValueStrategy(), null);
    // Box folder
    final Label boxFolderLabel = new Label(container, SWT.NONE);
    // $NON-NLS-1$
    boxFolderLabel.setText(WizardMessages.getString("PackageVMPage.folder.label"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(boxFolderLabel);
    final Text boxFolderText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(boxFolderText);
    boxFolderText.setToolTipText(// $NON-NLS-1$
    WizardMessages.getString("PackageVMPage.folder.desc"));
    // Folder binding
    final IObservableValue<String> boxFolderObservable = BeanProperties.value(PackageVMPageModel.class, PackageVMPageModel.BOX_FOLDER).observe(model);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(boxFolderText), boxFolderObservable, new UpdateValueStrategy(), null);
    // search
    final Button searchButton = new Button(container, SWT.NONE);
    searchButton.setText(// $NON-NLS-1$
    WizardMessages.getString("ImagePull.search.label"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(searchButton);
    searchButton.addSelectionListener(onSearchFolder());
    dbc.addValidationStatusProvider(new PackageVMValidationStatusProvider(boxNameObservable, boxFolderObservable));
    // setup validation support
    WizardPageSupport.create(this, dbc);
    scrollTop.setContent(container);
    Point point = container.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    scrollTop.setSize(point);
    scrollTop.setMinSize(point);
    setControl(container);
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point)

Example 17 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy 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 18 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy in project n4js by eclipse.

the class WorkspaceWizardPage method setupBindings.

private void setupBindings(WorkspaceWizardPageForm wizardForm) {
    databindingContext = new DataBindingContext();
    WorkspaceWizardModelValidator<M> validator = getValidator();
    // Project property binding
    @SuppressWarnings("unchecked") IObservableValue<IPath> projectModelValue = BeanProperties.value(WorkspaceWizardModel.class, WorkspaceWizardModel.PROJECT_PROPERTY).observe(model);
    @SuppressWarnings("unchecked") IObservableValue<String> projectUI = WidgetProperties.text(SWT.Modify).observe(wizardForm.getProjectText());
    // Note: No model to UI conversation here as IPath is castable to String (default behavior)
    databindingContext.bindValue(projectUI, projectModelValue, new StringToPathConverter().updatingValueStrategy(), new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
    // Source folder property binding
    @SuppressWarnings("unchecked") IObservableValue<IPath> sourceFolderModelValue = BeanProperties.value(WorkspaceWizardModel.class, WorkspaceWizardModel.SOURCE_FOLDER_PROPERTY).observe(model);
    @SuppressWarnings("unchecked") IObservableValue<String> sourceFolderUI = WidgetProperties.text(SWT.Modify).observe(wizardForm.getSourceFolderText());
    // Note: No model to UI conversation (see above)
    databindingContext.bindValue(sourceFolderUI, sourceFolderModelValue, new StringToPathConverter().updatingValueStrategy(), new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
    @SuppressWarnings("unchecked") IObservableValue<Boolean> projectValidModelValue = BeanProperties.value(WorkspaceWizardModelValidator.class, WorkspaceWizardModelValidator.PROJECT_PROPERTY_VALID).observe(validator);
    @SuppressWarnings("unchecked") IObservableValue<Boolean> sourceFolderBrowseEnabled = WidgetProperties.enabled().observe(wizardForm.getSourceFolderBrowseButton());
    databindingContext.bindValue(sourceFolderBrowseEnabled, projectValidModelValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
    // Module specifier property binding
    @SuppressWarnings("unchecked") IObservableValue<String> moduleSpecifierModelValue = BeanProperties.value(WorkspaceWizardModel.class, WorkspaceWizardModel.MODULE_SPECIFIER_PROPERTY).observe(model);
    @SuppressWarnings("unchecked") IObservableValue<String> moduleSpecifierUI = BeanProperties.value(SuffixText.class, SuffixText.TEXT_PROPERTY).observe(wizardForm.getModuleSpecifierText());
    databindingContext.bindValue(moduleSpecifierUI, moduleSpecifierModelValue);
    // Conditional activation of the browse buttons according to the precedent input fields validity
    @SuppressWarnings("unchecked") IObservableValue<Boolean> moduleSpecifierBrowseEnabled = WidgetProperties.enabled().observe(wizardForm.getModuleSpecifierBrowseButton());
    @SuppressWarnings("unchecked") IObservableValue<Boolean> sourceFolderValidValue = BeanProperties.value(WorkspaceWizardModelValidator.class, WorkspaceWizardModelValidator.SOURCE_FOLDER_PROPERTY_VALID).observe(validator);
    @SuppressWarnings("unchecked") IObservableValue<Boolean> projectValidValue = BeanProperties.value(WorkspaceWizardModelValidator.class, WorkspaceWizardModelValidator.PROJECT_PROPERTY_VALID).observe(validator);
    ConditionalConverter moduleSpecifierBrowseableConverter = new ConditionalConverter() {

        @Override
        public boolean validate(Object object) {
            return validator.getSourceFolderValid() && validator.getProjectValid();
        }
    };
    // Bind model changes of project or source folder property to the enabled state of the module specifier browse
    // button.
    databindingContext.bindValue(moduleSpecifierBrowseEnabled, projectValidValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), moduleSpecifierBrowseableConverter.updatingValueStrategy());
    databindingContext.bindValue(moduleSpecifierBrowseEnabled, sourceFolderValidValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), moduleSpecifierBrowseableConverter.updatingValueStrategy());
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) IPath(org.eclipse.core.runtime.IPath) StringToPathConverter(org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters.StringToPathConverter) ConditionalConverter(org.eclipse.n4js.ui.wizard.components.WizardComponentDataConverters.ConditionalConverter) DataBindingContext(org.eclipse.core.databinding.DataBindingContext)

Example 19 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy in project meclipse by flaper87.

the class ConnectionWizardPage method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 3;
    layout.verticalSpacing = 9;
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 250;
    Label label;
    label = new Label(container, SWT.NULL);
    label.setText(getCaption("connectionWizard.label.name"));
    connName = new Text(container, SWT.BORDER | SWT.SINGLE);
    connName.setLayoutData(gd);
    label = new Label(container, SWT.NULL);
    label.setImage(help);
    label.setToolTipText(getCaption("connectionWizard.tooltip.name"));
    label = new Label(container, SWT.NULL);
    label.setText(getCaption("connectionWizard.label.host"));
    host = new Text(container, SWT.BORDER | SWT.SINGLE);
    host.setLayoutData(gd);
    label = new Label(container, SWT.NULL);
    label.setImage(help);
    label.setToolTipText(getCaption("connectionWizard.tooltip.host"));
    label = new Label(container, SWT.NULL);
    label.setText(getCaption("connectionWizard.label.port"));
    port = new Text(container, SWT.BORDER | SWT.SINGLE);
    port.setLayoutData(gd);
    port.setText("27017");
    label = new Label(container, SWT.NULL);
    label.setImage(help);
    label.setToolTipText(getCaption("connectionWizard.tooltip.port"));
    /*
		 * label = new Label(container, SWT.NULL); label.setText("&Username:");
		 * username= new Text(container, SWT.BORDER | SWT.SINGLE);
		 * username.setLayoutData(gd);
		 */
    /*
		 * label = new Label(container, SWT.NULL); label.setText("Passwo&rd:");
		 * password = new Text(container, SWT.BORDER | SWT.SINGLE);
		 * password.setLayoutData(gd);
		 */
    label = new Label(container, SWT.NULL);
    label.setText("Auth not supported yet...");
    // add WizardPage validators
    DataBindingContext dbc = new DataBindingContext();
    WizardPageSupport.create(this, dbc);
    dbc.bindValue(SWTObservables.observeText(connName, SWT.Modify), nameValue, new UpdateValueStrategy().setBeforeSetValidator(new NameValidator()), null);
    dbc.bindValue(SWTObservables.observeText(host, SWT.Modify), hostValue, new UpdateValueStrategy().setBeforeSetValidator(new HostNameValidator()), null);
    dbc.bindValue(SWTObservables.observeText(port, SWT.Modify), portValue, new UpdateValueStrategy().setBeforeSetValidator(new PortValidator()), null);
    initialize();
    setControl(container);
    // disable Save until everything matches
    setPageComplete(false);
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DataBindingContext(org.eclipse.core.databinding.DataBindingContext)

Example 20 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy in project meclipse by flaper87.

the class FilterWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.FILL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 3;
    layout.verticalSpacing = 9;
    GridData gd = new GridData(SWT.FILL);
    gd.widthHint = 250;
    Label label;
    label = new Label(container, SWT.NULL);
    label.setText(getCaption("filterWizard.label.name"));
    nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    nameText.setLayoutData(gd);
    label = new Label(container, SWT.NULL);
    label.setImage(help);
    label.setToolTipText(getCaption("filterWizard.tooltip.name"));
    label = new Label(container, SWT.NULL);
    label.setText(getCaption("filterWizard.label.query"));
    queryText = new Text(container, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.FILL);
    queryText.setLayoutData(gd);
    label = new Label(container, SWT.NULL);
    label.setToolTipText(getCaption("filterWizard.tooltip.query"));
    label.setImage(help);
    // add WizardPage validators
    DataBindingContext dbc = new DataBindingContext();
    WizardPageSupport.create(this, dbc);
    dbc.bindValue(SWTObservables.observeText(nameText, SWT.Modify), nameValue, new UpdateValueStrategy().setBeforeSetValidator(new FilterNameValidator()), null);
    dbc.bindValue(SWTObservables.observeText(queryText, SWT.Modify), queryValue, new UpdateValueStrategy().setBeforeSetValidator(new JSONValidator()), null);
    setControl(container);
    // disable save until everything matches
    setPageComplete(false);
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DataBindingContext(org.eclipse.core.databinding.DataBindingContext)

Aggregations

UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)30 Label (org.eclipse.swt.widgets.Label)14 Text (org.eclipse.swt.widgets.Text)13 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)11 Composite (org.eclipse.swt.widgets.Composite)11 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)10 IValidator (org.eclipse.core.databinding.validation.IValidator)7 Button (org.eclipse.swt.widgets.Button)7 ISWTObservableValue (org.eclipse.jface.databinding.swt.ISWTObservableValue)6 IStatus (org.eclipse.core.runtime.IStatus)5 BeanProperties (org.eclipse.core.databinding.beans.BeanProperties)4 IEMFValueProperty (org.eclipse.emf.databinding.IEMFValueProperty)4 WidgetProperties (org.eclipse.jface.databinding.swt.WidgetProperties)4 LabelProvider (org.eclipse.jface.viewers.LabelProvider)4 MessageFormat (java.text.MessageFormat)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Messages (name.abuchen.portfolio.ui.Messages)3 ValidationStatus (org.eclipse.core.databinding.validation.ValidationStatus)3 EObject (org.eclipse.emf.ecore.EObject)3