Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Furnadjiev2016-10-26 08:45:13 +0000
committerIvan Furnadjiev2016-10-26 10:07:02 +0000
commit4510729f34ea57f51c8699e839b2a0d44daafc03 (patch)
tree7f1960fac956b8605b9f52ab242ef9d33bd46663 /bundles
parent4de1647b024adbc2ed96d2916394e443b508aaee (diff)
downloadorg.eclipse.rap-4510729f34ea57f51c8699e839b2a0d44daafc03.tar.gz
org.eclipse.rap-4510729f34ea57f51c8699e839b2a0d44daafc03.tar.xz
org.eclipse.rap-4510729f34ea57f51c8699e839b2a0d44daafc03.zip
Add support for filter extensions to FileUpload widget
All current browsers (but IE9) support "accept" attribute on HTML "file" input type to specify the types of files that the server accepts. Add new API set/getFilterExtensions for FileUpload widget. Apply filter extensions by using "accept" attribute on HTML input element. 433501: [FileDialog] Filtering of extensions, path and filename not possible anymore https://bugs.eclipse.org/bugs/show_bug.cgi?id=433501 Change-Id: I7684b3cd8d90cac9b34bcd8886bfeaac3d361ef2
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/FileUploadHandler.js3
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/widgets/FileUpload.js13
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/FileUpload.java42
-rw-r--r--bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/rap/rwt/internal/widgets/fileuploadkit/FileUploadLCA.java10
4 files changed, 65 insertions, 3 deletions
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/FileUploadHandler.js b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/FileUploadHandler.js
index 3eb8cf5811..9aa23eabe5 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/FileUploadHandler.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/FileUploadHandler.js
@@ -26,7 +26,8 @@ rwt.remote.HandlerRegistry.add( "rwt.widgets.FileUpload", {
properties : rwt.remote.HandlerUtil.extendControlProperties( [
"text",
- "image"
+ "image",
+ "filterExtensions"
] ),
propertyHandler : rwt.remote.HandlerUtil.extendControlPropertyHandler( {
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/FileUpload.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/FileUpload.js
index dac42f3d44..6509e4c68c 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/FileUpload.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/FileUpload.js
@@ -22,6 +22,7 @@ rwt.qx.Class.define( "rwt.widgets.FileUpload", {
this._inputElement = null;
this._iframe = null;
this._multi = multi;
+ this._filterExtensions = null;
this._cursor = "";
this.__onValueChange = rwt.util.Functions.bind( this._onValueChange, this );
this.setEnableElementFocus( false );
@@ -35,6 +36,15 @@ rwt.qx.Class.define( "rwt.widgets.FileUpload", {
members : {
+ setFilterExtensions : function( extensions ) {
+ this._filterExtensions = extensions.filter( function( extension ) {
+ return extension != null;
+ }).join();
+ if( this._inputElement ) {
+ this._inputElement.setAttribute( "accept", this._filterExtensions );
+ }
+ },
+
submit : function( url ) {
if( typeof url !== "string" ) {
throw new Error( "No url given!" );
@@ -93,6 +103,9 @@ rwt.qx.Class.define( "rwt.widgets.FileUpload", {
if( this._multi ) {
this._inputElement.setAttribute( "multiple", "multiple" );
}
+ if( this._filterExtensions ) {
+ this._inputElement.setAttribute( "accept", this._filterExtensions );
+ }
this._inputElement.style.cursor = this._cursor;
this._inputElement.onchange = this.__onValueChange;
this._inputElement.style.opacity = 0;
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/FileUpload.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/FileUpload.java
index 7337eede36..5fef90b1a6 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/FileUpload.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/FileUpload.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 EclipseSource and others.
+ * Copyright (c) 2011, 2016 EclipseSource 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
@@ -64,6 +64,7 @@ public class FileUpload extends Canvas {
private String text;
private Image image;
private String[] fileNames = new String[ 0 ];
+ private String[] filterExtensions = new String[ 0 ];
private String url;
/**
@@ -204,6 +205,45 @@ public class FileUpload extends Canvas {
}
/**
+ * Set the file extensions which the widget will use to filter the files it shows to the argument,
+ * which may not be null.
+ * <p>
+ * An extension filter string must be of the form ".extension".
+ * </p>
+ *
+ * @param extensions the file extension filter
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if the extensions is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @since 3.2
+ */
+ public void setFilterExtensions( String[] extensions ) {
+ checkWidget();
+ if( extensions == null ) {
+ SWT.error( SWT.ERROR_INVALID_ARGUMENT );
+ }
+ filterExtensions = extensions;
+ }
+
+ /**
+ * Returns the file extensions which the widget will use to filter the files it shows.
+ *
+ * @return the file extensions filter
+ *
+ * @since 3.2
+ */
+ public String[] getFilterExtensions() {
+ checkWidget();
+ return filterExtensions;
+ }
+
+ /**
* Starts to upload the selected file to the given URL using HTTP POST. If no file has been
* selected, nothing happens.
* <p>
diff --git a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/rap/rwt/internal/widgets/fileuploadkit/FileUploadLCA.java b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/rap/rwt/internal/widgets/fileuploadkit/FileUploadLCA.java
index d4a14cef64..c9b511470f 100644
--- a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/rap/rwt/internal/widgets/fileuploadkit/FileUploadLCA.java
+++ b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/rap/rwt/internal/widgets/fileuploadkit/FileUploadLCA.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 EclipseSource and others.
+ * Copyright (c) 2011, 2016 EclipseSource 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
@@ -39,11 +39,15 @@ public final class FileUploadLCA extends WidgetLCA<FileUpload> {
private static final String PROP_TEXT = "text";
private static final String PROP_IMAGE = "image";
+ private static final String PROP_FILTER_EXTENSIONS = "filterExtensions";
+
+ private static final String[] DEFAUT_FILTER_EXTENSIONS = new String[ 0 ];
@Override
public void preserveValues( FileUpload fileUpload ) {
preserveProperty( fileUpload, PROP_TEXT, fileUpload.getText() );
preserveProperty( fileUpload, PROP_IMAGE, fileUpload.getImage() );
+ preserveProperty( fileUpload, PROP_FILTER_EXTENSIONS, fileUpload.getFilterExtensions() );
}
@Override
@@ -60,6 +64,10 @@ public final class FileUploadLCA extends WidgetLCA<FileUpload> {
WidgetLCAUtil.renderCustomVariant( fileUpload );
renderProperty( fileUpload, PROP_TEXT, fileUpload.getText(), "" );
renderProperty( fileUpload, PROP_IMAGE, fileUpload.getImage(), null );
+ renderProperty( fileUpload,
+ PROP_FILTER_EXTENSIONS,
+ fileUpload.getFilterExtensions(),
+ DEFAUT_FILTER_EXTENSIONS );
renderListenSelection( fileUpload );
renderSubmit( fileUpload );
}

Back to the top