From 78dd8a015cbfdedca1a962d03d16b89ee8187b8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 15 May 2008 08:27:44 +0000 Subject: [PATCH] first stab add project addition git-svn-id: http://trooper/svn/projects/jSite/trunk@886 c3eda9e8-030b-0410-8277-bc7414b0a119 --- src/net/pterodactylus/jsite/core/Core.java | 14 +++++++++++++ src/net/pterodactylus/jsite/core/CoreImpl.java | 15 ++++++++++++++ src/net/pterodactylus/jsite/core/NodeManager.java | 23 ++++++++++++++++++++++ src/net/pterodactylus/jsite/gui/MainWindow.java | 15 ++++++++++++-- .../pterodactylus/jsite/gui/SwingInterface.java | 10 +++++++--- 5 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/net/pterodactylus/jsite/core/Core.java b/src/net/pterodactylus/jsite/core/Core.java index 38e8914..2815e38 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -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 null if key generation + * failed + * @throws IOException + * if an I/O error occured communicating with the node + */ + public Project addProject(String projectName) throws IOException; + } diff --git a/src/net/pterodactylus/jsite/core/CoreImpl.java b/src/net/pterodactylus/jsite/core/CoreImpl.java index d2fa1ac..eae7b3a 100644 --- a/src/net/pterodactylus/jsite/core/CoreImpl.java +++ b/src/net/pterodactylus/jsite/core/CoreImpl.java @@ -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 // diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index 1e61980..f772dc2 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -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, PropertyChangeListener, High return clientNodes.get(highLevelClient); } + /** + * Generates a new SSK key pair. + * + * @return An array with the private key at index 0 and the + * public key at index 1 + * @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 // diff --git a/src/net/pterodactylus/jsite/gui/MainWindow.java b/src/net/pterodactylus/jsite/gui/MainWindow.java index 04c51d2..6708f5e 100644 --- a/src/net/pterodactylus/jsite/gui/MainWindow.java +++ b/src/net/pterodactylus/jsite/gui/MainWindow.java @@ -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); } diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index 65fcebe..0accb58 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -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); + } } /** -- 2.7.4