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