first stab add project addition
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 May 2008 08:27:44 +0000 (08:27 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 May 2008 08:27:44 +0000 (08:27 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@886 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/core/Core.java
src/net/pterodactylus/jsite/core/CoreImpl.java
src/net/pterodactylus/jsite/core/NodeManager.java
src/net/pterodactylus/jsite/gui/MainWindow.java
src/net/pterodactylus/jsite/gui/SwingInterface.java

index 38e8914..2815e38 100644 (file)
@@ -19,6 +19,7 @@
 
 package net.pterodactylus.jsite.core;
 
+import java.io.IOException;
 import java.net.UnknownHostException;
 import java.util.List;
 
@@ -109,4 +110,17 @@ public interface Core {
         */
        public void disconnectFromNode(Node node);
 
+       /**
+        * Creates a new project with the given name. The returned {@link Project}
+        * will contain a newly generated key pair.
+        * 
+        * @param projectName
+        *            The name of the project
+        * @return A newly created project, or <code>null</code> if key generation
+        *         failed
+        * @throws IOException
+        *             if an I/O error occured communicating with the node
+        */
+       public Project addProject(String projectName) throws IOException;
+
 }
index d2fa1ac..eae7b3a 100644 (file)
@@ -438,6 +438,21 @@ public class CoreImpl implements Core, NodeListener, RequestListener {
                nodeManager.disconnect(node);
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       public Project addProject(String projectName) throws IOException {
+               Project project = new Project();
+               project.setName(projectName);
+               String[] keyPair = nodeManager.generateKeyPair();
+               if (keyPair == null) {
+                       return null;
+               }
+               project.setPrivateKey(keyPair[0]);
+               project.setPublicKey(keyPair[1]);
+               return project;
+       }
+
        //
        // PRIVATE METHODS
        //
index 1e61980..f772dc2 100644 (file)
@@ -40,6 +40,7 @@ import java.util.logging.Logger;
 
 import net.pterodactylus.fcp.highlevel.HighLevelClient;
 import net.pterodactylus.fcp.highlevel.HighLevelClientListener;
+import net.pterodactylus.fcp.highlevel.KeyGenerationResult;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
 
@@ -421,6 +422,28 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                return clientNodes.get(highLevelClient);
        }
 
+       /**
+        * Generates a new SSK key pair.
+        * 
+        * @return An array with the private key at index <code>0</code> and the
+        *         public key at index <code>1</code>
+        * @throws IOException
+        *             if an I/O error occurs communicating with the node
+        */
+       public String[] generateKeyPair() throws IOException {
+               if (!nodes.isEmpty()) {
+                       Node node = nodes.get(0);
+                       HighLevelClient highLevelClient = nodeClients.get(node);
+                       try {
+                               KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
+                               return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
+                       } catch (InterruptedException e) {
+                               /* ignore. */
+                       }
+               }
+               return null;
+       }
+
        //
        // PRIVATE METHODS
        //
index 04c51d2..6708f5e 100644 (file)
@@ -110,7 +110,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable {
 
        /** The request table. */
        private JTable requestTable;
-       
+
        /**
         * Creates a new main window that redirects all actions to the given swing
         * interface.
@@ -236,6 +236,17 @@ public class MainWindow extends JFrame implements WindowListener, I18nable {
                }
        }
 
+       /**
+        * Adds a project to the project pane.
+        * 
+        * @param project
+        *            The project to add
+        */
+       void addProject(Project project) {
+               ProjectPanel projectPanel = new ProjectPanel(swingInterface, project);
+               projectPane.add(project.getName(), projectPanel);
+       }
+
        //
        // PRIVATE METHODS
        //
@@ -342,7 +353,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable {
 
                requestTable = new JTable(swingInterface.getRequestTableModel());
                getContentPane().add(new JScrollPane(requestTable), BorderLayout.CENTER);
-               
+
 // JPanel lowerPanel = new JPanel(new BorderLayout(12, 12));
 // getContentPane().add(lowerPanel, BorderLayout.CENTER);
        }
index 65fcebe..0accb58 100644 (file)
@@ -816,9 +816,13 @@ public class SwingInterface implements CoreListener, LoggingListener {
         * Adds a project.
         */
        private void addProject() {
-               Project project = new Project();
-               project.setName("New Project");
-               project.setDescription("");
+               try {
+                       Project project = core.addProject("New Project");
+                       System.out.println("private: " + project.getPrivateKey() + ", public: " + project.getPublicKey());
+                       mainWindow.addProject(project);
+               } catch (IOException e) {
+                       JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
+               }
        }
 
        /**