Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Trouble configuring the AWT file chooser(How to parametrise the AWT file chooser dialog)
Trouble configuring the AWT file chooser [message #991804] Thu, 20 December 2012 08:36 Go to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
I am using a FileChooser in two places. In one place I directly create a new FileChooser instance as described in this thread. In the other place I use a FileChooserField in a form.

In both cases I am able to set the default path, the default file name, the file extensions to use in the extension drop down box.

However, I think the default file chooser is ugly as sin, so I added the following code to my SwingEnvironment class to use the native windows file dialog instead:
  @Override
  public ISwingScoutFileChooser createFileChooser(Window w, IFileChooser fc) {
    ISwingScoutFileChooser ui = new SwingScoutFileChooser(this, fc, w, true);
    decorate(fc, ui);
    return ui;
  }


This works and lets me use the windows file dialog, however, it seems that this ignores any parameters I set on the file chooser.

  • I cannot set a default directory (it seems the file dialog under windows 7 manages that on its own)
  • I cannot set the extension for the extension drop down box (I always have the single entry "All files (*.*)" in there. Instead, the extension I define are used as title text for the FileDialog
  • I does honour the filename that I set


Is there something more I need to do to make sure the FileChooser.setXxxx() methods have an effect for the native (AWT) file chooser? If not, I can live with not being able to set a specific directory and just having the file dialog use the last one I selected a file from. I can live with not being able to populate the extension filter dropdown, but the extensions showing in the title bar is truly annoying!
index.php/fa/12751/0/

Is there a way to get rid of the extensions from the title bar?
Re: Trouble configuring the AWT file chooser [message #993397 is a reply to message #991804] Mon, 24 December 2012 08:58 Go to previous messageGo to next message
Adrian MoserFriend
Messages: 67
Registered: March 2011
Member
When I check the code in SwingScoutFileChooser, I think the title is created the way you describe (StringBuffer buf) and cannot be changed without changing Scout Code. Of course you could always create your own SwingScoutFileChooser and return it in SwingEnvironment.

      StringBuffer buf = new StringBuffer();
      if (extensions != null) {
        for (int i = 0; i < extensions.length; i++) {
          if (i > 0) {
            buf.append(", ");
          }
          buf.append("*." + extensions[i]);
        }
      }
      if (buf.length() == 0) {
        buf.append("*.*");
      }
      if (m_owner instanceof Dialog) {
        dlg = new FileDialog((Dialog) m_owner, buf.toString(), openMode ? FileDialog.LOAD : FileDialog.SAVE);
      }
      else if (m_owner instanceof Frame) {
        dlg = new FileDialog((Frame) m_owner, buf.toString(), openMode ? FileDialog.LOAD : FileDialog.SAVE);
      }
      else {
        dlg = new FileDialog(new Frame(), buf.toString(), openMode ? FileDialog.LOAD : FileDialog.SAVE);
      }


Adrian
Re: Trouble configuring the AWT file chooser [message #996928 is a reply to message #993397] Thu, 03 January 2013 08:11 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Adrian

Thanks for your suggestion, I've been able to fix the title problem using this approach. It's a shame that SwingScoutFileChooser.showFileChooserSwing and SwingScoutFileChooser.showFileChooserAWT are private, otherwise it would have been very easy to just have my own file chooser inherit from SwingScoutFileChooser and then overwrite showFileChooserAWT. On the other hand, the class is not so big that having an almost 1:1 copy of the code will be a huge problem.

However, it seems that there is no way to adjust the file extension filter dropdown content for the AWT version of the file chooser (but I can live with that limitation).

Cheers
/urs

[Updated on: Thu, 03 January 2013 08:31]

Report message to a moderator

Re: Trouble configuring the AWT file chooser [message #996959 is a reply to message #996928] Thu, 03 January 2013 09:42 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Urs Beeli wrote on Thu, 03 January 2013 09:11
It's a shame that SwingScoutFileChooser.showFileChooserSwing and SwingScoutFileChooser.showFileChooserAWT are private


I don't know this class, but I can imagine the frustration. I can not discuss this particular case, but if something is private where someone prefer having it protected, I see only two solutions:
* 1. There is a good reason
* 2. There is no good reason (historical reason, or no need to have this possibility, mistake in the API conception...)

In most of the case it is the second solution. Feel free to open a bug to get the change. If there is a good reason why the method is private, you will get a WONTFIX, otherwsie it is for the benefit of everybody.
Re: Trouble configuring the AWT file chooser [message #997076 is a reply to message #996959] Thu, 03 January 2013 14:51 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Done: Bug 397381
Re: Trouble configuring the AWT file chooser [message #1001505 is a reply to message #997076] Wed, 16 January 2013 20:57 Go to previous messageGo to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
Hi Urs,

I can't see any reason too why the methods showFileChooserSwing and showFileChooserAWT should have the private modifier since this limits the extensibility of the file chooser. It makes sense to declare the modifier as protected to allow them to be exchanged by another implementation.

Furthermore, it would probably be reasonable to move the code

if (m_owner instanceof Dialog) {
  dlg = new FileDialog((Dialog) m_owner, buf.toString(), openMode ? FileDialog.LOAD : FileDialog.SAVE);
}
else if (m_owner instanceof Frame) {
  dlg = new FileDialog((Frame) m_owner, buf.toString(), openMode ? FileDialog.LOAD : FileDialog.SAVE);
}
else {
  dlg = new FileDialog(new Frame(), buf.toString(), openMode ? FileDialog.LOAD : FileDialog.SAVE);
}


to a protected factory method. In your case you could ignore the string buffer containing the file extension and leave or set a different title for the dialog.

I'm going to assign the Bugzilla 397381 to me.

Cheers,

Ken
Re: Trouble configuring the AWT file chooser [message #1001665 is a reply to message #1001505] Thu, 17 January 2013 06:56 Go to previous message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thanks Ken.
Previous Topic:Export war file
Next Topic:Problem after Deployment in Tomcat
Goto Forum:
  


Current Time: Tue Apr 23 14:19:32 GMT 2024

Powered by FUDForum. Page generated in 0.03558 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top