01: package desktop;
02:
03: import org.wings.SFileChooser;
04: import org.wings.SOptionPane;
05:
06: import java.awt.event.ActionEvent;
07: import java.awt.event.ActionListener;
08: import java.io.File;
09:
10: public class FileOpenerItem extends EditorItem {
11:
12: public FileOpenerItem() {
13: super ();
14: pref.put(TOOL, "FileOpenerTool");
15: }
16:
17: public FileOpenerItem(String name) {
18: super (name);
19: }
20:
21: @Override
22: public void activated() {
23: System.out.println("NAME:" + getValue(NAME));
24: System.out.println("TEXT:" + getValue(TEXT));
25:
26: if (getValue(TEXT) != null)
27: return;
28:
29: final SFileChooser chooser = new SFileChooser();
30: chooser.setColumns(20);
31:
32: final SOptionPane dialog = new SOptionPane();
33: dialog.setEncodingType("multipart/form-data");
34: dialog.showInput(getComponent(), "Choose file", chooser,
35: "Open file");
36: dialog.addActionListener(new ActionListener() {
37: public void actionPerformed(ActionEvent evt) {
38: if (evt.getActionCommand() == SOptionPane.OK_ACTION) {
39: try {
40: File file = chooser.getSelectedFile();
41: putValue(NAME, chooser.getFileName());
42: putValue(TEXT, ((EditorPanel) getComponent())
43: .openFile(file));
44:
45: } catch (Exception e) {
46: dialog.show((EditorPanel) getComponent()); // show again ..
47: // .. but first, show error-message on top ..
48: SOptionPane.showMessageDialog(
49: (EditorPanel) getComponent(),
50: "Error opening file", e.getMessage());
51: }
52: }
53:
54: }
55: });
56: }
57:
58: }
|