package net.pterodactylus.jsite.core;
+import java.io.IOException;
import java.net.UnknownHostException;
import java.util.List;
*/
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;
+
}
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
//
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;
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
//
/** The request table. */
private JTable requestTable;
-
+
/**
* Creates a new main window that redirects all actions to the given swing
* interface.
}
}
+ /**
+ * 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
//
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);
}
* 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);
+ }
}
/**