From: David ‘Bombe’ Roden Date: Tue, 27 May 2008 18:39:27 +0000 (+0200) Subject: make delete and clone buttons project specific X-Git-Url: https://git.pterodactylus.net/?p=jSite2.git;a=commitdiff_plain;h=03d89340924164e1158490999186383217e9d2bd make delete and clone buttons project specific --- diff --git a/src/net/pterodactylus/jsite/core/Core.java b/src/net/pterodactylus/jsite/core/Core.java index 4909b4d..325d4c5 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -112,16 +112,22 @@ public interface Core { public void disconnectFromNode(Node node); /** - * Creates a new project. The returned {@link Project} will contain a newly - * generated key pair. + * Creates a new project. * - * @return A newly created project * @throws IOException * if an I/O error occured communicating with the node * @throws JSiteException * if there is a problem with the node */ - public Project createProject() throws IOException, JSiteException; + public void createProject() throws IOException, JSiteException; + + /** + * Removes the given project. + * + * @param project + * The project to remove + */ + public void removeProject(Project project); /** * Returns a list of all projects. diff --git a/src/net/pterodactylus/jsite/core/CoreImpl.java b/src/net/pterodactylus/jsite/core/CoreImpl.java index d0e78b9..dbc5997 100644 --- a/src/net/pterodactylus/jsite/core/CoreImpl.java +++ b/src/net/pterodactylus/jsite/core/CoreImpl.java @@ -120,6 +120,30 @@ public class CoreImpl implements Core, NodeListener, RequestListener { } /** + * 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 @@ -414,10 +438,19 @@ public class CoreImpl implements Core, NodeListener, RequestListener { /** * {@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 // diff --git a/src/net/pterodactylus/jsite/core/CoreListener.java b/src/net/pterodactylus/jsite/core/CoreListener.java index d4a522e..977e2fe 100644 --- a/src/net/pterodactylus/jsite/core/CoreListener.java +++ b/src/net/pterodactylus/jsite/core/CoreListener.java @@ -69,6 +69,22 @@ public interface CoreListener { */ public void savingProjectsFailed(String directory, Throwable throwable); + /** + * Notifies a listener that the given project was added. + * + * @param project + * The project that was added. + */ + public void projectAdded(Project project); + + /** + * Notifies a listener that the given project was removed. + * + * @param project + * The project that was removed. + */ + public void projectRemoved(Project project); + // // node configuration // diff --git a/src/net/pterodactylus/jsite/gui/MainWindow.java b/src/net/pterodactylus/jsite/gui/MainWindow.java index 7c2795f..843eaa1 100644 --- a/src/net/pterodactylus/jsite/gui/MainWindow.java +++ b/src/net/pterodactylus/jsite/gui/MainWindow.java @@ -478,8 +478,6 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop swingInterface.getQuitAction().updateI18n(); swingInterface.getAddNodeAction().updateI18n(); swingInterface.getAddProjectAction().updateI18n(); - swingInterface.getCloneProjectAction().updateI18n(); - swingInterface.getDeleteProjectAction().updateI18n(); swingInterface.getHelpAboutAction().updateI18n(); jSiteMenu.updateI18n(); nodeMenu.updateI18n(); @@ -490,6 +488,10 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop swingInterface.getNodeEditAction(node).updateI18n(); swingInterface.getNodeDeleteAction(node).updateI18n(); } + for (Project project: swingInterface.getProjects()) { + swingInterface.getCloneProjectAction(project).updateI18n(); + swingInterface.getDeleteProjectAction(project).updateI18n(); + } for (I18nAction languageAction: swingInterface.getLanguageActions()) { languageAction.updateI18n(); } diff --git a/src/net/pterodactylus/jsite/gui/ProjectPanel.java b/src/net/pterodactylus/jsite/gui/ProjectPanel.java index 837f5fe..73d901f 100644 --- a/src/net/pterodactylus/jsite/gui/ProjectPanel.java +++ b/src/net/pterodactylus/jsite/gui/ProjectPanel.java @@ -211,8 +211,8 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12)); - buttonPanel.add(new JButton(swingInterface.getDeleteProjectAction())); - buttonPanel.add(new JButton(swingInterface.getCloneProjectAction())); + buttonPanel.add(new JButton(swingInterface.getDeleteProjectAction(project))); + buttonPanel.add(new JButton(swingInterface.getCloneProjectAction(project))); return buttonPanel; } 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")); }