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

Last change on this file since 36135 was 36135, checked in by kjdon, 2 years ago

added solr option to build types. Also setCaretPosition on the indexer description area so it always starts scrolled to the top

  • 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_LUCENE, BUILD_TYPE_SOLR, 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 mg_button = new JRadioButton(BUILD_TYPE_MG_STR);
188 mg_button.setComponentOrientation(Dictionary.getOrientation());
189 mg_button.setActionCommand(BUILD_TYPE_MG);
190 mgpp_button = new JRadioButton(BUILD_TYPE_MGPP_STR);
191 mgpp_button.setComponentOrientation(Dictionary.getOrientation());
192 mgpp_button.setActionCommand(BUILD_TYPE_MGPP);
193 lucene_button = new JRadioButton(BUILD_TYPE_LUCENE_STR);
194 lucene_button.setComponentOrientation(Dictionary.getOrientation());
195 lucene_button.setActionCommand(BUILD_TYPE_LUCENE);
196 solr_button = new JRadioButton(BUILD_TYPE_SOLR_STR);
197 solr_button.setComponentOrientation(Dictionary.getOrientation());
198 solr_button.setActionCommand(BUILD_TYPE_SOLR);
199
200 BuildTypeButtonListener btbl = new BuildTypeButtonListener();
201 mg_button.addActionListener(btbl);
202 mgpp_button.addActionListener(btbl);
203 lucene_button.addActionListener(btbl);
204 solr_button.addActionListener(btbl);
205
206 ButtonGroup build_type_group = new ButtonGroup();
207 build_type_group.add(lucene_button);
208 build_type_group.add(solr_button);
209 build_type_group.add(mgpp_button);
210 build_type_group.add(mg_button);
211
212 if (current_build_type != null) {
213 if (current_build_type.equals(BUILD_TYPE_MGPP)) {
214 mgpp_button.setSelected(true);
215 } else if (current_build_type.equals(BUILD_TYPE_MG)) {
216 mg_button.setSelected(true);
217 } else if (current_build_type.equals(BUILD_TYPE_LUCENE)) {
218 lucene_button.setSelected(true);
219 } else if (current_build_type.equals(BUILD_TYPE_SOLR)) {
220 solr_button.setSelected(true);
221 }
222
223 }
224
225 JPanel radio_pane = new JPanel();
226 radio_pane.setLayout(new GridLayout(4,1));
227 radio_pane.add(lucene_button);
228 radio_pane.add(solr_button);
229 radio_pane.add(mgpp_button);
230 radio_pane.add(mg_button);
231
232 radio_pane.setComponentOrientation(Dictionary.getOrientation());
233
234 description_textarea = new JTextArea();
235 description_textarea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
236 /* may be CDM.BuildTypeManager.mg_Description, CDM.BuildTYpeManager.mgpp_Description, CDM.BuildTypeManager.lucene_Description, CDM.BUildTypeMamanger.solr_Description*/
237 description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+current_build_type+"_Description"));
238 description_textarea.setCaretPosition(0);
239 description_textarea.setLineWrap(true);
240 description_textarea.setWrapStyleWord(true);
241 description_textarea.setComponentOrientation(Dictionary.getOrientation());
242
243 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
244
245 cancel_button.addActionListener(new ActionListener() {
246 public void actionPerformed(ActionEvent event) {
247 self.dispose();
248 }
249 });
250
251 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
252
253 ok_button.addActionListener(new ActionListener() {
254 public void actionPerformed(ActionEvent event) {
255 String new_build_type = BUILD_TYPE_MGPP;
256 if (mgpp_button.isSelected()) {
257 new_build_type = BUILD_TYPE_MGPP;
258 } else if (mg_button.isSelected()) {
259 new_build_type = BUILD_TYPE_MG;
260 } else if (lucene_button.isSelected()) {
261 new_build_type = BUILD_TYPE_LUCENE;
262 } else if (solr_button.isSelected()) {
263 new_build_type = BUILD_TYPE_SOLR;
264 }
265 if (!build_type_meta.getValue(CollectionMeta.TEXT).equals(new_build_type)) {
266 manager.notifyListeners(new_build_type);
267 build_type_meta.setValue(new_build_type);
268 }
269 self.dispose();
270 }
271 });
272 // tell the CDM that we have (possibly) changed
273 ok_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
274 JPanel button_pane = new JPanel();
275 button_pane.setLayout(new GridLayout(1,2));
276 button_pane.add(ok_button);
277 button_pane.add(cancel_button);
278 button_pane.setComponentOrientation(Dictionary.getOrientation());
279
280 JPanel content_pane = (JPanel) getContentPane();
281 content_pane.setOpaque(true);
282 content_pane.setLayout(new BorderLayout());
283 content_pane.add(radio_pane, BorderLayout.NORTH);
284 content_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
285 content_pane.add(button_pane, BorderLayout.SOUTH);
286 content_pane.setComponentOrientation(Dictionary.getOrientation());
287
288 // Center and display.
289 Dimension screen_size = Configuration.screen_size;
290 this.setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
291 this.setVisible(true); // blocks until the dialog is killed
292
293 }
294
295 public void loseFocus() {
296
297 }
298 public void gainFocus() {
299
300 }
301 public void destroy() {
302
303 }
304
305 private class BuildTypeButtonListener
306 implements ActionListener {
307
308 public void actionPerformed(ActionEvent event) {
309 description_textarea.setText(Dictionary.get("CDM.BuildTypeManager."+event.getActionCommand()+"_Description"));
310 description_textarea.setCaretPosition(0);
311 }
312 }
313 }
314}
Note: See TracBrowser for help on using the repository browser.