make delete and clone buttons project specific
[jSite2.git] / src / net / pterodactylus / jsite / gui / SwingInterface.java
index 3b8971c..2c032ea 100644 (file)
@@ -115,11 +115,11 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        /** 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;
@@ -133,6 +133,9 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        /** 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
        //
@@ -350,21 +353,25 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        }
 
        /**
-        * 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);
        }
 
        /**
@@ -377,6 +384,15 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        }
 
        /**
+        * 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
@@ -574,26 +590,6 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
                                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();
-                       }
-               };
        }
 
        /**
@@ -765,10 +761,7 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
         */
        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);
@@ -780,16 +773,23 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
 
        /**
         * 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);
        }
 
        //
@@ -802,7 +802,7 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        public void loadingProjectsDone(String directory) {
                mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.projectLoadingDone"));
                for (Project project: core.getProjects()) {
-                       mainWindow.addProject(project, false);
+                       projectAdded(project, false);
                }
        }
 
@@ -830,6 +830,52 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        /**
         * {@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"));
        }