import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
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;
/** The “apply mime type override” action. */
private I18nAction applyMimeTypeOverrideAction;
+ /** The “remove override” action. */
+ private I18nAction removeOverrideAction;
+
/**
* Creates a new file manager.
*
applyMimeTypeOverride();
}
};
+ removeOverrideAction = new I18nAction("fileManager.menu.item.removeOverride") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ removeOverride();
+ }
+ };
}
/**
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));
return;
}
logger.log(Level.INFO, "selected insert override: " + insertCheckBox.isSelected());
- TreePath[] selectedPaths = fileTree.getSelectionPaths();
- for (TreePath selectedPath: selectedPaths) {
- ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPath.getLastPathComponent();
- ProjectFile projectFile = projectFileWrapper.getProjectFile();
- if (!projectFile.isFile()) {
- continue;
- }
+ List<ProjectFileWrapper> selectedProjectFileWrappers = getSelectedProjectFileWrappers(true);
+ for (ProjectFileWrapper selectedProjectFileWrapper : selectedProjectFileWrappers) {
+ ProjectFile projectFile = selectedProjectFileWrapper.getProjectFile();
FileOverride fileOverride = project.getFileOverride(projectFile);
if (fileOverride == null) {
fileOverride = new FileOverride();
* override for the “mime type” setting for multiple files.
*/
private void applyMimeTypeOverride() {
- /* TODO */
+ 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();
+ for (TreePath selectedPath : selectedPaths) {
+ ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPath.getLastPathComponent();
+ if (filesOnly && !projectFileWrapper.getProjectFile().isFile()) {
+ continue;
+ }
+ selectedProjectFileWrappers.add(projectFileWrapper);
+ }
+ return selectedProjectFileWrappers;
}
//
filePathTextField.setText("");
fileNameTextField.setText("");
fileSizeTextField.setText("");
+ overrideAction.setEnabled(false);
if ((selectedPaths != null) && (selectedPaths.length == 1)) {
Object lastPathComponent = selectedPaths[0].getLastPathComponent();
if (!(lastPathComponent instanceof ProjectFileWrapper)) {
fileNameTextField.setText(projectFile.getName());
fileSizeTextField.setText(String.valueOf(projectFile.getSize()));
}
+ overrideAction.setEnabled(true);
} else if ((selectedPaths != null) && (selectedPaths.length > 1)) {
- /* TODO */
}
}
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);
}
}
* @param newRootNode
*/
protected void fireTreeStructureChanged(ProjectFileWrapper newRootNode) {
- for (TreeModelListener treeModelListener: treeModelListeners) {
+ for (TreeModelListener treeModelListener : treeModelListeners) {
treeModelListener.treeStructureChanged(new TreeModelEvent(this, new Object[] { newRootNode }));
}
}
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);
}
general.button.okay.shortDescription: Confirm
general.button.okay.longDescription: Confirm and close dialog
+general.button.continue.name: Continue
+general.button.continue.mnemonic: VK_C
+general.button.continue.accelerator: VK_UNDEFINED
+general.button.continue.shortDescription: Continue
+general.button.continue.longDescription: Continue with the action
+
general.button.cancel.name: Cancel
general.button.cancel.mnemonic: VK_C
general.button.cancel.accelerator: VK_ESCAPE
fileManager.menu.item.applyMimeTypeOverride.shortDescription: Overrides default \u201cContent Type\u201d setting
fileManager.menu.item.applyMimeTypeOverride.longDescription: Overrides default \u201cContent Type\u201d setting
+fileManager.menu.item.removeOverride.name: Remove
+fileManager.menu.item.removeOverride.mnemonic: VK_R
+fileManager.menu.item.removeOverride.accelerator: VK_UNDEFINED
+fileManager.menu.item.removeOverride.shortDescription: Removes the override from the selected files
+fileManager.menu.item.removeOverride.longDescription: Removes the override from the selected files
+
fileManager.dialog.insertOverride.title: Apply Insert Override
fileManager.dialog.insertOverride.message: Please choose a setting for the \u201cInsert\u201d override.
+
+fileManager.dialog.mimeTypeOverride.title: Apply MIME Type Override
+fileManager.dialog.mimeTypeOverride.message: Please choose an override MIME type.
+
+fileManager.dialog.removeOverride.title: Remove Override?
+fileManager.dialog.removeOverride.message: You are about to remove the override for the {0} selected file{0,choice,0#s|1#|2#s}.
general.button.okay.shortDescription: \u00c4nderungen akzeptieren
general.button.okay.longDescription: Dialog schlie\u00dfen und \u00c4nderungen akzeptieren
+general.button.continue.name: Weiter
+general.button.continue.mnemonic: VK_W
+general.button.continue.accelerator: VK_UNDEFINED
+general.button.continue.shortDescription: Weiter
+general.button.continue.longDescription: Setzt die Aktion fort
+
general.button.cancel.name: Abbrechen
general.button.cancel.mnemonic: VK_B
general.button.cancel.accelerator: VK_ESCAPE
fileManager.menu.item.applyMimeTypeOverride.shortDescription: \u00dcberschreibt die \u201eMIME-Typ\u201c-Einstellung
fileManager.menu.item.applyMimeTypeOverride.longDescription: \u00dcberschreibt die \u201eMIME-Typ\u201c-Einstellung
+fileManager.menu.item.removeOverride.name: Entfernen
+fileManager.menu.item.removeOverride.mnemonic: VK_N
+fileManager.menu.item.removeOverride.accelerator: VK_UNDEFINED
+fileManager.menu.item.removeOverride.shortDescription: Entfernt die \u00dcberschreibung der ausgew\u00e4hlten Dateien
+fileManager.menu.item.removeOverride.longDescription: Entfernt die \u00dcberschreibung der ausgew\u00e4hlten Dateien
+
fileManager.dialog.insertOverride.title: \u201eEinf\u00fcgen\u201c-Einstellung \u00fcberschreiben
fileManager.dialog.insertOverride.message: Bitte eine Option zum \u00dcberschreiben der \u201eEinf\u00fcgen\u201c-Einstellung ausw\u00e4hlen.
+
+fileManager.dialog.mimeTypeOverride.title: \u201eMIME-Typ\u201c-Einstellung \u00fcberschreiben
+fileManager.dialog.mimeTypeOverride.message: Bitte einen MIME-Typ zum \u00dcberschreiben ausw\u00e4hlen.
+
+fileManager.dialog.removeOverride.title: \u00dcberschreibungen entfernen?
+fileManager.dialog.removeOverride.message: Die \u00dcberschreibungen f\u00fcr {0} Datei{0,choice,0#en|1#|2#en} werden entfernt.