/**
* 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 {
/**
* 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) {
}
};
overrideAction = new I18nAction("fileManager.checkbox.overrideActive") {
+
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
/**
* Creates the main panel with the file tree and the file properties.
- *
+ *
* @return The mail panel
*/
private Component createFileManagerPanel() {
/**
* 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
*/
/**
* 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
/**
* 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 {
/**
* 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
*/
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);
}
}
/**
* Notifies all listeners that the tree structure has changed
* significantly.
- *
+ *
* @see TreeModelListener#treeStructureChanged(TreeModelEvent)
* @param newRootNode
*/
protected void fireTreeStructureChanged(ProjectFileWrapper newRootNode) {
- for (TreeModelListener treeModelListener : treeModelListeners) {
+ for (TreeModelListener treeModelListener: treeModelListeners) {
treeModelListener.treeStructureChanged(new TreeModelEvent(this, new Object[] { 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
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);
}
/**
* @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
*/