Added setEnabled(boolean)/isEnabled() methods to FileUpload.java Patch by: jlabanca Review by: rjrjr Issue: 633 git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5040 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/FileUpload.java b/user/src/com/google/gwt/user/client/ui/FileUpload.java index dba1f02..792c8d8 100644 --- a/user/src/com/google/gwt/user/client/ui/FileUpload.java +++ b/user/src/com/google/gwt/user/client/ui/FileUpload.java
@@ -90,7 +90,8 @@ // Trigger a change event now. if (eventPending) { allowEvent = true; - fileUpload.getElement().dispatchEvent(Document.get().createChangeEvent()); + fileUpload.getElement().dispatchEvent( + Document.get().createChangeEvent()); allowEvent = false; eventPending = false; } @@ -165,6 +166,15 @@ return getInputElement().getName(); } + /** + * Gets whether this widget is enabled. + * + * @return <code>true</code> if the widget is enabled + */ + public boolean isEnabled() { + return !getElement().getPropertyBoolean("disabled"); + } + @Override public void onBrowserEvent(Event event) { if (impl.onBrowserEvent(event)) { @@ -172,6 +182,16 @@ } } + /** + * Sets whether this widget is enabled. + * + * @param enabled <code>true</code> to enable the widget, <code>false</code> + * to disable it + */ + public void setEnabled(boolean enabled) { + getElement().setPropertyBoolean("disabled", !enabled); + } + public void setName(String name) { getInputElement().setName(name); }
diff --git a/user/test/com/google/gwt/user/UISuite.java b/user/test/com/google/gwt/user/UISuite.java index 0566294..f5ec867 100644 --- a/user/test/com/google/gwt/user/UISuite.java +++ b/user/test/com/google/gwt/user/UISuite.java
@@ -45,6 +45,7 @@ import com.google.gwt.user.client.ui.DockPanelTest; import com.google.gwt.user.client.ui.ElementWrappingTest; import com.google.gwt.user.client.ui.FastStringMapTest; +import com.google.gwt.user.client.ui.FileUploadTest; import com.google.gwt.user.client.ui.FlexTableTest; import com.google.gwt.user.client.ui.FlowPanelTest; import com.google.gwt.user.client.ui.FocusPanelTest; @@ -125,6 +126,7 @@ suite.addTestSuite(ElementWrappingTest.class); suite.addTestSuite(EventTest.class); suite.addTestSuite(FastStringMapTest.class); + suite.addTestSuite(FileUploadTest.class); suite.addTestSuite(FlexTableTest.class); suite.addTestSuite(FlowPanelTest.class); suite.addTestSuite(FocusPanelTest.class);
diff --git a/user/test/com/google/gwt/user/client/ui/FileUploadTest.java b/user/test/com/google/gwt/user/client/ui/FileUploadTest.java new file mode 100644 index 0000000..8663d03 --- /dev/null +++ b/user/test/com/google/gwt/user/client/ui/FileUploadTest.java
@@ -0,0 +1,38 @@ +/* + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.user.client.ui; + +import com.google.gwt.junit.client.GWTTestCase; + +/** + * Tests for {@link FileUpload}. + * + */ +public class FileUploadTest extends GWTTestCase { + + public String getModuleName() { + return "com.google.gwt.user.User"; + } + + public void testDisable() { + FileUpload fileUpload = new FileUpload(); + assertTrue(fileUpload.isEnabled()); + fileUpload.setEnabled(false); + assertFalse(fileUpload.isEnabled()); + fileUpload.setEnabled(true); + assertTrue(fileUpload.isEnabled()); + } +}