X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FSwingInterface.java;h=2c032ea40ecd066d31d20a17445f589f59784ec8;hb=03d89340924164e1158490999186383217e9d2bd;hp=3b8971c6c23b2ac138763682e05bf8e35d5c1496;hpb=ed4e59490c6f91adcd0fdbc31f32684fdf6224eb;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index 3b8971c..2c032ea 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -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 cloneProjectActions = new HashMap(); - /** The “delete project” action. */ - private I18nAction deleteProjectAction; + /** The “delete project” actions. */ + private Map deleteProjectActions = new HashMap(); /** 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 nodeList = Collections.synchronizedList(new ArrayList()); + /** The list of all projects. */ + private List projectList = Collections.synchronizedList(new ArrayList()); + // // 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 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")); }