[6051] | 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 | *
|
---|
[6318] | 8 | * Author: John Thompson, Greenstone Project, NZDL, University of Waikato
|
---|
[6051] | 9 | *
|
---|
[6318] | 10 | * Copyright (C) 2003 New Zealand Digital Library Project
|
---|
[6051] | 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 | */
|
---|
[4803] | 27 | package org.greenstone.gatherer.gui;
|
---|
| 28 |
|
---|
| 29 | import java.awt.*;
|
---|
| 30 | import java.awt.event.*;
|
---|
| 31 | import java.io.File;
|
---|
| 32 | import java.util.*;
|
---|
| 33 | import javax.swing.*;
|
---|
| 34 | import javax.swing.event.*;
|
---|
| 35 | import javax.swing.text.*;
|
---|
[22605] | 36 | import javax.swing.filechooser.FileFilter;
|
---|
| 37 | import javax.swing.filechooser.FileView;
|
---|
[8231] | 38 | import org.greenstone.gatherer.Configuration;
|
---|
[5536] | 39 | import org.greenstone.gatherer.Dictionary;
|
---|
[4803] | 40 | import org.greenstone.gatherer.Gatherer;
|
---|
[6051] | 41 | import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
|
---|
[11939] | 42 | import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
|
---|
[22605] | 43 | import org.greenstone.gatherer.util.JarTools;
|
---|
[6159] | 44 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
| 45 | import org.greenstone.gatherer.util.Utility;
|
---|
[4803] | 46 |
|
---|
| 47 | public class NewCollectionDetailsPrompt
|
---|
| 48 | extends ModalDialog {
|
---|
[6159] | 49 |
|
---|
[22605] | 50 |
|
---|
| 51 | static public boolean titleClashes(String collectDir, String title, File current_config_file) {
|
---|
[7280] | 52 | // An empty collection title never clashes with anything. It may look ugly in the final collection but there is nothing wrong with having no title for a particular language.
|
---|
[6638] | 53 | if(title == null || title.length() == 0) {
|
---|
| 54 | return false;
|
---|
| 55 | }
|
---|
[22605] | 56 | File collect_directory = new File(collectDir);
|
---|
[14045] | 57 | String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
|
---|
[9045] | 58 | File children[] = collect_directory.listFiles();
|
---|
[6159] | 59 | for(int i = 0; children != null && i < children.length; i++) {
|
---|
| 60 | if(children[i].isDirectory()) {
|
---|
[14045] | 61 | File config_file = new File(children[i], file_name);
|
---|
[6168] | 62 | if(current_config_file == null || !config_file.equals(current_config_file)) {
|
---|
| 63 | BasicCollectionConfiguration other_collection = new BasicCollectionConfiguration(config_file);
|
---|
| 64 | if(other_collection.getName().equalsIgnoreCase(title)) {
|
---|
| 65 | return true;
|
---|
| 66 | }
|
---|
| 67 | other_collection = null;
|
---|
[6159] | 68 | }
|
---|
[6168] | 69 | config_file = null;
|
---|
[6159] | 70 | }
|
---|
| 71 | }
|
---|
| 72 | return false;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[4803] | 75 | private boolean cancelled;
|
---|
[22605] | 76 | private boolean collectDirChanged;
|
---|
[4803] | 77 | private File base_final;
|
---|
[22605] | 78 | private JButton chdir_button;
|
---|
[4803] | 79 | private JButton create_button;
|
---|
| 80 | private JComboBox base_collection;
|
---|
| 81 | private JDialog self;
|
---|
[11939] | 82 | private JRadioButton personal_collection_button = null;
|
---|
[4803] | 83 | private JTextArea description;
|
---|
| 84 | private JTextField title;
|
---|
[22605] | 85 | private String collectBasePath;
|
---|
| 86 | private String newCollectPath;
|
---|
[4803] | 87 | private String description_final;
|
---|
[11778] | 88 | private String title_final="";
|
---|
[22605] | 89 |
|
---|
[7158] | 90 | static private Dimension COMPONENT_SIZE = new Dimension(230, 25);
|
---|
[4803] | 91 | /** The size of this new collection dialog box. */
|
---|
[7158] | 92 | static private Dimension SIZE = new Dimension(600, 280);
|
---|
[4803] | 93 | static private int FILENAME_SIZE = 8;
|
---|
| 94 |
|
---|
| 95 | /** Constructor.
|
---|
| 96 | * @see org.greenstone.gatherer.util.Utility
|
---|
| 97 | */
|
---|
| 98 | public NewCollectionDetailsPrompt() {
|
---|
[18370] | 99 | super(Gatherer.g_man, true);
|
---|
[4803] | 100 | this.cancelled = true;
|
---|
[18370] | 101 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
[4803] | 102 | this.self = this;
|
---|
[22605] | 103 | newCollectPath = Gatherer.getCollectDirectoryPath();
|
---|
| 104 | collectBasePath = null;
|
---|
| 105 | collectDirChanged = false;
|
---|
| 106 |
|
---|
[4803] | 107 | // Setup
|
---|
[5527] | 108 | setJMenuBar(new SimpleMenuBar("creatingacollection"));
|
---|
[7158] | 109 | setSize(SIZE);
|
---|
[12119] | 110 | setTitle(Dictionary.get("NewCollectionPrompt.Title"));
|
---|
| 111 |
|
---|
[7014] | 112 | // Model building. Build a model of all of the collections in the gsdl collect directory with the appropriate directories.
|
---|
[4803] | 113 | Vector base_collection_model = new Vector();
|
---|
[22605] | 114 | setupBaseCollections(base_collection_model, null); // if no collect directory passed in: use default collect directory
|
---|
[6051] | 115 |
|
---|
[5536] | 116 |
|
---|
| 117 | // Creation
|
---|
[4803] | 118 | JPanel content_pane = (JPanel) getContentPane();
|
---|
[18370] | 119 | content_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
[4803] | 120 | content_pane.setOpaque(true);
|
---|
| 121 | JPanel upper_pane = new JPanel();
|
---|
[18370] | 122 | upper_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
[12119] | 123 | JLabel instructions_label = new JLabel(Dictionary.get("NewCollectionPrompt.Instructions"));
|
---|
[18370] | 124 | instructions_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 125 |
|
---|
[4803] | 126 | JPanel title_pane = new JPanel();
|
---|
[18370] | 127 | title_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
[12119] | 128 | JLabel title_label = new JLabel(Dictionary.get("CDM.General.Collection_Name"));
|
---|
[18370] | 129 | title_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
[4803] | 130 | title = new JTextField();
|
---|
[18370] | 131 | title.setComponentOrientation(Dictionary.getOrientation());
|
---|
[7158] | 132 | title.setPreferredSize(COMPONENT_SIZE);
|
---|
[12119] | 133 | title.setToolTipText(Dictionary.get("CDM.General.Collection_Name_Tooltip"));
|
---|
| 134 | JLabel name_label = new JLabel(Dictionary.get("NewCollectionPrompt.Collection_Name"));
|
---|
[18370] | 135 | name_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 136 |
|
---|
[4803] | 137 | JPanel center_pane = new JPanel();
|
---|
[18370] | 138 | center_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
[4803] | 139 | JPanel description_pane = new JPanel();
|
---|
[18370] | 140 | description_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
[12119] | 141 | JLabel description_label = new JLabel(Dictionary.get("NewCollectionPrompt.Collection_Description"));
|
---|
[18370] | 142 | description_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
[4803] | 143 | description = new JTextArea();
|
---|
[18370] | 144 | description.setComponentOrientation(Dictionary.getOrientation());
|
---|
[8231] | 145 | description.setBackground(Configuration.getColor("coloring.editable_background", false));
|
---|
| 146 | description.setForeground(Configuration.getColor("coloring.editable_foreground", false));
|
---|
[4803] | 147 | description.setRows(5);
|
---|
[12119] | 148 | description.setToolTipText(Dictionary.get("CDM.General.Collection_Extra_Tooltip"));
|
---|
| 149 |
|
---|
[4803] | 150 | JPanel bottom_pane = new JPanel();
|
---|
[18370] | 151 | bottom_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
[4803] | 152 | // Base Collection
|
---|
| 153 | JPanel base_collection_pane = new JPanel();
|
---|
[18370] | 154 | base_collection_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 155 |
|
---|
| 156 | JLabel base_collection_label = new JLabel(Dictionary.get("NewCollectionPrompt.Base_Collection"));
|
---|
| 157 | base_collection_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 158 |
|
---|
| 159 | base_collection = new JComboBox(base_collection_model);
|
---|
| 160 | base_collection.setComponentOrientation(Dictionary.getOrientation());
|
---|
[13195] | 161 | base_collection.setOpaque(false);
|
---|
[12119] | 162 | base_collection.setToolTipText(Dictionary.get("NewCollectionPrompt.Base_Collection_Tooltip"));
|
---|
| 163 |
|
---|
[11939] | 164 | JPanel collection_scope_pane = new JPanel();
|
---|
[18370] | 165 | collection_scope_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 166 |
|
---|
| 167 | personal_collection_button = new JRadioButton(Dictionary.get("NewCollectionPrompt.Collection_Scope_Personal"));
|
---|
[14563] | 168 | personal_collection_button.setToolTipText(Dictionary.get("NewCollectionPrompt.Collection_Scope_Personal_Tooltip"));
|
---|
[11939] | 169 | personal_collection_button.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
|
---|
| 170 | personal_collection_button.setOpaque(false);
|
---|
[18370] | 171 | personal_collection_button.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 172 |
|
---|
| 173 | JRadioButton shared_collection_button = new JRadioButton(Dictionary.get("NewCollectionPrompt.Collection_Scope_Shared"));
|
---|
[14563] | 174 | shared_collection_button.setToolTipText(Dictionary.get("NewCollectionPrompt.Collection_Scope_Shared_Tooltip"));
|
---|
[11939] | 175 | shared_collection_button.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
|
---|
| 176 | shared_collection_button.setOpaque(false);
|
---|
[18370] | 177 | shared_collection_button.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 178 |
|
---|
| 179 | ButtonGroup collection_scope_group = new ButtonGroup();
|
---|
[11939] | 180 | collection_scope_group.add(personal_collection_button);
|
---|
| 181 | collection_scope_group.add(shared_collection_button);
|
---|
| 182 | personal_collection_button.setSelected(true);
|
---|
| 183 |
|
---|
[4803] | 184 | JPanel button_pane = new JPanel();
|
---|
[18370] | 185 | button_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
[12119] | 186 | create_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
|
---|
[22605] | 187 | chdir_button = new GLIButton(Dictionary.get("General.CD"), Dictionary.get("General.CD_Tooltip"));
|
---|
[12119] | 188 | JButton cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
|
---|
| 189 |
|
---|
[4803] | 190 | // Connection
|
---|
[22605] | 191 | chdir_button.addActionListener(new ChangeDirListener());
|
---|
| 192 | if(Gatherer.isGsdlRemote) { // for client GLI disable changing directories
|
---|
| 193 | chdir_button.setEnabled(false);
|
---|
| 194 | } else { // can't base collections on any in OTHER collect dirs in client GLI
|
---|
| 195 | base_collection.addActionListener(new OtherCollectionsListener());
|
---|
| 196 | }
|
---|
[4803] | 197 | cancel_button.addActionListener(new CancelListener());
|
---|
| 198 | create_button.addActionListener(new CreateListener());
|
---|
| 199 | description.addKeyListener(new DescriptionListener());
|
---|
[7280] | 200 |
|
---|
[4803] | 201 | // Layout
|
---|
[7158] | 202 | title_pane.setLayout(new BorderLayout(5,0));
|
---|
[18370] | 203 | title_pane.add(title_label, BorderLayout.LINE_START);
|
---|
[4803] | 204 | title_pane.add(title, BorderLayout.CENTER);
|
---|
| 205 |
|
---|
[6041] | 206 | upper_pane.setLayout(new GridLayout(2,1));
|
---|
[4803] | 207 | upper_pane.add(instructions_label);
|
---|
| 208 | upper_pane.add(title_pane);
|
---|
| 209 |
|
---|
[18370] | 210 | JScrollPane scrol_tmp;
|
---|
| 211 |
|
---|
[4803] | 212 | description_pane.setLayout(new BorderLayout());
|
---|
[18370] | 213 | description_pane.add(description_label, BorderLayout.NORTH);
|
---|
| 214 | scrol_tmp=new JScrollPane(description);
|
---|
| 215 | scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 216 | description_pane.add(scrol_tmp, BorderLayout.CENTER);
|
---|
[4803] | 217 |
|
---|
[7158] | 218 | base_collection_pane.setLayout(new BorderLayout(5,0));
|
---|
[18370] | 219 | base_collection_pane.add(base_collection_label, BorderLayout.LINE_START);
|
---|
[4803] | 220 | base_collection_pane.add(base_collection, BorderLayout.CENTER);
|
---|
| 221 |
|
---|
[11939] | 222 | collection_scope_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
|
---|
| 223 | collection_scope_pane.setLayout(new GridLayout(1,2));
|
---|
| 224 | collection_scope_pane.add(personal_collection_button);
|
---|
| 225 | collection_scope_pane.add(shared_collection_button);
|
---|
| 226 |
|
---|
[4803] | 227 | center_pane.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
|
---|
| 228 | center_pane.setLayout(new BorderLayout());
|
---|
| 229 | center_pane.add(description_pane, BorderLayout.CENTER);
|
---|
[6051] | 230 |
|
---|
[4803] | 231 | bottom_pane.setLayout(new BorderLayout());
|
---|
[11939] | 232 | bottom_pane.add(base_collection_pane, BorderLayout.NORTH);
|
---|
| 233 | if (Gatherer.isGsdlRemote) {
|
---|
| 234 | bottom_pane.add(collection_scope_pane, BorderLayout.CENTER);
|
---|
| 235 | bottom_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
| 236 | }
|
---|
| 237 | else {
|
---|
| 238 | bottom_pane.add(button_pane, BorderLayout.CENTER);
|
---|
| 239 | }
|
---|
[4803] | 240 |
|
---|
| 241 | button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
|
---|
[22605] | 242 | button_pane.setLayout(new GridLayout(1,3));
|
---|
| 243 | button_pane.add(chdir_button);
|
---|
[4803] | 244 | button_pane.add(create_button);
|
---|
| 245 | button_pane.add(cancel_button);
|
---|
| 246 |
|
---|
| 247 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 248 | content_pane.setLayout(new BorderLayout());
|
---|
| 249 | content_pane.add(upper_pane, BorderLayout.NORTH);
|
---|
| 250 | content_pane.add(center_pane, BorderLayout.CENTER);
|
---|
| 251 | content_pane.add(bottom_pane, BorderLayout.SOUTH);
|
---|
| 252 | // Final dialog setup & positioning.
|
---|
[18130] | 253 | getRootPane().setDefaultButton(create_button);
|
---|
[8231] | 254 | Dimension screen_size = Configuration.screen_size;
|
---|
[7158] | 255 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
[4803] | 256 | setVisible(true);
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | public boolean isCancelled() {
|
---|
| 260 | return cancelled;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | public File getBase() {
|
---|
| 264 | return base_final;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | public String getDescription() {
|
---|
| 268 | return description_final;
|
---|
| 269 | }
|
---|
[7280] | 270 |
|
---|
[6041] | 271 | /** Generates the collection short filename by taking the first eight characters of the title (spaces removed) and then adjusting by further truncating and then adding an unique suffix as necessary.
|
---|
| 272 | * @return the filename as a String
|
---|
| 273 | */
|
---|
[11391] | 274 | public String getName()
|
---|
| 275 | {
|
---|
| 276 | // Retrieve the first 8 non-whitespace ASCII characters of title_final.
|
---|
[7280] | 277 | StringBuffer name_buffer = new StringBuffer("");
|
---|
[11391] | 278 | for (int i = 0, u = 0; (i < title_final.length() && u < 8); i++) {
|
---|
| 279 | // To be safe we make sure the internal collection name (folder name) contains only ASCII characters
|
---|
[7280] | 280 | char c = title_final.charAt(i);
|
---|
[11391] | 281 | if ((int) c < 128 && Character.isLetterOrDigit(c)) {
|
---|
[7280] | 282 | name_buffer.append(Character.toLowerCase(c));
|
---|
[7740] | 283 | u++;
|
---|
[7280] | 284 | }
|
---|
[6041] | 285 | }
|
---|
[11391] | 286 |
|
---|
| 287 | // Use "col" as the base collection name if we have nothing left
|
---|
| 288 | if (name_buffer.length() == 0) {
|
---|
| 289 | name_buffer = new StringBuffer("col");
|
---|
| 290 | }
|
---|
| 291 |
|
---|
[11939] | 292 | // Remote collections that aren't shared have the user's username prefixed to the collection name
|
---|
| 293 | if (Gatherer.isGsdlRemote && personal_collection_button.isSelected()) {
|
---|
[17612] | 294 | name_buffer = new StringBuffer(Gatherer.remoteGreenstoneServer.getUsername() + "-" + name_buffer.toString());
|
---|
[11939] | 295 | }
|
---|
| 296 |
|
---|
[7280] | 297 | // We need to ensure the filename is unique
|
---|
| 298 | int counter = 0;
|
---|
| 299 | StringBuffer new_name_buffer = new StringBuffer(name_buffer.toString());
|
---|
| 300 | while(filenameClashes(new_name_buffer.toString())) {
|
---|
| 301 | new_name_buffer = new StringBuffer(name_buffer.toString());
|
---|
| 302 | counter++;
|
---|
| 303 | String suffix = String.valueOf(counter);
|
---|
| 304 | // If we have to truncate the namestring so as to fit the suffix
|
---|
| 305 | if(suffix.length() + new_name_buffer.length() > 8) {
|
---|
| 306 | new_name_buffer.replace(new_name_buffer.length() - suffix.length(), new_name_buffer.length(), suffix);
|
---|
| 307 | }
|
---|
| 308 | // Or just append it if that isn't necessary
|
---|
| 309 | else {
|
---|
| 310 | new_name_buffer.append(suffix);
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
[11939] | 313 |
|
---|
[7280] | 314 | // All done
|
---|
| 315 | return new_name_buffer.toString();
|
---|
| 316 | }
|
---|
| 317 |
|
---|
[9045] | 318 | private boolean filenameClashes(String filename)
|
---|
| 319 | {
|
---|
| 320 | File collect_directory = new File(Gatherer.getCollectDirectoryPath());
|
---|
| 321 | File children[] = collect_directory.listFiles();
|
---|
[6041] | 322 | for(int i = 0; children != null && i < children.length; i++) {
|
---|
| 323 | if(children[i].getName().equals(filename)) {
|
---|
| 324 | return true;
|
---|
| 325 | }
|
---|
| 326 | }
|
---|
| 327 | return false;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
[4803] | 330 | public String getTitle() {
|
---|
| 331 | return title_final;
|
---|
| 332 | }
|
---|
[7326] | 333 |
|
---|
[22605] | 334 | private void setupBaseCollections(Vector base_collection_model, String collectDirectory) {
|
---|
| 335 |
|
---|
| 336 | File collect_directory = null;
|
---|
| 337 | if(collectDirectory != null) {
|
---|
| 338 | collect_directory = new File(collectDirectory);
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | // need to modify this to base a coll on any collection from any site
|
---|
| 342 | if (Gatherer.GS3 && !Gatherer.isGsdlRemote) {
|
---|
| 343 | File sites_dir = new File(Gatherer.getSitesDirectoryPath());
|
---|
| 344 | File [] sites = sites_dir.listFiles();
|
---|
| 345 | for (int i=0; i<sites.length; i++) {
|
---|
| 346 | if(collect_directory == null) {
|
---|
| 347 | collect_directory = new File(sites_dir + File.separator + sites[i].getName() + File.separator + "collect");
|
---|
| 348 | }
|
---|
| 349 | if (collect_directory.exists()) {
|
---|
| 350 | addCollectionsToModel(base_collection_model, collect_directory, sites[i].getName());
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
| 353 | } else {
|
---|
| 354 | if(collect_directory == null) { // if no collect directory passed in: use default collect directory
|
---|
| 355 | collect_directory = new File(Gatherer.getCollectDirectoryPath());
|
---|
| 356 | }
|
---|
| 357 | addCollectionsToModel(base_collection_model, collect_directory, null);
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | // Sort the result.
|
---|
| 361 | Collections.sort(base_collection_model);
|
---|
| 362 | base_collection_model.add(0, new Item(null, Dictionary.get("NewCollectionPrompt.NewCollection")));
|
---|
| 363 |
|
---|
| 364 | // last item allows one to open up collections from other collect folders to base the new one on
|
---|
| 365 | if(!Gatherer.isGsdlRemote) { // Not yet implemented for client GLI
|
---|
| 366 | base_collection_model.add(new Item(null, Dictionary.get("NewCollectionPrompt.OtherCollections")));
|
---|
| 367 | }
|
---|
| 368 | }
|
---|
| 369 |
|
---|
[7341] | 370 | private void addCollectionsToModel(Vector base_collection_model, File collect_directory, String site) {
|
---|
| 371 | File[] possible_collections = collect_directory.listFiles();
|
---|
[14045] | 372 | String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
|
---|
[7341] | 373 | for (int i = 0; possible_collections != null && i < possible_collections.length; i++) {
|
---|
| 374 | // If the directory has a etc/collect.cfg file then it looks like a collection
|
---|
[14045] | 375 | File collect_cfg_file = new File(possible_collections[i], file_name);
|
---|
[7341] | 376 | if (collect_cfg_file.exists()) {
|
---|
[18947] | 377 | // Check for group coll: Check the collect.cfg for collectgroup=true
|
---|
| 378 | BasicCollectionConfiguration config = new BasicCollectionConfiguration(collect_cfg_file);
|
---|
| 379 | if (config.getCollectGroup().equals("true")) {
|
---|
[18607] | 380 | // try subdirs in here
|
---|
| 381 | addCollectionsToModel(base_collection_model, possible_collections[i], site);
|
---|
[18947] | 382 | }
|
---|
| 383 | else {
|
---|
| 384 |
|
---|
| 385 | // If the directory has a metadata/ then the collection can be used as a base
|
---|
| 386 | File metadata_directory = new File(possible_collections[i], "metadata");
|
---|
| 387 | if (metadata_directory.exists()) {
|
---|
| 388 | // Add to model
|
---|
| 389 | BasicCollectionConfiguration collect_cfg = new BasicCollectionConfiguration(collect_cfg_file);
|
---|
| 390 | if (Gatherer.GS3 && site != null) {
|
---|
| 391 | collect_cfg.setSite(site);
|
---|
| 392 | }
|
---|
| 393 | Item item = new Item(possible_collections[i], collect_cfg);
|
---|
| 394 | if (!base_collection_model.contains(item)) {
|
---|
| 395 | base_collection_model.add(item);
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
[7341] | 398 | }
|
---|
| 399 | }
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | }
|
---|
| 403 |
|
---|
[22605] | 404 | private class OtherCollectionsListener implements ActionListener {
|
---|
| 405 |
|
---|
| 406 | // the JComboBox listener will receive an ActionEvent
|
---|
| 407 | // when a selection has been made
|
---|
| 408 |
|
---|
| 409 | public void actionPerformed(ActionEvent event) {
|
---|
| 410 |
|
---|
| 411 | // If the Other Collections item was selected (which is the last one in the list)
|
---|
| 412 | if(base_collection.getSelectedIndex() == base_collection.getItemCount()-1) {
|
---|
| 413 |
|
---|
| 414 | // open a filechooser in whatever is the current collect directory
|
---|
| 415 | // within the NewCollectionDetailsPrompt's settings
|
---|
| 416 | if(collectBasePath == null) {
|
---|
| 417 | collectBasePath = newCollectPath;
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | JFileChooser chooser = new JFileChooser(collectBasePath);
|
---|
| 421 | chooser.setFileView(new CollectionFileView());
|
---|
| 422 | chooser.setDialogTitle(Dictionary.get("NewCollectionPrompt.ChooseACollection"));
|
---|
| 423 | chooser.setApproveButtonText(Dictionary.get("NewCollectionPrompt.Select"));
|
---|
| 424 |
|
---|
| 425 | // to prevent the user from traversing into collection folders,
|
---|
| 426 | // need to:
|
---|
| 427 | // - NOT set the filechooser to Directories only, but files and directories
|
---|
| 428 | // (so that they can still select directories)
|
---|
| 429 | // - add a filefilter that accepts only directories (i.e. rejects files)
|
---|
| 430 | // - remove the accept all filter
|
---|
| 431 | chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
---|
| 432 | //chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
---|
| 433 | chooser.setFileFilter(new CollectionFileFilter());
|
---|
| 434 | chooser.setAcceptAllFileFilterUsed(false);
|
---|
| 435 |
|
---|
| 436 | int returnVal = chooser.showOpenDialog(NewCollectionDetailsPrompt.this);
|
---|
| 437 | if(returnVal == JFileChooser.APPROVE_OPTION) {
|
---|
| 438 |
|
---|
| 439 | File selectedFile = chooser.getSelectedFile();
|
---|
| 440 |
|
---|
| 441 | // don't bother reloading if nothing has changed
|
---|
| 442 | if(collectBasePath.equals(selectedFile.getAbsolutePath() + File.separator)) {
|
---|
| 443 | // don't want Other Collections... selected
|
---|
| 444 | base_collection.setSelectedIndex(0);
|
---|
| 445 | } else {
|
---|
| 446 |
|
---|
| 447 | // If the selected directory is a collection folder get its collect dir,
|
---|
| 448 | // make collectBasePath the collect dir, and select the collection itself
|
---|
| 449 | String cfg = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
|
---|
| 450 | boolean isCollection = false;
|
---|
| 451 | while(new File(selectedFile, cfg).exists()) { // while loop handles collectgroup
|
---|
| 452 | selectedFile = selectedFile.getParentFile();
|
---|
| 453 | isCollection = true;
|
---|
| 454 | } // else may be a collect dir, in which case leave it as it is again
|
---|
| 455 |
|
---|
| 456 | // found collect directory for base collections
|
---|
| 457 | collectBasePath = selectedFile.getAbsolutePath()+File.separator;
|
---|
| 458 |
|
---|
| 459 | // change the available collections to base this collection on
|
---|
| 460 | base_collection.removeAllItems();
|
---|
| 461 | Vector base_collection_model = new Vector();
|
---|
| 462 | setupBaseCollections(base_collection_model, collectBasePath);
|
---|
| 463 | for(int i = 0; i < base_collection_model.size(); i++) {
|
---|
| 464 | Item item = (Item)base_collection_model.get(i);
|
---|
| 465 | base_collection.addItem(item);
|
---|
| 466 |
|
---|
| 467 | // select the originally chosen collection, if any, in the combobox
|
---|
| 468 | if(isCollection && chooser.getSelectedFile().equals(item.getFile())) {
|
---|
| 469 | base_collection.setSelectedIndex(i);
|
---|
| 470 | }
|
---|
| 471 | }
|
---|
| 472 |
|
---|
| 473 | // But if the user selected a collect group, set combobox to New Collection
|
---|
| 474 | if(!isCollection) {
|
---|
| 475 | // if it was a collectgroup, nothing new would be selected, set to New Coll
|
---|
| 476 | if(base_collection.getSelectedIndex() == base_collection.getItemCount()-1) {
|
---|
| 477 | base_collection.setSelectedIndex(0);
|
---|
| 478 | }
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | }
|
---|
| 482 |
|
---|
| 483 | } else { // cancelled out of dialog, so jump to New Collection
|
---|
| 484 | base_collection.setSelectedIndex(0);
|
---|
| 485 | }
|
---|
| 486 | }
|
---|
| 487 | }
|
---|
| 488 | }
|
---|
| 489 |
|
---|
| 490 | private class ChangeDirListener implements ActionListener {
|
---|
| 491 | public void actionPerformed(ActionEvent event) {
|
---|
| 492 | String oldCollectPath = newCollectPath;
|
---|
| 493 | JFileChooser chooser = new JFileChooser(newCollectPath);
|
---|
| 494 | chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
---|
| 495 | chooser.setDialogTitle(Dictionary.get("General.ChooseCollectDirectory"));
|
---|
| 496 |
|
---|
| 497 | int returnVal = chooser.showOpenDialog(NewCollectionDetailsPrompt.this);
|
---|
| 498 | if(returnVal == JFileChooser.APPROVE_OPTION) {
|
---|
| 499 | newCollectPath = chooser.getSelectedFile().getAbsolutePath() + File.separator;
|
---|
| 500 |
|
---|
| 501 | // Must NOT change the available collections to base this collection on here.
|
---|
| 502 | // It will change any collection the user previously chose to base the newcoll on.
|
---|
| 503 |
|
---|
| 504 | // will be used to test for duplicate collection names in current collect dir
|
---|
| 505 | collectDirChanged = newCollectPath.equals(oldCollectPath) ? false : true;
|
---|
| 506 | }
|
---|
| 507 | }
|
---|
| 508 | }
|
---|
| 509 |
|
---|
[4803] | 510 | private class CancelListener
|
---|
| 511 | implements ActionListener {
|
---|
| 512 | public void actionPerformed(ActionEvent event) {
|
---|
| 513 | cancelled = true;
|
---|
| 514 | self.dispose();
|
---|
| 515 | }
|
---|
| 516 | }
|
---|
| 517 |
|
---|
[7280] | 518 |
|
---|
[6159] | 519 | private class CreateListener
|
---|
| 520 | implements ActionListener {
|
---|
| 521 |
|
---|
[4803] | 522 | public void actionPerformed(ActionEvent event) {
|
---|
[6159] | 523 | // Validate.
|
---|
| 524 | title_final = title.getText();
|
---|
| 525 | if(title_final.length() == 0) {
|
---|
[13195] | 526 | JOptionPane jOptionPane=new JOptionPane();
|
---|
[18370] | 527 | jOptionPane.setComponentOrientation(Dictionary.getOrientation());
|
---|
[13195] | 528 | jOptionPane.setOpaque(!Utility.isMac());
|
---|
| 529 | jOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
|
---|
[6159] | 530 | return;
|
---|
| 531 | }
|
---|
| 532 | // We must ensure that the collection title is unique. This is a pain in the nether regions as we are forced to load the collect.cfg of each other collection in turn looking for a conflicting title
|
---|
| 533 | else {
|
---|
[22605] | 534 | String collectDir = collectDirChanged ? newCollectPath : Gatherer.getCollectDirectoryPath();
|
---|
| 535 | if(titleClashes(collectDir, title_final, null)) {
|
---|
[13195] | 536 | JOptionPane jOptionPane=new JOptionPane();
|
---|
[18370] | 537 | jOptionPane.setComponentOrientation(Dictionary.getOrientation());
|
---|
[13195] | 538 | jOptionPane.setOpaque(!Utility.isMac());
|
---|
| 539 | if (jOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Clash"), Dictionary.get("General.Warning"), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
|
---|
[6051] | 540 | return;
|
---|
[4803] | 541 | }
|
---|
| 542 | }
|
---|
| 543 | }
|
---|
[9753] | 544 |
|
---|
[22605] | 545 | // going through with collection creation
|
---|
| 546 | if(collectDirChanged) {
|
---|
| 547 | Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(), newCollectPath);
|
---|
| 548 | // will tell the server that the collect directory has changed and that
|
---|
| 549 | // the workspace needs to be refreshed (Documents in Greenstone Collections)
|
---|
| 550 | }
|
---|
| 551 |
|
---|
[4803] | 552 | description_final = description.getText();
|
---|
[9753] | 553 |
|
---|
[5164] | 554 | // If we got this far there are no errors.
|
---|
[4803] | 555 | Item item_final = (Item) base_collection.getSelectedItem();
|
---|
| 556 | base_final = item_final.getFile();
|
---|
[6159] | 557 |
|
---|
[4803] | 558 | cancelled = false;
|
---|
[6159] | 559 |
|
---|
[4803] | 560 | self.dispose();
|
---|
| 561 | }
|
---|
| 562 | }
|
---|
[6159] | 563 |
|
---|
[4803] | 564 | private class DescriptionListener
|
---|
| 565 | extends KeyAdapter {
|
---|
| 566 | public void keyPressed(KeyEvent event) {
|
---|
| 567 | if(event.getKeyCode() == KeyEvent.VK_TAB) {
|
---|
| 568 | event.consume();
|
---|
| 569 | base_collection.grabFocus();
|
---|
| 570 | }
|
---|
| 571 | }
|
---|
| 572 | }
|
---|
| 573 |
|
---|
[6051] | 574 | private class Item
|
---|
[4803] | 575 | implements Comparable {
|
---|
[6159] | 576 | private BasicCollectionConfiguration config;
|
---|
[4803] | 577 | private File file;
|
---|
| 578 | private String name;
|
---|
[6159] | 579 | public Item(File file, BasicCollectionConfiguration config) {
|
---|
| 580 | this.config = config;
|
---|
| 581 | this.file = file;
|
---|
| 582 | this.name = null;
|
---|
| 583 | }
|
---|
[4803] | 584 | public Item(File file, String name) {
|
---|
[6159] | 585 | this.config = null;
|
---|
[4803] | 586 | this.file = file;
|
---|
| 587 | this.name = name;
|
---|
| 588 | }
|
---|
| 589 | public int compareTo(Object other) {
|
---|
[22605] | 590 | if(this == null && other == null) {
|
---|
| 591 | return 0;
|
---|
| 592 | }
|
---|
| 593 | else if(other == null) {
|
---|
| 594 | return 1;
|
---|
| 595 | }
|
---|
| 596 | else if(this == null) {
|
---|
| 597 | return -1;
|
---|
| 598 | }
|
---|
| 599 | else {
|
---|
| 600 | return toString().toLowerCase().compareTo(other.toString().toLowerCase());
|
---|
| 601 | }
|
---|
[4803] | 602 | }
|
---|
| 603 | public boolean equals(Object other) {
|
---|
| 604 | return compareTo(other) == 0;
|
---|
| 605 | }
|
---|
| 606 | public File getFile() {
|
---|
| 607 | return file;
|
---|
| 608 | }
|
---|
| 609 | public String toString() {
|
---|
[6159] | 610 | if(name == null && config != null) {
|
---|
[7280] | 611 | name = config.toString();
|
---|
[6159] | 612 | }
|
---|
[4803] | 613 | return name;
|
---|
| 614 | }
|
---|
| 615 | }
|
---|
[22605] | 616 |
|
---|
| 617 | /** FileFilter for the Filechooser to choose the collection to base the new one on:
|
---|
| 618 | * Only displays directories. */
|
---|
| 619 | private class CollectionFileFilter extends FileFilter {
|
---|
| 620 | public boolean accept(File f) {
|
---|
| 621 | return f.isDirectory();
|
---|
| 622 | }
|
---|
| 623 | public String getDescription() {
|
---|
| 624 | return "greenstone collection view"; //return "directories only";
|
---|
| 625 | }
|
---|
| 626 | }
|
---|
| 627 |
|
---|
| 628 | /** Folders that can be used as a base collection have a special icon */
|
---|
| 629 | private class CollectionFileView extends FileView {
|
---|
| 630 | final String configfile_name;
|
---|
| 631 | final ImageIcon COLLECTION_ICON = JarTools.getImage("gsCollection.gif", true);
|
---|
| 632 |
|
---|
| 633 | private File previous = null;
|
---|
| 634 | private boolean previousWasCollection = false;
|
---|
| 635 |
|
---|
| 636 | public CollectionFileView() {
|
---|
| 637 | configfile_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 | // A human readable description of the file.
|
---|
| 641 | public String getDescription(File f) {
|
---|
| 642 | if(!f.equals(previous)) {
|
---|
| 643 | previous = f;
|
---|
| 644 | // no idea if it's a collection or not, calculate this next time
|
---|
| 645 | previousWasCollection = false;
|
---|
| 646 | }
|
---|
| 647 | return null; // FilewView superclass will handle it
|
---|
| 648 | }
|
---|
| 649 |
|
---|
| 650 | // The icon that represents this file in the JFileChooser.
|
---|
| 651 | public Icon getIcon(File f) {
|
---|
| 652 |
|
---|
| 653 | if(f.equals(previous) && previousWasCollection) {
|
---|
| 654 | return COLLECTION_ICON;
|
---|
| 655 | }
|
---|
| 656 |
|
---|
| 657 | if(isCollectionBase(f)) {
|
---|
| 658 | return COLLECTION_ICON;
|
---|
| 659 | }
|
---|
| 660 |
|
---|
| 661 | return null; // FileView superclass will do the default
|
---|
| 662 | }
|
---|
| 663 |
|
---|
| 664 | // The name of the file.
|
---|
| 665 | public String getName(File f) {
|
---|
| 666 | if(!f.equals(previous)) {
|
---|
| 667 | previous = f;
|
---|
| 668 | // no idea if it's a collection or not, calculate this next time
|
---|
| 669 | previousWasCollection = false;
|
---|
| 670 | }
|
---|
| 671 | return f.getName();
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | // A human readable description of the type of the file.
|
---|
| 675 | public String getTypeDescription(File f) {
|
---|
| 676 | if(f.equals(previous) && previousWasCollection) {
|
---|
| 677 | return "collection";
|
---|
| 678 | }
|
---|
| 679 | if(isCollectionBase(f)) {
|
---|
| 680 | return "collection";
|
---|
| 681 | }
|
---|
| 682 | // else
|
---|
| 683 | return "not a collection";
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 | // Whether the directory is traversable or not.
|
---|
| 687 | public Boolean isTraversable(File f) {
|
---|
| 688 | if(f.equals(previous) && previousWasCollection) {
|
---|
| 689 | return Boolean.FALSE;
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | if(isCollectionBase(f)) {
|
---|
| 693 | return Boolean.FALSE;
|
---|
| 694 | }
|
---|
| 695 |
|
---|
| 696 | if(f.isFile()) { // not traversable
|
---|
| 697 | return Boolean.FALSE;
|
---|
| 698 | }
|
---|
| 699 | // any other kind of directory is traversable
|
---|
| 700 | return Boolean.TRUE;
|
---|
| 701 | }
|
---|
| 702 |
|
---|
| 703 |
|
---|
| 704 | /** returns false for collect groups and collect dirs. */
|
---|
| 705 | private boolean isCollectionBase(File f) {
|
---|
| 706 | previous = f;
|
---|
| 707 | previousWasCollection = false;
|
---|
| 708 |
|
---|
| 709 | if(!f.isFile()) {
|
---|
| 710 | // If the directory has a etc/collect.cfg file then it looks like a collection
|
---|
| 711 | File collect_cfg_file = new File(f, configfile_name);
|
---|
| 712 | if (collect_cfg_file.exists()) {
|
---|
| 713 | // Check for group coll: Check the collect.cfg for collectgroup=true
|
---|
| 714 | BasicCollectionConfiguration config = new BasicCollectionConfiguration(collect_cfg_file);
|
---|
| 715 | if (!config.getCollectGroup().equals("true")) {
|
---|
| 716 | previousWasCollection = true;
|
---|
| 717 | }
|
---|
| 718 | }
|
---|
| 719 | }
|
---|
| 720 | return previousWasCollection;
|
---|
| 721 | }
|
---|
| 722 |
|
---|
| 723 | }
|
---|
[4803] | 724 | }
|
---|
[6041] | 725 |
|
---|
| 726 |
|
---|
| 727 |
|
---|