List of usage examples for org.eclipse.jface.fieldassist ControlDecoration hide
public void hide()
From source file:ac.soton.eventb.classdiagrams.diagram.sheet.custom.PropertySectionUtil.java
License:Open Source License
/** * Returns new control decorator initialised with message. * // w ww .jav a2s.c om * @param control control widget * @param message initial message or null if none * @param type decorator type constant from FieldDecorationRegistry * @param visible is it visible when created * @return control decorator */ public static ControlDecoration createDecorator(Control control, String message, String type, boolean visible) { ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP); controlDecoration.setDescriptionText(message); FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(type); controlDecoration.setImage(fieldDecoration.getImage()); if (!visible) controlDecoration.hide(); return controlDecoration; }
From source file:ac.soton.multisim.diagram.sheet.custom.common.DecoratedInputValidator.java
License:Open Source License
/** * Returns new control decorator initialised with message. * /*from w ww .j av a 2 s.co m*/ * @param control control widget * @param type decorator type constant from FieldDecorationRegistry * @param visible is it visible when created * @return control decorator */ public static ControlDecoration createDecorator(Control control, String type, boolean visible) { ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP); FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(type); controlDecoration.setImage(fieldDecoration.getImage()); if (!visible) controlDecoration.hide(); return controlDecoration; }
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(); } else { startangDec.setImage(errorDec.getImage()); startangDec.setDescriptionText(validator.getErrorMessage()); startangDec.show();/*from ww w .j a va 2s. c o m*/ } } }); }
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(); } else { startangDec.setImage(errorDec.getImage()); startangDec.setDescriptionText(validator.getErrorMessage()); startangDec.show();/* w w w . j a v a 2 s .c om*/ } } }); }
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 av 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 a v a2 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./*ww w. j a v a2 s .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 a v 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.// w w w . j a v a 2 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.//from w w w .j av a 2 s .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); } } }); }