List of usage examples for org.eclipse.jface.databinding.wizard WizardPageSupport setValidationMessageProvider
public void setValidationMessageProvider(IValidationMessageProvider messageProvider)
From source file:mlm.eclipse.ide.jsworkingset.internal.JSWorkingSetPage.java
License:Open Source License
@Override public void createControl(final Composite pParent) { mDataBindingContext = new DataBindingContext(SWTObservables.getRealm(pParent.getDisplay())); final Composite composite = new Composite(pParent, SWT.NONE); composite.setLayout(GridLayoutFactory.fillDefaults() // .numColumns(3) // .create());// ww w . ja v a 2 s . c om setControl(composite); // working set label { final String workingSetLabel = mWorkingSet != null ? mWorkingSet.getLabel() : ""; //$NON-NLS-1$ mWorkingSetLabel = WritableValue.withValueType(String.class); mWorkingSetLabel.setValue(workingSetLabel); final Label label = new Label(composite, SWT.WRAP); label.setText("Label:"); final Text text = new Text(composite, SWT.BORDER | SWT.SINGLE); text.setToolTipText("The label for the working set."); text.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(true, false) // .span(2, 1) // .create()); final IValidator validator = (v) -> { final String value = (String) v; if (value == null || value.trim().isEmpty()) { return ValidationStatus.ok(); } return ValidationStatus.info("This may likely be overridden by the script."); }; final UpdateValueStrategy targetToModel = new UpdateValueStrategy() // .setAfterConvertValidator(validator) // ; final ISWTObservableValue target = WidgetProperties.text(SWT.Modify) // .observe(text) // ; final Binding binding = mDataBindingContext.bindValue(target, mWorkingSetLabel, targetToModel, null); binding.getValidationStatus().setValue(ValidationStatus.ok()); ControlDecorationSupport.create(binding, SWT.LEFT | SWT.TOP); } // working set name { final String workingSetName = JSWorkingSetPrefs.getName(mWorkingSet); mWorkingSetName = WritableValue.withValueType(String.class); mWorkingSetName.setValue(workingSetName); final Label label = new Label(composite, SWT.WRAP); label.setText("Name:"); final Text text = new Text(composite, SWT.BORDER | SWT.SINGLE); text.setToolTipText("The name for the working set."); text.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(true, false) // .span(2, 1) // .create()); text.setFocus(); final IValidator validator = (v) -> { final String value = (String) v; if (value == null || value.trim().isEmpty()) { return ValidationStatus.error("Please provide a name!"); } return ValidationStatus.ok(); }; final UpdateValueStrategy targetToModel = new UpdateValueStrategy() // .setAfterConvertValidator(validator) // ; final ISWTObservableValue target = WidgetProperties.text(SWT.Modify) // .observe(text) // ; final Binding binding = mDataBindingContext.bindValue(target, mWorkingSetName, targetToModel, null); ControlDecorationSupport.create(binding, SWT.LEFT | SWT.TOP); } // script { final String workingSetScript = JSWorkingSetPrefs.getScript(mWorkingSet); mWorkingSetScript = WritableValue.withValueType(String.class); mWorkingSetScript.setValue(workingSetScript); final String linkText = String.format("<a href=\"native\">%s</a>", "Script:"); //$NON-NLS-1$ final Link link = new Link(composite, SWT.NONE); link.setText(linkText); final Text text = new Text(composite, SWT.BORDER | SWT.SINGLE); text.setToolTipText("Enter a workspace file."); text.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(true, false) // .create()); link.addListener(SWT.Selection, (e) -> { final String filename = text.getText(); if (filename.isEmpty()) { return; } final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IResource resource = root.findMember(filename); if (resource == null || !resource.isAccessible() || resource.getType() != IResource.FILE) { return; } final IWorkbench workbench = PlatformUI.getWorkbench(); final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) { return; } final IWorkbenchPage page = window.getActivePage(); if (page == null) { return; } try { final FileEditorInput input = new FileEditorInput((IFile) resource); final IEditorDescriptor editor = workbench.getEditorRegistry() .getDefaultEditor(resource.getName()); final String editorId = editor != null ? editor.getId() : EditorsUI.DEFAULT_TEXT_EDITOR_ID; page.openEditor(input, editorId); } catch (final PartInitException ex) { Activator.log(IStatus.ERROR, String.format("Failed to open editor for '%s'!", filename), ex); //$NON-NLS-1$ } }); // TODO history or path completion for script? final Button button = new Button(composite, SWT.PUSH); button.setText("Browse..."); //$NON-NLS-1$ button.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(false, false) // .create()); button.addListener(SWT.Selection, (e) -> { final Shell shell = button.getShell(); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final SelectionDialog dialog = new ResourceListSelectionDialog(shell, root, IResource.FILE); dialog.setTitle("Select a JavaScript file"); if (dialog.open() == Window.OK) { final Object[] objects = dialog.getResult(); if (objects.length == 1) { final IResource resource = (IResource) objects[0]; final IPath path = resource.getFullPath(); text.setText(path.toString()); } else { text.setText(""); //$NON-NLS-1$ } } }); final IValidator validator = (v) -> { final String value = (String) v; if (value == null || value.trim().isEmpty()) { return ValidationStatus.error("Please provide a script!"); } final IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(value); if (member == null || !member.exists()) { return ValidationStatus.error("The provided script does not exist in the workspace!"); } return ValidationStatus.ok(); }; final UpdateValueStrategy targetToModel = new UpdateValueStrategy() // .setAfterConvertValidator(validator) // ; final ISWTObservableValue target = WidgetProperties.text(SWT.Modify) // .observe(text) // ; final Binding binding = mDataBindingContext.bindValue(target, mWorkingSetScript, targetToModel, null); ControlDecorationSupport.create(binding, SWT.LEFT | SWT.TOP); } final WizardPageSupport wizardPageSupport = WizardPageSupport.create(this, mDataBindingContext); wizardPageSupport.setValidationMessageProvider(new ValidationMessageProvider() { @Override public String getMessage(final ValidationStatusProvider pStatusProvider) { final String message = super.getMessage(pStatusProvider); if (message != null) { return message; } return "Enter a working set label and name and select the script that makes up the content of the working set."; } }); // provide a clean start setErrorMessage(null); setMessage( "Enter a working set label and name and select the script that makes up the content of the working set."); }
From source file:org.fusesource.ide.syndesis.extensions.ui.wizards.pages.SyndesisExtensionProjectWizardExtensionDetailsPage.java
License:Open Source License
@Override public void createControl(Composite parent) { DataBindingContext dbc = new DataBindingContext(); WizardPageSupport wps = WizardPageSupport.create(this, dbc); wps.setValidationMessageProvider(dummyMessageProvider); wizard = (SyndesisExtensionProjectWizard) getWizard(); Composite container = new Composite(parent, SWT.NULL); container.setLayout(new GridLayout(4, false)); createSyndesisVersionControls(container, dbc); Label spacer = new Label(container, SWT.NONE); GridData gridData = GridDataFactory.fillDefaults().grab(true, false).span(4, 1).indent(8, 0).create(); spacer.setLayoutData(gridData);// w w w.j a v a 2s .co m Label extensionDetailsLabel = new Label(container, SWT.NONE); extensionDetailsLabel.setText(Messages.newProjectWizardExtensionDetailsPageExtensionDetailsLabel); gridData = GridDataFactory.fillDefaults().grab(true, false).span(4, 1).indent(8, 0).create(); extensionDetailsLabel.setLayoutData(gridData); Text extensionIdText = createField(container, Messages.newProjectWizardExtensionDetailsPageExtensionIdLabel, null, Messages.newProjectWizardExtensionDetailsPageExtensionIdTooltip); UpdateValueStrategy updateStrategy = UpdateValueStrategy.create(null); updateStrategy.setBeforeSetValidator(new SyndesisExtensionIdValidator()); createBinding(dbc, extensionIdText, "extensionId", updateStrategy); // set a default value extensionIdText.setText(DEFAULT_EXTENSION_ID); Text extensionNameText = createField(container, Messages.newProjectWizardExtensionDetailsPageNameLabel, null, Messages.newProjectWizardExtensionDetailsPageNameTooltip); updateStrategy = UpdateValueStrategy.create(null); updateStrategy.setBeforeSetValidator(new SyndesisExtensionNameValidator()); createBinding(dbc, extensionNameText, "name", updateStrategy); // set a default value extensionNameText.setText(DEFAULT_EXTENSION_NAME); Text extensionDescriptionText = createField(container, Messages.newProjectWizardExtensionDetailsPageDescriptionLabel, Messages.newProjectWizardExtensionDetailsPageOptionalDescriptionFieldHint, Messages.newProjectWizardExtensionDetailsPageDescriptionTooltip); createBinding(dbc, extensionDescriptionText, "description"); Text extensionVersionText = createField(container, Messages.newProjectWizardExtensionDetailsPageVersionLabel, null, Messages.newProjectWizardExtensionDetailsPageVersionTooltip); updateStrategy = UpdateValueStrategy.create(null); updateStrategy.setBeforeSetValidator(new SyndesisExtensionVersionValidator()); createBinding(dbc, extensionVersionText, "version", updateStrategy); // set a default value extensionVersionText.setText(DEFAULT_EXTENSION_VERSION); spacer = new Label(container, SWT.NONE); gridData = GridDataFactory.fillDefaults().grab(true, false).span(4, 1).indent(8, 0).create(); spacer.setLayoutData(gridData); createExtensionTypeRadioGroup(container); spacer = new Label(container, SWT.NONE); gridData = GridDataFactory.fillDefaults().grab(true, false).span(4, 1).indent(8, 0).create(); spacer.setLayoutData(gridData); createStepTypeRadioGroup(container); setControl(container); extensionIdText.setFocus(); }