source: trunk/gli/src/org/greenstone/gatherer/cdm/GeneralManager.java@ 12093

Last change on this file since 12093 was 12093, checked in by kjdon, 18 years ago

general manager only handles its own stuff now - it doesn't control the other pages. removed the annoying warning about collection title matching

  • Property svn:keywords set to Author Date Id Revision
File size: 19.3 KB
RevLine 
[4932]1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
[5529]28
[4932]29import java.awt.*;
30import java.awt.event.*;
[6003]31import java.io.*;
32import java.util.regex.*;
[4932]33import javax.swing.*;
[6003]34import javax.swing.filechooser.*;
[4932]35import javax.swing.event.*;
36import org.greenstone.gatherer.Configuration;
[8236]37import org.greenstone.gatherer.DebugStream;
[4932]38import org.greenstone.gatherer.Dictionary;
39import org.greenstone.gatherer.Gatherer;
[11031]40import org.greenstone.gatherer.gui.DesignPaneHeader;
[4932]41import org.greenstone.gatherer.gui.EmailField;
[6323]42import org.greenstone.gatherer.gui.GLIButton;
[12093]43import org.greenstone.gatherer.gui.GUIUtils;
[10374]44import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
[6003]45import org.greenstone.gatherer.util.StaticStrings;
[5536]46
[12093]47/** This class provides a graphical interface for editing general metadata for the collection, such as name, description, icons etc.
[4932]48*/
[12093]49public class GeneralManager {
50
[4932]51 /** The controls used to modify the general options. */
52 private Control controls;
53 /** Constructor. */
54 public GeneralManager() {
55 }
56
57 /** Destructor. */
58 public void destroy() {
[12093]59 if (controls != null) {
60 controls.destroy();
61 controls = null;
62 }
[4932]63 }
64
[12093]65 public void loseFocus() {
[4932]66 }
67
68 public void gainFocus() {
69
70 }
71 /** This class is resposible for generating the controls for the editing of general options.
72 * @return the Control for editing the general options
73 */
[12093]74 public Control getControls() {
75 if (controls == null) {
76 controls = new GeneralControl();
77 }
[4932]78 return controls;
79 }
[12093]80
[4932]81
[12093]82 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
83 * @param mode the new mode as an int
84 */
85 public void modeChanged(int mode) {
86
87 }
88
[4932]89 /** This class represents the visual component of the general options stored in the CollectionDesignManager. */
90 private class GeneralControl
[6051]91 extends JPanel
[4932]92 implements Control {
[6662]93
[12093]94 //private boolean has_been_warned = false;
[4932]95 private boolean ready = false;
96 private CollectionMeta collection_extra_collectionmeta;
97 private CollectionMeta collection_name_collectionmeta;
98 private CollectionMeta creator_collectionmeta;
99 private CollectionMeta icon_collection_collectionmeta;
100 private CollectionMeta icon_collection_small_collectionmeta;
101 private CollectionMeta maintainer_collectionmeta;
102 private CollectionMeta public_collectionmeta;
103 /** The creators email. */
104 private EmailField creator_emailfield;
105 /** The maintainers email. */
106 private EmailField maintainer_emailfield;
[6003]107 /** Button to browse for the collection about page icon. */
108 private JButton browse_about_icon_button;
109 /** Button to browse for the collection home page icon. */
110 private JButton browse_home_icon_button;
[4932]111 /** The checkbox controlling public access to the collection. */
112 private JCheckBox public_checkbox;
113 private JLabel creator_label;
114 private JLabel description_label;
115 private JLabel icon_label;
116 private JLabel maintainer_label;
117 private JLabel name_label;
118 private JLabel small_icon_label;
119 /** The text field used to edit the file name of the collections icon. */
120 private JTextField icon_textfield;
121 /** The text field used to edit the collections title. */
122 private JTextField name_textfield;
123 /** The text field used to edit the file name of the collections small icon. */
124 private JTextField small_icon_textfield;
125 /** A text area used to modify the collection description. */
126 private JTextArea description_textarea;
127 /** Constructor. */
128 public GeneralControl() {
129 super();
130 // Retrieve some of the model elements, those we know aren't language dependant
[5086]131 public_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getPublic());
[5529]132
[4932]133 // Creation
[11031]134 JPanel header_panel = new DesignPaneHeader("CDM.GUI.General", "generalsettings");
[5529]135
[4932]136 JPanel all_details_panel = new JPanel();
137 JPanel details_panel = new JPanel();
[6843]138 JPanel fields_panel = new JPanel();
139
[5529]140 creator_label = new JLabel();
[5536]141 Dictionary.registerText(creator_label, "CDM.General.Email.Creator");
[5529]142
[8231]143 creator_emailfield = new EmailField(Configuration.getColor("coloring.error_background", false));
[5536]144 Dictionary.registerTooltip(creator_emailfield, "CDM.General.Email.Creator_Tooltip");
[5529]145
146 maintainer_label = new JLabel();
[5536]147 Dictionary.registerText(maintainer_label, "CDM.General.Email.Maintainer");
[5529]148
[8231]149 maintainer_emailfield = new EmailField(Configuration.getColor("coloring.error_background", false));
[5536]150 Dictionary.registerTooltip(maintainer_emailfield, "CDM.General.Email.Maintainer_Tooltip");
[6843]151
[5529]152 name_label = new JLabel();
[5536]153 Dictionary.registerText(name_label, "CDM.General.Collection_Name");
[5529]154 name_textfield = new JTextField("CDM.General.Collection_Name");
[5536]155 Dictionary.registerTooltip(name_textfield, "CDM.General.Collection_Name_Tooltip");
[6152]156 JLabel short_name_label = new JLabel();
157 Dictionary.registerText(short_name_label, "NewCollectionPrompt.Collection_Name");
158 JTextField short_name_textfield = new JTextField(Gatherer.c_man.getCollection().getName());
159 short_name_textfield.setEditable(false);
[8231]160 short_name_textfield.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
[4932]161 JPanel icon_panel = new JPanel();
[5529]162 icon_label = new JLabel();
[5536]163 Dictionary.registerText(icon_label, "CDM.General.Icon_Collection");
[5529]164 icon_textfield = new JTextField("CDM.General.Icon_Collection");
[5536]165 Dictionary.registerTooltip(icon_textfield, "CDM.General.Icon_Collection_Tooltip");
[6323]166 browse_about_icon_button = new GLIButton();
167 browse_about_icon_button.setMnemonic(KeyEvent.VK_A);
[6003]168 Dictionary.registerText(browse_about_icon_button, "General.Browse");
[4932]169 JPanel small_icon_panel = new JPanel();
170 small_icon_label = new JLabel("CDM.General.Icon_Collection_Small");
[5536]171 Dictionary.registerText(small_icon_label, "CDM.General.Icon_Collection_Small");
[5529]172 small_icon_textfield = new JTextField("CDM.General.Icon_Collection_Small");
[5536]173 Dictionary.registerTooltip(small_icon_textfield, "CDM.General.Icon_Collection_Small_Tooltip");
[6323]174 browse_home_icon_button = new GLIButton();
175 browse_home_icon_button.setMnemonic(KeyEvent.VK_A);
[6003]176 Dictionary.registerText(browse_home_icon_button, "General.Browse");
[6843]177
[10552]178 // public
[6843]179 JPanel box_panel = new JPanel();
180 public_checkbox = new JCheckBox("", public_collectionmeta.getValue(CollectionMeta.TEXT).equals(CollectionConfiguration.TRUE_STR));
181 Dictionary.registerText(public_checkbox, "CDM.General.Access");
182
[4932]183 JPanel description_panel = new JPanel();
[5529]184 description_label = new JLabel();
[5536]185 Dictionary.registerText(description_label, "CDM.General.Collection_Extra");
[4932]186 description_textarea = new JTextArea();
[8231]187 description_textarea.setBackground(Configuration.getColor("coloring.editable_background", false));
[5536]188 Dictionary.registerTooltip(description_textarea, "CDM.General.Collection_Extra_Tooltip");
[4932]189 // Connection
[6152]190 BrowseListener browse_listener = new BrowseListener(StaticStrings.IMAGES_PATH_RELATIVE_TO_GSDL_PREFIX);
191 browse_about_icon_button.addActionListener(browse_listener);
192 browse_home_icon_button.addActionListener(browse_listener);
193 browse_listener = null;
[4932]194 public_checkbox.addActionListener(CollectionDesignManager.change_listener);
[10237]195 public_checkbox.addActionListener(CollectionDesignManager.buildcol_change_listener);
[4932]196 creator_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
[10237]197 creator_emailfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
[4932]198 description_textarea.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
[10237]199 description_textarea.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
[4932]200 icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
[10237]201 icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
[4932]202 maintainer_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
[10237]203 maintainer_emailfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
[4932]204 name_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
[6152]205 name_textfield.getDocument().addDocumentListener(new CollectionTitleUpdater());
[10237]206 name_textfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
[4932]207 small_icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
[10237]208 small_icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.buildcol_change_listener);
209 //Note: unfortunately just loading the General Design panel fires the buildcol_change_listener (even if nothing is changed).
[5529]210
[4932]211 // Layout
[6843]212 fields_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
213 fields_panel.setLayout(new BorderLayout(5,2));
214
215 JPanel fields_label_panel = new JPanel();
216 fields_label_panel.setLayout(new GridLayout(6,1));
[4932]217
[6843]218 JPanel fields_box_panel = new JPanel();
219 fields_box_panel.setLayout(new GridLayout(6,1));
220
221 // creator
222 fields_label_panel.add(creator_label);
223 fields_box_panel.add(creator_emailfield);
[4932]224
[6843]225 // maintainer
226 fields_label_panel.add(maintainer_label);
227 fields_box_panel.add(maintainer_emailfield);
[4932]228
[6843]229 // title
230 fields_label_panel.add(name_label);
231 fields_box_panel.add(name_textfield);
[6152]232
[6843]233 // collection short name
234 fields_label_panel.add(short_name_label);
235 fields_box_panel.add(short_name_textfield);
236
237 // icon
238 fields_label_panel.add(icon_label);
239 fields_box_panel.add(icon_panel);
240
241 // small icon
242 fields_label_panel.add(small_icon_label);
243 fields_box_panel.add(small_icon_panel);
244
245 fields_panel.add(fields_label_panel, BorderLayout.WEST);
246 fields_panel.add(fields_box_panel, BorderLayout.CENTER);
247
[4932]248 icon_panel.setLayout(new BorderLayout());
249 icon_panel.add(icon_textfield, BorderLayout.CENTER);
[6003]250 icon_panel.add(browse_about_icon_button, BorderLayout.EAST);
[4932]251
252 small_icon_panel.setLayout(new BorderLayout());
253 small_icon_panel.add(small_icon_textfield, BorderLayout.CENTER);
[6003]254 small_icon_panel.add(browse_home_icon_button, BorderLayout.EAST);
[4932]255
[7365]256 box_panel.setLayout(new GridLayout(1,1,5,2));
[6843]257 box_panel.add(public_checkbox);
[4932]258
259 description_panel.setLayout(new BorderLayout());
260 description_panel.add(description_label, BorderLayout.NORTH);
261 description_panel.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
[6843]262
263 details_panel.setLayout(new BorderLayout());
264 details_panel.add(fields_panel, BorderLayout.NORTH);
265 details_panel.add(box_panel, BorderLayout.CENTER);
[4932]266
267 all_details_panel.setLayout(new BorderLayout());
268 all_details_panel.add(details_panel, BorderLayout.NORTH);
269 all_details_panel.add(description_panel, BorderLayout.CENTER);
270
[11038]271 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
[4932]272 setLayout(new BorderLayout());
[11031]273 add(header_panel, BorderLayout.NORTH);
[4932]274 add(all_details_panel, BorderLayout.CENTER);
275 }
[5529]276
[4932]277 /** Destructor. */
278 public void destroy() {
279 }
[5529]280
[4932]281 /** Called to refresh the components. */
282 public void gainFocus() {
283 // Retrieve all of the elements that are dependant on default language.
284 collection_extra_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
285 collection_name_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_COLLECTIONNAME_STR);
[10556]286
[5086]287 creator_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getCreator());
[4932]288 icon_collection_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);
289 icon_collection_small_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
[5086]290 maintainer_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getMaintainer());
[4932]291 // Make sure the components are up to date
[5255]292 creator_emailfield.setText(creator_collectionmeta.getValue(CollectionMeta.TEXT));
[4932]293 creator_emailfield.setCaretPosition(0);
[5255]294 description_textarea.setText(collection_extra_collectionmeta.getValue(CollectionMeta.TEXT));
[4932]295 description_textarea.setCaretPosition(0);
[5255]296 icon_textfield.setText(icon_collection_collectionmeta.getValue(CollectionMeta.TEXT));
[4932]297 icon_textfield.setCaretPosition(0);
[5255]298 maintainer_emailfield.setText(maintainer_collectionmeta.getValue(CollectionMeta.TEXT));
[4932]299 maintainer_emailfield.setCaretPosition(0);
[5255]300 name_textfield.setText(collection_name_collectionmeta.getValue(CollectionMeta.TEXT));
[4932]301 name_textfield.setCaretPosition(0);
[5255]302 small_icon_textfield.setText(icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT));
[4932]303 small_icon_textfield.setCaretPosition(0);
[6051]304 public_checkbox.setSelected(public_collectionmeta.getValue(CollectionMeta.TEXT).equals(CollectionConfiguration.TRUE_STR));
[4932]305 ready = true;
306 }
[6662]307
[4932]308 /** Called to store the current value of the components. */
309 public void loseFocus() {
310 // String values. Have to test if this component has actually ever recieved focus anyway.
311 if(ready) {
312 // Boolean values
313 public_collectionmeta.setValue((public_checkbox.isSelected() ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
[6051]314 String creator_email_str = creator_emailfield.getText();
315 creator_collectionmeta.setValue(creator_email_str);
[6636]316 // If the email is currently empty, store this email
[8231]317 if(Configuration.getEmail() == null) {
318 Configuration.setEmail(creator_email_str); // Store the email address in the configuration
[6636]319 }
[4932]320 collection_extra_collectionmeta.setValue(description_textarea.getText());
321 icon_collection_collectionmeta.setValue(icon_textfield.getText());
322 maintainer_collectionmeta.setValue(maintainer_emailfield.getText());
323 icon_collection_small_collectionmeta.setValue(small_icon_textfield.getText());
[12093]324 collection_name_collectionmeta.setValue(name_textfield.getText());
[4932]325 ready = false;
[11477]326 }
327
[4932]328 }
329
[6003]330 /** Listens for a click on either browse button, and when detected opens a file browser window initially pointed at the images folder of the collection. Once a user has selected a path, does it's best to construct the best address to the resource, such as _httpcollection_/images/about.gif */
331 private class BrowseListener
332 implements ActionListener {
[6051]333
[6088]334 private String prefix;
335
[6152]336 public BrowseListener(String prefix_raw) {
337 this.prefix = prefix_raw.replaceAll(StaticStrings.COLNAME_PATTERN, Gatherer.c_man.getCollection().getName());
[6088]338 }
339
[6003]340 public void actionPerformed(ActionEvent event) {
341 // Open an almost standard file browser to the images folder of the current collection
[9045]342 File images_folder = new File(Gatherer.c_man.getCollectionImagesDirectoryPath());
[6003]343 // If images isn't already there, create it
344 if(!images_folder.exists()) {
345 images_folder.mkdirs();
346 }
347 JFileChooser file_chooser = new JFileChooser(images_folder);
348 file_chooser.setAcceptAllFileFilterUsed(false);
349 file_chooser.setDialogTitle(Dictionary.get("CDM.General.Browser_Title"));
350 file_chooser.setFileFilter(new ImageFilter());
351 file_chooser.setSize(400,300);
[12093]352 GUIUtils.disableRename(file_chooser);
[6003]353 int value = file_chooser.showOpenDialog(Gatherer.g_man);
354 // If the user hasn't cancelled, retrieve the file path selected
355 if(value == JFileChooser.APPROVE_OPTION) {
356 // If the file isn't in the images folder, then ask the user if they want to copy it there
357 File file = file_chooser.getSelectedFile();
[11049]358 if (!file.getParentFile().equals(images_folder)) {
359 // Copy the file
360 try {
361 File collection_image_file = new File(images_folder, file.getName());
[11491]362 Gatherer.f_man.getQueue().copyFile(file, collection_image_file, true);
[10374]363
[11049]364 // If we're using a remote Greenstone server, upload the image
365 if (Gatherer.isGsdlRemote) {
366 RemoteGreenstoneServer.uploadCollectionFile(Gatherer.c_man.getCollection().getName(), collection_image_file);
[6003]367 }
368 }
[11049]369 catch(Exception exception) {
370 DebugStream.printStackTrace(exception);
371 // Show warning
[11477]372 String[] args = new String[] {file.getAbsolutePath(), images_folder.getAbsolutePath()};
373 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.General.Image_Copy_Failed", args), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
[11049]374 // Nothing else we can do.
[6003]375 return;
376 }
377 }
[11049]378
[6003]379 // Create the path starting _httpcollection_/images/<filename>
[6088]380 String path = prefix + file.getName();
[6003]381 if(event.getSource() == browse_about_icon_button) {
382 icon_textfield.setText(path);
383 }
384 else {
385 small_icon_textfield.setText(path);
386 }
387 path = null;
388 }
389 }
[6051]390
[6003]391 /** ImageFilter.java is a 1.4 example used by FileChooserDemo2.java. */
[6051]392 private class ImageFilter
[6003]393 extends javax.swing.filechooser.FileFilter {
[6051]394
[6003]395 private Pattern pattern = null;
[6051]396
[6003]397 public ImageFilter() {
398 pattern = Pattern.compile(".*\\.(gif|png|jpe?g)");
399 }
[6051]400
[6003]401 // Accept all directories and all .col files
402 public boolean accept(File f) {
403 String filename = f.getName().toLowerCase();
404 Matcher matcher = pattern.matcher(filename);
405 return f.isDirectory() || matcher.matches();
406 }
[6051]407
[6003]408 // The description of this filter
409 public String getDescription() {
410 return Dictionary.get("CDM.General.Image_Filter");
411 }
412 }
413 }
[6152]414
415 private class CollectionTitleUpdater
416 implements DocumentListener {
417 /** Gives notification that an attribute or set of attributes changed. */
418 public void changedUpdate(DocumentEvent e) {
419 setTitle();
420 }
421 /** Gives notification that there was an insert into the document. */
422 public void insertUpdate(DocumentEvent e) {
423 setTitle();
424 }
425 /** Gives notification that a portion of the document has been removed. */
426 public void removeUpdate(DocumentEvent e) {
427 setTitle();
428 }
429
430 private void setTitle() {
431 // Set the title
432 String collection_title = name_textfield.getText();
433 String collection_name = Gatherer.c_man.getCollection().getName();
434 Gatherer.g_man.setTitle(collection_title, collection_name);
435 collection_title = null;
436 collection_name = null;
437 }
438 }
[4932]439 }
440}
Note: See TracBrowser for help on using the repository browser.