Treat an empty index file as no index file.
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectFilesPage.java
1 /*
2  * jSite - a tool for uploading websites into Freenet
3  * Copyright (C) 2006 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package de.todesbaum.jsite.gui;
21
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.FlowLayout;
25 import java.awt.GridBagConstraints;
26 import java.awt.GridBagLayout;
27 import java.awt.Insets;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.KeyEvent;
31 import java.text.MessageFormat;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Set;
38
39 import javax.swing.AbstractAction;
40 import javax.swing.Action;
41 import javax.swing.DefaultComboBoxModel;
42 import javax.swing.JButton;
43 import javax.swing.JCheckBox;
44 import javax.swing.JComboBox;
45 import javax.swing.JComponent;
46 import javax.swing.JLabel;
47 import javax.swing.JList;
48 import javax.swing.JOptionPane;
49 import javax.swing.JPanel;
50 import javax.swing.JScrollPane;
51 import javax.swing.JSpinner;
52 import javax.swing.JTextField;
53 import javax.swing.ListSelectionModel;
54 import javax.swing.SpinnerNumberModel;
55 import javax.swing.SwingUtilities;
56 import javax.swing.border.EmptyBorder;
57 import javax.swing.event.ChangeEvent;
58 import javax.swing.event.ChangeListener;
59 import javax.swing.event.DocumentEvent;
60 import javax.swing.event.DocumentListener;
61 import javax.swing.event.ListSelectionEvent;
62 import javax.swing.event.ListSelectionListener;
63 import javax.swing.text.BadLocationException;
64 import javax.swing.text.Document;
65
66 import de.todesbaum.jsite.application.FileOption;
67 import de.todesbaum.jsite.application.Project;
68 import de.todesbaum.jsite.i18n.I18n;
69 import de.todesbaum.jsite.i18n.I18nContainer;
70 import de.todesbaum.util.mime.DefaultMIMETypes;
71 import de.todesbaum.util.swing.TLabel;
72 import de.todesbaum.util.swing.TWizard;
73 import de.todesbaum.util.swing.TWizardPage;
74
75 /**
76  * Wizard page that lets the user manage the files of a project.
77  *
78  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
79  */
80 public class ProjectFilesPage extends TWizardPage implements ActionListener, ListSelectionListener, DocumentListener, FileScannerListener, ChangeListener {
81
82         /** The project. */
83         private Project project;
84
85         /** The “scan files” action. */
86         private Action scanAction;
87
88         /** The “edit container” action. */
89         private Action editContainerAction;
90
91         /** The “add container” action. */
92         private Action addContainerAction;
93
94         /** The “delete container” action. */
95         protected Action deleteContainerAction;
96
97         /** The list of project files. */
98         private JList projectFileList;
99
100         /** The “default file” checkbox. */
101         private JCheckBox defaultFileCheckBox;
102
103         /** The “insert” checkbox. */
104         private JCheckBox fileOptionsInsertCheckBox;
105
106         /** The “custom key” textfield. */
107         private JTextField fileOptionsCustomKeyTextField;
108
109         /** The “mime type” combo box. */
110         private JComboBox fileOptionsMIMETypeComboBox;
111
112         /** The “mime type” combo box model. */
113         private DefaultComboBoxModel containerComboBoxModel;
114
115         /** The “container” combo box. */
116         private JComboBox fileOptionsContainerComboBox;
117
118         /** The “edition replacement range” spinner. */
119         private JSpinner replaceEditionRangeSpinner;
120
121         /** The “replacement” check box. */
122         private JCheckBox replacementCheckBox;
123
124         /**
125          * Creates a new project file page.
126          *
127          * @param wizard
128          *            The wizard the page belongs to
129          */
130         public ProjectFilesPage(final TWizard wizard) {
131                 super(wizard);
132                 pageInit();
133         }
134
135         /**
136          * Initializes the page and all its actions and components.
137          */
138         private void pageInit() {
139                 createActions();
140                 setLayout(new BorderLayout(12, 12));
141                 add(createProjectFilesPanel(), BorderLayout.CENTER);
142         }
143
144         /**
145          * Creates all actions.
146          */
147         private void createActions() {
148                 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
149
150                         @SuppressWarnings("synthetic-access")
151                         public void actionPerformed(ActionEvent actionEvent) {
152                                 actionScan();
153                         }
154                 };
155                 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
156                 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
157
158                 addContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.add-container")) {
159
160                         @SuppressWarnings("synthetic-access")
161                         public void actionPerformed(ActionEvent actionEvent) {
162                                 actionAddContainer();
163                         }
164                 };
165                 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
166                 addContainerAction.setEnabled(false);
167
168                 editContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.edit-container")) {
169
170                         @SuppressWarnings("synthetic-access")
171                         public void actionPerformed(ActionEvent actionEvent) {
172                                 actionEditContainer();
173                         }
174                 };
175                 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
176                 editContainerAction.setEnabled(false);
177
178                 deleteContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.delete-container")) {
179
180                         @SuppressWarnings("synthetic-access")
181                         public void actionPerformed(ActionEvent actionEvent) {
182                                 actionDeleteContainer();
183                         }
184                 };
185                 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
186                 deleteContainerAction.setEnabled(false);
187
188                 I18nContainer.getInstance().registerRunnable(new Runnable() {
189
190                         @SuppressWarnings("synthetic-access")
191                         public void run() {
192                                 scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
193                                 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
194                                 addContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.add-container"));
195                                 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
196                                 editContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.edit-container"));
197                                 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
198                                 deleteContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.delete-container"));
199                                 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
200                         }
201                 });
202         }
203
204         /**
205          * {@inheritDoc}
206          */
207         @Override
208         public void pageAdded(TWizard wizard) {
209                 actionScan();
210                 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
211                 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
212                 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
213         }
214
215         /**
216          * Creates the panel contains the project file list and options.
217          *
218          * @return The created panel
219          */
220         private JComponent createProjectFilesPanel() {
221                 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
222
223                 projectFileList = new JList();
224                 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
225                 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
226                 projectFileList.addListSelectionListener(this);
227
228                 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
229
230                 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
231                 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
232                 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
233                 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
234
235                 fileOptionsPanel.add(new JButton(scanAction), new GridBagConstraints(0, 0, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
236
237                 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
238                 fileOptionsPanel.add(fileOptionsLabel, new GridBagConstraints(0, 1, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
239
240                 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
241                 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
242                 defaultFileCheckBox.setName("default-file");
243                 defaultFileCheckBox.addActionListener(this);
244                 defaultFileCheckBox.setEnabled(false);
245
246                 fileOptionsPanel.add(defaultFileCheckBox, new GridBagConstraints(0, 2, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
247
248                 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
249                 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
250                 fileOptionsInsertCheckBox.setName("insert");
251                 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
252                 fileOptionsInsertCheckBox.addActionListener(this);
253                 fileOptionsInsertCheckBox.setEnabled(false);
254
255                 fileOptionsPanel.add(fileOptionsInsertCheckBox, new GridBagConstraints(0, 3, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
256
257                 fileOptionsCustomKeyTextField = new JTextField(45);
258                 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
259                 fileOptionsCustomKeyTextField.setEnabled(false);
260                 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
261
262                 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
263                 fileOptionsPanel.add(customKeyLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
264                 fileOptionsPanel.add(fileOptionsCustomKeyTextField, new GridBagConstraints(1, 4, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
265
266                 fileOptionsMIMETypeComboBox = new JComboBox(DefaultMIMETypes.getAllMIMETypes());
267                 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
268                 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
269                 fileOptionsMIMETypeComboBox.addActionListener(this);
270                 fileOptionsMIMETypeComboBox.setEditable(true);
271                 fileOptionsMIMETypeComboBox.setEnabled(false);
272
273                 final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
274                 fileOptionsPanel.add(mimeTypeLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
275                 fileOptionsPanel.add(fileOptionsMIMETypeComboBox, new GridBagConstraints(1, 5, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
276
277                 containerComboBoxModel = new DefaultComboBoxModel();
278                 fileOptionsContainerComboBox = new JComboBox(containerComboBoxModel);
279                 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
280                 fileOptionsContainerComboBox.setName("project-files.container");
281                 fileOptionsContainerComboBox.addActionListener(this);
282                 fileOptionsContainerComboBox.setEnabled(false);
283                 fileOptionsContainerComboBox.setVisible(false);
284
285                 final TLabel containerLabel = new TLabel(I18n.getMessage("jsite.project-files.container") + ":", KeyEvent.VK_C, fileOptionsContainerComboBox);
286                 containerLabel.setVisible(false);
287                 JButton addContainerButton = new JButton(addContainerAction);
288                 addContainerButton.setVisible(false);
289                 JButton editContainerButton = new JButton(editContainerAction);
290                 editContainerButton.setVisible(false);
291                 JButton deleteContainerButton = new JButton(deleteContainerAction);
292                 deleteContainerButton.setVisible(false);
293                 fileOptionsPanel.add(containerLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
294                 fileOptionsPanel.add(fileOptionsContainerComboBox, new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
295                 fileOptionsPanel.add(addContainerButton, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
296                 fileOptionsPanel.add(editContainerButton, new GridBagConstraints(3, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
297                 fileOptionsPanel.add(deleteContainerButton, new GridBagConstraints(4, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
298
299                 JPanel fileOptionsReplacementPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 6, 6));
300                 fileOptionsReplacementPanel.setBorder(new EmptyBorder(-6, -6, -6, -6));
301
302                 replacementCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.replacement"));
303                 replacementCheckBox.setName("project-files.replace-edition");
304                 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
305                 replacementCheckBox.addActionListener(this);
306                 replacementCheckBox.setEnabled(false);
307                 replacementCheckBox.setVisible(false);
308                 fileOptionsReplacementPanel.add(replacementCheckBox);
309
310                 replaceEditionRangeSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
311                 replaceEditionRangeSpinner.setName("project-files.replace-edition-range");
312                 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
313                 replaceEditionRangeSpinner.addChangeListener(this);
314                 replaceEditionRangeSpinner.setEnabled(false);
315                 replaceEditionRangeSpinner.setVisible(false);
316                 final JLabel editionRangeLabel = new JLabel(I18n.getMessage("jsite.project-files.replacement.edition-range"));
317                 editionRangeLabel.setVisible(false);
318                 fileOptionsReplacementPanel.add(editionRangeLabel);
319                 fileOptionsReplacementPanel.add(replaceEditionRangeSpinner);
320
321                 fileOptionsPanel.add(fileOptionsReplacementPanel, new GridBagConstraints(0, 7, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
322
323                 I18nContainer.getInstance().registerRunnable(new Runnable() {
324
325                         @SuppressWarnings("synthetic-access")
326                         public void run() {
327                                 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
328                                 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
329                                 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
330                                 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
331                                 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
332                                 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
333                                 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
334                                 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
335                                 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
336                                 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
337                                 containerLabel.setText(I18n.getMessage("jsite.project-files.container") + ":");
338                                 replacementCheckBox.setText(I18n.getMessage("jsite.project-files.replacement"));
339                                 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
340                                 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
341                                 editionRangeLabel.setText(I18n.getMessage("jsite.project-files.replacement.edition-range"));
342                         }
343                 });
344
345                 return projectFilesPanel;
346         }
347
348         /**
349          * Sets the project whose files to manage.
350          *
351          * @param project
352          *            The project whose files to manage
353          */
354         public void setProject(final Project project) {
355                 this.project = project;
356                 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
357                 setDescription(I18n.getMessage("jsite.project-files.description"));
358                 I18nContainer.getInstance().registerRunnable(new Runnable() {
359
360                         public void run() {
361                                 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
362                                 setDescription(I18n.getMessage("jsite.project-files.description"));
363                         }
364                 });
365         }
366
367         /**
368          * Returns a list of all project files.
369          *
370          * @return All project files
371          */
372         private List<String> getProjectFiles() {
373                 List<String> files = new ArrayList<String>();
374                 for (int index = 0, size = projectFileList.getModel().getSize(); index < size; index++) {
375                         files.add((String) projectFileList.getModel().getElementAt(index));
376                 }
377                 return files;
378         }
379
380         /**
381          * Updates the container combo box model.
382          */
383         private void rebuildContainerComboBox() {
384                 /* scan files for containers */
385                 List<String> files = getProjectFiles();
386                 List<String> containers = new ArrayList<String>(); // ComboBoxModel
387                 // sucks. No
388                 // contains()!
389                 containers.add("");
390                 for (String filename : files) {
391                         String container = project.getFileOption(filename).getContainer();
392                         if (!containers.contains(container)) {
393                                 containers.add(container);
394                         }
395                 }
396                 Collections.sort(containers);
397                 containerComboBoxModel.removeAllElements();
398                 for (String container : containers) {
399                         containerComboBoxModel.addElement(container);
400                 }
401         }
402
403         //
404         // ACTIONS
405         //
406
407         /**
408          * Rescans the project’s files.
409          */
410         private void actionScan() {
411                 projectFileList.clearSelection();
412                 projectFileList.setListData(new Object[0]);
413
414                 wizard.setNextEnabled(false);
415                 wizard.setPreviousEnabled(false);
416                 wizard.setQuitEnabled(false);
417
418                 FileScanner fileScanner = new FileScanner(project);
419                 fileScanner.addFileScannerListener(this);
420                 new Thread(fileScanner).start();
421         }
422
423         /**
424          * Adds a container.
425          */
426         private void actionAddContainer() {
427                 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.add-container.message") + ":", null, JOptionPane.INFORMATION_MESSAGE);
428                 if (containerName == null) {
429                         return;
430                 }
431                 containerName = containerName.trim();
432                 String filename = (String) projectFileList.getSelectedValue();
433                 FileOption fileOption = project.getFileOption(filename);
434                 fileOption.setContainer(containerName);
435                 rebuildContainerComboBox();
436                 fileOptionsContainerComboBox.setSelectedItem(containerName);
437         }
438
439         /**
440          * Edits the container.
441          */
442         private void actionEditContainer() {
443                 String selectedFilename = (String) projectFileList.getSelectedValue();
444                 FileOption fileOption = project.getFileOption(selectedFilename);
445                 String oldContainerName = fileOption.getContainer();
446                 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.edit-container.message") + ":", oldContainerName);
447                 if (containerName == null) {
448                         return;
449                 }
450                 if (containerName.equals("")) {
451                         fileOption.setContainer("");
452                         fileOptionsContainerComboBox.setSelectedItem("");
453                         return;
454                 }
455                 List<String> files = getProjectFiles();
456                 for (String filename : files) {
457                         fileOption = project.getFileOption(filename);
458                         if (fileOption.getContainer().equals(oldContainerName)) {
459                                 fileOption.setContainer(containerName);
460                         }
461                 }
462                 rebuildContainerComboBox();
463                 fileOptionsContainerComboBox.setSelectedItem(containerName);
464         }
465
466         /**
467          * Deletes the container.
468          */
469         private void actionDeleteContainer() {
470                 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.action.delete-container.message"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
471                         String containerName = (String) fileOptionsContainerComboBox.getSelectedItem();
472                         List<String> files = getProjectFiles();
473                         for (String filename : files) {
474                                 FileOption fileOption = project.getFileOption(filename);
475                                 if (fileOption.getContainer().equals(containerName)) {
476                                         fileOption.setContainer("");
477                                 }
478                         }
479                         fileOptionsContainerComboBox.setSelectedItem("");
480                 }
481         }
482
483         /**
484          * {@inheritDoc}
485          * <p>
486          * Updates the file list.
487          */
488         public void fileScannerFinished(FileScanner fileScanner) {
489                 final boolean error = fileScanner.isError();
490                 if (!error) {
491                         final List<String> files = fileScanner.getFiles();
492                         SwingUtilities.invokeLater(new Runnable() {
493
494                                 @SuppressWarnings("synthetic-access")
495                                 public void run() {
496                                         projectFileList.setListData(files.toArray(new String[files.size()]));
497                                         projectFileList.clearSelection();
498                                         rebuildContainerComboBox();
499                                 }
500                         });
501                         Set<String> entriesToRemove = new HashSet<String>();
502                         Iterator<String> filenames = project.getFileOptions().keySet().iterator();
503                         while (filenames.hasNext()) {
504                                 String filename = filenames.next();
505                                 if (!files.contains(filename)) {
506                                         entriesToRemove.add(filename);
507                                 }
508                         }
509                         for (String filename : entriesToRemove) {
510                                 project.setFileOption(filename, null);
511                         }
512                 } else {
513                         JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
514                 }
515                 SwingUtilities.invokeLater(new Runnable() {
516
517                         @SuppressWarnings("synthetic-access")
518                         public void run() {
519                                 wizard.setPreviousEnabled(true);
520                                 wizard.setNextEnabled(!error);
521                                 wizard.setQuitEnabled(true);
522                         }
523                 });
524         }
525
526         //
527         // INTERFACE ActionListener
528         //
529
530         /**
531          * {@inheritDoc}
532          */
533         public void actionPerformed(ActionEvent actionEvent) {
534                 String filename = (String) projectFileList.getSelectedValue();
535                 if (filename == null) {
536                         return;
537                 }
538                 FileOption fileOption = project.getFileOption(filename);
539                 Object source = actionEvent.getSource();
540                 if (source instanceof JCheckBox) {
541                         JCheckBox checkBox = (JCheckBox) source;
542                         if ("default-file".equals(checkBox.getName())) {
543                                 if (checkBox.isSelected()) {
544                                         project.setIndexFile(filename);
545                                 } else {
546                                         project.setIndexFile(null);
547                                 }
548                         } else if ("insert".equals(checkBox.getName())) {
549                                 boolean isInsert = checkBox.isSelected();
550                                 fileOptionsCustomKeyTextField.setEnabled(!isInsert);
551                                 fileOption.setInsert(isInsert);
552                                 if (!isInsert) {
553                                         fileOptionsContainerComboBox.setSelectedItem("");
554                                 }
555                         } else if ("project-files.replace-edition".equals(checkBox.getName())) {
556                                 boolean replaceEdition = checkBox.isSelected();
557                                 fileOption.setReplaceEdition(replaceEdition);
558                                 replaceEditionRangeSpinner.setEnabled(replaceEdition);
559                         }
560                 } else if (source instanceof JComboBox) {
561                         JComboBox comboBox = (JComboBox) source;
562                         if ("project-files.mime-type".equals(comboBox.getName())) {
563                                 fileOption.setMimeType((String) comboBox.getSelectedItem());
564                         } else if ("project-files.container".equals(comboBox.getName())) {
565                                 String containerName = (String) comboBox.getSelectedItem();
566                                 fileOption.setContainer(containerName);
567                                 boolean enabled = !"".equals(containerName);
568                                 editContainerAction.setEnabled(enabled);
569                                 deleteContainerAction.setEnabled(enabled);
570                                 if (enabled) {
571                                         fileOptionsInsertCheckBox.setSelected(true);
572                                 }
573                         }
574                 }
575         }
576
577         //
578         // INTERFACE ListSelectionListener
579         //
580
581         /**
582          * {@inheritDoc}
583          */
584         public void valueChanged(ListSelectionEvent e) {
585                 String filename = (String) projectFileList.getSelectedValue();
586                 boolean enabled = filename != null;
587                 boolean insert = fileOptionsInsertCheckBox.isSelected();
588                 defaultFileCheckBox.setEnabled(enabled);
589                 fileOptionsInsertCheckBox.setEnabled(enabled);
590                 fileOptionsCustomKeyTextField.setEnabled(enabled && !insert);
591                 fileOptionsMIMETypeComboBox.setEnabled(enabled);
592                 fileOptionsContainerComboBox.setEnabled(enabled);
593                 addContainerAction.setEnabled(enabled);
594                 editContainerAction.setEnabled(enabled);
595                 deleteContainerAction.setEnabled(enabled);
596                 replacementCheckBox.setEnabled(enabled && insert);
597                 if (filename != null) {
598                         FileOption fileOption = project.getFileOption(filename);
599                         defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
600                         fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
601                         fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
602                         fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
603                         fileOptionsContainerComboBox.setSelectedItem(fileOption.getContainer());
604                         replacementCheckBox.setSelected(fileOption.getReplaceEdition());
605                         replaceEditionRangeSpinner.setValue(fileOption.getEditionRange());
606                         replaceEditionRangeSpinner.setEnabled(fileOption.getReplaceEdition());
607                 } else {
608                         defaultFileCheckBox.setSelected(false);
609                         fileOptionsInsertCheckBox.setSelected(true);
610                         fileOptionsCustomKeyTextField.setText("CHK@");
611                         fileOptionsMIMETypeComboBox.getModel().setSelectedItem(DefaultMIMETypes.DEFAULT_MIME_TYPE);
612                         fileOptionsContainerComboBox.setSelectedItem("");
613                         replacementCheckBox.setSelected(false);
614                         replaceEditionRangeSpinner.setValue(0);
615                 }
616         }
617
618         //
619         // INTERFACE DocumentListener
620         //
621
622         /**
623          * Updates the options of the currently selected file with the changes made
624          * in the “custom key” textfield.
625          *
626          * @param documentEvent
627          *            The document event to process
628          */
629         private void processDocumentUpdate(DocumentEvent documentEvent) {
630                 String filename = (String) projectFileList.getSelectedValue();
631                 if (filename == null) {
632                         return;
633                 }
634                 FileOption fileOption = project.getFileOption(filename);
635                 Document document = documentEvent.getDocument();
636                 try {
637                         String text = document.getText(0, document.getLength());
638                         fileOption.setCustomKey(text);
639                 } catch (BadLocationException ble1) {
640                         /* ignore. */
641                 }
642         }
643
644         /**
645          * {@inheritDoc}
646          */
647         public void changedUpdate(DocumentEvent documentEvent) {
648                 processDocumentUpdate(documentEvent);
649         }
650
651         /**
652          * {@inheritDoc}
653          */
654         public void insertUpdate(DocumentEvent documentEvent) {
655                 processDocumentUpdate(documentEvent);
656         }
657
658         /**
659          * {@inheritDoc}
660          */
661         public void removeUpdate(DocumentEvent documentEvent) {
662                 processDocumentUpdate(documentEvent);
663         }
664
665         //
666         // INTERFACE ChangeListener
667         //
668
669         /**
670          * {@inheritDoc}
671          */
672         public void stateChanged(ChangeEvent changeEvent) {
673                 String filename = (String) projectFileList.getSelectedValue();
674                 if (filename == null) {
675                         return;
676                 }
677                 FileOption fileOption = project.getFileOption(filename);
678                 Object source = changeEvent.getSource();
679                 if (source instanceof JSpinner) {
680                         JSpinner spinner = (JSpinner) source;
681                         fileOption.setEditionRange((Integer) spinner.getValue());
682                 }
683         }
684
685 }