}
/**
+ * Notifies all listeners that a project was added.
+ *
+ * @param project
+ * The project that was added
+ */
+ private void fireProjectAdded(Project project) {
+ for (CoreListener coreListener: coreListeners) {
+ coreListener.projectAdded(project);
+ }
+ }
+
+ /**
+ * Notifies all listeners that a project was removed.
+ *
+ * @param project
+ * The project that was removed
+ */
+ private void fireProjectRemoved(Project project) {
+ for (CoreListener coreListener: coreListeners) {
+ coreListener.projectRemoved(project);
+ }
+ }
+
+ /**
* Notifies all listeners that the nodes were successfully loaded.
*
* @param directory
/**
* {@inheritDoc}
*/
- public Project createProject() throws IOException, JSiteException {
- return projectManager.createProject();
+ public void createProject() throws IOException, JSiteException {
+ Project newProject = projectManager.createProject();
+ fireProjectAdded(newProject);
}
+ /**
+ * {@inheritDoc}
+ */
+ public void removeProject(Project project) {
+ projectManager.removeProject(project);
+ fireProjectRemoved(project);
+ }
+
//
// PRIVATE METHODS
//
/** The “add project” action. */
private I18nAction addProjectAction;
- /** The “clone project” action. */
- private I18nAction cloneProjectAction;
+ /** The “clone project” actions. */
+ private Map<Project, I18nAction> cloneProjectActions = new HashMap<Project, I18nAction>();
- /** The “delete project” action. */
- private I18nAction deleteProjectAction;
+ /** The “delete project” actions. */
+ private Map<Project, I18nAction> deleteProjectActions = new HashMap<Project, I18nAction>();
/** The “about” dialog. */
private AboutDialog aboutDialog;
/** The list of all defined nodes. */
private List<Node> nodeList = Collections.synchronizedList(new ArrayList<Node>());
+ /** The list of all projects. */
+ private List<Project> projectList = Collections.synchronizedList(new ArrayList<Project>());
+
//
// CONFIGURATION
//
}
/**
- * Returns the “clone project” action.
+ * Returns the “clone project” action for the given project.
*
+ * @param project
+ * The project to get the “clone project” action for
* @return The “clone project” action
*/
- I18nAction getCloneProjectAction() {
- return cloneProjectAction;
+ I18nAction getCloneProjectAction(Project project) {
+ return cloneProjectActions.get(project);
}
/**
- * Returns the “delete project” action.
+ * Returns the “delete project” action for the given project.
*
+ * @param project
+ * The project to get the “delete project” action for
* @return The “delete project” action
*/
- I18nAction getDeleteProjectAction() {
- return deleteProjectAction;
+ I18nAction getDeleteProjectAction(Project project) {
+ return deleteProjectActions.get(project);
}
/**
}
/**
+ * Returns a list of all projects.
+ *
+ * @return All projects
+ */
+ List<Project> getProjects() {
+ return projectList;
+ }
+
+ /**
* Returns the thread pool used for off-thread processes.
*
* @return The thread pool
addProject();
}
};
- cloneProjectAction = new I18nAction("mainWindow.button.cloneProject") {
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("synthetic-access")
- public void actionPerformed(ActionEvent actionEvent) {
- cloneProject();
- }
- };
- deleteProjectAction = new I18nAction("mainWindow.button.deleteProject") {
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("synthetic-access")
- public void actionPerformed(ActionEvent actionEvent) {
- deleteProject();
- }
- };
}
/**
*/
private void addProject() {
try {
- Project project = core.createProject();
- project.setName(I18n.get("general.newProject.name"));
- project.setDescription(I18n.get("general.newProject.description", new Date()));
- mainWindow.addProject(project, true);
+ core.createProject();
} catch (JSiteException nne1) {
/* TODO - add i18n */
JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
/**
* Clones a project.
+ *
+ * @param project
+ * The project to clone
*/
- private void cloneProject() {
+ private void cloneProject(Project project) {
+ System.out.println("clone " + project);
/* TODO */
}
/**
* Deletes a project.
+ *
+ * @param project
+ * The project to delete
*/
- private void deleteProject() {
- /* TODO */
+ private void deleteProject(Project project) {
+ System.out.println("delete " + project);
}
//
public void loadingProjectsDone(String directory) {
mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.projectLoadingDone"));
for (Project project: core.getProjects()) {
- mainWindow.addProject(project, false);
+ projectAdded(project, false);
}
}
/**
* {@inheritDoc}
*/
+ public void projectAdded(Project project) {
+ projectAdded(project, true);
+ }
+
+ /**
+ *
+ * @param project
+ * @param switchToProject
+ */
+ private void projectAdded(final Project project, boolean switchToProject) {
+ project.setName(I18n.get("general.newProject.name"));
+ project.setDescription(I18n.get("general.newProject.description", new Date()));
+ cloneProjectActions.put(project, new I18nAction("mainWindow.button.cloneProject") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ cloneProject(project);
+ }
+ });
+ deleteProjectActions.put(project, new I18nAction("mainWindow.button.deleteProject") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ deleteProject(project);
+ }
+ });
+ projectList.add(project);
+ mainWindow.addProject(project, switchToProject);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void projectRemoved(Project project) {
+ /* TODO - implement */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void loadingNodesDone(String directory) {
mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.loadingNodesDone"));
}