9514f5d5a4b57323ce1b90b98cb13d31e8c6430c
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectFilesPage.java
1 /*
2  * jSite - ProjectFilesPage.java - Copyright © 2006–2011 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.text.MessageFormat;
30 import java.util.HashSet;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.Set;
34
35 import javax.swing.AbstractAction;
36 import javax.swing.Action;
37 import javax.swing.JButton;
38 import javax.swing.JCheckBox;
39 import javax.swing.JComboBox;
40 import javax.swing.JComponent;
41 import javax.swing.JLabel;
42 import javax.swing.JList;
43 import javax.swing.JOptionPane;
44 import javax.swing.JPanel;
45 import javax.swing.JScrollPane;
46 import javax.swing.JTextField;
47 import javax.swing.ListSelectionModel;
48 import javax.swing.SwingUtilities;
49 import javax.swing.event.DocumentEvent;
50 import javax.swing.event.DocumentListener;
51 import javax.swing.event.ListSelectionEvent;
52 import javax.swing.event.ListSelectionListener;
53 import javax.swing.text.BadLocationException;
54 import javax.swing.text.Document;
55
56 import de.todesbaum.jsite.application.FileOption;
57 import de.todesbaum.jsite.application.Project;
58 import de.todesbaum.jsite.gui.FileScanner.ScannedFile;
59 import de.todesbaum.jsite.i18n.I18n;
60 import de.todesbaum.jsite.i18n.I18nContainer;
61 import de.todesbaum.util.mime.DefaultMIMETypes;
62 import de.todesbaum.util.swing.TLabel;
63 import de.todesbaum.util.swing.TWizard;
64 import de.todesbaum.util.swing.TWizardPage;
65
66 /**
67  * Wizard page that lets the user manage the files of a project.
68  *
69  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
70  */
71 public class ProjectFilesPage extends TWizardPage implements ActionListener, ListSelectionListener, DocumentListener, FileScannerListener {
72
73         /** The project. */
74         private Project project;
75
76         /** The “scan files” action. */
77         private Action scanAction;
78
79         /** The “ignore hidden files” checkbox. */
80         private JCheckBox ignoreHiddenFilesCheckBox;
81
82         /** The list of project files. */
83         private JList projectFileList;
84
85         /** The “default file” checkbox. */
86         private JCheckBox defaultFileCheckBox;
87
88         /** The “insert” checkbox. */
89         private JCheckBox fileOptionsInsertCheckBox;
90
91         /** The “insert redirect” checkbox. */
92         private JCheckBox fileOptionsInsertRedirectCheckBox;
93
94         /** The “custom key” textfield. */
95         private JTextField fileOptionsCustomKeyTextField;
96
97         /** The “rename” check box. */
98         private JCheckBox fileOptionsRenameCheckBox;
99
100         /** The “new name” text field. */
101         private JTextField fileOptionsRenameTextField;
102
103         /** The “mime type” combo box. */
104         private JComboBox fileOptionsMIMETypeComboBox;
105
106         /**
107          * Creates a new project file page.
108          *
109          * @param wizard
110          *            The wizard the page belongs to
111          */
112         public ProjectFilesPage(final TWizard wizard) {
113                 super(wizard);
114                 pageInit();
115         }
116
117         /**
118          * Initializes the page and all its actions and components.
119          */
120         private void pageInit() {
121                 createActions();
122                 setLayout(new BorderLayout(12, 12));
123                 add(createProjectFilesPanel(), BorderLayout.CENTER);
124         }
125
126         /**
127          * Creates all actions.
128          */
129         private void createActions() {
130                 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
131
132                         @SuppressWarnings("synthetic-access")
133                         public void actionPerformed(ActionEvent actionEvent) {
134                                 actionScan();
135                         }
136                 };
137                 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
138                 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
139
140                 I18nContainer.getInstance().registerRunnable(new Runnable() {
141
142                         @SuppressWarnings("synthetic-access")
143                         public void run() {
144                                 scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
145                                 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
146                         }
147                 });
148         }
149
150         /**
151          * {@inheritDoc}
152          */
153         @Override
154         public void pageAdded(TWizard wizard) {
155                 actionScan();
156                 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
157                 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
158                 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
159         }
160
161         /**
162          * Creates the panel contains the project file list and options.
163          *
164          * @return The created panel
165          */
166         private JComponent createProjectFilesPanel() {
167                 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
168
169                 projectFileList = new JList();
170                 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
171                 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
172                 projectFileList.addListSelectionListener(this);
173
174                 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
175
176                 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
177                 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
178                 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
179                 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
180
181                 ignoreHiddenFilesCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
182                 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.ignore-hidden-files.tooltip"));
183                 ignoreHiddenFilesCheckBox.setName("ignore-hidden-files");
184                 ignoreHiddenFilesCheckBox.addActionListener(this);
185                 fileOptionsPanel.add(ignoreHiddenFilesCheckBox, new GridBagConstraints(0, 0, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
186
187                 fileOptionsPanel.add(new JButton(scanAction), new GridBagConstraints(0, 1, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
188
189                 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
190                 fileOptionsPanel.add(fileOptionsLabel, new GridBagConstraints(0, 2, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
191
192                 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
193                 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
194                 defaultFileCheckBox.setName("default-file");
195                 defaultFileCheckBox.addActionListener(this);
196                 defaultFileCheckBox.setEnabled(false);
197
198                 fileOptionsPanel.add(defaultFileCheckBox, new GridBagConstraints(0, 3, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
199
200                 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
201                 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
202                 fileOptionsInsertCheckBox.setName("insert");
203                 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
204                 fileOptionsInsertCheckBox.addActionListener(this);
205                 fileOptionsInsertCheckBox.setEnabled(false);
206
207                 fileOptionsPanel.add(fileOptionsInsertCheckBox, new GridBagConstraints(0, 4, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
208
209                 fileOptionsCustomKeyTextField = new JTextField(45);
210                 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
211                 fileOptionsCustomKeyTextField.setEnabled(false);
212                 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
213
214                 fileOptionsInsertRedirectCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert-redirect"), false);
215                 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
216                 fileOptionsInsertRedirectCheckBox.setName("insert-redirect");
217                 fileOptionsInsertRedirectCheckBox.setMnemonic(KeyEvent.VK_R);
218                 fileOptionsInsertRedirectCheckBox.addActionListener(this);
219                 fileOptionsInsertRedirectCheckBox.setEnabled(false);
220
221                 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
222                 fileOptionsPanel.add(fileOptionsInsertRedirectCheckBox, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
223                 fileOptionsPanel.add(customKeyLabel, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 6, 0, 0), 0, 0));
224                 fileOptionsPanel.add(fileOptionsCustomKeyTextField, new GridBagConstraints(2, 5, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
225
226                 fileOptionsRenameCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.rename"), false);
227                 fileOptionsRenameCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.rename.tooltip"));
228                 fileOptionsRenameCheckBox.setName("rename");
229                 fileOptionsRenameCheckBox.setMnemonic(KeyEvent.VK_N);
230                 fileOptionsRenameCheckBox.addActionListener(this);
231                 fileOptionsRenameCheckBox.setEnabled(false);
232
233                 fileOptionsRenameTextField = new JTextField();
234                 fileOptionsRenameTextField.setEnabled(false);
235                 fileOptionsRenameTextField.getDocument().addDocumentListener(new DocumentListener() {
236
237                         @SuppressWarnings("synthetic-access")
238                         private void storeText(DocumentEvent documentEvent) {
239                                 FileOption fileOption = getSelectedFile();
240                                 Document document = documentEvent.getDocument();
241                                 int documentLength = document.getLength();
242                                 try {
243                                         fileOption.setChangedName(document.getText(0, documentLength).trim());
244                                 } catch (BadLocationException ble1) {
245                                         /* ignore, it should never happen. */
246                                 }
247                         }
248
249                         public void changedUpdate(DocumentEvent documentEvent) {
250                                 storeText(documentEvent);
251                         }
252
253                         public void insertUpdate(DocumentEvent documentEvent) {
254                                 storeText(documentEvent);
255                         }
256
257                         public void removeUpdate(DocumentEvent documentEvent) {
258                                 storeText(documentEvent);
259                         }
260
261                 });
262
263                 fileOptionsPanel.add(fileOptionsRenameCheckBox, new GridBagConstraints(0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
264                 fileOptionsPanel.add(fileOptionsRenameTextField, new GridBagConstraints(2, 6, 3, 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, 7, 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, 7, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
276
277                 I18nContainer.getInstance().registerRunnable(new Runnable() {
278
279                         @SuppressWarnings("synthetic-access")
280                         public void run() {
281                                 ignoreHiddenFilesCheckBox.setText(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
282                                 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.projet-files.ignore-hidden-files.tooltip"));
283                                 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
284                                 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
285                                 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
286                                 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
287                                 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
288                                 fileOptionsInsertRedirectCheckBox.setText(I18n.getMessage("jsite.project-files.insert-redirect"));
289                                 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
290                                 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
291                                 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
292                                 fileOptionsRenameCheckBox.setText("jsite.project-files.rename");
293                                 fileOptionsRenameCheckBox.setToolTipText("jsite.project-files.rename.tooltip");
294                                 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
295                                 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
296                         }
297                 });
298
299                 return projectFilesPanel;
300         }
301
302         /**
303          * Sets the project whose files to manage.
304          *
305          * @param project
306          *            The project whose files to manage
307          */
308         public void setProject(final Project project) {
309                 this.project = project;
310                 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
311                 setDescription(I18n.getMessage("jsite.project-files.description"));
312                 ignoreHiddenFilesCheckBox.setSelected(project.isIgnoreHiddenFiles());
313                 I18nContainer.getInstance().registerRunnable(new Runnable() {
314
315                         public void run() {
316                                 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
317                                 setDescription(I18n.getMessage("jsite.project-files.description"));
318                         }
319                 });
320         }
321
322         //
323         // ACTIONS
324         //
325
326         /**
327          * Rescans the project’s files.
328          */
329         private void actionScan() {
330                 projectFileList.clearSelection();
331                 projectFileList.setListData(new Object[0]);
332
333                 wizard.setNextEnabled(false);
334                 wizard.setPreviousEnabled(false);
335                 wizard.setQuitEnabled(false);
336
337                 FileScanner fileScanner = new FileScanner(project);
338                 fileScanner.addFileScannerListener(this);
339                 new Thread(fileScanner).start();
340         }
341
342         /**
343          * {@inheritDoc}
344          * <p>
345          * Updates the file list.
346          */
347         public void fileScannerFinished(FileScanner fileScanner) {
348                 final boolean error = fileScanner.isError();
349                 if (!error) {
350                         final List<ScannedFile> files = fileScanner.getFiles();
351                         SwingUtilities.invokeLater(new Runnable() {
352
353                                 @SuppressWarnings("synthetic-access")
354                                 public void run() {
355                                         String[] filenames = new String[files.size()];
356                                         for (int fileIndex = 0; fileIndex < files.size(); ++fileIndex) {
357                                                 filenames[fileIndex] = files.get(fileIndex).getFilename();
358                                         }
359                                         projectFileList.setListData(filenames);
360                                         projectFileList.clearSelection();
361                                 }
362                         });
363                         Set<String> entriesToRemove = new HashSet<String>();
364                         Iterator<String> filenames = new HashSet<String>(project.getFileOptions().keySet()).iterator();
365                         while (filenames.hasNext()) {
366                                 String filename = filenames.next();
367                                 if (!files.contains(filename)) {
368                                         entriesToRemove.add(filename);
369                                 }
370                         }
371                         for (String filename : entriesToRemove) {
372                                 project.setFileOption(filename, null);
373                         }
374                 } else {
375                         JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
376                 }
377                 SwingUtilities.invokeLater(new Runnable() {
378
379                         @SuppressWarnings("synthetic-access")
380                         public void run() {
381                                 wizard.setPreviousEnabled(true);
382                                 wizard.setNextEnabled(!error);
383                                 wizard.setQuitEnabled(true);
384                         }
385                 });
386         }
387
388         /**
389          * Returns the {@link FileOption file options} for the currently selected
390          * file.
391          *
392          * @return The {@link FileOption}s for the selected file, or {@code null} if
393          *         no file is selected
394          */
395         private FileOption getSelectedFile() {
396                 String filename = (String) projectFileList.getSelectedValue();
397                 if (filename == null) {
398                         return null;
399                 }
400                 return project.getFileOption(filename);
401         }
402
403         //
404         // INTERFACE ActionListener
405         //
406
407         /**
408          * {@inheritDoc}
409          */
410         public void actionPerformed(ActionEvent actionEvent) {
411                 Object source = actionEvent.getSource();
412                 if ((source instanceof JCheckBox) && ("ignore-hidden-files".equals(((JCheckBox) source).getName()))) {
413                         project.setIgnoreHiddenFiles(((JCheckBox) source).isSelected());
414                         actionScan();
415                         return;
416                 }
417                 String filename = (String) projectFileList.getSelectedValue();
418                 if (filename == null) {
419                         return;
420                 }
421                 FileOption fileOption = project.getFileOption(filename);
422                 if (source instanceof JCheckBox) {
423                         JCheckBox checkBox = (JCheckBox) source;
424                         if ("default-file".equals(checkBox.getName())) {
425                                 if (checkBox.isSelected()) {
426                                         if (filename.indexOf('/') > -1) {
427                                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.invalid-default-file"), null, JOptionPane.ERROR_MESSAGE);
428                                                 checkBox.setSelected(false);
429                                         } else {
430                                                 project.setIndexFile(filename);
431                                         }
432                                 } else {
433                                         if (filename.equals(project.getIndexFile())) {
434                                                 project.setIndexFile(null);
435                                         }
436                                 }
437                         } else if ("insert".equals(checkBox.getName())) {
438                                 boolean isInsert = checkBox.isSelected();
439                                 fileOption.setInsert(isInsert);
440                                 fileOptionsInsertRedirectCheckBox.setEnabled(!isInsert);
441                         } else if ("insert-redirect".equals(checkBox.getName())) {
442                                 boolean isInsertRedirect = checkBox.isSelected();
443                                 fileOption.setInsertRedirect(isInsertRedirect);
444                                 fileOptionsCustomKeyTextField.setEnabled(isInsertRedirect);
445                         } else if ("rename".equals(checkBox.getName())) {
446                                 boolean isRenamed = checkBox.isSelected();
447                                 fileOptionsRenameTextField.setEnabled(isRenamed);
448                                 fileOption.setChangedName(isRenamed ? fileOptionsRenameTextField.getText() : "");
449                         }
450                 } else if (source instanceof JComboBox) {
451                         JComboBox comboBox = (JComboBox) source;
452                         if ("project-files.mime-type".equals(comboBox.getName())) {
453                                 fileOption.setMimeType((String) comboBox.getSelectedItem());
454                         }
455                 }
456         }
457
458         //
459         // INTERFACE ListSelectionListener
460         //
461
462         /**
463          * {@inheritDoc}
464          */
465         public void valueChanged(ListSelectionEvent e) {
466                 String filename = (String) projectFileList.getSelectedValue();
467                 boolean enabled = filename != null;
468                 defaultFileCheckBox.setEnabled(enabled);
469                 fileOptionsInsertCheckBox.setEnabled(enabled);
470                 fileOptionsRenameCheckBox.setEnabled(enabled);
471                 fileOptionsMIMETypeComboBox.setEnabled(enabled);
472                 if (filename != null) {
473                         FileOption fileOption = project.getFileOption(filename);
474                         defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
475                         fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
476                         fileOptionsInsertRedirectCheckBox.setEnabled(!fileOption.isInsert());
477                         fileOptionsInsertRedirectCheckBox.setSelected(fileOption.isInsertRedirect());
478                         fileOptionsCustomKeyTextField.setEnabled(fileOption.isInsertRedirect());
479                         fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
480                         fileOptionsRenameCheckBox.setSelected(fileOption.hasChangedName());
481                         fileOptionsRenameTextField.setEnabled(fileOption.hasChangedName());
482                         fileOptionsRenameTextField.setText(fileOption.getChangedName());
483                         fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
484                 } else {
485                         defaultFileCheckBox.setSelected(false);
486                         fileOptionsInsertCheckBox.setSelected(true);
487                         fileOptionsInsertRedirectCheckBox.setEnabled(false);
488                         fileOptionsInsertRedirectCheckBox.setSelected(false);
489                         fileOptionsCustomKeyTextField.setEnabled(false);
490                         fileOptionsCustomKeyTextField.setText("CHK@");
491                         fileOptionsRenameCheckBox.setEnabled(false);
492                         fileOptionsRenameCheckBox.setSelected(false);
493                         fileOptionsRenameTextField.setEnabled(false);
494                         fileOptionsRenameTextField.setText("");
495                         fileOptionsMIMETypeComboBox.getModel().setSelectedItem(DefaultMIMETypes.DEFAULT_MIME_TYPE);
496                 }
497         }
498
499         //
500         // INTERFACE DocumentListener
501         //
502
503         /**
504          * Updates the options of the currently selected file with the changes made
505          * in the “custom key” textfield.
506          *
507          * @param documentEvent
508          *            The document event to process
509          */
510         private void processDocumentUpdate(DocumentEvent documentEvent) {
511                 String filename = (String) projectFileList.getSelectedValue();
512                 if (filename == null) {
513                         return;
514                 }
515                 FileOption fileOption = project.getFileOption(filename);
516                 Document document = documentEvent.getDocument();
517                 try {
518                         String text = document.getText(0, document.getLength());
519                         fileOption.setCustomKey(text);
520                 } catch (BadLocationException ble1) {
521                         /* ignore. */
522                 }
523         }
524
525         /**
526          * {@inheritDoc}
527          */
528         public void changedUpdate(DocumentEvent documentEvent) {
529                 processDocumentUpdate(documentEvent);
530         }
531
532         /**
533          * {@inheritDoc}
534          */
535         public void insertUpdate(DocumentEvent documentEvent) {
536                 processDocumentUpdate(documentEvent);
537         }
538
539         /**
540          * {@inheritDoc}
541          */
542         public void removeUpdate(DocumentEvent documentEvent) {
543                 processDocumentUpdate(documentEvent);
544         }
545
546 }