1
2
3
4
5
6 package net.kwfgrid.gwui.gui;
7
8 import net.kwfgrid.gwui.SwingFactory2;
9
10 import org.glassbox.widgets.VisibleExecutor;
11 import org.glassbox.widgets.StatusBarExecutor;
12 import org.glassbox.SwingFactory;
13 import org.glassbox.executor.Executor;
14
15 import javax.swing.*;
16
17 import org.apache.log4j.Logger;
18
19 /***
20 <ul>
21 <li>kwfgrid.GUIMethodCallTask.background.color</li>
22 <li>kwfgrid.GUIMethodCallTask.text.color</li>
23 <li>kwfgrid.GUIMethodCallTask.insets</li>
24 <li>kwfgrid.GUIMethodCallTask.font</li>
25 </ul>
26 */
27 public abstract class GUIMethodCallTask implements VisibleExecutor.VisibleTask, StatusBarExecutor.Task {
28 public interface Callback {
29 void notifyTaskFinished();
30 void notifyTaskFailed();
31 }
32
33 private static final Logger logger = Logger.getLogger(GUIMethodCallTask.class);
34
35 private static final String TASK_THEME_PREFIX = "kwfgrid.GUIMethodCallTask";
36
37 private JLabel _view;
38 private String _description;
39 private Callback _editor;
40
41 public GUIMethodCallTask(String description, Executor executor, Callback editor) {
42 _editor = editor;
43 _description = description;
44 _view = null;
45 }
46
47 public String getMessage() {
48 return _description;
49 }
50
51 public JComponent getView() {
52 if (_view == null) {
53 _view = SwingFactory.createLabel(TASK_THEME_PREFIX);
54 _view.setText(_description);
55 }
56 return _view;
57 }
58
59 public void run() {
60 try {
61 execute();
62 _editor.notifyTaskFinished();
63 } catch (Throwable x) {
64 logger.error(_description+" Failed!", x);
65 JDialog e = SwingFactory2.createErrorDialog("Error", _description+" FAILED!", x);
66 e.show();
67 _editor.notifyTaskFailed();
68 }
69 }
70
71 protected abstract void execute() throws Throwable;
72 }