Changeset 25776 for main/trunk/gli/src/org/greenstone
- Timestamp:
- 2012-06-07T14:06:44+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/DatabaseTypeManager.java
r22970 r25776 13 13 import org.greenstone.gatherer.gui.ModalDialog; 14 14 15 public class DatabaseTypeManager { 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 DATABASE_TYPE_GDBM = "gdbm"; 21 static final public String DATABASE_TYPE_JDBM = "jdbm"; 22 static final public String DATABASE_TYPE_SQLITE = "sqlite"; 23 24 static final public String DATABASE_TYPE_GDBM_STR = "GDBM"; 25 static final public String DATABASE_TYPE_JDBM_STR = "JDBM"; 26 static final public String DATABASE_TYPE_SQLITE_STR = "SQLITE"; 27 28 static final public String[] DATABASE_TYPES = { DATABASE_TYPE_GDBM, DATABASE_TYPE_JDBM, DATABASE_TYPE_SQLITE }; 29 30 private EventListenerList listeners = null; 31 /** the databasetype element in the config file - uses CollectionMeta */ 32 public CollectionMeta database_type_meta = null; 33 private Control controls = null; 34 35 protected DatabaseTypeManager manager = null; 36 public DatabaseTypeManager() { 37 database_type_meta = new CollectionMeta(CollectionDesignManager.collect_config.getDatabaseType()); 38 if (getDatabaseType().equals("")) { 39 database_type_meta.setValue(DATABASE_TYPE_GDBM); 40 // must have an old collection, assume MG 41 } 42 listeners = new EventListenerList(); 43 manager = this; 44 } 45 46 public void addDatabaseTypeListener(DatabaseTypeListener listener) { 47 listeners.add(DatabaseTypeListener.class, listener); 48 } 49 50 protected void notifyListeners(String new_database_type) { 51 Object[] concerned = listeners.getListenerList(); 52 for(int i = 0; i < concerned.length ; i++) { 53 if(concerned[i] == DatabaseTypeListener.class) { 54 ((DatabaseTypeListener)concerned[i+1]).databaseTypeChanged(new_database_type); 55 } 56 } 57 concerned = null; 58 } 59 60 61 public void promptForNewDatabaseType() { 62 63 DatabaseTypePrompt dtp = new DatabaseTypePrompt(database_type_meta.getValue(CollectionMeta.TEXT)); 64 } 65 66 public boolean isGDBM () { 67 68 return getDatabaseType().equals(DATABASE_TYPE_GDBM); 69 } 70 public boolean isJDBM () { 71 72 return getDatabaseType().equals(DATABASE_TYPE_JDBM); 73 } 74 public boolean isSQLITE () { 75 76 return getDatabaseType().equals(DATABASE_TYPE_SQLITE); 77 } 78 79 80 public String getDatabaseType() { 81 return database_type_meta.getValue(CollectionMeta.TEXT); 82 } 83 84 public Control getControls() { 85 if (controls == null) { 86 controls = new DatabaseTypeControl(); 87 } 88 return controls; 89 } 90 91 public interface DatabaseTypeListener 92 extends EventListener { 93 public void databaseTypeChanged(String new_database_type); 94 } 95 96 private class DatabaseTypeControl 97 extends JPanel 98 implements Control, DatabaseTypeListener { 99 100 JLabel label = null; 101 JButton change_button = null; 102 103 public DatabaseTypeControl() { 104 super(); 105 this.setComponentOrientation(Dictionary.getOrientation()); 106 107 JPanel spacer_panel = new JPanel(); 108 spacer_panel.setComponentOrientation(Dictionary.getOrientation()); 109 110 JPanel main_panel = new JPanel(); 111 main_panel.setComponentOrientation(Dictionary.getOrientation()); 112 /* may be CDM.DatabaseTypeManager.gdbm, CDM.DatabaseTypeManager.jdbm, CDM.DatabaseTypeManager.sqlite */ 113 label = new JLabel(Dictionary.get("CDM.DatabaseTypeManager.Current_Type", getDatabaseTypeString(getDatabaseType()))); 114 label.setComponentOrientation(Dictionary.getOrientation()); 115 116 change_button = new GLIButton(Dictionary.get("CDM.DatabaseTypeManager.Change"), Dictionary.get("CDM.DatabaseTypeManager.Change_Tooltip")); 117 118 change_button.addActionListener(new ActionListener() { 119 public void actionPerformed(ActionEvent event) { 120 promptForNewDatabaseType(); 121 } 122 }); 123 124 main_panel.setLayout(new BorderLayout(10,10)); 125 main_panel.add(label, BorderLayout.CENTER); 126 main_panel.add(change_button, BorderLayout.LINE_END); 127 128 setBorder(BorderFactory.createEmptyBorder(0,5,0,0)); 129 setLayout(new BorderLayout()); 130 add(spacer_panel, BorderLayout.CENTER); 131 add(main_panel, BorderLayout.LINE_END); 132 133 manager.addDatabaseTypeListener(this); 134 } 135 136 public void loseFocus() {} 137 public void gainFocus() {} 138 public void destroy() {} 139 140 private String getDatabaseTypeString(String database_type) { 141 if (database_type.equals(DATABASE_TYPE_GDBM)) { 142 return DATABASE_TYPE_GDBM_STR; 143 } 144 if (database_type.equals(DATABASE_TYPE_JDBM)) { 145 return DATABASE_TYPE_JDBM_STR; 146 } 147 if (database_type.equals(DATABASE_TYPE_SQLITE)) { 148 return DATABASE_TYPE_SQLITE_STR; 149 } 150 return ""; 151 } 152 153 154 public void databaseTypeChanged(String new_database_type) { 155 label.setText(Dictionary.get("CDM.DatabaseTypeManager.Current_Type", getDatabaseTypeString(new_database_type))); 156 } 157 } 158 159 private class DatabaseTypePrompt 160 extends ModalDialog { 161 162 private JDialog self; 163 164 private JRadioButton gdbm_button = null; 165 private JRadioButton jdbm_button = null; 166 private JRadioButton sqlite_button = null; 167 168 private JTextArea description_textarea = null; 169 170 JButton ok_button = null; 171 JButton cancel_button = null; 172 173 public DatabaseTypePrompt(String current_database_type) { 174 super(Gatherer.g_man, true); 175 this.self = this; 176 setSize(DIALOG_SIZE); 177 setTitle(Dictionary.get("CDM.DatabaseTypeManager.Title")); 178 this.setComponentOrientation(Dictionary.getOrientation()); 179 gdbm_button = new JRadioButton(DATABASE_TYPE_GDBM_STR); 180 gdbm_button.setComponentOrientation(Dictionary.getOrientation()); 181 gdbm_button.setActionCommand(DATABASE_TYPE_GDBM); 182 jdbm_button = new JRadioButton(DATABASE_TYPE_JDBM_STR); 183 jdbm_button.setComponentOrientation(Dictionary.getOrientation()); 184 jdbm_button.setActionCommand(DATABASE_TYPE_JDBM); 185 sqlite_button = new JRadioButton(DATABASE_TYPE_SQLITE_STR); 186 sqlite_button.setComponentOrientation(Dictionary.getOrientation()); 187 sqlite_button.setActionCommand(DATABASE_TYPE_SQLITE); 188 189 DatabaseTypeButtonListener dtbl = new DatabaseTypeButtonListener(); 190 gdbm_button.addActionListener(dtbl); 191 jdbm_button.addActionListener(dtbl); 192 sqlite_button.addActionListener(dtbl); 193 194 ButtonGroup database_type_group = new ButtonGroup(); 195 database_type_group.add(gdbm_button); 196 database_type_group.add(jdbm_button); 197 database_type_group.add(sqlite_button); 198 199 if (current_database_type != null) { 200 if (current_database_type.equals(DATABASE_TYPE_GDBM)) { 201 gdbm_button.setSelected(true); 202 } else if (current_database_type.equals(DATABASE_TYPE_JDBM)) { 203 jdbm_button.setSelected(true); 204 } else if (current_database_type.equals(DATABASE_TYPE_SQLITE)) { 205 sqlite_button.setSelected(true); 206 } 207 } 208 209 JPanel radio_pane = new JPanel(); 210 radio_pane.setLayout(new GridLayout(3,1)); 211 radio_pane.add(gdbm_button); 212 radio_pane.add(jdbm_button); 213 radio_pane.add(sqlite_button); 214 radio_pane.setComponentOrientation(Dictionary.getOrientation()); 215 216 description_textarea = new JTextArea(); 217 description_textarea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 218 /* may be CDM.DatabaseTypeManager.gdbm_Description, CDM.DatabaseTypeManager.jdbm_Description, CDM.DatabaseTypeManager.sqlite_Description */ 219 description_textarea.setText(Dictionary.get("CDM.DatabaseTypeManager."+current_database_type+"_Description")); 220 description_textarea.setLineWrap(true); 221 description_textarea.setWrapStyleWord(true); 222 description_textarea.setComponentOrientation(Dictionary.getOrientation()); 223 224 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip")); 225 226 cancel_button.addActionListener(new ActionListener() { 227 public void actionPerformed(ActionEvent event) { 228 self.dispose(); 229 } 230 }); 231 232 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip")); 233 234 ok_button.addActionListener(new ActionListener() { 235 public void actionPerformed(ActionEvent event) { 236 String new_database_type = DATABASE_TYPE_GDBM; 237 if (gdbm_button.isSelected()) { 238 new_database_type = DATABASE_TYPE_GDBM; 239 } else if (jdbm_button.isSelected()) { 240 new_database_type = DATABASE_TYPE_JDBM; 241 } else if (sqlite_button.isSelected()) { 242 new_database_type = DATABASE_TYPE_SQLITE; 243 } 244 if (!database_type_meta.getValue(CollectionMeta.TEXT).equals(new_database_type)) { 245 manager.notifyListeners(new_database_type); 246 database_type_meta.setValue(new_database_type); 247 } 248 self.dispose(); 249 } 250 }); 251 // tell the CDM that we have (possibly) changed 252 ok_button.addActionListener(CollectionDesignManager.databasecol_change_listener); 253 JPanel button_pane = new JPanel(); 254 button_pane.setLayout(new GridLayout(1,2)); 255 button_pane.add(ok_button); 256 button_pane.add(cancel_button); 257 button_pane.setComponentOrientation(Dictionary.getOrientation()); 258 259 JPanel content_pane = (JPanel) getContentPane(); 260 content_pane.setOpaque(true); 261 content_pane.setLayout(new BorderLayout()); 262 content_pane.add(radio_pane, BorderLayout.NORTH); 263 content_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER); 264 content_pane.add(button_pane, BorderLayout.SOUTH); 265 content_pane.setComponentOrientation(Dictionary.getOrientation()); 266 267 // Center and display. 268 Dimension screen_size = Configuration.screen_size; 269 this.setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2); 270 this.setVisible(true); // blocks until the dialog is killed 271 272 } 273 274 public void loseFocus() { 275 276 } 277 public void gainFocus() { 278 279 } 280 public void destroy() { 281 282 } 283 284 private class DatabaseTypeButtonListener 285 implements ActionListener { 286 287 public void actionPerformed(ActionEvent event) { 288 description_textarea.setText(Dictionary.get("CDM.DatabaseTypeManager."+event.getActionCommand()+"_Description")); 289 } 290 } 291 } 15 public class DatabaseTypeManager 16 { 17 18 /** The size of this new collection dialog box. */ 19 static private Dimension DIALOG_SIZE = new Dimension(600, 280); 20 21 static final public String DATABASE_TYPE_GDBM = "gdbm"; 22 static final public String DATABASE_TYPE_JDBM = "jdbm"; 23 static final public String DATABASE_TYPE_SQLITE = "sqlite"; 24 25 static final public String DATABASE_TYPE_GDBM_STR = "GDBM"; 26 static final public String DATABASE_TYPE_JDBM_STR = "JDBM"; 27 static final public String DATABASE_TYPE_SQLITE_STR = "SQLITE"; 28 29 static final public String[] DATABASE_TYPES = { DATABASE_TYPE_GDBM, DATABASE_TYPE_JDBM, DATABASE_TYPE_SQLITE }; 30 31 private EventListenerList listeners = null; 32 /** the databasetype element in the config file - uses CollectionMeta */ 33 public CollectionMeta database_type_meta = null; 34 private Control controls = null; 35 36 protected DatabaseTypeManager manager = null; 37 38 public DatabaseTypeManager() 39 { 40 database_type_meta = new CollectionMeta(CollectionDesignManager.collect_config.getDatabaseType()); 41 if (getDatabaseType().equals("")) 42 { 43 database_type_meta.setValue(DATABASE_TYPE_GDBM); 44 // must have an old collection, assume MG 45 } 46 listeners = new EventListenerList(); 47 manager = this; 48 } 49 50 public void addDatabaseTypeListener(DatabaseTypeListener listener) 51 { 52 listeners.add(DatabaseTypeListener.class, listener); 53 } 54 55 protected void notifyListeners(String new_database_type) 56 { 57 Object[] concerned = listeners.getListenerList(); 58 for (int i = 0; i < concerned.length; i++) 59 { 60 if (concerned[i] == DatabaseTypeListener.class) 61 { 62 ((DatabaseTypeListener) concerned[i + 1]).databaseTypeChanged(new_database_type); 63 } 64 } 65 concerned = null; 66 } 67 68 public void promptForNewDatabaseType() 69 { 70 71 DatabaseTypePrompt dtp = new DatabaseTypePrompt(database_type_meta.getValue(CollectionMeta.TEXT)); 72 } 73 74 public boolean isGDBM() 75 { 76 77 return getDatabaseType().equals(DATABASE_TYPE_GDBM); 78 } 79 80 public boolean isJDBM() 81 { 82 83 return getDatabaseType().equals(DATABASE_TYPE_JDBM); 84 } 85 86 public boolean isSQLITE() 87 { 88 89 return getDatabaseType().equals(DATABASE_TYPE_SQLITE); 90 } 91 92 public String getDatabaseType() 93 { 94 return database_type_meta.getValue(CollectionMeta.TEXT); 95 } 96 97 public Control getControls() 98 { 99 if (controls == null) 100 { 101 controls = new DatabaseTypeControl(); 102 } 103 return controls; 104 } 105 106 public interface DatabaseTypeListener extends EventListener 107 { 108 public void databaseTypeChanged(String new_database_type); 109 } 110 111 private class DatabaseTypeControl extends JPanel implements Control, DatabaseTypeListener 112 { 113 114 JLabel label = null; 115 JButton change_button = null; 116 117 public DatabaseTypeControl() 118 { 119 super(); 120 this.setComponentOrientation(Dictionary.getOrientation()); 121 122 JPanel spacer_panel = new JPanel(); 123 spacer_panel.setComponentOrientation(Dictionary.getOrientation()); 124 125 JPanel main_panel = new JPanel(); 126 main_panel.setComponentOrientation(Dictionary.getOrientation()); 127 /* 128 * may be CDM.DatabaseTypeManager.gdbm, 129 * CDM.DatabaseTypeManager.jdbm, CDM.DatabaseTypeManager.sqlite 130 */ 131 label = new JLabel(Dictionary.get("CDM.DatabaseTypeManager.Current_Type", getDatabaseTypeString(getDatabaseType()))); 132 label.setComponentOrientation(Dictionary.getOrientation()); 133 134 change_button = new GLIButton(Dictionary.get("CDM.DatabaseTypeManager.Change"), Dictionary.get("CDM.DatabaseTypeManager.Change_Tooltip")); 135 136 change_button.addActionListener(new ActionListener() 137 { 138 public void actionPerformed(ActionEvent event) 139 { 140 promptForNewDatabaseType(); 141 } 142 }); 143 144 main_panel.setLayout(new BorderLayout(10, 10)); 145 main_panel.add(label, BorderLayout.CENTER); 146 main_panel.add(change_button, BorderLayout.LINE_END); 147 148 setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); 149 setLayout(new BorderLayout()); 150 add(spacer_panel, BorderLayout.CENTER); 151 add(main_panel, BorderLayout.LINE_END); 152 153 manager.addDatabaseTypeListener(this); 154 } 155 156 public void loseFocus() 157 { 158 } 159 160 public void gainFocus() 161 { 162 } 163 164 public void destroy() 165 { 166 } 167 168 private String getDatabaseTypeString(String database_type) 169 { 170 if (database_type.equals(DATABASE_TYPE_GDBM)) 171 { 172 return DATABASE_TYPE_GDBM_STR; 173 } 174 if (database_type.equals(DATABASE_TYPE_JDBM)) 175 { 176 return DATABASE_TYPE_JDBM_STR; 177 } 178 if (database_type.equals(DATABASE_TYPE_SQLITE)) 179 { 180 return DATABASE_TYPE_SQLITE_STR; 181 } 182 return ""; 183 } 184 185 public void databaseTypeChanged(String new_database_type) 186 { 187 label.setText(Dictionary.get("CDM.DatabaseTypeManager.Current_Type", getDatabaseTypeString(new_database_type))); 188 } 189 } 190 191 private class DatabaseTypePrompt extends ModalDialog 192 { 193 194 private JDialog self; 195 196 private JRadioButton gdbm_button = null; 197 private JRadioButton jdbm_button = null; 198 private JRadioButton sqlite_button = null; 199 200 private JTextArea description_textarea = null; 201 202 JButton ok_button = null; 203 JButton cancel_button = null; 204 205 public DatabaseTypePrompt(String current_database_type) 206 { 207 super(Gatherer.g_man, true); 208 this.self = this; 209 setSize(DIALOG_SIZE); 210 setTitle(Dictionary.get("CDM.DatabaseTypeManager.Title")); 211 this.setComponentOrientation(Dictionary.getOrientation()); 212 gdbm_button = new JRadioButton(DATABASE_TYPE_GDBM_STR); 213 gdbm_button.setComponentOrientation(Dictionary.getOrientation()); 214 gdbm_button.setActionCommand(DATABASE_TYPE_GDBM); 215 jdbm_button = new JRadioButton(DATABASE_TYPE_JDBM_STR); 216 jdbm_button.setComponentOrientation(Dictionary.getOrientation()); 217 jdbm_button.setActionCommand(DATABASE_TYPE_JDBM); 218 sqlite_button = new JRadioButton(DATABASE_TYPE_SQLITE_STR); 219 sqlite_button.setComponentOrientation(Dictionary.getOrientation()); 220 sqlite_button.setActionCommand(DATABASE_TYPE_SQLITE); 221 222 DatabaseTypeButtonListener dtbl = new DatabaseTypeButtonListener(); 223 gdbm_button.addActionListener(dtbl); 224 jdbm_button.addActionListener(dtbl); 225 sqlite_button.addActionListener(dtbl); 226 227 ButtonGroup database_type_group = new ButtonGroup(); 228 database_type_group.add(gdbm_button); 229 database_type_group.add(jdbm_button); 230 database_type_group.add(sqlite_button); 231 232 if (current_database_type != null) 233 { 234 if (current_database_type.equals(DATABASE_TYPE_GDBM)) 235 { 236 gdbm_button.setSelected(true); 237 } 238 else if (current_database_type.equals(DATABASE_TYPE_JDBM)) 239 { 240 jdbm_button.setSelected(true); 241 } 242 else if (current_database_type.equals(DATABASE_TYPE_SQLITE)) 243 { 244 sqlite_button.setSelected(true); 245 } 246 } 247 248 JPanel radio_pane = new JPanel(); 249 radio_pane.setLayout(new GridLayout(3, 1)); 250 radio_pane.add(gdbm_button); 251 radio_pane.add(jdbm_button); 252 radio_pane.add(sqlite_button); 253 radio_pane.setComponentOrientation(Dictionary.getOrientation()); 254 255 description_textarea = new JTextArea(); 256 description_textarea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 257 /* 258 * may be CDM.DatabaseTypeManager.gdbm_Description, 259 * CDM.DatabaseTypeManager.jdbm_Description, 260 * CDM.DatabaseTypeManager.sqlite_Description 261 */ 262 description_textarea.setText(Dictionary.get("CDM.DatabaseTypeManager." + current_database_type + "_Description")); 263 description_textarea.setLineWrap(true); 264 description_textarea.setWrapStyleWord(true); 265 description_textarea.setComponentOrientation(Dictionary.getOrientation()); 266 267 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip")); 268 269 cancel_button.addActionListener(new ActionListener() 270 { 271 public void actionPerformed(ActionEvent event) 272 { 273 self.dispose(); 274 } 275 }); 276 277 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip")); 278 279 ok_button.addActionListener(new ActionListener() 280 { 281 public void actionPerformed(ActionEvent event) 282 { 283 String new_database_type = DATABASE_TYPE_GDBM; 284 if (gdbm_button.isSelected()) 285 { 286 new_database_type = DATABASE_TYPE_GDBM; 287 } 288 else if (jdbm_button.isSelected()) 289 { 290 new_database_type = DATABASE_TYPE_JDBM; 291 } 292 else if (sqlite_button.isSelected()) 293 { 294 new_database_type = DATABASE_TYPE_SQLITE; 295 } 296 if (!database_type_meta.getValue(CollectionMeta.TEXT).equals(new_database_type)) 297 { 298 manager.notifyListeners(new_database_type); 299 database_type_meta.setValue(new_database_type); 300 } 301 self.dispose(); 302 } 303 }); 304 // tell the CDM that we have (possibly) changed 305 ok_button.addActionListener(CollectionDesignManager.databasecol_change_listener); 306 JPanel button_pane = new JPanel(); 307 button_pane.setLayout(new GridLayout(1, 2)); 308 button_pane.add(ok_button); 309 button_pane.add(cancel_button); 310 button_pane.setComponentOrientation(Dictionary.getOrientation()); 311 312 JPanel content_pane = (JPanel) getContentPane(); 313 content_pane.setOpaque(true); 314 content_pane.setLayout(new BorderLayout()); 315 content_pane.add(radio_pane, BorderLayout.NORTH); 316 content_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER); 317 content_pane.add(button_pane, BorderLayout.SOUTH); 318 content_pane.setComponentOrientation(Dictionary.getOrientation()); 319 320 // Center and display. 321 Dimension screen_size = Configuration.screen_size; 322 this.setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2); 323 this.setVisible(true); // blocks until the dialog is killed 324 325 } 326 327 public void loseFocus() 328 { 329 330 } 331 332 public void gainFocus() 333 { 334 335 } 336 337 public void destroy() 338 { 339 340 } 341 342 private class DatabaseTypeButtonListener implements ActionListener 343 { 344 345 public void actionPerformed(ActionEvent event) 346 { 347 description_textarea.setText(Dictionary.get("CDM.DatabaseTypeManager." + event.getActionCommand() + "_Description")); 348 } 349 } 350 } 292 351 }
Note:
See TracChangeset
for help on using the changeset viewer.