public void widgetSelected(SelectionEvent e) {
String[] name = openDialog();
if (name != null) {
- setFilename(name);
+ setFilename(name,true);
}
}
});
@Override
public void modifyText(ModifyEvent e) {
String file = fileText.getText();
- setFilename(file.split(","));
+ String files[] = file.split(",");
+ for (int i = 0; i < files.length; i++) {
+ files[i] = files[i].trim();
+ }
+ setFilename(files, false);
}
});
protected abstract boolean isValid(File file);
protected void setFilename(String[] filename) {
+ setFilename(filename, true);
+ }
+
+ protected void setFilename(String[] filename, boolean update) {
String text = "";
- for (String s : filename) {
- text += s + ",";
+ if (filename.length < 6) {
+ for (String s : filename) {
+ text += s + ",";
+ }
+ if (text.length() > 2)
+ text = text.substring(0, text.length() - 1);
+ } else {
+ text = filename[0] + " and " + (filename.length -1) + " other files.";
}
- if (text.length() > 2)
- text = text.substring(0, text.length() - 1);
- if (!text.equals(fileText.getText()))
+ if (update && !text.equals(fileText.getText()))
fileText.setText(text);
boolean accept = true;
FileDialog dialog = new FileDialog(getShell(),style);
dialog.setFilterExtensions(getFilterExtensions());
dialog.setFilterNames(getFilterNames());
+ if (filename != null && filename.length == 1)
+ dialog.setFileName(filename[0]);
String filename = dialog.open();
if (filename == null)
return null;