1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hiveboard.command; |
16 | |
17 | import org.jdesktop.application.ApplicationContext; |
18 | |
19 | import net.sourceforge.hiveboard.WhiteBoardUserService; |
20 | import net.sourceforge.hivegui.application.ApplicationContextHolder; |
21 | import net.sourceforge.hivegui.application.HiveGuiApplicationMain; |
22 | import net.sourceforge.hivegui.dialog.DialogPanel; |
23 | import net.sourceforge.hivegui.message.UserChoice; |
24 | import net.sourceforge.hiveutils.service.ObjectBuilder; |
25 | |
26 | /** |
27 | * Abstract class for most GUI commands in HiveBoard. This class allows for |
28 | * setter-injection of most objects that are needed by actual commands. |
29 | * |
30 | * @author Jean-Francois Poilpret |
31 | */ |
32 | public abstract class AbstractCommandHolder extends GuiContextHandler |
33 | { |
34 | protected UserChoice showMessage(String id, Object... args) |
35 | { |
36 | return _application.showMessage(id, args); |
37 | } |
38 | |
39 | protected boolean showDialog(String panelName, Object... args) |
40 | { |
41 | if (args.length > 0 && args[0] == null) |
42 | { |
43 | return false; |
44 | } |
45 | DialogPanel panel = (DialogPanel) _builder.create(panelName, args); |
46 | return _application.showDialog(panel); |
47 | } |
48 | |
49 | public void setContextHolder(ApplicationContextHolder holder) |
50 | { |
51 | _context = holder.getContext(); |
52 | _application = holder.getApplication(); |
53 | } |
54 | |
55 | public void setService(WhiteBoardUserService service) |
56 | { |
57 | _service = service; |
58 | } |
59 | public WhiteBoardUserService getService() |
60 | { |
61 | return _service; |
62 | } |
63 | |
64 | public void setObjectBuilder(ObjectBuilder builder) |
65 | { |
66 | _builder = builder; |
67 | } |
68 | public ObjectBuilder getObjectBuilder() |
69 | { |
70 | return _builder; |
71 | } |
72 | |
73 | protected ApplicationContext _context; |
74 | protected HiveGuiApplicationMain _application; |
75 | protected WhiteBoardUserService _service; |
76 | protected ObjectBuilder _builder; |
77 | } |