Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 144289 Details for
Bug 11233
[Dialogs] Add error icon to InputDialog class
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
InputStatusDialog
bug_11233_InputStatusDialog_patch.txt (text/plain), 8.56 KB, created by
Andrew Gvozdev
on 2009-08-12 14:38:40 EDT
(
hide
)
Description:
InputStatusDialog
Filename:
MIME Type:
Creator:
Andrew Gvozdev
Created:
2009-08-12 14:38:40 EDT
Size:
8.56 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface >Index: src/org/eclipse/jface/dialogs/IInputStatusValidator.java >=================================================================== >RCS file: src/org/eclipse/jface/dialogs/IInputStatusValidator.java >diff -N src/org/eclipse/jface/dialogs/IInputStatusValidator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/dialogs/IInputStatusValidator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,34 @@ >+/******************************************************************************* >+ * Copyright (c) 2009, 2009 Andrew Gvozdev and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Andrew Gvozdev - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jface.dialogs; >+ >+ >+import org.eclipse.core.runtime.IStatus; >+ >+/** >+ * The IInputStatusValidator is the interface for IStatus validators. >+ */ >+public interface IInputStatusValidator { >+ /** >+ * Validates the given string. Returns the status with an error/warning/info message to display if the new >+ * text fails validation. >+ * >+ * @param newText >+ * the text to check for validity >+ * >+ * @return {@link IStatus} object. For the purpose of validation severity and message are considered. >+ * <li/>{@link IStatus#OK} or null indicate no error. >+ * <li/>{@link IStatus#ERROR} indicates an error. >+ * <li/>{@link IStatus#WARNING} indicates a warning. >+ * <li/>{@link IStatus#INFO} indicates an informational message. >+ */ >+ public IStatus isValid(String newText); >+} >Index: src/org/eclipse/jface/dialogs/InputStatusDialog.java >=================================================================== >RCS file: src/org/eclipse/jface/dialogs/InputStatusDialog.java >diff -N src/org/eclipse/jface/dialogs/InputStatusDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/dialogs/InputStatusDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,205 @@ >+/******************************************************************************* >+ * Copyright (c) 2009, 2009 Andrew Gvozdev and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Andrew Gvozdev - initial API and implementation combining StatusDialog and InputDialog >+ *******************************************************************************/ >+package org.eclipse.jface.dialogs; >+ >+ >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.ModifyEvent; >+import org.eclipse.swt.events.ModifyListener; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Text; >+ >+/** >+ * An input dialog for soliciting an input string from the user. >+ * The string can be validated. In case of problem error/warning/info message >+ * is shown in status line and decorated with appropriate status icon. >+ * <p> >+ * This concrete dialog class can be instantiated as is, or further subclassed as required. >+ * </p> >+ */ >+public class InputStatusDialog extends StatusDialog { >+ /** >+ * The title of the dialog. >+ */ >+ private String title; >+ >+ /** >+ * The message to display, or <code>null</code> if none. >+ */ >+ private String message; >+ >+ /** >+ * The input value; the empty string by default. >+ */ >+ private String value = "";//$NON-NLS-1$ >+ >+ /** >+ * The input validator, or <code>null</code> if none. >+ */ >+ private IInputStatusValidator validator; >+ >+ /** >+ * Input text widget. >+ */ >+ private Text text; >+ >+ /** >+ * Creates an input dialog with OK and Cancel buttons. Note that the dialog >+ * will have no visual representation (no widgets) until it is told to open. >+ * <p> >+ * Note that the <code>open</code> method blocks for input dialogs. >+ * </p> >+ * >+ * @param parentShell >+ * the parent shell, or <code>null</code> to create a top-level >+ * shell >+ * @param dialogTitle >+ * the dialog title, or <code>null</code> if none >+ * @param dialogMessage >+ * the dialog message, or <code>null</code> if none >+ * @param initialValue >+ * the initial input value, or <code>null</code> if none >+ * (equivalent to the empty string) >+ * @param validator >+ * an input validator, or <code>null</code> if none >+ * For a validator, following return statuses are recognized: >+ * <li/>{@link IStatus#OK} or null indicate no error. >+ * <li/>{@link IStatus#ERROR} indicates an error. >+ * <li/>{@link IStatus#WARNING} indicates a warning. >+ * <li/>{@link IStatus#INFO} indicates an informational message >+ */ >+ public InputStatusDialog(Shell parentShell, String dialogTitle, String dialogMessage, >+ String initialValue, IInputStatusValidator validator) { >+ super(parentShell); >+ this.title = dialogTitle; >+ this.message = dialogMessage; >+ if (initialValue == null) { >+ this.value = ""; //$NON-NLS-1$ >+ } else { >+ value = initialValue; >+ } >+ this.validator = validator; >+ } >+ >+ /* >+ * (non-Javadoc) Method declared on Dialog. >+ */ >+ protected void buttonPressed(int buttonId) { >+ if (buttonId == IDialogConstants.OK_ID) { >+ value = text.getText(); >+ } else { >+ value = null; >+ } >+ super.buttonPressed(buttonId); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) >+ */ >+ protected void configureShell(Shell shell) { >+ super.configureShell(shell); >+ if (title != null) { >+ shell.setText(title); >+ } >+ } >+ >+ protected Control createDialogArea(Composite parent) { >+ Composite composite = (Composite) super.createDialogArea(parent); >+ >+ Label label = new Label(composite, SWT.WRAP); >+ label.setText(message); >+ GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL >+ | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER); >+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); >+ label.setLayoutData(data); >+ label.setFont(parent.getFont()); >+ >+ text = new Text(composite, getInputTextStyle()); >+ text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); >+ text.addModifyListener(new ModifyListener() { >+ public void modifyText(ModifyEvent e) { >+ validateInput(); >+ } >+ }); >+ text.setFocus(); >+ if (value != null) { >+ text.setText(value); >+ text.selectAll(); >+ } >+ >+ applyDialogFont(composite); >+ >+ return composite; >+ } >+ >+ /** >+ * Returns the text area. >+ * >+ * @return the text area >+ */ >+ protected Text getText() { >+ return text; >+ } >+ >+ /** >+ * Returns the validator. >+ * >+ * @return the validator >+ */ >+ protected IInputStatusValidator getValidator() { >+ return validator; >+ } >+ >+ /** >+ * Returns the string typed into this input dialog. >+ * >+ * @return the input string >+ */ >+ public String getValue() { >+ return value; >+ } >+ >+ /** >+ * Validates the input. >+ * <p> >+ * The default implementation of this framework method delegates the request to the supplied input >+ * validator object; if it finds the input invalid, the error message is displayed in the dialog's message >+ * line. This hook method is called whenever the text changes in the input field. >+ * </p> >+ */ >+ protected void validateInput() { >+ IStatus status = Status.OK_STATUS; >+ if (validator != null) { >+ status = validator.isValid(text.getText()); >+ } >+ updateStatus(status); >+ } >+ >+ /** >+ * Returns the style bits that should be used for the input text field. Defaults to a single line entry. >+ * Subclasses may override. >+ * >+ * @return the integer style bits that should be used when creating the input text >+ * >+ */ >+ protected int getInputTextStyle() { >+ return SWT.SINGLE | SWT.BORDER; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 11233
:
144289
|
146500
|
150326