List of usage examples for org.eclipse.jface.fieldassist ControlDecoration show
public void show()
From source file:au.gov.ansto.bragg.echidna.exp.task.AbstractEchidnaScanTask.java
License:Open Source License
public static void addValidator(final Text textBox, final Validator validator) { final ControlDecoration startangDec = new ControlDecoration(textBox, SWT.LEFT | SWT.BOTTOM); textBox.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (validator.isValid(textBox.getText())) { startangDec.hide();//www. ja v a2 s. c om } else { startangDec.setImage(errorDec.getImage()); startangDec.setDescriptionText(validator.getErrorMessage()); startangDec.show(); } } }); }
From source file:au.gov.ansto.bragg.kowari.exp.command.AbstractScanParameter.java
License:Open Source License
protected void addValidator(final Text textBox, final ParameterValidator validator) { final ControlDecoration startangDec = new ControlDecoration(textBox, SWT.LEFT | SWT.BOTTOM); textBox.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (validator.isValid(textBox.getText())) { startangDec.hide();/* w w w .java 2 s.c om*/ } else { startangDec.setImage(errorDec.getImage()); startangDec.setDescriptionText(validator.getErrorMessage()); startangDec.show(); } } }); }
From source file:au.gov.ansto.bragg.kowari.exp.command.AbstractScanParameter.java
License:Open Source License
protected void addSelectionValidator(final Combo combo, final ParameterValidator validator) { final ControlDecoration startangDec = new ControlDecoration(combo, SWT.LEFT | SWT.BOTTOM); combo.addModifyListener(new ModifyListener() { @Override//w ww. j a v a 2s. c o m public void modifyText(ModifyEvent arg0) { if (validator.isValid(combo.getText())) startangDec.hide(); else { startangDec.setImage(errorDec.getImage()); startangDec.setDescriptionText(validator.getErrorMessage()); startangDec.show(); } } }); }
From source file:carisma.ui.eclipse.editors.AdfEditorCheckDetailsPage.java
License:Open Source License
/** * Handles Integer parameter.//from w w w .j av a 2 s . c om * * @param comp * the composite for the parameter input elements * @param checkParameter * the checkParameter to handle */ private void handleIntParameter(final Composite comp, final CheckParameter checkParameter) { final String errorText = "Please insert an integer value!"; final Text text = this.toolkit.createText(comp, "", SWT.SINGLE); GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); layoutData.horizontalSpan = 2; text.setLayoutData(layoutData); int value = ((IntegerParameter) checkParameter).getValue(); text.setText(String.valueOf(value)); text.setToolTipText(checkParameter.getDescriptor().getDescription()); final ControlDecoration decoration = new ControlDecoration(text, SWT.LEFT | SWT.TOP); Image contpro = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR) .getImage(); decoration.setImage(contpro); decoration.hide(); text.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { try { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, Integer.valueOf(text.getText())); decoration.hide(); } catch (Exception exc) { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, new Integer(0)); decoration.show(); decoration.showHoverText(errorText); } if (text.getText().isEmpty()) { if (!checkParameter.getDescriptor().isOptional()) { AdfEditorCheckDetailsPage.this.controller.setParameterQod(checkParameter, true); } } else { AdfEditorCheckDetailsPage.this.controller.setParameterQod(checkParameter, false); } AdfEditorCheckDetailsPage.this.qodButtonMap.get(checkParameter) .setSelection(checkParameter.isQueryOnDemand()); } }); text.addListener(SWT.Verify, new Listener() { @Override public void handleEvent(final Event e) { String newCharacter = e.text; String newText = applyEventToText(text, e); try { if (!newCharacter.equals("") && !newCharacter.equals("-")) { Integer.parseInt(newCharacter); } if (!newText.equals("")) { Integer.parseInt(newText); } decoration.hide(); } catch (Exception exc) { e.doit = false; decoration.show(); decoration.showHoverText(errorText); } } }); text.addFocusListener(new FocusListener() { @Override public void focusGained(final FocusEvent e) { } @Override public void focusLost(final FocusEvent e) { decoration.hide(); } }); text.addListener(SWT.Modify, this.masterListener); }
From source file:carisma.ui.eclipse.editors.AdfEditorCheckDetailsPage.java
License:Open Source License
/** * Handles Float parameter./* www . j a v a2s . c o m*/ * * @param comp * the composite for the parameter input elements * @param checkParameter * the checkParamter to handle */ private void handleFloatParameter(final Composite comp, final CheckParameter checkParameter) { final String errorText = "Please insert a float value!"; final Text text = this.toolkit.createText(comp, "", SWT.SINGLE); GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); layoutData.horizontalSpan = 2; text.setLayoutData(layoutData); float value = ((FloatParameter) checkParameter).getValue(); text.setText(String.valueOf(value)); text.setToolTipText(checkParameter.getDescriptor().getDescription()); final ControlDecoration decoration = new ControlDecoration(text, SWT.LEFT | SWT.TOP); Image contpro = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR) .getImage(); decoration.setImage(contpro); decoration.hide(); text.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { try { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, Float.valueOf(text.getText())); AdfEditorCheckDetailsPage.this.controller.setParameterQod(checkParameter, false); decoration.hide(); } catch (Exception exc) { // e.g. field is empty AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, new Float(0.0f)); if (!checkParameter.getDescriptor().isOptional()) { AdfEditorCheckDetailsPage.this.controller.setParameterQod(checkParameter, true); } decoration.show(); decoration.showHoverText(errorText); } AdfEditorCheckDetailsPage.this.qodButtonMap.get(checkParameter) .setSelection(checkParameter.isQueryOnDemand()); } }); text.addListener(SWT.Verify, new Listener() { @Override public void handleEvent(final Event e) { e.text = e.text.replace(",", "."); String newCharacter = e.text; String newText = applyEventToText(text, e); try { if (!newCharacter.equals("") && !newCharacter.equals("-") && !newCharacter.equals(".")) { Float.parseFloat(newCharacter); } if (!newText.equals("")) { float newFloat = Float.parseFloat(newText); if (newFloat != 0) { if ((newFloat > Float.MAX_VALUE || newFloat < Float.MIN_VALUE) && ((newFloat * -1) > Float.MAX_VALUE || (newFloat * -1) < Float.MIN_VALUE)) { throw new NumberFormatException("Float out of range"); } } } decoration.hide(); } catch (Exception exc) { e.doit = false; decoration.show(); decoration.showHoverText(errorText); } } }); text.addFocusListener(new FocusListener() { @Override public void focusGained(final FocusEvent e) { } @Override public void focusLost(final FocusEvent e) { decoration.hide(); } }); text.addListener(SWT.Modify, this.masterListener); }
From source file:carisma.ui.eclipse.editors.AdfEditorCheckDetailsPage.java
License:Open Source License
/** * Handles InputFile parameter.// ww w . j av a 2 s . c om * * @param comp * the composite for the parameter input elements * @param checkParameter * the checkParamter to handle */ private void handleInputFileParameter(final Composite comp, final CheckParameter checkParameter) { final Text text = this.toolkit.createText(comp, ""); text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); text.setEditable(false); text.setToolTipText(checkParameter.getDescriptor().getDescription()); Button browse = this.toolkit.createButton(comp, AdfEditorCheckDetailsPage.BROWSE, SWT.PUSH); browse.setToolTipText("Browse for an\ninput file"); browse.setLayoutData(new GridData(SWT.NONE, SWT.TOP, false, false)); final ControlDecoration decoration = new ControlDecoration(text, SWT.LEFT | SWT.TOP); Image contpro = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR) .getImage(); decoration.setImage(contpro); decoration.hide(); // Initially check if the file can be read final String parameterValue; if (((InputFileParameter) checkParameter).getValue() != null) { if (((InputFileParameter) checkParameter).getValue().canRead()) { parameterValue = ((InputFileParameter) checkParameter).getValue().toString(); } else { parameterValue = ""; decoration.show(); decoration.setShowHover(true); decoration.showHoverText("Invalid input file.\nFully qualified path is needed and has to exist."); } } else { parameterValue = ""; } text.setText(parameterValue); // Hide decoration if focus has been lost text.addFocusListener(new FocusListener() { @Override public void focusGained(final FocusEvent e) { } @Override public void focusLost(final FocusEvent e) { decoration.hide(); } }); text.addListener(SWT.Modify, this.masterListener); // Open file dialog browse.addSelectionListener(new SelectionAdapter() { private FileDialog fileDialog = null; @Override public void widgetSelected(final SelectionEvent e) { this.fileDialog = new FileDialog(comp.getShell()); this.fileDialog.setText("Input File Selection"); if (!text.getText().isEmpty()) { this.fileDialog.setFilterPath(text.getText()); } else { this.fileDialog .setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); } String path = this.fileDialog.open(); if (path != null) { File inputFile = new File(path); if (inputFile.canRead()) { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, inputFile); decoration.hide(); text.setText(inputFile.getPath()); text.update(); AdfEditorCheckDetailsPage.this.controller.setParameterQod(checkParameter, false); AdfEditorCheckDetailsPage.this.qodButtonMap.get(checkParameter).setSelection(false); } else { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, null); decoration.show(); decoration.setShowHover(true); decoration.showHoverText( "Invalid input file.\nFully qualified path is needed and has to exist."); text.setText(""); text.update(); if (!checkParameter.getDescriptor().isOptional()) { AdfEditorCheckDetailsPage.this.controller.setParameterQod(checkParameter, true); AdfEditorCheckDetailsPage.this.qodButtonMap.get(checkParameter).setSelection(true); } } } } }); }
From source file:carisma.ui.eclipse.editors.AdfEditorCheckDetailsPage.java
License:Open Source License
/** * Handles Folder parameter.//from ww w .j av a2 s . c om * * @param comp * the composite for the parameter input elements * @param checkParameter * the checkParamter to handle */ private void handleFolderParameter(final Composite comp, final CheckParameter checkParameter) { final String folderValue; if (((FolderParameter) checkParameter).getValue() != null) { folderValue = ((FolderParameter) checkParameter).getValue().getPath(); } else { folderValue = ""; } final Text text = this.toolkit.createText(comp, folderValue); text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); text.setEditable(false); text.setToolTipText(checkParameter.getDescriptor().getDescription()); final ControlDecoration decoration = new ControlDecoration(text, SWT.LEFT | SWT.TOP); Image contpro = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR) .getImage(); decoration.setImage(contpro); decoration.hide(); text.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { File inputFile = new File(text.getText()); if (!inputFile.canRead() || !inputFile.isDirectory()) { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, null); decoration.show(); decoration.setShowHover(true); decoration.showHoverText( "Invalid input folder.\nFully qualified path is needed and has to exist."); } else { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, inputFile); decoration.hide(); } } }); text.addFocusListener(new FocusListener() { @Override public void focusGained(final FocusEvent e) { } @Override public void focusLost(final FocusEvent e) { decoration.hide(); } }); text.addListener(SWT.Modify, this.masterListener); Button folderOpen = this.toolkit.createButton(comp, AdfEditorCheckDetailsPage.BROWSE, SWT.PUSH); folderOpen.setLayoutData(new GridData(SWT.NONE, SWT.TOP, false, false)); folderOpen.setToolTipText("Browse for a folder"); folderOpen.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { DirectoryDialog dirDialog = new DirectoryDialog(comp.getShell()); dirDialog.setText("Folder Selection"); if (!text.getText().isEmpty()) { dirDialog.setFilterPath(text.getText()); } else { dirDialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); } String result = dirDialog.open(); if (result != null && !result.isEmpty()) { File outputFile = new File(result); AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, outputFile); text.setText(outputFile.getPath()); text.update(); AdfEditorCheckDetailsPage.this.controller.setParameterQod(checkParameter, false); AdfEditorCheckDetailsPage.this.qodButtonMap.get(checkParameter).setSelection(false); } } }); }
From source file:carisma.ui.eclipse.editors.AdfEditorCheckDetailsPage.java
License:Open Source License
/** * Handles Output parameter.// w w w. ja va 2s . c o m * * @param comp * the composite for the parameter input elements * @param checkParameter * the checkParamter to handle */ private void handleOutputParameter(final Composite comp, final CheckParameter checkParameter) { final String outputFileValue; if (((OutputFileParameter) checkParameter).getValue() != null) { outputFileValue = (((OutputFileParameter) checkParameter).getValue()).getPath(); } else { outputFileValue = ""; } final Text text = this.toolkit.createText(comp, outputFileValue); text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); text.setEditable(false); text.setToolTipText(checkParameter.getDescriptor().getDescription()); Button outputFileOpen = this.toolkit.createButton(comp, AdfEditorCheckDetailsPage.BROWSE, SWT.PUSH); outputFileOpen.setLayoutData(new GridData(SWT.NONE, SWT.TOP, false, false)); outputFileOpen.setToolTipText("Browse for an\noutput file"); final ControlDecoration decoration = new ControlDecoration(text, SWT.LEFT | SWT.TOP); final Image errorImage = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage(); decoration.setImage(errorImage); decoration.setShowHover(true); decoration.hide(); text.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { try { if (!text.getText().isEmpty()) { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, new File(text.getText())); } else { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, null); } if (((OutputFileParameter) checkParameter).isInsertedValueValid()) { decoration.hide(); } else { decoration.show(); decoration.showHoverText( "Invalid output file.\nFully qualified path is needed and has to exist."); } } catch (SWTException exc) { Logger.log(LogLevel.ERROR, "", exc); } } }); text.addFocusListener(new FocusListener() { @Override public void focusGained(final FocusEvent e) { } @Override public void focusLost(final FocusEvent e) { decoration.hide(); } }); text.addListener(SWT.Modify, this.masterListener); outputFileOpen.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { FileDialog fDialog = new FileDialog(comp.getShell(), SWT.SAVE); fDialog.setText("Output File Selection"); if (!text.getText().isEmpty()) { fDialog.setFilterPath(text.getText()); } else { fDialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); } String selection = fDialog.open(); if (selection != null && !selection.isEmpty()) { AdfEditorCheckDetailsPage.this.controller.setParameter(checkParameter, new File(selection)); text.setText(selection); text.update(); AdfEditorCheckDetailsPage.this.controller.setParameterQod(checkParameter, false); AdfEditorCheckDetailsPage.this.qodButtonMap.get(checkParameter).setSelection(false); } } }); }
From source file:com.amalto.workbench.dialogs.SimpleXpathInputDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { // Should not really be here but well,.... parent.getShell().setText(this.title); Composite composite = (Composite) super.createDialogArea(parent); GridLayout layout = (GridLayout) composite.getLayout(); layout.numColumns = 2;/*from w w w . j a v a 2 s . co m*/ Label dialogMessageLbl = new Label(composite, SWT.NULL); dialogMessageLbl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); dialogMessageLbl.setText(dialogMessage); final Text textControl = new Text(composite, SWT.BORDER | SWT.SINGLE); textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); ((GridData) textControl.getLayoutData()).minimumWidth = 300; final ControlDecoration deco = new ControlDecoration(textControl, SWT.TOP | SWT.LEFT); Image image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR) .getImage(); deco.setImage(image); deco.hide(); textControl.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { SimpleXpathInputDialog.this.xpath = textControl.getText(); btnSep.setEnabled(xpath != null && xpath.length() > 0); boolean validXpath = pkXPaths.contains(xpath); if (getButton(IDialogConstants.OK_ID) != null) { getButton(IDialogConstants.OK_ID).setEnabled(validXpath); } if (validXpath) { deco.hide(); } else { deco.show(); deco.setDescriptionText(Messages.InvalidXpathForFK); } } }); Button xpathButton = new Button(composite, SWT.PUSH | SWT.CENTER); xpathButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); xpathButton.setImage(ImageCache.getCreatedImage(EImage.DOTS_BUTTON.getPath())); xpathButton.setToolTipText(Messages.SchematronExpressBuilder_selectXPath); xpathButton.addSelectionListener(new SelectionAdapter() { private IXPathSelectionFilter xpathSelectionFilter; @Override public void widgetSelected(SelectionEvent e) { XpathSelectDialog dlg = getNewXpathSelectDialog(parentPage, dataModelName); // new XpathSelectDialog(parentPage.getSite().getShell(), parentPage.getXObject() // .getParent(), "Select Xpath", parentPage.getSite(), false, dataModelName); dlg.setSelectionFilter(getXPathSelectionFilter()); dlg.setLock(lock); dlg.setBlockOnOpen(true); dlg.open(); if (dlg.getReturnCode() == Window.OK) { textControl.setText(dlg.getXpath()); dlg.close(); } } private IXPathSelectionFilter getXPathSelectionFilter() { if (xpathSelectionFilter == null) { xpathSelectionFilter = new SimpleXPathSelectionFilter(); } return xpathSelectionFilter; } }); textControl.forceFocus(); btnSep = new Button(composite, SWT.CHECK); btnSep.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1)); btnSep.setText(Messages.SimpleXpathInputDialog_sepFkTabPanel); btnSep.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { sepFk = btnSep.getSelection(); } }); // init value textControl.setText(initialValue == null ? "" : initialValue);//$NON-NLS-1$ btnSep.setSelection(sepFk); return composite; }
From source file:com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectPage.java
License:Open Source License
private void updateDecorator(ControlDecoration decorator, IStatus status, boolean hasInfo) { if (hasInfo) { int severity = status != null ? status.getSeverity() : IStatus.OK; setDecoratorType(decorator, severity); } else {/* ww w . j a v a 2s. c om*/ if (status == null || status.isOK()) { decorator.hide(); } else { decorator.show(); } } }