Problem with File Upload Widget [message #74625] |
Tue, 19 February 2008 06:13  |
Eclipse User |
|
|
|
Originally posted by: nindl_go.hotmail.com
Hello,
i checked out the file upload widget contribution from the org.eclipse.rap
sandboy CVS. It works perfect, when I include in a tab (UploadTab). When I
want to include it in a dialog window, it works only one time. In case of
closing the "file upload dialog window" and a reopening the
whole RAP System crashes with the following error message displayed in the
browser
TypeError: org.eclipse.swt.WidetManager.getInstance()._current.reiInit is
not function
Is this a JavaScript object reassignment or a cache problem?
Further I receive a java.util.ConcurrentModificationException when the
upload event is fired.
Are the problems related to each other?
Thx, for help
|
|
|
|
|
|
|
Re: Problem with File Upload Widget [message #75035 is a reply to message #74928] |
Wed, 20 February 2008 12:14   |
Eclipse User |
|
|
|
Originally posted by: nindl_go.hotmail.com
This is a multi-part message in MIME format.
------=_NextPart_000_017F_01C873EC.5F9F4A50
Content-Type: text/plain;
format=flowed;
charset="ISO-8859-15";
reply-type=response
Content-Transfer-Encoding: 7bit
Hi,
finally i figured it out myself.
Adding a Shell Listener, when a dialog is closed/disposed is too late for
calling the performFinish()-method.
You have to override this method like this:
protected boolean canHandleShellCloseEvent() {
performFinish();
return true;
}
and the file upload is stable.
I have attached my code for anyone who is interested in it.
"Gottfried Nindl" <nindl_go@hotmail.com> schrieb im Newsbeitrag
news:fpgpu9$c2r$1@build.eclipse.org...
> Hi, David
>
> I create a JFace Dialog (class extending Dialog)
>
> The method configureShell adds the shell listener when creating the
> dialog. It calls the performFinished(...)-method
>
> protected void configureShell( final Shell shell ) {
> super.configureShell( shell );
> if ( title != null ) {
> shell.setText( title );
> }
>
> shell.addShellListener(new ShellAdapter() {
> public void shellClosed(ShellEvent e) {
> performFinish();
> }
> });
> }
>
> I added the close()-method in order to dispose the dialog when the upload
> is finished:
>
> public boolean performFinish() {
> upload.removeUploadListener(uploadAdapter);
> upload.dispose();
> close();
> return true;
> }
>
> The performFinished()-method is also called at the end of the
> UploadAdapter's uploadFinished(UploadEvent event)-method. This
> works pretty well for some reason. When I X the dialog, I get the
> JavaScript failure response.
>
>
>
>
> "David Donohue" <dd@daviddonohue.com> schrieb im Newsbeitrag
> news:f44b89301758dcb616a003be4bb0d511$1@www.eclipse.org...
>> Gottfried,
>> Could you share your shell listener code?
>> Thanks!
>> David
>>
>
------=_NextPart_000_017F_01C873EC.5F9F4A50
Content-Type: application/octet-stream;
name="UploadDialog.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="UploadDialog.java"
/*********************************************************** *************=
*******=0A=
* Copyright (c) 2007 BOC Asset Management GmbH=0A=
* All rights reserved. This program and the accompanying materials=0A=
* are made available under the terms of the Eclipse Public License v1.0=0A=
* which accompanies this distribution, and is available at=0A=
* http://www.eclipse.org/legal/epl-v10.html=0A=
*=0A=
* Contributors:=0A=
* BOC Asset Management GmbH - ADOweb Community Portal=0A=
* Author:=0A=
* Gottfried Nindl=0A=
************************************************************ *************=
*****/=0A=
=0A=
package org.eclipse.rap.demo.controls;=0A=
=0A=
import java.io.File;=0A=
=0A=
import org.eclipse.jface.dialogs.Dialog;=0A=
import org.eclipse.rwt.widgets.Upload;=0A=
import org.eclipse.rwt.widgets.UploadAdapter;=0A=
import org.eclipse.rwt.widgets.UploadEvent;=0A=
import org.eclipse.swt.SWT;=0A=
import org.eclipse.swt.layout.GridData;=0A=
import org.eclipse.swt.widgets.*;=0A=
=0A=
=0A=
/**=0A=
* File Upload Dialog=0A=
* @author gnindl=0A=
*/=0A=
=0A=
public class UploadDialog extends Dialog {=0A=
=0A=
private Upload upload;=0A=
private FileUploadAdapter uploadAdapter;=0A=
=0A=
private String title;=0A=
private boolean showProgress;=0A=
=0A=
private File uploadedFile;=0A=
private String filePath;=0A=
private String uploadInfo;=0A=
=0A=
=0A=
public UploadDialog( final Shell parent,=0A=
final String title ) {=0A=
this( parent, title, true );=0A=
}=0A=
=0A=
public UploadDialog( final Shell parent,=0A=
final String title,=0A=
final boolean showProgress ) =0A=
{=0A=
super( parent );=0A=
this.title =3D title;=0A=
this.showProgress =3D showProgress;=0A=
}=0A=
=0A=
protected void createButtonsForButtonBar( final Composite parent ) {=0A=
} =0A=
=0A=
protected Control createDialogArea( final Composite parent ) {=0A=
upload =3D new Upload( parent, SWT.NONE, null, showProgress );=0A=
upload.setLayoutData( new GridData( 300, SWT.DEFAULT ) );=0A=
uploadAdapter =3D new FileUploadAdapter();=0A=
upload.addUploadListener( uploadAdapter ); =0A=
return parent;=0A=
}=0A=
=0A=
protected boolean canHandleShellCloseEvent() {=0A=
performFinish();=0A=
return true;=0A=
}=0A=
=0A=
protected void configureShell( final Shell shell ) {=0A=
super.configureShell( shell ); =0A=
if ( title !=3D null ) {=0A=
shell.setText( title );=0A=
}=0A=
}=0A=
=0A=
private boolean performFinish() {=0A=
upload.removeUploadListener(uploadAdapter);=0A=
upload.dispose();=0A=
close();=0A=
return true;=0A=
}=0A=
=0A=
=0A=
=0A=
public String getFilePath() {=0A=
return filePath;=0A=
}=0A=
=0A=
public String getUploadInfoDetail() {=0A=
return uploadInfo;=0A=
}=0A=
=0A=
public File getUploadedFile() {=0A=
return uploadedFile;=0A=
}=0A=
=0A=
private class FileUploadAdapter extends UploadAdapter {=0A=
public void uploadFinished( final UploadEvent event ) {=0A=
if( event.isFinished() ) {=0A=
uploadedFile =3D new File( upload.getLastFileUploaded() );=0A=
=0A=
//provide detail upload information=0A=
uploadInfo =3D "File sucessfully uploaded!\r\n"=0A=
+"Absolute Path: "+uploadedFile.getAbsoluteFile()+"\r\n"=0A=
+"Name: "+uploadedFile.getName()+"\r\n"=0A=
+"Total File size: " +event.getUploadedTotal()+"\r\n"=0A=
+"Parcial size: "+event.getUploadedParcial();=0A=
=0A=
filePath =3D uploadedFile.getName();=0A=
}=0A=
else {=0A=
uploadInfo =3D "File couldn't be uploaded yet";=0A=
}=0A=
// MessageDialog.openInformation(getShell(), "File successfully =
uploaded", uploadInfo);=0A=
performFinish();=0A=
}=0A=
}=0A=
}=0A=
------=_NextPart_000_017F_01C873EC.5F9F4A50--
|
|
|
Re: Problem with File Upload Widget [message #75130 is a reply to message #75035] |
Thu, 21 February 2008 19:33  |
Eclipse User |
|
|
|
I had a similar set of problems trying to get the Upload widget (in bundle
org.eclipse.rwt.widgets.upload) to close properly. I was instantiating
this widget in a wizard. Thanks to Gottfried for pointing me toward the
below solution, which is slightly different that his (Dialog-based)
solution.
I had to subclass WizardDialog to intercept the close window events, then
call a cleanup method in my wizard class
Here is the cleanup() method in my wizard
public class MyWizard extends Wizard {
...
public void cleanup() {
upload.dispose();
}
}
/**
* Create our own WizardDialog subclass so we can intercept any closing
* events, and dispose of the uploader widget. If we fail to do this,
* repeated invocations of the uploader will cause a Javascript error
* @author David Donohue
* Feb 21, 2008
*/
class LoadDataWizardDialog extends WizardDialog {
public LoadDataWizardDialog(Shell parentShell, LoadDataWizard newWizard)
{
super(parentShell, newWizard);
}
/**
* this disposes of uploader on clicking the wizard's cancel button
*/
@Override
protected void cancelPressed() {
closeUploader();
}
/**
* this disposes of uploader on clicking the wizard's "X" in upper right
*/
@Override
protected boolean canHandleShellCloseEvent() {
closeUploader();
return true;
}
private void closeUploader() {
MyWizard wizard = (MyWizard)getWizard();
wizard.cleanup();
close();
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.04490 seconds