/* (non-Javadoc) * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) */ @Override public IStatus validate(Object value) { IStatus validate = validator.validate(value); int severity = validate.getSeverity(); if (severity > IStatus.OK) { controlDecoration.show(); if (severity >= IStatus.ERROR) { controlDecoration.setImage(error); } else if (severity == IStatus.WARNING) { controlDecoration.setImage(warn); } else if (severity == IStatus.INFO) { controlDecoration.setImage(info); } if (updateMessage) { controlDecoration.setDescriptionText(validate.getMessage()); } } else { controlDecoration.hide(); } if (onlyChangeDecoration) { return Status.OK_STATUS; } else { return validate; } }
/** Adds validation overlay component to the control. */ private void addValidationOverlay( final AttributeDescriptor descriptor, final IAttributeEditor editor, final Object defaultValue, final Control label) { final ControlDecoration decoration = new ControlDecoration(label, SWT.LEFT | SWT.BOTTOM); decoration.hide(); final FieldDecoration requiredDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); decoration.setImage(requiredDecoration.getImage()); decoration.setDescriptionText("Invalid value"); final IAttributeListener validationListener = new InvalidStateDecorationListener(decoration, descriptor, defaultValue); globalEventsProvider.addAttributeListener(validationListener); editor.addAttributeListener(validationListener); label.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { globalEventsProvider.removeAttributeListener(validationListener); editor.removeAttributeListener(validationListener); decoration.dispose(); } }); }
ControlDecoration createDecorator(final Control control) { final ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP); final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); controlDecoration.setImage(fieldDecoration.getImage()); return controlDecoration; }
protected Control createResourceComposite( Section section, TabbedPropertySheetWidgetFactory widgetFactory) { final Composite client = widgetFactory.createComposite(section); client.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); client.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create()); resourceText = widgetFactory.createText(client, ""); resourceText.setLayoutData( GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create()); final ControlDecoration cd = new ControlDecoration(resourceText, SWT.LEFT); cd.setImage(Pics.getImage(PicsConstants.hint)); cd.setDescriptionText(Messages.filewidget_resource_hint); final Button browseResourceButton = widgetFactory.createButton(client, Messages.Browse, SWT.PUSH); browseResourceButton.setLayoutData(GridDataFactory.fillDefaults().create()); browseResourceButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { final SelectDocumentInBonitaStudioRepository selectDocumentInBonitaStudioRepository = new SelectDocumentInBonitaStudioRepository(Display.getDefault().getActiveShell()); if (IDialogConstants.OK_ID == selectDocumentInBonitaStudioRepository.open()) { resourceText.setText( selectDocumentInBonitaStudioRepository.getSelectedDocument().getName()); } } }); return client; }
private ControlDecoration createControlDecoration(Control control, Label label) { ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP); controlDecoration.setDescriptionText( label.getText() + " Not a valid entry. Data must be numeric."); FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); controlDecoration.setImage(fieldDecoration.getImage()); return controlDecoration; }
public TextVarWarning(VariableSpace space, Composite composite, int flags) { super(composite, SWT.NONE); warningInterfaces = new ArrayList<WarningInterface>(); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = 0; formLayout.marginHeight = 0; formLayout.marginTop = 0; formLayout.marginBottom = 0; this.setLayout(formLayout); // add a text field on it... wText = new TextVar(space, this, flags); warningControlDecoration = new ControlDecoration(wText, SWT.CENTER | SWT.RIGHT); Image warningImage = GUIResource.getInstance().getImageWarning(); warningControlDecoration.setImage(warningImage); warningControlDecoration.setDescriptionText( BaseMessages.getString(PKG, "TextVar.tooltip.FieldIsInUse")); warningControlDecoration.hide(); // If something has changed, check the warning interfaces // wText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent arg0) { // Verify all the warning interfaces. // Show the first that has a warning to show... // boolean foundOne = false; for (WarningInterface warningInterface : warningInterfaces) { WarningMessageInterface warningSituation = warningInterface.getWarningSituation(wText.getText(), wText, this); if (warningSituation.isWarning()) { foundOne = true; warningControlDecoration.show(); warningControlDecoration.setDescriptionText(warningSituation.getWarningMessage()); break; } } if (!foundOne) { warningControlDecoration.hide(); } } }); FormData fdText = new FormData(); fdText.top = new FormAttachment(0, 0); fdText.left = new FormAttachment(0, 0); fdText.right = new FormAttachment(100, -warningImage.getBounds().width); wText.setLayoutData(fdText); }
private static ControlDecoration createDecoration( String text, String fieldDecorationImageKey, int position, Control control) { ControlDecoration decoration = new ControlDecoration(control, position); Image icon = FieldDecorationRegistry.getDefault().getFieldDecoration(fieldDecorationImageKey).getImage(); decoration.setImage(icon); decoration.setDescriptionText(text); decoration.setShowHover(true); decoration.hide(); return decoration; }
public static void addDecoration(Text text) { Image imageDecoration = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION) .getImage(); ControlDecoration decoration = new ControlDecoration(text, SWT.RIGHT | SWT.TOP); decoration.setImage(imageDecoration); decoration.setDescriptionText(POINTS); decoration.setMarginWidth(2); }
/** * Adds little bulb decoration to given control. Bulb will appear in top left corner of control * after giving focus for this control. * * <p>After clicking on bulb image text from <code>tooltip</code> will appear. * * @param control instance of {@link Control} object with should be decorated * @param tooltip text value which should appear after clicking on bulb image. */ public static void addBulbDecorator(final Control control, final String tooltip) { ControlDecoration dec = new ControlDecoration(control, SWT.TOP | SWT.LEFT); dec.setImage( FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL) .getImage()); dec.setShowOnlyOnFocus(true); dec.setShowHover(true); dec.setDescriptionText(tooltip); }
public Composite createPreferenceComposite( Composite parent, final IBuildParticipantWorkingCopy participant) { Composite master = new Composite(parent, SWT.NONE); master.setLayout(GridLayoutFactory.fillDefaults().create()); GridDataFactory fillHoriz = GridDataFactory.fillDefaults().grab(true, false); // JSON Options Group group = new Group(master, SWT.BORDER); group.setText(Messages.JSLintValidatorPreferenceCompositeFactory_OptionsTitle); group.setLayout(new GridLayout()); group.setLayoutData(fillHoriz.create()); Label label = new Label(group, SWT.WRAP); label.setText(Messages.JSLintValidatorPreferenceCompositeFactory_OptionsMsg); fillHoriz.applyTo(label); final Text text = new Text(group, SWT.MULTI | SWT.V_SCROLL); final ControlDecoration decoration = new ControlDecoration(text, SWT.LEFT | SWT.TOP); decoration.setDescriptionText( Messages.JSLintValidatorPreferenceCompositeFactory_OptionsParseError); decoration.setImage( PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEC_FIELD_ERROR)); decoration.hide(); text.setText(participant.getPreferenceString(IPreferenceConstants.JS_LINT_OPTIONS)); fillHoriz.hint(SWT.DEFAULT, 100).applyTo(text); text.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { decoration.hide(); try { String optionsAsJSON = text.getText(); JSON.parse(optionsAsJSON); participant.setPreference(IPreferenceConstants.JS_LINT_OPTIONS, text.getText()); } catch (IllegalStateException e1) { decoration.show(); } } }); // Filters Composite filtersGroup = new ValidatorFiltersPreferenceComposite(master, participant); filtersGroup.setLayoutData(fillHoriz.grab(true, true).hint(SWT.DEFAULT, 150).create()); return master; }
protected void mostrarErroresValidacion(CheckValidationException e) { bindingManager.clearWarnings(); for (Errores err : e.getValidationErrors()) { Control c = bindingManager.getBindedControl(err.getPropiedad(), err.getClase()); if (c != null) { ControlDecoration controlDecoration = new ControlDecoration(c, SWT.RIGHT); controlDecoration.setImage( SWTResourceManager.getImage(Composite.class, "/resources/exclamacion_16.png")); controlDecoration.setDescriptionText(err.getMensaje()); bindingManager.addWarning(controlDecoration); } else { DialogManager.mostrarMensaje( getShell(), "Cuidado, hay un error de validación pero no se está mostrando"); } } }
@Override protected void createButtonsForButtonBar(Composite parent) { super.createButtonsForButtonBar(parent); Button okButton = getButton(IDialogConstants.OK_ID); okButtonDecoration = new ControlDecoration(okButton, SWT.TOP | SWT.LEFT); okButton.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { okButtonDecoration.dispose(); } }); okButtonDecoration.hide(); okButtonDecoration.setMarginWidth(1); okButtonDecoration.setImage(warningDecoration.getImage()); okButtonDecoration.setDescriptionText( "The dialog contains warnings. Closing the dialog is discouraged."); }
private void createUIFieldDecorationTemplate() { // Decorate the combo with the info image int bits = SWT.TOP | SWT.LEFT; fControlDecoration = new ControlDecoration(fFieldTemplateCombo.getControl(), bits); // Configure decoration // No margin fControlDecoration.setMarginWidth(0); // Custom hover tip text fControlDecoration.setDescriptionText( PDEUIMessages.SplashConfigurationSection_msgDecorationTemplateSupport); // Custom hover properties fControlDecoration.setShowHover(true); // Hover image to use FieldDecoration contentProposalImage = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION); fControlDecoration.setImage(contentProposalImage.getImage()); // Hide the decoration initially fControlDecoration.hide(); }
private void addDecorator(final Composite composite) { checkBoxDecoration = new ControlDecoration(checkBoxControl, SWT.RIGHT, composite); checkBoxDecoration.setImage(Pics.getImage(PicsConstants.hint)); refreshDecoration(); }
/* (non-Javadoc) * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory, org.bonitasoft.studio.common.properties.ExtensibleGridPropertySection) */ @Override public void createControl( Composite composite, TabbedPropertySheetWidgetFactory widgetFactory, ExtensibleGridPropertySection extensibleGridPropertySection) { SimulationTransition transition; if (((Activity) eObject).getLoopTransition() == null) { transition = SimulationFactory.eINSTANCE.createSimulationTransition(); editingDomain .getCommandStack() .execute( new SetCommand( editingDomain, eObject, SimulationPackage.Literals.SIMULATION_ACTIVITY__LOOP_TRANSITION, transition)); } else { transition = ((Activity) eObject).getLoopTransition(); } composite.setLayout(new GridLayout(2, false)); Composite radioComposite = widgetFactory.createComposite(composite); radioComposite.setLayout(new FillLayout()); radioComposite.setLayoutData(GridDataFactory.fillDefaults().create()); Button expressionRadio = widgetFactory.createButton(radioComposite, "Expression", SWT.RADIO); Button probaRadio = widgetFactory.createButton(radioComposite, "Probability", SWT.RADIO); final Composite stackComposite = widgetFactory.createComposite(composite); stackComposite.setLayoutData(GridDataFactory.fillDefaults().hint(300, SWT.DEFAULT).create()); final StackLayout stackLayout = new StackLayout(); stackComposite.setLayout(stackLayout); final Composite probaComposite = widgetFactory.createComposite(stackComposite); FillLayout layout = new FillLayout(); layout.marginWidth = 10; probaComposite.setLayout(layout); Text probaText = widgetFactory.createText(probaComposite, "", SWT.BORDER); ControlDecoration controlDecoration = new ControlDecoration(probaText, SWT.LEFT | SWT.TOP); FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); controlDecoration.setImage(fieldDecoration.getImage()); controlDecoration.setDescriptionText(Messages.mustBeAPercentage); final Composite expressionComposite = widgetFactory.createComposite(stackComposite); FillLayout layout2 = new FillLayout(); layout2.marginWidth = 10; expressionComposite.setLayout(layout2); ExpressionViewer expressionText = new ExpressionViewer( expressionComposite, SWT.BORDER, widgetFactory, editingDomain, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION); Expression selection = transition.getExpression(); if (selection == null) { selection = ExpressionFactory.eINSTANCE.createExpression(); editingDomain .getCommandStack() .execute( SetCommand.create( editingDomain, transition, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION, selection)); } context.bindValue( ViewerProperties.singleSelection().observe(expressionText), EMFEditProperties.value( editingDomain, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION) .observe(eObject)); expressionText.setInput(eObject); boolean useExpression = transition.isUseExpression(); if (useExpression) { stackLayout.topControl = expressionComposite; } else { stackLayout.topControl = probaComposite; } expressionRadio.setSelection(useExpression); probaRadio.setSelection(!useExpression); expressionRadio.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (((Button) e.getSource()).getSelection()) { stackLayout.topControl = expressionComposite; } else { stackLayout.topControl = probaComposite; } stackComposite.layout(); } }); context = new EMFDataBindingContext(); context.bindValue( SWTObservables.observeSelection(expressionRadio), EMFEditObservables.observeValue( editingDomain, transition, SimulationPackage.Literals.SIMULATION_TRANSITION__USE_EXPRESSION)); context.bindValue( SWTObservables.observeText(probaText, SWT.Modify), EMFEditObservables.observeValue( editingDomain, transition, SimulationPackage.Literals.SIMULATION_TRANSITION__PROBABILITY), new UpdateValueStrategy() .setConverter( StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), false)) .setAfterGetValidator( new WrappingValidator( controlDecoration, new StringToDoubleValidator( StringToNumberConverter.toDouble( BonitaNumberFormat.getPercentInstance(), false)))), new UpdateValueStrategy() .setConverter( NumberToStringConverter.fromDouble( BonitaNumberFormat.getPercentInstance(), false))); }
protected Control createMultipleResourceComposite( Section section, TabbedPropertySheetWidgetFactory widgetFactory) { final Composite client = widgetFactory.createComposite(section); client.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); client.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create()); resourceTableViewer = new TableViewer(client, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL); resourceTableViewer .getControl() .setLayoutData( GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 60).create()); resourceTableViewer.setContentProvider(new ArrayContentProvider()); resourceTableViewer.setLabelProvider(new LabelProvider()); final ControlDecoration cd = new ControlDecoration(resourceTableViewer.getControl(), SWT.TOP | SWT.LEFT); cd.setImage(Pics.getImage(PicsConstants.hint)); cd.setDescriptionText(Messages.filewidget_resource_hint_multiple); final Composite buttonComposite = widgetFactory.createComposite(client); buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create()); buttonComposite.setLayout( GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 3).create()); final Button addResourceButton = widgetFactory.createButton(buttonComposite, Messages.Add, SWT.PUSH); addResourceButton.setLayoutData( GridDataFactory.fillDefaults().grab(true, false).hint(85, SWT.DEFAULT).create()); addResourceButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { final SelectDocumentInBonitaStudioRepository selectDocumentInBonitaStudioRepository = new SelectDocumentInBonitaStudioRepository(Display.getDefault().getActiveShell()); if (IDialogConstants.OK_ID == selectDocumentInBonitaStudioRepository.open()) { editingDomain .getCommandStack() .execute( AddCommand.create( editingDomain, element, FormPackage.Literals.FILE_WIDGET__INTIAL_RESOURCE_LIST, selectDocumentInBonitaStudioRepository.getSelectedDocument().getName())); resourceTableViewer.refresh(); } } }); final Button removeResourceButton = widgetFactory.createButton(buttonComposite, Messages.Remove, SWT.PUSH); removeResourceButton.setLayoutData( GridDataFactory.fillDefaults().grab(true, false).hint(85, SWT.DEFAULT).create()); removeResourceButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { editingDomain .getCommandStack() .execute( RemoveCommand.create( editingDomain, element, FormPackage.Literals.FILE_WIDGET__INTIAL_RESOURCE_LIST, ((IStructuredSelection) resourceTableViewer.getSelection()).toList())); resourceTableViewer.refresh(); } }); resourceTableViewer.setInput( EMFEditProperties.list( editingDomain, FormPackage.Literals.FILE_WIDGET__INTIAL_RESOURCE_LIST) .observe(element)); return client; }
@Override public void createControl(Composite parent) { final Composite compo = new Composite(parent, SWT.NONE); compo.setLayout(new GridLayout(3, false)); Label label = new Label(compo, SWT.NONE); label.setText("File"); final Text text = new Text(compo, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(text); // decorator for text, starts with warning because the text starts empty final ControlDecoration controlDecoration = new ControlDecoration(text, SWT.RIGHT | SWT.TOP); controlDecoration.setDescriptionText("Please enter a new .fet file"); controlDecoration.setImage( FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR) .getImage()); // listener which validates the text: if the input is a non-existing file, and it's extension is // fet: // hides the decorator + puts the file in the model + sets the page to complete text.addModifyListener( new ModifyListener() { @Override public void modifyText(ModifyEvent e) { if (e.getSource() instanceof Text) { String text = ((Text) e.getSource()).getText(); File f = new File(text); if (!f.exists() && getFileExtension(text).equals("fet")) { controlDecoration.hide(); model.setFile(f); setPageComplete(true); } else { controlDecoration.show(); model.setFile(null); setPageComplete(false); } } } }); // button opens a save file dialog and sets the text to the selected file with path with .fet // appended to it Button saveButton = new Button(compo, SWT.NONE); saveButton.setText("Save..."); GridDataFactory.fillDefaults().indent(5, 0).applyTo(saveButton); saveButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); dialog.setFilterExtensions(new String[] {"*.fet"}); String fileName = dialog.open(); if (fileName != null) { fileName = fileName.endsWith(".fet") ? fileName : fileName + ".fet"; text.setText(fileName); } } }); setControl(compo); }
@Override public void createControl(Composite parent) { FieldDecoration infoDecor = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION); // Create controls super.createControl(parent); Composite control = (Composite) getControl(); Group grpProjectSettings = new Group(control, SWT.NONE); grpProjectSettings.setText("Project Settings"); new Label(grpProjectSettings, SWT.NONE).setText("Version:"); txtVersion = new Text(grpProjectSettings, SWT.BORDER); new Label(grpProjectSettings, SWT.NONE).setText("Name:"); txtName = new Text(grpProjectSettings, SWT.BORDER); ControlDecoration txtNameDecor = new ControlDecoration(txtName, SWT.LEFT | SWT.CENTER); txtNameDecor.setImage(infoDecor.getImage()); txtNameDecor.setDescriptionText("Defines a human-readable name for the bundle"); new Label(grpProjectSettings, SWT.NONE).setText("Description:"); txtDescription = new Text(grpProjectSettings, SWT.BORDER); ControlDecoration txtDescDecor = new ControlDecoration(txtDescription, SWT.LEFT | SWT.CENTER); txtDescDecor.setImage(infoDecor.getImage()); txtDescDecor.setDescriptionText("Defines a short human-readable description for the bundle"); new Label(grpProjectSettings, SWT.NONE).setText("Provider:"); txtVendor = new Text(grpProjectSettings, SWT.BORDER); ControlDecoration txtVendorDecor = new ControlDecoration(txtVendor, SWT.LEFT | SWT.CENTER); txtVendorDecor.setImage(infoDecor.getImage()); txtVendorDecor.setDescriptionText( "The name of the company, organisation or individual providing the bundle"); // Set values txtDescription.setText(description); txtVersion.setText(version.toString()); txtVendor.setText(vendor); txtName.setText(name); // Add listeners ModifyListener txtModListener = new ModifyListener() { public void modifyText(ModifyEvent e) { description = txtDescription.getText(); vendor = txtVendor.getText(); name = txtName.getText(); validateSettings(); } }; txtDescription.addModifyListener(txtModListener); txtVersion.addModifyListener(txtModListener); txtVendor.addModifyListener(txtModListener); txtName.addModifyListener(txtModListener); // Layout control.setLayout(new GridLayout()); grpProjectSettings.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); grpProjectSettings.setLayout(new GridLayout(2, false)); txtDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); txtVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); txtVendor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); txtName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); }