Add and expose “Insert Project” actions.
[jSite2.git] / src / net / pterodactylus / jsite / gui / SwingInterface.java
index 9531717..f8a43d0 100644 (file)
@@ -49,9 +49,9 @@ import net.pterodactylus.jsite.core.Core;
 import net.pterodactylus.jsite.core.CoreListener;
 import net.pterodactylus.jsite.core.JSiteException;
 import net.pterodactylus.jsite.core.Node;
+import net.pterodactylus.jsite.core.Project;
 import net.pterodactylus.jsite.i18n.I18n;
 import net.pterodactylus.jsite.i18n.gui.I18nAction;
-import net.pterodactylus.jsite.project.Project;
 import net.pterodactylus.util.image.IconLoader;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
@@ -115,6 +115,9 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        /** The “add project” action. */
        private I18nAction addProjectAction;
 
+       /** The “insert project” actions. */
+       private Map<Project, I18nAction> insertProjectActions = new HashMap<Project, I18nAction>();
+
        /** The “clone project” actions. */
        private Map<Project, I18nAction> cloneProjectActions = new HashMap<Project, I18nAction>();
 
@@ -353,6 +356,17 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        }
 
        /**
+        * Returns the “insert project” action for the given project.
+        *
+        * @param project
+        *            The project to get the “insert project” action for
+        * @return The “insert project” action
+        */
+       I18nAction getInsertProjectAction(Project project) {
+               return insertProjectActions.get(project);
+       }
+
+       /**
         * Returns the “clone project” action for the given project.
         *
         * @param project
@@ -546,8 +560,9 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
                        }
                };
                List<Locale> availableLanguages = I18n.findAvailableLanguages();
-               for (final Locale locale: availableLanguages) {
-                       I18nAction languageAction = new I18nAction("general.language." + locale.getLanguage(), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
+               for (final Locale locale : availableLanguages) {
+                       String language = locale.getLanguage();
+                       I18nAction languageAction = new I18nAction("general.language." + language, IconLoader.loadIcon("/flag-" + language + ".png")) {
 
                                @SuppressWarnings("synthetic-access")
                                public void actionPerformed(ActionEvent e) {
@@ -555,7 +570,7 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
                                }
 
                        };
-                       if (I18n.getLocale().getLanguage().equals(locale.getLanguage())) {
+                       if (I18n.getLocale().getLanguage().equals(language)) {
                                languageAction.setEnabled(false);
                        }
                        languageActions.add(languageAction);
@@ -743,7 +758,7 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
         *            The action that triggered the change
         */
        private void changeLanguage(Locale newLocale, I18nAction languageAction) {
-               for (I18nAction i18nAction: languageActions) {
+               for (I18nAction i18nAction : languageActions) {
                        i18nAction.setEnabled(i18nAction != languageAction);
                }
                I18n.setLocale(newLocale);
@@ -762,9 +777,8 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        private void addProject() {
                try {
                        core.createProject();
-               } catch (JSiteException nne1) {
-                       /* TODO - add i18n */
-                       JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
+               } catch (JSiteException jse1) {
+                       JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.error.notConnected.message"), I18n.get("mainWindow.error.notConnected.title"), JOptionPane.ERROR_MESSAGE);
                } catch (IOException e) {
                        /* TODO - add i18n */
                        JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
@@ -804,7 +818,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()) {
+               for (Project project : core.getProjects()) {
                        projectAdded(project, false);
                }
        }
@@ -1037,14 +1051,14 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        }
 
        /**
-        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertStarted(net.pterodactylus.jsite.project.Project)
+        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertStarted(net.pterodactylus.jsite.core.Project)
         */
        public void projectInsertStarted(Project project) {
                mainWindow.projectInsertStarted(project);
        }
 
        /**
-        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertProgressed(net.pterodactylus.jsite.project.Project,
+        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertProgressed(net.pterodactylus.jsite.core.Project,
         *      int, int, int, int, int, boolean)
         */
        public void projectInsertProgressed(Project project, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean finalizedTotal) {
@@ -1052,7 +1066,7 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        }
 
        /**
-        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertGeneratedURI(net.pterodactylus.jsite.project.Project,
+        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertGeneratedURI(net.pterodactylus.jsite.core.Project,
         *      java.lang.String)
         */
        public void projectInsertGeneratedURI(Project project, String uri) {
@@ -1060,7 +1074,7 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh
        }
 
        /**
-        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertFinished(net.pterodactylus.jsite.project.Project,
+        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertFinished(net.pterodactylus.jsite.core.Project,
         *      boolean)
         */
        public void projectInsertFinished(Project project, boolean success) {