X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FFileManager.java;h=5bd52e8833bd8725e57c9166065c3d133d7cbc00;hb=b6e4ce772f4c7a823dad0d3aa0a28f6432a7540b;hp=ad4d0ab9871cb003802140a5308200d75a331764;hpb=a5ebacd3beea5b83347f66cc8b8dac79d3f66e14;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index ad4d0ab..5bd52e8 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -28,9 +28,7 @@ import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.awt.Point; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.beans.PropertyChangeEvent; @@ -44,10 +42,13 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.AbstractAction; +import javax.swing.AbstractButton; +import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -72,6 +73,7 @@ import net.pterodactylus.jsite.i18n.gui.I18nMenu; import net.pterodactylus.jsite.project.FileOverride; import net.pterodactylus.jsite.project.Project; import net.pterodactylus.jsite.project.ProjectFile; +import net.pterodactylus.util.io.MimeTypes; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.swing.SwingUtils; @@ -80,7 +82,7 @@ import net.pterodactylus.util.swing.SwingUtils; * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ -public class FileManager extends JDialog implements I18nable, ActionListener, TreeSelectionListener, MouseListener { +public class FileManager extends JDialog implements I18nable, TreeSelectionListener, MouseListener { /** Logger. */ private static final Logger logger = Logging.getLogger(FileManager.class.getName()); @@ -106,9 +108,6 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** The “set default file” action. */ private I18nAction setDefaultFileAction; - /** The “insert” action. */ - private I18nAction insertAction; - /** The “project files” label. */ private I18nLabel projectFilesLabel; @@ -140,13 +139,25 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private JTextField fileSizeTextField; /** The “override” label. */ - private I18nLabel overrideLabel; + private I18nLabel fileSettingsLabel; + + /** The “insert default” label. */ + private I18nLabel insertDefaultLabel; + + /** The “insert default” checkbox. */ + private JCheckBox insertDefaultCheckBox; - /** The “override active” action. */ - private I18nAction overrideAction; + /** The “override insert default” action. */ + private I18nAction overrideInsertDefaultAction; - /** The “override action” checkbox. */ - private JCheckBox overrideCheckBox; + /** The “override insert default” checkbox. */ + private JCheckBox overrideInsertDefaultCheckBox; + + /** The “override insert” action. */ + private Action insertOverrideAction; + + /** The “override insert” checkbox. */ + private JCheckBox insertOverrideCheckBox; /** The context menu for the tree. */ private JPopupMenu treeContextMenu; @@ -160,8 +171,8 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** The “apply mime type override” action. */ private I18nAction applyMimeTypeOverrideAction; - /** The “insert” checkbox. */ - private JCheckBoxMenuItem insertCheckBoxMenuItem; + /** The “remove override” action. */ + private I18nAction removeOverrideAction; /** * Creates a new file manager. @@ -266,40 +277,81 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr project.setDefaultFile(completePath); } }; - insertAction = new I18nAction("fileManager.menu.item.insert") { + applyInsertOverrideAction = new I18nAction("fileManager.menu.item.applyInsertOverride") { /** * {@inheritDoc} */ - public void actionPerformed(ActionEvent e) { - /* TODO */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + applyInsertOverride(); } }; - overrideAction = new I18nAction("fileManager.checkbox.overrideActive") { + applyMimeTypeOverrideAction = new I18nAction("fileManager.menu.item.applyMimeTypeOverride") { /** - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + * {@inheritDoc} */ + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { - /* TODO */ + applyMimeTypeOverride(); } }; - applyInsertOverrideAction = new I18nAction("fileManager.menu.item.applyInsertOverride") { + removeOverrideAction = new I18nAction("fileManager.menu.item.removeOverride") { + /** * {@inheritDoc} */ + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { - /* TODO */ + removeOverride(); } }; - applyMimeTypeOverrideAction = new I18nAction("fileManager.menu.item.applyMimeTypeOverride") { + overrideInsertDefaultAction = new I18nAction("fileManager.checkbox.overrideInsertDefault") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + boolean overrideInsert = overrideInsertDefaultCheckBox.isSelected(); + insertOverrideAction.setEnabled(overrideInsert); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); + ProjectFile projectFile = projectFileWrapper.getProjectFile(); + FileOverride fileOverride = project.getFileOverride(projectFile); + if (overrideInsert) { + if (fileOverride == null) { + fileOverride = new FileOverride(); + project.addFileOverride(projectFile, fileOverride); + fileOverride.setInsert(!projectFile.isHidden()); + } + } else { + fileOverride.setInsert(null); + if (fileOverride.isEmpty()) { + project.removeFileOverride(projectFile); + } + } + } + }; + overrideInsertDefaultAction.setEnabled(false); + insertOverrideAction = new AbstractAction() { + /** * {@inheritDoc} */ public void actionPerformed(ActionEvent actionEvent) { - /* TODO */ + boolean insertOverride = insertOverrideCheckBox.isSelected(); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); + ProjectFile projectFile = projectFileWrapper.getProjectFile(); + FileOverride fileOverride = project.getFileOverride(projectFile); + fileOverride.setInsert(insertOverride); + fileTree.setShowsRootHandles(false); + fileTree.repaint(); } }; + insertOverrideAction.setEnabled(false); } /** @@ -308,14 +360,14 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private void initComponents() { treeContextMenu = new JPopupMenu(); treeContextMenu.add(setDefaultFileAction); - insertCheckBoxMenuItem = new JCheckBoxMenuItem(insertAction); - treeContextMenu.add(insertCheckBoxMenuItem); - + overrideMenu = new I18nMenu("fileManager.menu.override"); treeContextMenu.add(overrideMenu); - + overrideMenu.add(applyInsertOverrideAction); overrideMenu.add(applyMimeTypeOverrideAction); + overrideMenu.addSeparator(); + overrideMenu.add(removeOverrideAction); JPanel contentPanel = new JPanel(new BorderLayout(12, 12)); contentPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); @@ -363,36 +415,43 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr filePropertiesLabel = new I18nLabel("fileManager.label.fileProperties"); filePropertiesLabel.setFont(filePropertiesLabel.getFont().deriveFont(Font.BOLD)); - propertiesPanel.add(filePropertiesLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + propertiesPanel.add(filePropertiesLabel, new GridBagConstraints(0, 0, 4, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); filePathLabel = new I18nLabel("fileManager.label.filePath"); filePathTextField = new JTextField(); filePathTextField.setEditable(false); propertiesPanel.add(filePathLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); - propertiesPanel.add(filePathTextField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + propertiesPanel.add(filePathTextField, new GridBagConstraints(1, 1, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); fileNameLabel = new I18nLabel("fileManager.label.fileName"); fileNameTextField = new JTextField(); fileNameTextField.setEditable(false); propertiesPanel.add(fileNameLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); - propertiesPanel.add(fileNameTextField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + propertiesPanel.add(fileNameTextField, new GridBagConstraints(1, 2, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); fileSizeLabel = new I18nLabel("fileManager.label.fileSize"); fileSizeTextField = new JTextField(); fileSizeTextField.setEditable(false); propertiesPanel.add(fileSizeLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); - propertiesPanel.add(fileSizeTextField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); - - /* override settings. */ - overrideLabel = new I18nLabel("fileManager.label.override"); - overrideLabel.setFont(overrideLabel.getFont().deriveFont(Font.BOLD)); - propertiesPanel.add(overrideLabel, new GridBagConstraints(0, 4, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(24, 0, 0, 0), 0, 0)); - - overrideCheckBox = new JCheckBox(overrideAction); - propertiesPanel.add(overrideCheckBox, new GridBagConstraints(0, 5, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); + propertiesPanel.add(fileSizeTextField, new GridBagConstraints(1, 3, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + + /* file settings. */ + fileSettingsLabel = new I18nLabel("fileManager.label.fileSettings"); + fileSettingsLabel.setFont(fileSettingsLabel.getFont().deriveFont(Font.BOLD)); + propertiesPanel.add(fileSettingsLabel, new GridBagConstraints(0, 4, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(24, 0, 0, 0), 0, 0)); + + insertDefaultLabel = new I18nLabel("fileManager.label.insertDefault"); + propertiesPanel.add(insertDefaultLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); + insertDefaultCheckBox = new JCheckBox(); + insertDefaultCheckBox.setEnabled(false); + propertiesPanel.add(insertDefaultCheckBox, new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + overrideInsertDefaultCheckBox = new JCheckBox(overrideInsertDefaultAction); + propertiesPanel.add(overrideInsertDefaultCheckBox, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + insertOverrideCheckBox = new JCheckBox(insertOverrideAction); + propertiesPanel.add(insertOverrideCheckBox, new GridBagConstraints(3, 5, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); /* glue panel. */ - propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 6, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 6, 4, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); /* action button panel */ JPanel actionButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12)); @@ -457,16 +516,23 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr if (!mouseEvent.isPopupTrigger()) { return; } - Point eventLocation = mouseEvent.getPoint(); - TreePath clickedPath = fileTree.getPathForLocation(eventLocation.x, eventLocation.y); - if (clickedPath == null) { - return; + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(false); + TreePath clickedPath = fileTree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); + ProjectFileWrapper clickedProjectFileWrapper = (ProjectFileWrapper) clickedPath.getLastPathComponent(); + if (!selectedProjectFileWrappers.contains(clickedProjectFileWrapper)) { + fileTree.setSelectionPath(clickedPath); + selectedProjectFileWrappers = getSelectedProjectFileWrappers(false); } - fileTree.setSelectionPath(clickedPath); - ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) clickedPath.getLastPathComponent(); - setDefaultFileAction.setEnabled(projectFileWrapper.getProjectFile().isFile() && !isHidden(projectFileWrapper)); - insertCheckBoxMenuItem.setSelected(!isHidden(projectFileWrapper)); - treeContextMenu.show(fileTree, eventLocation.x, eventLocation.y); + logger.log(Level.FINEST, "selectedProjectFileWrappers.size(): " + selectedProjectFileWrappers.size()); + if (selectedProjectFileWrappers.size() == 1) { + ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); + ProjectFile projectFile = projectFileWrapper.getProjectFile(); + setDefaultFileAction.setEnabled(!isHidden(projectFileWrapper) && projectFile.isFile() && !projectFile.getCompletePath().equals(project.getDefaultFile())); + } else { + setDefaultFileAction.setEnabled(false); + } + overrideMenu.setVisible(selectedProjectFileWrappers.size() > 1); + treeContextMenu.show(fileTree, mouseEvent.getX(), mouseEvent.getY()); } /** @@ -481,7 +547,132 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private boolean isHidden(ProjectFileWrapper projectFileWrapper) { ProjectFile projectFile = projectFileWrapper.getProjectFile(); FileOverride fileOverride = project.getFileOverrides().get(projectFile.getCompletePath()); - return ((fileOverride == null) && projectFile.isHidden()) || ((fileOverride != null) && (fileOverride.isInsert())); + logger.log(Level.FINEST, "fileOverride: " + fileOverride); + return ((fileOverride == null) && projectFile.isHidden()) || ((fileOverride != null) && (fileOverride.isInsert() == null) && projectFile.isHidden()) || ((fileOverride != null) && (fileOverride.isInsert() != null) && (Boolean.FALSE.equals(fileOverride.isInsert()))); + } + + /** + * Opens the “apply insert override” dialog and lets the user apply an + * override for the “insert” setting for multiple files. + */ + private void applyInsertOverride() { + JCheckBox insertCheckBox = new JCheckBox(I18n.get("fileManager.menu.item.insert.name")); + String okString = I18n.get("general.button.okay.name"); + String cancelString = I18n.get("general.button.cancel.name"); + int choice = JOptionPane.showOptionDialog(this, new Object[] { I18n.get("fileManager.dialog.insertOverride.message"), insertCheckBox }, I18n.get("fileManager.dialog.insertOverride.title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { okString, cancelString }, okString); + logger.log(Level.FINEST, "choice: " + choice); + if ((choice == JOptionPane.CLOSED_OPTION) || (choice == 1)) { + return; + } + logger.log(Level.INFO, "selected insert override: " + insertCheckBox.isSelected()); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + for (ProjectFileWrapper selectedProjectFileWrapper : selectedProjectFileWrappers) { + ProjectFile projectFile = selectedProjectFileWrapper.getProjectFile(); + FileOverride fileOverride = project.getFileOverride(projectFile); + if (fileOverride == null) { + fileOverride = new FileOverride(); + project.addFileOverride(projectFile, fileOverride); + } + fileOverride.setInsert(insertCheckBox.isSelected()); + } + /* HACK - Swing sucks a bit */ + fileTree.setShowsRootHandles(false); + } + + /** + * Opens the “apply mime type override” dialog and lets the user apply an + * override for the “mime type” setting for multiple files. + */ + private void applyMimeTypeOverride() { + List allMimeTypes = MimeTypes.getAllMimeTypes(); + allMimeTypes.add(0, null); + JComboBox mimeTypeComboBox = new JComboBox(allMimeTypes.toArray()); + String okString = I18n.get("general.button.okay.name"); + String cancelString = I18n.get("general.button.cancel.name"); + int choice = JOptionPane.showOptionDialog(this, new Object[] { I18n.get("fileManager.dialog.mimeTypeOverride.message"), mimeTypeComboBox }, I18n.get("fileManager.dialog.mimeTypeOverride.title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { okString, cancelString }, okString); + if ((choice == JOptionPane.CLOSED_OPTION) || (choice == 1)) { + return; + } + logger.log(Level.FINE, "selected mime type: " + mimeTypeComboBox.getSelectedItem()); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + for (ProjectFileWrapper selectedProjectFileWrapper : selectedProjectFileWrappers) { + ProjectFile projectFile = selectedProjectFileWrapper.getProjectFile(); + FileOverride fileOverride = project.getFileOverride(projectFile); + if (fileOverride == null) { + fileOverride = new FileOverride(); + project.addFileOverride(projectFile, fileOverride); + } + fileOverride.setContentType((String) mimeTypeComboBox.getSelectedItem()); + } + } + + /** + * Removes the overrides of all selected files. + */ + private void removeOverride() { + String continueString = I18n.get("general.button.continue.name"); + String cancelString = I18n.get("general.button.cancel.name"); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + int choice = JOptionPane.showOptionDialog(this, I18n.get("fileManager.dialog.removeOverride.message", selectedProjectFileWrappers.size()), I18n.get("fileManager.dialog.removeOverride.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new Object[] { continueString, cancelString }, continueString); + if ((choice == JOptionPane.CLOSED_OPTION) || (choice == 1)) { + return; + } + for (ProjectFileWrapper selectedProjectFileWrapper : selectedProjectFileWrappers) { + project.removeFileOverride(selectedProjectFileWrapper.getProjectFile()); + } + } + + /** + * Returns all currently selected {@link ProjectFileWrapper}s. + * + * @param filesOnly + * true to return only selected files, + * false to include directories + * @return All selected project file wrappers + */ + private List getSelectedProjectFileWrappers(boolean filesOnly) { + List selectedProjectFileWrappers = new ArrayList(); + TreePath[] selectedPaths = fileTree.getSelectionPaths(); + if (selectedPaths != null) { + for (TreePath selectedPath : selectedPaths) { + ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPath.getLastPathComponent(); + if (filesOnly && !projectFileWrapper.getProjectFile().isFile()) { + continue; + } + selectedProjectFileWrappers.add(projectFileWrapper); + } + } + return selectedProjectFileWrappers; + } + + /** + * Sets the given action’s enabled state to the given enabled state if the + * action’s current enabled state is not the given enabled state. + * + * @param action + * The action to set the enabled state on + * @param enabled + * The new enabled state of the action + */ + private void setEnabled(Action action, boolean enabled) { + if (action.isEnabled() != enabled) { + action.setEnabled(enabled); + } + } + + /** + * Sets the given button’s selected state to the given selected state if the + * button’s current selected state is not the given selected state. + * + * @param button + * The button to set the selected state on + * @param selected + * The new selected state of the button + */ + private void setSelected(AbstractButton button, boolean selected) { + if (button.isSelected() != selected) { + button.setSelected(selected); + } } // @@ -506,43 +697,47 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr * {@inheritDoc} */ public void valueChanged(TreeSelectionEvent treeSelectionEvent) { - TreePath[] selectedPaths = fileTree.getSelectionPaths(); - filePathTextField.setText(""); - fileNameTextField.setText(""); - fileSizeTextField.setText(""); - if ((selectedPaths != null) && (selectedPaths.length == 1)) { - Object lastPathComponent = selectedPaths[0].getLastPathComponent(); - if (!(lastPathComponent instanceof ProjectFileWrapper)) { - logger.log(Level.SEVERE, "lastPathComponent is not a ProjectFileWrapper!"); - return; - } - ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) lastPathComponent; + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + String filePathText = ""; + String fileNameText = ""; + String fileSizeText = ""; + boolean insertDefaultSelected = false; + boolean overrideInsertEnabled = false; + boolean overrideInsertSelected = false; + boolean insertOverrideEnabled = false; + boolean insertOverrideSelected = false; + if (selectedProjectFileWrappers.size() == 1) { + ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); ProjectFile projectFile = projectFileWrapper.getProjectFile(); if (projectFile.isFile()) { String completePath = projectFile.getCompletePath(); int lastSeparator = completePath.lastIndexOf(File.separatorChar); - if (lastSeparator == -1) { - filePathTextField.setText(""); - } else { - filePathTextField.setText(completePath.substring(0, lastSeparator)); + if (lastSeparator != -1) { + filePathText = completePath.substring(0, lastSeparator); + } + fileNameText = projectFile.getName(); + fileSizeText = String.valueOf(projectFile.getSize()); + insertDefaultSelected = !projectFile.isHidden(); + overrideInsertEnabled = true; + FileOverride fileOverride = project.getFileOverride(projectFile); + if (fileOverride != null) { + Boolean overrideInsert = fileOverride.isInsert(); + overrideInsertSelected = overrideInsert != null; + insertOverrideEnabled = overrideInsertSelected; + insertOverrideSelected = overrideInsertSelected ? overrideInsert : !projectFile.isHidden(); } - fileNameTextField.setText(projectFile.getName()); - fileSizeTextField.setText(String.valueOf(projectFile.getSize())); } - } else if ((selectedPaths != null) && (selectedPaths.length > 1)) { + } else if (selectedProjectFileWrappers.size() > 1) { /* TODO */ } - } - - // - // INTERFACE ActionListener - // - - /** - * {@inheritDoc} - */ - public void actionPerformed(ActionEvent actionEvent) { - /* TODO */ + filePathTextField.setText(filePathText); + fileNameTextField.setText(fileNameText); + fileSizeTextField.setText(fileSizeText); + setSelected(insertDefaultCheckBox, insertDefaultSelected); + setEnabled(overrideInsertDefaultAction, overrideInsertEnabled); + setSelected(overrideInsertDefaultCheckBox, overrideInsertSelected); + setEnabled(insertOverrideAction, insertOverrideEnabled); + setSelected(insertOverrideCheckBox, insertOverrideSelected); } // @@ -617,11 +812,18 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr } ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) value; ProjectFile projectFile = projectFileWrapper.getProjectFile(); + FileOverride fileOverride = project.getFileOverride(projectFile); String completePath = projectFile.getCompletePath(); boolean paintBold = false; boolean paintHalfColor = false; - if (projectFile.isFile() && projectFile.isHidden()) { - /* TODO - check override */ + boolean showFile = !projectFile.isHidden(); + if (fileOverride != null) { + Boolean insertOverride = fileOverride.isInsert(); + if (insertOverride != null) { + showFile = insertOverride; + } + } + if (projectFile.isFile() && !showFile) { paintHalfColor = true; } else if (completePath.equals(project.getDefaultFile())) { paintBold = true; @@ -707,7 +909,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr currentProjectFileParent = currentProjectFileParent.getParent(); } while (currentProjectFileParent != null); TreeModelEvent treeModelEvent = new TreeModelEvent(this, parentProjectFileWrappers.toArray(), new int[] { getIndexOfChild(projectFileWrappers.get(changedProjectFileParent), changedProjectFileWrapper) }, new Object[] { changedProjectFileWrapper }); - for (TreeModelListener treeModelListener: treeModelListeners) { + for (TreeModelListener treeModelListener : treeModelListeners) { treeModelListener.treeNodesChanged(treeModelEvent); } } @@ -720,7 +922,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr * @param newRootNode */ protected void fireTreeStructureChanged(ProjectFileWrapper newRootNode) { - for (TreeModelListener treeModelListener: treeModelListeners) { + for (TreeModelListener treeModelListener : treeModelListeners) { treeModelListener.treeStructureChanged(new TreeModelEvent(this, new Object[] { newRootNode })); } } @@ -760,7 +962,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private void createWrappers(ProjectFile projectFile) { projectFileWrappers.put(projectFile, new ProjectFileWrapper(projectFile)); pathProjectFiles.put(projectFile.getCompletePath(), projectFile); - for (ProjectFile projectFileChild: projectFile.getFiles()) { + for (ProjectFile projectFileChild : projectFile.getFiles()) { if (projectFileChild.isDirectory()) { createWrappers(projectFileChild); } @@ -858,9 +1060,11 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr if (Project.PROPERTY_DEFAULT_FILE.equals(propertyChangeEvent.getPropertyName())) { if (propertyChangeEvent.getOldValue() != null) { String oldCompletePath = (String) propertyChangeEvent.getOldValue(); + logger.log(Level.FINEST, "oldCompletePath: " + oldCompletePath); ProjectFile oldProjectFile = pathProjectFiles.get(oldCompletePath); + logger.log(Level.FINEST, "oldProjectFile: " + oldProjectFile); ProjectFileWrapper oldProjectFileWrapper = projectFileWrappers.get(oldProjectFile); - System.out.println("oldProjectFileWrapper: " + oldProjectFileWrapper); + logger.log(Level.FINEST, "oldProjectFileWrapper: " + oldProjectFileWrapper); fireTreeNodesChanged(oldProjectFileWrapper); } String newCompletePath = (String) propertyChangeEvent.getNewValue();