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;
import java.beans.PropertyChangeListener;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JButton;
-import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import net.pterodactylus.jsite.i18n.I18nable;
import net.pterodactylus.jsite.i18n.gui.I18nAction;
import net.pterodactylus.jsite.i18n.gui.I18nLabel;
+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;
/**
* Manages physical and virtual files in a project.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
public class FileManager extends JDialog implements I18nable, ActionListener, TreeSelectionListener, MouseListener {
/** The “set default file” action. */
private I18nAction setDefaultFileAction;
- /** The “insert” action. */
- private I18nAction insertAction;
-
/** The “project files” label. */
private I18nLabel projectFilesLabel;
/** The “file size” text field. */
private JTextField fileSizeTextField;
+ /** The “override” label. */
+ private I18nLabel fileSettingsLabel;
+
+ /** The “insert default” label. */
+ private I18nLabel insertDefaultLabel;
+
+ /** The “insert default” checkbox. */
+ private JCheckBox insertDefaultCheckBox;
+
+ /** The “override insert default” action. */
+ private I18nAction overrideInsertDefaultAction;
+
+ /** 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;
- /** The “insert” checkbox. */
- private JCheckBoxMenuItem insertCheckBoxMenuItem;
+ /** The “apply override” menu. */
+ private I18nMenu overrideMenu;
+
+ /** The “apply insert override” action. */
+ private I18nAction applyInsertOverrideAction;
+
+ /** The “apply mime type override” action. */
+ private I18nAction applyMimeTypeOverrideAction;
+
+ /** The “remove override” action. */
+ private I18nAction removeOverrideAction;
/**
* Creates a new file manager.
- *
+ *
* @param swingInterface
* The Swing interface
* @param project
/**
* {@inheritDoc}
*/
+ @SuppressWarnings("synthetic-access")
public void actionPerformed(ActionEvent e) {
+ String defaultFile = project.getDefaultFile();
+ if ((defaultFile == null) || (defaultFile.length() == 0)) {
+ /* TODO - i18n */
+ JOptionPane.showMessageDialog(FileManager.this, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ ProjectFile projectFile = project.getFile(defaultFile);
+ if (projectFile == null) {
+ JOptionPane.showMessageDialog(FileManager.this, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
+ return;
+ }
setVisible(false);
}
};
/**
* {@inheritDoc}
*/
+ @SuppressWarnings("synthetic-access")
public void actionPerformed(ActionEvent actionEvent) {
TreePath selectedPath = fileTree.getSelectionPath();
if (selectedPath == null) {
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();
+ }
+ };
+ applyMimeTypeOverrideAction = new I18nAction("fileManager.menu.item.applyMimeTypeOverride") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ applyMimeTypeOverride();
+ }
+ };
+ removeOverrideAction = new I18nAction("fileManager.menu.item.removeOverride") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ removeOverride();
}
};
+ overrideInsertDefaultAction = new I18nAction("fileManager.checkbox.overrideInsertDefault") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ boolean overrideInsert = overrideInsertDefaultCheckBox.isSelected();
+ insertOverrideAction.setEnabled(overrideInsert);
+ List<ProjectFileWrapper> 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);
+ }
+ }
+ }
+ };
+ insertOverrideAction = new AbstractAction() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void actionPerformed(ActionEvent actionEvent) {
+ boolean insertOverride = insertOverrideCheckBox.isSelected();
+ List<ProjectFileWrapper> selectedProjectFileWrappers = getSelectedProjectFileWrappers(true);
+ ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0);
+ ProjectFile projectFile = projectFileWrapper.getProjectFile();
+ FileOverride fileOverride = project.getFileOverride(projectFile);
+ fileOverride.setInsert(insertOverride);
+ }
+ };
+ insertOverrideAction.setEnabled(false);
}
/**
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));
/**
* Creates the main panel with the file tree and the file properties.
- *
+ *
* @return The mail panel
*/
private Component createFileManagerPanel() {
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));
+ 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, 4, 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));
/**
* Creates the button panel.
- *
+ *
* @return The button panel
*/
private Component createButtonPanel() {
/**
* Checks whether the given mouse event is a popup trigger and occured over
* a file. If so, the context menu is shown.
- *
+ *
* @param mouseEvent
* The mouse event to check
*/
if (!mouseEvent.isPopupTrigger()) {
return;
}
- Point eventLocation = mouseEvent.getPoint();
- TreePath clickedPath = fileTree.getPathForLocation(eventLocation.x, eventLocation.y);
- if (clickedPath == null) {
- return;
+ List<ProjectFileWrapper> 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();
- insertCheckBoxMenuItem.setSelected(!isHidden(projectFileWrapper));
- treeContextMenu.show(fileTree, eventLocation.x, eventLocation.y);
+ 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());
}
/**
* Finds whether the {@link ProjectFile} given by
* <code>projectFileWrapper</code> is hidden.
- *
+ *
* @param projectFileWrapper
* The wrapped project file
* @return <code>true</code> if the file is hidden and should not be
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) && (Boolean.TRUE.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.checkbox.insertFile.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<ProjectFileWrapper> 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());
+ }
+ }
+
+ /**
+ * 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<String> 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<ProjectFileWrapper> 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<ProjectFileWrapper> 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
+ * <code>true</code> to return only selected files,
+ * <code>false</code> to include directories
+ * @return All selected project file wrappers
+ */
+ private List<ProjectFileWrapper> getSelectedProjectFileWrappers(boolean filesOnly) {
+ List<ProjectFileWrapper> selectedProjectFileWrappers = new ArrayList<ProjectFileWrapper>();
+ 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;
}
//
* {@inheritDoc}
*/
public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
- TreePath[] selectedPaths = fileTree.getSelectionPaths();
- 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<ProjectFileWrapper> selectedProjectFileWrappers = getSelectedProjectFileWrappers(true);
+ filePathTextField.setText("");
+ fileNameTextField.setText("");
+ fileSizeTextField.setText("");
+ 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));
+ }
fileNameTextField.setText(projectFile.getName());
fileSizeTextField.setText(String.valueOf(projectFile.getSize()));
+ overrideInsertDefaultCheckBox.setEnabled(true);
+ insertDefaultCheckBox.setSelected(!projectFile.isHidden());
+ FileOverride fileOverride = project.getFileOverride(projectFile);
+ if (fileOverride != null) {
+ Boolean overrideInsert = fileOverride.isInsert();
+ insertOverrideCheckBox.setEnabled(overrideInsert != null);
+ if (overrideInsert != null) {
+ overrideInsertDefaultCheckBox.setSelected(true);
+ insertOverrideCheckBox.setSelected(overrideInsert);
+ } else {
+ overrideInsertDefaultCheckBox.setSelected(false);
+ insertOverrideCheckBox.setSelected(!projectFile.isHidden());
+ }
+ } else {
+ overrideInsertDefaultCheckBox.setSelected(false);
+ insertOverrideCheckBox.setEnabled(false);
+ insertOverrideCheckBox.setSelected(!projectFile.isHidden());
+ }
}
+ } else if (selectedProjectFileWrappers.size() > 1) {
+ insertDefaultCheckBox.setEnabled(false);
+ insertDefaultCheckBox.setSelected(false);
+ overrideInsertDefaultAction.setEnabled(false);
+ overrideInsertDefaultCheckBox.setSelected(false);
+ insertOverrideAction.setEnabled(false);
+ insertOverrideCheckBox.setSelected(false);
}
}
/**
* Tree cell renderer that takes care of certain display properties for
* project-specific stuff.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
private class FileCellRenderer extends DefaultTreeCellRenderer {
}
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;
/**
* TreeModel that is based on {@link Project#getBaseFile()}.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
private class ProjectFileTreeModel implements TreeModel, PropertyChangeListener {
/**
* Notifies all listeners that a node has changed.
- *
+ *
* @param changedProjectFileWrapper
* The wrapper around the changed project file
*/
/**
* Notifies all listeners that the tree structure has changed
* significantly.
- *
+ *
* @see TreeModelListener#treeStructureChanged(TreeModelEvent)
* @param newRootNode
*/
/**
* Sets the new base project file. This causes the model to reload.
- *
+ *
* @param baseProjectFile
* The new base project file
*/
/**
* Creates {@link ProjectFileWrapper}s for all files below the given
* project file.
- *
+ *
* @param projectFile
* The base project file for all project files to create
* wrappers for
logger.log(Level.SEVERE, "node is not a ProjectFileWrapper!");
return true;
}
- if (node == projectFileWrappers.get(baseProjectFile)) {
- return false;
- }
ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) node;
- ProjectFile projectFile = projectFileWrapper.getProjectFile();
- return projectFile.getFiles().isEmpty();
+ return projectFileWrapper.getProjectFile().isFile();
}
/**
/**
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
*/
+ @SuppressWarnings("synthetic-access")
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
if (Project.PROPERTY_DEFAULT_FILE.equals(propertyChangeEvent.getPropertyName())) {
- String oldCompletePath = (String) propertyChangeEvent.getOldValue();
+ if (propertyChangeEvent.getOldValue() != null) {
+ String oldCompletePath = (String) propertyChangeEvent.getOldValue();
+ ProjectFile oldProjectFile = pathProjectFiles.get(oldCompletePath);
+ ProjectFileWrapper oldProjectFileWrapper = projectFileWrappers.get(oldProjectFile);
+ System.out.println("oldProjectFileWrapper: " + oldProjectFileWrapper);
+ fireTreeNodesChanged(oldProjectFileWrapper);
+ }
String newCompletePath = (String) propertyChangeEvent.getNewValue();
- ProjectFile oldProjectFile = pathProjectFiles.get(oldCompletePath);
ProjectFile newProjectFile = pathProjectFiles.get(newCompletePath);
- ProjectFileWrapper oldProjectFileWrapper = projectFileWrappers.get(oldProjectFile);
ProjectFileWrapper newProjectFileWrapper = projectFileWrappers.get(newProjectFile);
- System.out.println("oldProjectFileWrapper: " + oldProjectFileWrapper);
System.out.println("newProjectFileWrapper: " + newProjectFileWrapper);
- fireTreeNodesChanged(oldProjectFileWrapper);
fireTreeNodesChanged(newProjectFileWrapper);
/* HACK - swing sucks a bit. */
fileTree.setShowsRootHandles(false);
/**
* Wrapper around a {@link ProjectFile} that overwrites
* {@link Object#toString()} to return the project file’s name.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
private static class ProjectFileWrapper {
/**
* Creates a new wrapper around a project file.
- *
+ *
* @param projectFile
* The project file to wrap
*/
/**
* Returns the wrapped project file.
- *
+ *
* @return The wrapped project file
*/
public ProjectFile getProjectFile() {
/**
* Sets the name override. If the name override is not <code>null</code>
* it will be shown insted of the project file’s name.
- *
+ *
* @param nameOverride
* The name override
*/