Hi,

You might also consider Apache FileUpload:

-> http://uptick.com.au/content/taking-advantage-apache-fileupload-and-opencsv

Cheers
Rob

http://code.google.com/p/gwt-cx/


On Sep 23, 5:31 am, Manuel Carrasco Moñino <[email protected]> wrote:
> Take a look to gwtupload you can use either all the library in your
> application or just the DecoratedFileUpload to customize your button with
> whatever widget you want.
>
> http://code.google.com/p/gwtupload/wiki/CustomWidgets
>
> - Manolo
>
>
>
>
>
>
>
> On Thu, Sep 22, 2011 at 9:56 AM, Sante <[email protected]> wrote:
> > I've tryed, but not go this post.
>
> > mimelist are set in VUpload constructor
>
> > I post java file:
>
> > /*
> > @ITMillApache2LicenseForJavaFiles@
> >  */
>
> > package com.vaadin.terminal.gwt.client.ui;
>
> > import com.google.gwt.core.client.GWT;
> > import com.google.gwt.core.client.Scheduler;
> > import com.google.gwt.dom.client.DivElement;
> > import com.google.gwt.dom.client.Document;
> > import com.google.gwt.dom.client.FormElement;
> > import com.google.gwt.event.dom.client.ClickEvent;
> > import com.google.gwt.event.dom.client.ClickHandler;
> > import com.google.gwt.user.client.Command;
> > import com.google.gwt.user.client.Element;
> > import com.google.gwt.user.client.Event;
> > import com.google.gwt.user.client.Timer;
> > import com.google.gwt.user.client.ui.FileUpload;
> > import com.google.gwt.user.client.ui.FlowPanel;
> > import com.google.gwt.user.client.ui.FormPanel;
> > import com.google.gwt.user.client.ui.Hidden;
> > import com.google.gwt.user.client.ui.Panel;
> > import com.google.gwt.user.client.ui.SimplePanel;
> > import com.vaadin.terminal.gwt.client.ApplicationConnection;
> > import com.vaadin.terminal.gwt.client.BrowserInfo;
> > import com.vaadin.terminal.gwt.client.Paintable;
> > import com.vaadin.terminal.gwt.client.UIDL;
> > import com.vaadin.terminal.gwt.client.VConsole;
> > import com.vaadin.terminal.gwt.client.VTooltip;
> > import com.google.gwt.dom.client.InputElement;
>
> > /**
> >  *
> >  * Note, we are not using GWT FormPanel as we want to listen
> > submitcomplete
> >  * events even though the upload component is already detached.
> >  *
> >  */
> > public class VUpload extends SimplePanel implements Paintable {
>
> >        private final class MyFileUpload extends FileUpload {
> >                @Override
> >                public void onBrowserEvent(Event event) {
>
> >                        super.onBrowserEvent(event);
> >                        if (event.getTypeInt() == Event.ONCHANGE) {
> >                                if (immediate && fu.getFilename() != null
> >                                                &&
> > !"".equals(fu.getFilename())) {
> >                                        submit();
> >                                }
> >                        } else if (BrowserInfo.get().isIE()
> >                                        && event.getTypeInt() ==
> > Event.ONFOCUS) {
> >                                // IE and user has clicked on hidden
> > textarea part of upload
> >                                // field. Manually open file selector, other
> > browsers do it by
> >                                // default.
> >                                fireNativeClick(fu.getElement());
> >                                // also remove focus to enable hack if user
> > presses cancel
> >                                // button
> >                                fireNativeBlur(fu.getElement());
> >                        }
> >                }
>
> >                public String getAccept() {
> >                        return ((InputElement)
> > fu.getElement().cast()).getAccept();
> >                }
>
> >                public void setAccept(String accept) {
> >                        ((InputElement)
> > fu.getElement().cast()).setAccept(accept);
> >                }
> >        }
>
> >        public static final String CLASSNAME = "v-upload";
>
> >        /**
> >         * FileUpload component that opens native OS dialog to select file.
> >         */
> >        MyFileUpload fu = new MyFileUpload();
>
> >        Panel panel = new FlowPanel();
>
> >        UploadIFrameOnloadStrategy onloadstrategy = GWT
> >                        .create(UploadIFrameOnloadStrategy.class);
>
> >        ApplicationConnection client;
>
> >        private String paintableId;
>
> >        /**
> >         * Button that initiates uploading
> >         */
> >        private final VButton submitButton;
>
> >        /**
> >         * When expecting big files, programmer may initiate some UI changes
> > when
> >         * uploading the file starts. Bit after submitting file we'll visit
> > the
> >         * server to check possible changes.
> >         */
> >        private Timer t;
>
> >        /**
> >         * some browsers tries to send form twice if submit is called in
> > button
> >         * click handler, some don't submit at all without it, so we need to
> > track
> >         * if form is already being submitted
> >         */
> >        private boolean submitted = false;
>
> >        private boolean enabled = true;
>
> >        private boolean immediate;
>
> >        private Hidden maxfilesize = new Hidden();
>
> >        private FormElement element;
>
> >        private com.google.gwt.dom.client.Element synthesizedFrame;
>
> >        private int nextUploadId;
>
> >        public VUpload() {
>
> >  super(com.google.gwt.dom.client.Document.get().createFormElement());
>
> >                element = getElement().cast();
> >                setEncoding(getElement(), FormPanel.ENCODING_MULTIPART);
> >                element.setMethod(FormPanel.METHOD_POST);
>
> >                String mimeList =
> > "application/vnd.ms-excel,application/msexcel," +
>
> >  "application/x-msexcel,application/x-ms-excel," +
>
> >  "application/vnd.ms-excel,application/x-excel," +
>
> >  "application/x-dos_ms_excel,application/xls," +
> >                                "application/vnd.openxmlformats-
> > officedocument.spreadsheetml.sheet";
>
> >                fu.getElement().setPropertyString("accept", mimeList);
>
> >                setWidget(panel);
> >                panel.add(maxfilesize);
> >                panel.add(fu);
> >                submitButton = new VButton();
> >                submitButton.addClickHandler(new ClickHandler() {
> >                        public void onClick(ClickEvent event) {
> >                                if (immediate) {
> >                                        // fire click on upload (eg. focused
> > button and hit space)
> >                                        fireNativeClick(fu.getElement());
> >                                } else {
> >                                        submit();
> >                                }
> >                        }
> >                });
> >                panel.add(submitButton);
>
> >                setStyleName(CLASSNAME);
>
> >                sinkEvents(VTooltip.TOOLTIP_EVENTS);
> >        }
>
> >        @Override
> >        public void onBrowserEvent(Event event) {
> >                if ((event.getTypeInt() & VTooltip.TOOLTIP_EVENTS) > 0) {
> >                        client.handleTooltipEvent(event, this);
> >                }
> >                super.onBrowserEvent(event);
> >        }
>
> >        private static native void setEncoding(Element form, String
> > encoding)
> >        /*-{
> >          form.enctype = encoding;
> >          // For IE6
> >          form.encoding = encoding;
> >        }-*/;
>
> >        public void updateFromUIDL(UIDL uidl, ApplicationConnection client)
> > {
> >                if (client.updateComponent(this, uidl, true)) {
> >                        return;
> >                }
> >                if (uidl.hasAttribute("notStarted")) {
> >                        t.schedule(400);
> >                        return;
> >                }
> >                if (uidl.hasAttribute("forceSubmit")) {
> >                        element.submit();
> >                        return;
> >                }
> >                setImmediate(uidl.getBooleanAttribute("immediate"));
> >                this.client = client;
> >                paintableId = uidl.getId();
> >                nextUploadId = uidl.getIntAttribute("nextid");
> >                final String action = client.translateVaadinUri(uidl
> >                                .getStringVariable("action"));
> >                element.setAction(action);
> >                if (uidl.hasAttribute("buttoncaption")) {
>
> >  submitButton.setText(uidl.getStringAttribute("buttoncaption"));
> >                        submitButton.setVisible(true);
> >                } else {
> >                        submitButton.setVisible(false);
> >                }
> >                fu.setName(paintableId + "_file");
>
> >                if (uidl.hasAttribute("disabled") ||
> > uidl.hasAttribute("readonly"))
> > {
> >                        disableUpload();
> >                } else if (!uidl.getBooleanAttribute("state")) {
> >                        // Enable the button only if an upload is not in
> > progress
> >                        enableUpload();
> >                        ensureTargetFrame();
> >                }
> >        }
>
> >        private void setImmediate(boolean booleanAttribute) {
> >                if (immediate != booleanAttribute) {
> >                        immediate = booleanAttribute;
> >                        if (immediate) {
> >                                fu.sinkEvents(Event.ONCHANGE);
> >                                fu.sinkEvents(Event.ONFOCUS);
> >                        }
> >                }
> >                setStyleName(getElement(), CLASSNAME + "-immediate",
> > immediate);
> >        }
>
> >        private static native void fireNativeClick(Element element)
> >        /*-{
> >            element.click();
> >        }-*/;
>
> >        private static native void fireNativeBlur(Element element)
> >        /*-{
> >            element.blur();
> >        }-*/;
>
> >        protected void disableUpload() {
> >                submitButton.setEnabled(false);
> >                if (!submitted) {
> >                        // Cannot disable the fileupload while submitting or
> > the file won't
> >                        // be submitted at all
> >                        fu.getElement().setPropertyBoolean("disabled",
> > true);
> >                }
> >                enabled = false;
> >        }
>
> >        protected void enableUpload() {
> >                submitButton.setEnabled(true);
> >                fu.getElement().setPropertyBoolean("disabled", false);
> >                enabled = true;
> >                if (submitted) {
> >                        /*
>
> ...
>
> read more »

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to