public void createProject() throws IOException, JSiteException;
/**
+ * Clones the given project. {@link CoreListener}s will be notified of the
+ * new clone via the {@link CoreListener#projectCloned(Project, Project)}
+ * event.
+ *
+ * @param project
+ * The project to clone
+ */
+ public void cloneProject(Project project);
+
+ /**
* Removes the given project.
*
* @param project
coreListener.projectAdded(project);
}
}
+
+ /**
+ * Notifies all listeners that a project was cloned.
+ * @param clonedProject The project that was cloned
+ * @param projectClone The clone of the project
+ */
+ private void fireProjectCloned(Project clonedProject, Project projectClone) {
+ for (CoreListener coreListener: coreListeners) {
+ coreListener.projectCloned(clonedProject, projectClone);
+ }
+ }
/**
* Notifies all listeners that a project was removed.
/**
* {@inheritDoc}
*/
+ public void cloneProject(Project project) {
+ Project projectClone = projectManager.cloneProject(project);
+ fireProjectCloned(project, projectClone);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void removeProject(Project project) {
projectManager.removeProject(project);
fireProjectRemoved(project);
public void projectAdded(Project project);
/**
+ * Notifies a listener that a project was cloned.
+ *
+ * @param clonedProject
+ * The clones project
+ * @param projectClone
+ * The clone of the project
+ */
+ public void projectCloned(Project clonedProject, Project projectClone);
+
+ /**
* Notifies a listener that the given project was removed.
*
* @param project
* The project to clone
*/
private void cloneProject(Project project) {
- /* TODO */
+ core.cloneProject(project);
}
/**
project.setDescription(I18n.get("general.newProject.description", new Date()));
projectAdded(project, true);
}
-
+
/**
- *
* @param project
* @param switchToProject
*/
/**
* {@inheritDoc}
*/
+ public void projectCloned(Project clonedProject, Project projectClone) {
+ projectAdded(projectClone, true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void projectRemoved(Project project) {
mainWindow.removeProject(project);
cloneProjectActions.remove(project);
private List<Entry> virtualEntries = new ArrayList<Entry>();
/**
+ * Creates a new project.
+ */
+ public Project() {
+ /* do nothing. */
+ }
+
+ /**
+ * Clones the given project.
+ *
+ * @param project
+ */
+ Project(Project project) {
+ this.name = project.name;
+ this.description = project.description;
+ this.publicKey = project.publicKey;
+ this.privateKey = project.privateKey;
+ this.basePath = project.basePath;
+ this.basePathEntries.addAll(project.basePathEntries);
+ this.virtualEntries.addAll(project.virtualEntries);
+ }
+
+ /**
* Returns the internal ID.
*
* @return The internal ID
public Project createProject() throws IOException, JSiteException {
Project project = new Project();
String[] keyPair = nodeManager.generateKeyPair();
- byte[] idBytes = new byte[16];
- random.nextBytes(idBytes);
- project.setId(Hex.toHex(idBytes));
+ project.setId(generateId());
project.setName("");
project.setDescription("");
project.setPrivateKey(keyPair[0]);
}
/**
+ * Clones the given project and returns the clone. The clone will be
+ * identical in all user-exposed fields, except for the project’s
+ * {@link Project#getId ID}.
+ *
+ * @param project
+ * The project to clone
+ * @return The cloned project
+ */
+ public Project cloneProject(Project project) {
+ Project projectClone = new Project(project);
+ projects.add(projectClone);
+ projectClone.setId(generateId());
+ projectClone.addPropertyChangeListener(this);
+ try {
+ save();
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
+ return projectClone;
+ }
+
+ /**
* Removes the given project.
*
* @param project
}
//
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Generates a new random ID, consisting of 16 random bytes converted to a
+ * hexadecimal number.
+ *
+ * @return The new ID
+ */
+ private static String generateId() {
+ byte[] idBytes = new byte[16];
+ random.nextBytes(idBytes);
+ return Hex.toHex(idBytes);
+ }
+
+ //
// INTERFACE PropertyChangeListener
//