remove subversion $Id$ tags
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectFilesPage.java
index d8bac9c..a171110 100644 (file)
@@ -31,8 +31,10 @@ import java.awt.event.KeyEvent;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import javax.swing.AbstractAction;
 import javax.swing.Action;
@@ -71,24 +73,23 @@ import de.todesbaum.util.swing.TWizard;
 import de.todesbaum.util.swing.TWizardPage;
 
 /**
- * @author David Roden <droden@gmail.com>
- * @version $Id$
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  */
 public class ProjectFilesPage extends TWizardPage implements ActionListener, ListSelectionListener, DocumentListener, FileScannerListener, ChangeListener {
 
-       protected Project project;
+       private Project project;
 
-       protected Action scanAction;
-       protected Action editContainerAction;
-       protected Action addContainerAction;
-       protected Action deleteContainerAction;
+       private Action scanAction;
+       private Action editContainerAction;
+       private Action addContainerAction;
+       private Action deleteContainerAction;
 
-       protected JList projectFileList;
+       private JList projectFileList;
        private JCheckBox defaultFileCheckBox;
        private JCheckBox fileOptionsInsertCheckBox;
        private JTextField fileOptionsCustomKeyTextField;
        private JComboBox fileOptionsMIMETypeComboBox;
-       protected DefaultComboBoxModel containerComboBoxModel;
+       private DefaultComboBoxModel containerComboBoxModel;
        private JComboBox fileOptionsContainerComboBox;
        private JSpinner replaceEditionRangeSpinner;
        private JCheckBox replacementCheckBox;
@@ -107,6 +108,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
        private void createActions() {
                scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
 
+                       @SuppressWarnings("synthetic-access")
                        public void actionPerformed(ActionEvent actionEvent) {
                                actionScan();
                        }
@@ -116,6 +118,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
 
                addContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.add-container")) {
 
+                       @SuppressWarnings("synthetic-access")
                        public void actionPerformed(ActionEvent actionEvent) {
                                actionAddContainer();
                        }
@@ -125,6 +128,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
 
                editContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.edit-container")) {
 
+                       @SuppressWarnings("synthetic-access")
                        public void actionPerformed(ActionEvent actionEvent) {
                                actionEditContainer();
                        }
@@ -134,6 +138,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
 
                deleteContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.delete-container")) {
 
+                       @SuppressWarnings("synthetic-access")
                        public void actionPerformed(ActionEvent actionEvent) {
                                actionDeleteContainer();
                        }
@@ -143,6 +148,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
 
                I18nContainer.getInstance().registerRunnable(new Runnable() {
 
+                       @SuppressWarnings("synthetic-access")
                        public void run() {
                                scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
                                scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
@@ -257,6 +263,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
 
                I18nContainer.getInstance().registerRunnable(new Runnable() {
 
+                       @SuppressWarnings("synthetic-access")
                        public void run() {
                                fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
                                defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
@@ -300,14 +307,14 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                return files;
        }
 
-       protected void rebuildContainerComboBox() {
+       private void rebuildContainerComboBox() {
                /* scan files for containers */
                List<String> files = getProjectFiles();
                List<String> containers = new ArrayList<String>(); // ComboBoxModel
                // sucks. No
                // contains()!
                containers.add("");
-               for (String filename: files) {
+               for (String filename : files) {
                        String container = project.getFileOption(filename).getContainer();
                        if (!containers.contains(container)) {
                                containers.add(container);
@@ -315,7 +322,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                }
                Collections.sort(containers);
                containerComboBoxModel.removeAllElements();
-               for (String container: containers) {
+               for (String container : containers) {
                        containerComboBoxModel.addElement(container);
                }
        }
@@ -324,7 +331,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
        // ACTIONS
        //
 
-       protected void actionScan() {
+       private void actionScan() {
                projectFileList.clearSelection();
                projectFileList.setListData(new Object[0]);
 
@@ -337,7 +344,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                new Thread(fileScanner).start();
        }
 
-       protected void actionAddContainer() {
+       private void actionAddContainer() {
                String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.add-container.message") + ":", null, JOptionPane.INFORMATION_MESSAGE);
                if (containerName == null) {
                        return;
@@ -350,7 +357,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                fileOptionsContainerComboBox.setSelectedItem(containerName);
        }
 
-       protected void actionEditContainer() {
+       private void actionEditContainer() {
                String selectedFilename = (String) projectFileList.getSelectedValue();
                FileOption fileOption = project.getFileOption(selectedFilename);
                String oldContainerName = fileOption.getContainer();
@@ -364,7 +371,7 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                        return;
                }
                List<String> files = getProjectFiles();
-               for (String filename: files) {
+               for (String filename : files) {
                        fileOption = project.getFileOption(filename);
                        if (fileOption.getContainer().equals(oldContainerName)) {
                                fileOption.setContainer(containerName);
@@ -374,11 +381,11 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                fileOptionsContainerComboBox.setSelectedItem(containerName);
        }
 
-       protected void actionDeleteContainer() {
+       private void actionDeleteContainer() {
                if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.action.delete-container.message"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
                        String containerName = (String) fileOptionsContainerComboBox.getSelectedItem();
                        List<String> files = getProjectFiles();
-                       for (String filename: files) {
+                       for (String filename : files) {
                                FileOption fileOption = project.getFileOption(filename);
                                if (fileOption.getContainer().equals(containerName)) {
                                        fileOption.setContainer("");
@@ -394,24 +401,30 @@ public class ProjectFilesPage extends TWizardPage implements ActionListener, Lis
                        final List<String> files = fileScanner.getFiles();
                        SwingUtilities.invokeLater(new Runnable() {
 
+                               @SuppressWarnings("synthetic-access")
                                public void run() {
                                        projectFileList.setListData(files.toArray(new String[files.size()]));
                                        projectFileList.clearSelection();
                                        rebuildContainerComboBox();
                                }
                        });
+                       Set<String> entriesToRemove = new HashSet<String>();
                        Iterator<String> filenames = project.getFileOptions().keySet().iterator();
                        while (filenames.hasNext()) {
                                String filename = filenames.next();
                                if (!files.contains(filename)) {
-                                       project.setFileOption(filename, null);
+                                       entriesToRemove.add(filename);
                                }
                        }
+                       for (String filename : entriesToRemove) {
+                               project.setFileOption(filename, null);
+                       }
                } else {
                        JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
                }
                SwingUtilities.invokeLater(new Runnable() {
 
+                       @SuppressWarnings("synthetic-access")
                        public void run() {
                                wizard.setPreviousEnabled(true);
                                wizard.setNextEnabled(!error);