Author: jawi
Date: Thu Nov 7 10:58:06 2013
New Revision: 1539591
URL: http://svn.apache.org/r1539591
Log:
Made the name/id field required:
- keep the Ok-button disabled until a non-empty value is given.
Modified:
ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/GenericAddWindow.java
Modified:
ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/GenericAddWindow.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/GenericAddWindow.java?rev=1539591&r1=1539590&r2=1539591&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/GenericAddWindow.java
(original)
+++
ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/GenericAddWindow.java
Thu Nov 7 10:58:06 2013
@@ -18,7 +18,10 @@
*/
package org.apache.ace.webui.vaadin;
+import com.vaadin.event.FieldEvents.TextChangeEvent;
+import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
@@ -39,9 +42,15 @@ public abstract class GenericAddWindow e
setCaption(caption);
m_name = new TextField("Name");
+ m_name.setNullSettingAllowed(false);
+ m_name.setRequired(true);
+ m_name.setImmediate(true);
m_name.setWidth("100%");
m_description = new TextField("Description");
+ m_name.setNullSettingAllowed(true);
+ m_description.setRequired(false);
+ m_description.setImmediate(true);
m_description.setWidth("100%");
initDialog();
@@ -50,7 +59,8 @@ public abstract class GenericAddWindow e
/**
* Shows this dialog on screen.
*
- * @param window the parent window to show this dialog on, cannot be
<code>null</code>.
+ * @param window
+ * the parent window to show this dialog on, cannot be
<code>null</code>.
*/
public void show(final Window window) {
if (getParent() != null) {
@@ -67,7 +77,8 @@ public abstract class GenericAddWindow e
/**
* Called when the {@link #onOk(String, String)} method failed with an
exception.
*
- * @param e the exception to handle, never <code>null</code>.
+ * @param e
+ * the exception to handle, never <code>null</code>.
*/
protected abstract void handleError(Exception e);
@@ -80,7 +91,7 @@ public abstract class GenericAddWindow e
fields.addComponent(m_name);
fields.addComponent(m_description);
- Button okButton = new Button("Ok", new Button.ClickListener() {
+ final Button okButton = new Button("Ok", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
try {
onOk((String) m_name.getValue(), (String)
m_description.getValue());
@@ -91,6 +102,7 @@ public abstract class GenericAddWindow e
}
}
});
+ okButton.setEnabled(false);
// Allow enter to be used to close this dialog with enter directly...
okButton.setClickShortcut(KeyCode.ENTER);
okButton.addStyleName(Reindeer.BUTTON_DEFAULT);
@@ -102,6 +114,16 @@ public abstract class GenericAddWindow e
});
cancelButton.setClickShortcut(KeyCode.ESCAPE);
+ m_name.addListener(new TextChangeListener() {
+ @Override
+ public void textChange(TextChangeEvent event) {
+ String text = event.getText();
+ okButton.setEnabled((text != null) && !"".equals(text.trim()));
+ }
+ });
+ m_name.setTextChangeTimeout(250);
+ m_name.setTextChangeEventMode(TextChangeEventMode.TIMEOUT);
+
HorizontalLayout buttonBar = new HorizontalLayout();
buttonBar.setSpacing(true);
buttonBar.addComponent(okButton);
@@ -116,7 +138,7 @@ public abstract class GenericAddWindow e
// The components added to the window are actually added to the
window's
// layout; you can use either. Alignments are set using the layout
layout.setComponentAlignment(buttonBar, Alignment.BOTTOM_RIGHT);
-
+
// Allow direct typing...
m_name.focus();
}
@@ -124,9 +146,12 @@ public abstract class GenericAddWindow e
/**
* Called when the user acknowledges this window by pressing Ok.
*
- * @param name the value of the name field;
- * @param description the value of the description field.
- * @throws Exception in case the creation failed.
+ * @param name
+ * the value of the name field;
+ * @param description
+ * the value of the description field.
+ * @throws Exception
+ * in case the creation failed.
*/
protected abstract void onOk(String name, String description) throws
Exception;
@@ -136,4 +161,4 @@ public abstract class GenericAddWindow e
private void setRelevantFocus() {
m_name.focus();
}
-}
\ No newline at end of file
+}