source: main/trunk/gli/src/org/greenstone/gatherer/cdm/BuildTypeManager.java@ 36243

Last change on this file since 36243 was 36243, checked in by kjdon, 23 months ago

solr button should only be available for gs3

  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 KB
Line 
1package org.greenstone.gatherer.cdm;
2
3import java.awt.*;
4import java.awt.event.*;
5import javax.swing.*;
6import java.util.EventListener;
7import javax.swing.event.EventListenerList;
8
9import org.greenstone.gatherer.Configuration;
10import org.greenstone.gatherer.Dictionary;
11import org.greenstone.gatherer.Gatherer;
12import org.greenstone.gatherer.gui.GLIButton;
13import org.greenstone.gatherer.gui.ModalDialog;
14
15public class BuildTypeManager {
16
17 /** The size of this new collection dialog box. */
18 static private Dimension DIALOG_SIZE = new Dimension(600, 280);
19
20 static final public String BUILD_TYPE_MG = "mg";
21 static final public String BUILD_TYPE_MGPP = "mgpp";
22 static final public String BUILD_TYPE_LUCENE = "lucene";
23 static final public String BUILD_TYPE_SOLR = "solr";
24
25 static final public String BUILD_TYPE_MG_STR = "MG";
26 static final public String BUILD_TYPE_MGPP_STR = "MGPP";
27 static final public String BUILD_TYPE_LUCENE_STR = "Lucene";
28 static final public String BUILD_TYPE_SOLR_STR = "SOLR";
29
30 static final public String[] BUILD_TYPES = {BUILD_TYPE_SOLR, BUILD_TYPE_LUCENE, BUILD_TYPE_MGPP, BUILD_TYPE_MG };
31
32 private EventListenerList listeners = null;
33 /** the buildtype element in the config file - uses CollectionMeta */
34 public CollectionMeta build_type_meta = null;
35 private Control controls = null;
36
37 protected BuildTypeManager manager = null;
38 public BuildTypeManager() {
39 build_type_meta = new CollectionMeta(CollectionDesignManager.collect_config.getBuildType());
40 if (getBuildType().equals("")) {
41 build_type_meta.setValue(BUILD_TYPE_MG);
42 // must have an old collection, assume MG
43 }
44 listeners = new EventListenerList();
45 manager = this;
46 }
47
48 public void addBuildTypeListener(BuildTypeListener listener) {
49 listeners.add(BuildTypeListener.class, listener);
50 }
51
52 protected void notifyListeners(String new_build_type) {
53 Object[] concerned = listeners.getListenerList();
54 for(int i = 0; i < concerned.length ; i++) {
55 if(concerned[i] == BuildTypeListener.class) {
56 ((BuildTypeListener)concerned[i+1]).buildTypeChanged(new_build_type);
57 }
58 }
59 concerned = null;
60 }
61
62
63 public void promptForNewBuildType() {
64
65 BuildTypePrompt btp = new BuildTypePrompt(build_type_meta.getValue(CollectionMeta.TEXT));
66 }
67
68 public boolean isMGPP () {
69
70 return getBuildType().equals(BUILD_TYPE_MGPP);
71 }
72 public boolean isMG () {
73
74 return getBuildType().equals(BUILD_TYPE_MG);
75 }
76 public boolean isLucene () {
77
78 return getBuildType().equals(BUILD_TYPE_LUCENE);
79 }
80
81 public boolean isSOLR () {
82 return getBuildType().equals(BUILD_TYPE_SOLR);
83 }
84 public String getBuildType() {
85 return build_type_meta.getValue(CollectionMeta.TEXT);
86 }
87
88 public Control getControls() {
89 if (controls == null) {
90 controls = new BuildTypeControl();
91 }
92 return controls;
93 }
94
95 public interface BuildTypeListener
96 extends EventListener {
97 public void buildTypeChanged(String new_build_type);
98 }
99
100 private class BuildTypeControl
101 extends JPanel
102 implements Control, BuildTypeListener {
103
104 JLabel label = null;
105 JButton change_button = null;
106
107 public BuildTypeControl() {
108 super();
109 this.setComponentOrientation(Dictionary.getOrientation());
110
111 JPanel spacer_panel = new JPanel();
112 spacer_panel.setComponentOrientation(Dictionary.getOrientation());
113
114 JPanel main_panel = new JPanel();
115 main_panel.setComponentOrientation(Dictionary.getOrientation());
116 /* may be CDM.BuildTypeManager.mg, CDM.BuildTYpeManager.mgpp, CDM.BuildTypeManager.lucene, CDM.BuildTypeManager.solr */
117 label = new JLabel(Dictionary.get("CDM.BuildTypeManager.Current_Type", getBuildTypeString(getBuildType())));
118 label.setComponentOrientation(Dictionary.getOrientation());
119
120 change_button = new GLIButton(Dictionary.get("CDM.BuildTypeManager.Change"), Dictionary.get("CDM.BuildTypeManager.Change_Tooltip"));
121
122 change_button.addActionListener(new ActionListener() {
123 public void actionPerformed(ActionEvent event) {
124 promptForNewBuildType();
125 }
126 });
127
128 main_panel.setLayout(new BorderLayout(10,10));
129 main_panel.add(label, BorderLayout.CENTER);
130 main_panel.add(change_button, BorderLayout.LINE_END);
131
132 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
133 setLayout(new BorderLayout());
134 add(spacer_panel, BorderLayout.CENTER);
135 add(main_panel, BorderLayout.LINE_END);
136
137 manager.addBuildTypeListener(this);
138 }
139
140 public void loseFocus() {}
141 public void gainFocus() {}
142 public void destroy() {}
143
144 private String getBuildTypeString(String build_type) {
145 if (build_type.equals(BUILD_TYPE_MG)) {
146 return BUILD_TYPE_MG_STR;
147 }
148 if (build_type.equals(BUILD_TYPE_MGPP)) {
149 return BUILD_TYPE_MGPP_STR;
150 }
151 if (build_type.equals(BUILD_TYPE_LUCENE)) {
152 return BUILD_TYPE_LUCENE_STR;
153 }
154 if (build_type.equals(BUILD_TYPE_SOLR)) {
155 return BUILD_TYPE_SOLR_STR;
156 }
157 return "";
158 }
159
160
161 public void buildTypeChanged(String new_build_type) {
162 label.setText(Dictionary.get("CDM.BuildTypeManager.Current_Type", getBuildTypeString(new_build_type)));
163 }
164 }
165
166 private class BuildTypePrompt
167 extends ModalDialog {
168
169 private JDialog self;
170
171 private JRadioButton mg_button = null;
172 private JRadioButton mgpp_button = null;
173 private JRadioButton lucene_button = null;
174 private JRadioButton solr_button = null;
175
176 private JTextArea description_textarea = null;
177
178 JButton ok_button = null;
179 JButton cancel_button = null;
180
181 public BuildTypePrompt(String current_build_type) {
182 super(Gatherer.g_man, true);
183 this.self = this;
184 setSize(DIALOG_SIZE);
185 setTitle(Dictionary.get("CDM.BuildTypeManager.Title"));
186 this.setComponentOrientation(Dictionary.getOrientation());
187
188 BuildTypeButtonListener btbl = new BuildTypeButtonListener();
189
190 mg_button = new JRadioButton(BUILD_TYPE_MG_STR);
191 mg_button.setComponentOrientation(Dictionary.getOrientation());
192 mg_button.setActionCommand(BUILD_TYPE_MG);
193 mg_button.addActionListener(btbl);
194
195 mgpp_button = new JRadioButton(BUILD_TYPE_MGPP_STR);
196 mgpp_button.setComponentOrientation(Dictionary.getOrientation());
197 mgpp_button.setActionCommand(BUILD_TYPE_MGPP);
198 mgpp_button.addActionListener(btbl);
199
200 lucene_button = new JRadioButton(BUILD_TYPE_LUCENE_STR);
201 lucene_button.setComponentOrientation(Dictionary.getOrientation());
202 lucene_button.setActionCommand(BUILD_TYPE_LUCENE);
203 lucene_button.addActionListener(btbl);
204
205 if (Gatherer.GS3) {
206 solr_button = new JRadioButton(BUILD_TYPE_SOLR_STR);
207 solr_button.setComponentOrientation(Dictionary.getOrientation());
208 solr_button.setActionCommand(BUILD_TYPE_SOLR);
209 solr_button.addActionListener(btbl);
210 }
211
212
213 ButtonGroup build_type_group = new ButtonGroup();
214 if (Gatherer.GS3) {
215 build_type_group.add(solr_button);
216 }
217 build_type_group.add(lucene_button);
218 build_type_group.add(mgpp_button);
219 build_type_group.add(mg_button);
220
221 if (current_build_type != null) {
222 if (current_build_type.equals(BUILD_TYPE_MGPP)) {
223 mgpp_button.setSelected(true);
224 } else if (current_build_type.equals(BUILD_TYPE_MG)) {
225 mg_button.setSelected(true);
226 } else if (current_build_type.equals(BUILD_TYPE_LUCENE)) {
227 lucene_button.setSelected(true);
228 } else if (current_build_type.equals(BUILD_TYPE_SOLR)) {
229 solr_button.setSelected(true);
230 }
231
232 }
233
234 JPanel radio_pane = new JPanel();
235 radio_pane.setLayout(new GridLayout(4,1));
236 if (Gatherer.GS3) {
237 radio_pane.add(solr_button);
238 }
239 radio_pane.add(lucene_button);
240 radio_pane.add(mgpp_button);
241 radio_pane.add(mg_button);
242
243 radio_pane.setComponentOrientation(Dictionary.getOrientation());
244
245 description_textarea = new JTextArea();
246 description_textarea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
247 /* may be CDM.BuildTypeManager.mg_Description, CDM.BuildTYpeManager.mgpp_Description, CDM.BuildTypeManager.lucene_Description, CDM.BUildTypeMamanger.solr_Description*/
248 description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+current_build_type+"_Description"));
249 description_textarea.setCaretPosition(0);
250 description_textarea.setLineWrap(true);
251 description_textarea.setWrapStyleWord(true);
252 description_textarea.setComponentOrientation(Dictionary.getOrientation());
253
254 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
255
256 cancel_button.addActionListener(new ActionListener() {
257 public void actionPerformed(ActionEvent event) {
258 self.dispose();
259 }
260 });
261
262 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
263
264 ok_button.addActionListener(new ActionListener() {
265 public void actionPerformed(ActionEvent event) {
266 String new_build_type = BUILD_TYPE_MGPP;
267 if (mgpp_button.isSelected()) {
268 new_build_type = BUILD_TYPE_MGPP;
269 } else if (mg_button.isSelected()) {
270 new_build_type = BUILD_TYPE_MG;
271 } else if (lucene_button.isSelected()) {
272 new_build_type = BUILD_TYPE_LUCENE;
273 } else if (solr_button.isSelected()) {
274 new_build_type = BUILD_TYPE_SOLR;
275 }
276 if (!build_type_meta.getValue(CollectionMeta.TEXT).equals(new_build_type)) {
277 manager.notifyListeners(new_build_type);
278 build_type_meta.setValue(new_build_type);
279 }
280 self.dispose();
281 }
282 });
283 // tell the CDM that we have (possibly) changed
284 ok_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
285 JPanel button_pane = new JPanel();
286 button_pane.setLayout(new GridLayout(1,2));
287 button_pane.add(ok_button);
288 button_pane.add(cancel_button);
289 button_pane.setComponentOrientation(Dictionary.getOrientation());
290
291 JPanel content_pane = (JPanel) getContentPane();
292 content_pane.setOpaque(true);
293 content_pane.setLayout(new BorderLayout());
294 content_pane.add(radio_pane, BorderLayout.NORTH);
295 content_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
296 content_pane.add(button_pane, BorderLayout.SOUTH);
297 content_pane.setComponentOrientation(Dictionary.getOrientation());
298
299 // Center and display.
300 Dimension screen_size = Configuration.screen_size;
301 this.setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
302 this.setVisible(true); // blocks until the dialog is killed
303
304 }
305
306 public void loseFocus() {
307
308 }
309 public void gainFocus() {
310
311 }
312 public void destroy() {
313
314 }
315
316 private class BuildTypeButtonListener
317 implements ActionListener {
318
319 public void actionPerformed(ActionEvent event) {
320 description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+event.getActionCommand()+"_Description"));
321 description_textarea.setCaretPosition(0);
322 }
323 }
324 }
325}
Note: See TracBrowser for help on using the repository browser.