X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FSwingInterface.java;h=3f2b8b414df9414af6172cfebe111797c8247b5b;hb=f01867ca12edbb3fd6a34ebc3572cdde9a1f280c;hp=397688a1049aa2d46afd4e8001d5dd231f78cf42;hpb=c63257e8cc0ba1a5aca9364b22171abe7279d479;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index 397688a..3f2b8b4 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -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; @@ -115,6 +117,9 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh /** The “add project” action. */ private I18nAction addProjectAction; + /** The “insert project” actions. */ + private Map insertProjectActions = new HashMap(); + /** The “clone project” actions. */ private Map cloneProjectActions = new HashMap(); @@ -353,6 +358,17 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh } /** + * Returns the “insert project” action for the given project. + * + * @param project + * The project to get the “insert project” action for + * @return The “insert project” action + */ + I18nAction getInsertProjectAction(Project project) { + return insertProjectActions.get(project); + } + + /** * Returns the “clone project” action for the given project. * * @param project @@ -772,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 @@ -844,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") { /**