gonuldas / gwtupload

Automatically exported from code.google.com/p/gwtupload
Other
0 stars 0 forks source link

Allow button to be any type of Widget or even null #82

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Enhancement suggestion.

Summary:
It would be nice to not restrict the given button to be a Button but rather a 
widget or null.

Why this is important:
public class MyFancyLookingButton extends Composite {

  public MyFancyLookingButton() {
    DecoratorPanel widget = new DecoratorPanel();
    initWidget(widget);
    setStylePrimaryName("sprite-this-ma");
  }
}

MyFancyLookingButton upload = new MyFancyLookingButton();
SingleUploader uploader = new SingleUploader(FileInputType.BROWSER_INPUT, null, 
upload);  // Will not currently work

_OR_

// This following will result in a NullPointerException
class MyEnty implements EntryPoint {

  @Override
  public void onModuleLoad() {
    SingleUploader uploader = new SingleUploader(FileInputType.BROWSER_INPUT, null, null);
    RootPanel.get().add(uploader);

    MyFanyLookingButton upload = new MyFancyLookingButton();
    upload.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent e) {
        uploader.submit();
      }
    });
    RootPanel.get().add(upload);
  }
}

Description:
This will make the code a little less "beautiful" to look at but would make it 
easier for users to integrate into an app that includes home made buttons (e.g. 
a DecoratorPanel instance).
For currently functionality that relies on interfaces not implemented by Widget 
a simple cast (e.g. if (button != null && button instanceof HasText) { HasText 
hasText = (HasText) button; if (hasText.getText().length() == 0) { ... }} or if 
(button != null && button instanceof FocusWidget) {
 ((FocusWidget) button).setEnabled/Focus(...) } ) would do.  

If desired I can submit a patch.

Original issue reported on code.google.com by philip.r...@gmail.com on 29 Nov 2010 at 10:29

GoogleCodeExporter commented 8 years ago
I added in r809, the option of a CUSTOM FileInputType, so your code could be:

public class MyFancyLookingButton extends Composite {
  public MyFancyLookingButton() {
    DecoratorPanel widget = new DecoratorPanel();
    initWidget(widget);
    setStylePrimaryName("sprite-this-ma");
  }
}

MyFancyLookingButton upload = new MyFancyLookingButton();
SingleUploader uploader = new SingleUploader(FileInputType.CUSTOM.with(upload));
RootPanel.get().add(uploader);

Let me know if it matches your needs, if not feel free to send patches which 
I'll be happy to include.

- Manolo

Original comment by manuel.carrasco.m on 29 Dec 2010 at 6:15

GoogleCodeExporter commented 8 years ago
Just a point i forgot, your class should implement HasClickHandlers in order to 
add the necessary handler to open the selection box. Optionally you can 
implement HasMouseOverHandlers and HasMouseOutHandlers in order to handle these 
events because your widget will be covered by the original file input 
(transparent). 

Original comment by manuel.carrasco.m on 29 Dec 2010 at 7:11

GoogleCodeExporter commented 8 years ago

Original comment by manuel.carrasco.m on 29 Dec 2010 at 3:29

GoogleCodeExporter commented 8 years ago

Original comment by manuel.carrasco.m on 7 Feb 2011 at 6:31