Create “Insert Project” action on project creation.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 13 Nov 2008 00:33:34 +0000 (01:33 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 13 Nov 2008 00:33:34 +0000 (01:33 +0100)
Let the user select a node on project insert if the project does not contain a default node.
Add English and German texts for node selection dialog and “Insert Project” button.

src/net/pterodactylus/jsite/gui/SwingInterface.java
src/net/pterodactylus/jsite/i18n/jSite.properties
src/net/pterodactylus/jsite/i18n/jSite_de.properties

index f8a43d0..3f2b8b4 100644 (file)
@@ -41,6 +41,8 @@ import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
 import javax.swing.JOptionPane;
 import javax.swing.UIManager;
 import javax.swing.UnsupportedLookAndFeelException;
@@ -786,6 +788,30 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        }
 
        /**
+        * Inserts the given project.
+        *
+        * @param project
+        *            The project to insert
+        */
+       private void insertProject(Project project) {
+               Node targetNode = project.getNode();
+               if (targetNode == null) {
+                       JComboBox nodeComboBox = new JComboBox();
+                       for (Node node : nodeList) {
+                               ((DefaultComboBoxModel) nodeComboBox.getModel()).addElement(node.getName() + " (" + node.getHostname() + ":" + node.getPort() + ")");
+                       }
+                       int selectedOption = JOptionPane.showConfirmDialog(mainWindow, new Object[] { I18n.get("nodeSelectionDialog.selectNode.text"), nodeComboBox }, I18n.get("nodeSelectionDialog.noNodeSelected.text"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
+                       if (selectedOption == JOptionPane.CANCEL_OPTION) {
+                               return;
+                       }
+                       int selectedNodeIndex = nodeComboBox.getSelectedIndex();
+                       logger.log(Level.FINE, "selected node index: " + selectedNodeIndex);
+                       targetNode = nodeList.get(selectedNodeIndex);
+               }
+               logger.log(Level.INFO, "Inserting project “" + project.getName() + "” to node “" + targetNode.getName() + "”...");
+       }
+
+       /**
         * Clones a project.
         *
         * @param project
@@ -858,6 +884,16 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
         * @param switchToProject
         */
        private void projectAdded(final Project project, boolean switchToProject) {
+               insertProjectActions.put(project, new I18nAction("mainWindow.button.insertProject") {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               insertProject(project);
+                       }
+               });
                cloneProjectActions.put(project, new I18nAction("mainWindow.button.cloneProject") {
 
                        /**
index 2cfa7c1..5dbe911 100644 (file)
@@ -170,6 +170,12 @@ mainWindow.button.addProject.accelerator: Ctrl-VK_A
 mainWindow.button.addProject.shortDescription: Add a project
 mainWindow.button.addProject.longDescription: Adds a project
 
+mainWindow.button.insertProject.name: Insert Project
+mainWindow.button.insertProject.mnemonic: VK_I
+mainWindow.button.insertProject.accelerator: Ctrl-VK_I
+mainWindow.button.insertProject.shortDescription: Inserts the selected project
+mainWindow.button.insertProject.longDescription: Inserts the selected project
+
 mainWindow.button.cloneProject.name: Clone Project
 mainWindow.button.cloneProject.mnemonic: VK_L
 mainWindow.button.cloneProject.accelerator: Ctrl-VK_L
@@ -432,3 +438,9 @@ 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}.
+
+#
+# the node selection dialog
+#
+nodeSelectionDialog.noNodeSelected.text: No node selected
+nodeSelectionDialog.selectNode.text: Please select a node.
index c483ebc..61c2d68 100644 (file)
@@ -170,6 +170,12 @@ mainWindow.button.addProject.accelerator: Ctrl-VK_N
 mainWindow.button.addProject.shortDescription: Erstellt ein neues Projekt
 mainWindow.button.addProject.longDescription: Erstellt ein neues Projekt
 
+mainWindow.button.insertProject.name: Projekt hoch laden
+mainWindow.button.insertProject.mnemonic: VK_H
+mainWindow.button.insertProject.accelerator: Ctrl-VK_H
+mainWindow.button.insertProject.shortDescription: L\u00e4dt das angezeigte Projekt hoch
+mainWindow.button.insertProject.longDescription: L\u00e4dt das angezeigte Projekt hoch
+
 mainWindow.button.cloneProject.name: Projekt klonen
 mainWindow.button.cloneProject.mnemonic: VK_K
 mainWindow.button.cloneProject.accelerator: Ctrl-VK_K
@@ -432,3 +438,9 @@ fileManager.dialog.mimeTypeOverride.message: Bitte einen MIME-Typ zum \u00dcbers
 
 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.
+
+#
+# the node selection dialog
+#
+nodeSelectionDialog.noNodeSelected.text: Kein Node ausgew\u00e4hlt
+nodeSelectionDialog.selectNode.text: Bitte einen Node ausw\u00e4hlen.