2 * jSite - a tool for uploading websites into Freenet
3 * Copyright (C) 2006 David Roden
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.
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.
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.
20 package de.todesbaum.jsite.gui;
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;
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;
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;
76 * Wizard page that lets the user manage the files of a project.
78 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
80 public class ProjectFilesPage extends TWizardPage implements ActionListener, ListSelectionListener, DocumentListener, FileScannerListener, ChangeListener {
83 private Project project;
85 /** The “scan files” action. */
86 private Action scanAction;
88 /** The “edit container” action. */
89 private Action editContainerAction;
91 /** The “add container” action. */
92 private Action addContainerAction;
94 /** The “delete container” action. */
95 protected Action deleteContainerAction;
97 /** The “ignore hidden files” checkbox. */
98 private JCheckBox ignoreHiddenFilesCheckBox;
100 /** The list of project files. */
101 private JList projectFileList;
103 /** The “default file” checkbox. */
104 private JCheckBox defaultFileCheckBox;
106 /** The “insert” checkbox. */
107 private JCheckBox fileOptionsInsertCheckBox;
109 /** The “custom key” textfield. */
110 private JTextField fileOptionsCustomKeyTextField;
112 /** The “mime type” combo box. */
113 private JComboBox fileOptionsMIMETypeComboBox;
115 /** The “mime type” combo box model. */
116 private DefaultComboBoxModel containerComboBoxModel;
118 /** The “container” combo box. */
119 private JComboBox fileOptionsContainerComboBox;
121 /** The “edition replacement range” spinner. */
122 private JSpinner replaceEditionRangeSpinner;
124 /** The “replacement” check box. */
125 private JCheckBox replacementCheckBox;
128 * Creates a new project file page.
131 * The wizard the page belongs to
133 public ProjectFilesPage(final TWizard wizard) {
139 * Initializes the page and all its actions and components.
141 private void pageInit() {
143 setLayout(new BorderLayout(12, 12));
144 add(createProjectFilesPanel(), BorderLayout.CENTER);
148 * Creates all actions.
150 private void createActions() {
151 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
153 @SuppressWarnings("synthetic-access")
154 public void actionPerformed(ActionEvent actionEvent) {
158 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
159 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
161 addContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.add-container")) {
163 @SuppressWarnings("synthetic-access")
164 public void actionPerformed(ActionEvent actionEvent) {
165 actionAddContainer();
168 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
169 addContainerAction.setEnabled(false);
171 editContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.edit-container")) {
173 @SuppressWarnings("synthetic-access")
174 public void actionPerformed(ActionEvent actionEvent) {
175 actionEditContainer();
178 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
179 editContainerAction.setEnabled(false);
181 deleteContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.delete-container")) {
183 @SuppressWarnings("synthetic-access")
184 public void actionPerformed(ActionEvent actionEvent) {
185 actionDeleteContainer();
188 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
189 deleteContainerAction.setEnabled(false);
191 I18nContainer.getInstance().registerRunnable(new Runnable() {
193 @SuppressWarnings("synthetic-access")
195 scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
196 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
197 addContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.add-container"));
198 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
199 editContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.edit-container"));
200 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
201 deleteContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.delete-container"));
202 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
211 public void pageAdded(TWizard wizard) {
213 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
214 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
215 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
219 * Creates the panel contains the project file list and options.
221 * @return The created panel
223 private JComponent createProjectFilesPanel() {
224 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
226 projectFileList = new JList();
227 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
228 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
229 projectFileList.addListSelectionListener(this);
231 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
233 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
234 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
235 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
236 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
238 ignoreHiddenFilesCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
239 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.ignore-hidden-files.tooltip"));
240 ignoreHiddenFilesCheckBox.setName("ignore-hidden-files");
241 ignoreHiddenFilesCheckBox.addActionListener(this);
242 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));
244 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));
246 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
247 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));
249 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
250 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
251 defaultFileCheckBox.setName("default-file");
252 defaultFileCheckBox.addActionListener(this);
253 defaultFileCheckBox.setEnabled(false);
255 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));
257 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
258 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
259 fileOptionsInsertCheckBox.setName("insert");
260 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
261 fileOptionsInsertCheckBox.addActionListener(this);
262 fileOptionsInsertCheckBox.setEnabled(false);
264 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));
266 fileOptionsCustomKeyTextField = new JTextField(45);
267 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
268 fileOptionsCustomKeyTextField.setEnabled(false);
269 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
271 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
272 fileOptionsPanel.add(customKeyLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
273 fileOptionsPanel.add(fileOptionsCustomKeyTextField, new GridBagConstraints(1, 5, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
275 fileOptionsMIMETypeComboBox = new JComboBox(DefaultMIMETypes.getAllMIMETypes());
276 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
277 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
278 fileOptionsMIMETypeComboBox.addActionListener(this);
279 fileOptionsMIMETypeComboBox.setEditable(true);
280 fileOptionsMIMETypeComboBox.setEnabled(false);
282 final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
283 fileOptionsPanel.add(mimeTypeLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
284 fileOptionsPanel.add(fileOptionsMIMETypeComboBox, new GridBagConstraints(1, 6, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
286 containerComboBoxModel = new DefaultComboBoxModel();
287 fileOptionsContainerComboBox = new JComboBox(containerComboBoxModel);
288 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
289 fileOptionsContainerComboBox.setName("project-files.container");
290 fileOptionsContainerComboBox.addActionListener(this);
291 fileOptionsContainerComboBox.setEnabled(false);
292 fileOptionsContainerComboBox.setVisible(false);
294 final TLabel containerLabel = new TLabel(I18n.getMessage("jsite.project-files.container") + ":", KeyEvent.VK_C, fileOptionsContainerComboBox);
295 containerLabel.setVisible(false);
296 JButton addContainerButton = new JButton(addContainerAction);
297 addContainerButton.setVisible(false);
298 JButton editContainerButton = new JButton(editContainerAction);
299 editContainerButton.setVisible(false);
300 JButton deleteContainerButton = new JButton(deleteContainerAction);
301 deleteContainerButton.setVisible(false);
302 fileOptionsPanel.add(containerLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
303 fileOptionsPanel.add(fileOptionsContainerComboBox, new GridBagConstraints(1, 7, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
304 fileOptionsPanel.add(addContainerButton, new GridBagConstraints(2, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
305 fileOptionsPanel.add(editContainerButton, new GridBagConstraints(3, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
306 fileOptionsPanel.add(deleteContainerButton, new GridBagConstraints(4, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
308 JPanel fileOptionsReplacementPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 6, 6));
309 fileOptionsReplacementPanel.setBorder(new EmptyBorder(-6, -6, -6, -6));
311 replacementCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.replacement"));
312 replacementCheckBox.setName("project-files.replace-edition");
313 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
314 replacementCheckBox.addActionListener(this);
315 replacementCheckBox.setEnabled(false);
316 replacementCheckBox.setVisible(false);
317 fileOptionsReplacementPanel.add(replacementCheckBox);
319 replaceEditionRangeSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
320 replaceEditionRangeSpinner.setName("project-files.replace-edition-range");
321 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
322 replaceEditionRangeSpinner.addChangeListener(this);
323 replaceEditionRangeSpinner.setEnabled(false);
324 replaceEditionRangeSpinner.setVisible(false);
325 final JLabel editionRangeLabel = new JLabel(I18n.getMessage("jsite.project-files.replacement.edition-range"));
326 editionRangeLabel.setVisible(false);
327 fileOptionsReplacementPanel.add(editionRangeLabel);
328 fileOptionsReplacementPanel.add(replaceEditionRangeSpinner);
330 fileOptionsPanel.add(fileOptionsReplacementPanel, new GridBagConstraints(0, 8, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
332 I18nContainer.getInstance().registerRunnable(new Runnable() {
334 @SuppressWarnings("synthetic-access")
336 ignoreHiddenFilesCheckBox.setText(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
337 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.projet-files.ignore-hidden-files.tooltip"));
338 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
339 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
340 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
341 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
342 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
343 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
344 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
345 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
346 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
347 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
348 containerLabel.setText(I18n.getMessage("jsite.project-files.container") + ":");
349 replacementCheckBox.setText(I18n.getMessage("jsite.project-files.replacement"));
350 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
351 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
352 editionRangeLabel.setText(I18n.getMessage("jsite.project-files.replacement.edition-range"));
356 return projectFilesPanel;
360 * Sets the project whose files to manage.
363 * The project whose files to manage
365 public void setProject(final Project project) {
366 this.project = project;
367 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
368 setDescription(I18n.getMessage("jsite.project-files.description"));
369 ignoreHiddenFilesCheckBox.setSelected(project.isIgnoreHiddenFiles());
370 I18nContainer.getInstance().registerRunnable(new Runnable() {
373 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
374 setDescription(I18n.getMessage("jsite.project-files.description"));
380 * Returns a list of all project files.
382 * @return All project files
384 private List<String> getProjectFiles() {
385 List<String> files = new ArrayList<String>();
386 for (int index = 0, size = projectFileList.getModel().getSize(); index < size; index++) {
387 files.add((String) projectFileList.getModel().getElementAt(index));
393 * Updates the container combo box model.
395 private void rebuildContainerComboBox() {
396 /* scan files for containers */
397 List<String> files = getProjectFiles();
398 List<String> containers = new ArrayList<String>(); // ComboBoxModel
402 for (String filename : files) {
403 String container = project.getFileOption(filename).getContainer();
404 if (!containers.contains(container)) {
405 containers.add(container);
408 Collections.sort(containers);
409 containerComboBoxModel.removeAllElements();
410 for (String container : containers) {
411 containerComboBoxModel.addElement(container);
420 * Rescans the project’s files.
422 private void actionScan() {
423 projectFileList.clearSelection();
424 projectFileList.setListData(new Object[0]);
426 wizard.setNextEnabled(false);
427 wizard.setPreviousEnabled(false);
428 wizard.setQuitEnabled(false);
430 FileScanner fileScanner = new FileScanner(project);
431 fileScanner.addFileScannerListener(this);
432 new Thread(fileScanner).start();
438 private void actionAddContainer() {
439 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.add-container.message") + ":", null, JOptionPane.INFORMATION_MESSAGE);
440 if (containerName == null) {
443 containerName = containerName.trim();
444 String filename = (String) projectFileList.getSelectedValue();
445 FileOption fileOption = project.getFileOption(filename);
446 fileOption.setContainer(containerName);
447 rebuildContainerComboBox();
448 fileOptionsContainerComboBox.setSelectedItem(containerName);
452 * Edits the container.
454 private void actionEditContainer() {
455 String selectedFilename = (String) projectFileList.getSelectedValue();
456 FileOption fileOption = project.getFileOption(selectedFilename);
457 String oldContainerName = fileOption.getContainer();
458 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.edit-container.message") + ":", oldContainerName);
459 if (containerName == null) {
462 if (containerName.equals("")) {
463 fileOption.setContainer("");
464 fileOptionsContainerComboBox.setSelectedItem("");
467 List<String> files = getProjectFiles();
468 for (String filename : files) {
469 fileOption = project.getFileOption(filename);
470 if (fileOption.getContainer().equals(oldContainerName)) {
471 fileOption.setContainer(containerName);
474 rebuildContainerComboBox();
475 fileOptionsContainerComboBox.setSelectedItem(containerName);
479 * Deletes the container.
481 private void actionDeleteContainer() {
482 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.action.delete-container.message"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
483 String containerName = (String) fileOptionsContainerComboBox.getSelectedItem();
484 List<String> files = getProjectFiles();
485 for (String filename : files) {
486 FileOption fileOption = project.getFileOption(filename);
487 if (fileOption.getContainer().equals(containerName)) {
488 fileOption.setContainer("");
491 fileOptionsContainerComboBox.setSelectedItem("");
498 * Updates the file list.
500 public void fileScannerFinished(FileScanner fileScanner) {
501 final boolean error = fileScanner.isError();
503 final List<String> files = fileScanner.getFiles();
504 SwingUtilities.invokeLater(new Runnable() {
506 @SuppressWarnings("synthetic-access")
508 projectFileList.setListData(files.toArray(new String[files.size()]));
509 projectFileList.clearSelection();
510 rebuildContainerComboBox();
513 Set<String> entriesToRemove = new HashSet<String>();
514 Iterator<String> filenames = new HashSet<String>(project.getFileOptions().keySet()).iterator();
515 while (filenames.hasNext()) {
516 String filename = filenames.next();
517 if (!files.contains(filename)) {
518 entriesToRemove.add(filename);
521 for (String filename : entriesToRemove) {
522 project.setFileOption(filename, null);
525 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
527 SwingUtilities.invokeLater(new Runnable() {
529 @SuppressWarnings("synthetic-access")
531 wizard.setPreviousEnabled(true);
532 wizard.setNextEnabled(!error);
533 wizard.setQuitEnabled(true);
539 // INTERFACE ActionListener
545 public void actionPerformed(ActionEvent actionEvent) {
546 Object source = actionEvent.getSource();
547 if ((source instanceof JCheckBox) && ("ignore-hidden-files".equals(((JCheckBox) source).getName()))) {
548 project.setIgnoreHiddenFiles(((JCheckBox) source).isSelected());
552 String filename = (String) projectFileList.getSelectedValue();
553 if (filename == null) {
556 FileOption fileOption = project.getFileOption(filename);
557 if (source instanceof JCheckBox) {
558 JCheckBox checkBox = (JCheckBox) source;
559 if ("default-file".equals(checkBox.getName())) {
560 if (checkBox.isSelected()) {
561 project.setIndexFile(filename);
563 project.setIndexFile(null);
565 } else if ("insert".equals(checkBox.getName())) {
566 boolean isInsert = checkBox.isSelected();
567 fileOptionsCustomKeyTextField.setEnabled(!isInsert);
568 fileOption.setInsert(isInsert);
570 fileOptionsContainerComboBox.setSelectedItem("");
572 } else if ("project-files.replace-edition".equals(checkBox.getName())) {
573 boolean replaceEdition = checkBox.isSelected();
574 fileOption.setReplaceEdition(replaceEdition);
575 replaceEditionRangeSpinner.setEnabled(replaceEdition);
577 } else if (source instanceof JComboBox) {
578 JComboBox comboBox = (JComboBox) source;
579 if ("project-files.mime-type".equals(comboBox.getName())) {
580 fileOption.setMimeType((String) comboBox.getSelectedItem());
581 } else if ("project-files.container".equals(comboBox.getName())) {
582 String containerName = (String) comboBox.getSelectedItem();
583 fileOption.setContainer(containerName);
584 boolean enabled = !"".equals(containerName);
585 editContainerAction.setEnabled(enabled);
586 deleteContainerAction.setEnabled(enabled);
588 fileOptionsInsertCheckBox.setSelected(true);
595 // INTERFACE ListSelectionListener
601 public void valueChanged(ListSelectionEvent e) {
602 String filename = (String) projectFileList.getSelectedValue();
603 boolean enabled = filename != null;
604 boolean insert = fileOptionsInsertCheckBox.isSelected();
605 defaultFileCheckBox.setEnabled(enabled);
606 fileOptionsInsertCheckBox.setEnabled(enabled);
607 fileOptionsCustomKeyTextField.setEnabled(enabled && !insert);
608 fileOptionsMIMETypeComboBox.setEnabled(enabled);
609 fileOptionsContainerComboBox.setEnabled(enabled);
610 addContainerAction.setEnabled(enabled);
611 editContainerAction.setEnabled(enabled);
612 deleteContainerAction.setEnabled(enabled);
613 replacementCheckBox.setEnabled(enabled && insert);
614 if (filename != null) {
615 FileOption fileOption = project.getFileOption(filename);
616 defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
617 fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
618 fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
619 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
620 fileOptionsContainerComboBox.setSelectedItem(fileOption.getContainer());
621 replacementCheckBox.setSelected(fileOption.getReplaceEdition());
622 replaceEditionRangeSpinner.setValue(fileOption.getEditionRange());
623 replaceEditionRangeSpinner.setEnabled(fileOption.getReplaceEdition());
625 defaultFileCheckBox.setSelected(false);
626 fileOptionsInsertCheckBox.setSelected(true);
627 fileOptionsCustomKeyTextField.setText("CHK@");
628 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(DefaultMIMETypes.DEFAULT_MIME_TYPE);
629 fileOptionsContainerComboBox.setSelectedItem("");
630 replacementCheckBox.setSelected(false);
631 replaceEditionRangeSpinner.setValue(0);
636 // INTERFACE DocumentListener
640 * Updates the options of the currently selected file with the changes made
641 * in the “custom key” textfield.
643 * @param documentEvent
644 * The document event to process
646 private void processDocumentUpdate(DocumentEvent documentEvent) {
647 String filename = (String) projectFileList.getSelectedValue();
648 if (filename == null) {
651 FileOption fileOption = project.getFileOption(filename);
652 Document document = documentEvent.getDocument();
654 String text = document.getText(0, document.getLength());
655 fileOption.setCustomKey(text);
656 } catch (BadLocationException ble1) {
664 public void changedUpdate(DocumentEvent documentEvent) {
665 processDocumentUpdate(documentEvent);
671 public void insertUpdate(DocumentEvent documentEvent) {
672 processDocumentUpdate(documentEvent);
678 public void removeUpdate(DocumentEvent documentEvent) {
679 processDocumentUpdate(documentEvent);
683 // INTERFACE ChangeListener
689 public void stateChanged(ChangeEvent changeEvent) {
690 String filename = (String) projectFileList.getSelectedValue();
691 if (filename == null) {
694 FileOption fileOption = project.getFileOption(filename);
695 Object source = changeEvent.getSource();
696 if (source instanceof JSpinner) {
697 JSpinner spinner = (JSpinner) source;
698 fileOption.setEditionRange((Integer) spinner.getValue());