Revision: 3798
Author: [email protected]
Date: Wed Jul 28 09:52:56 2010
Log: Added in hooks for the enterprise to change saving and loading behaviour. Also fixed bugs in the ProfileManager and InvadersAction.
http://code.google.com/p/power-architect/source/detail?r=3798

Modified:
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java /trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
 /trunk/src/main/java/ca/sqlpower/architect/profile/ProfileManagerImpl.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSession.java /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java /trunk/src/main/java/ca/sqlpower/architect/swingui/action/InvadersAction.java /trunk/src/main/java/ca/sqlpower/architect/swingui/action/OpenProjectAction.java

=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java Tue Jul 27 14:11:45 2010 +++ /trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java Wed Jul 28 09:52:56 2010
@@ -26,6 +26,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.Executor;

 import javax.swing.JComponent;
 import javax.swing.JDialog;
@@ -518,6 +519,12 @@
         // TODO Auto-generated method stub

     }
+
+    @Override
+    public Executor getSaveExecutor() {
+        // TODO Auto-generated method stub
+        return null;
+    }

     @Override
     public ArchitectStatusBar getStatusInformation() {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java Wed Jul 28 08:41:01 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java Wed Jul 28 09:52:56 2010
@@ -430,7 +430,7 @@
         }

     }
-
+
public static ProjectLocation createNewServerSession(SPServerInfo serviceInfo, String name, ArchitectSession session) throws URISyntaxException, ClientProtocolException, IOException, JSONException {

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/ProfileManagerImpl.java Fri Jul 16 13:23:39 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/ProfileManagerImpl.java Wed Jul 28 09:52:56 2010
@@ -303,6 +303,7 @@

     public void addTableProfileResult(TableProfileResult child) {
         results.add(child);
+        child.setParent(this);
         fireProfilesAdded(Collections.singletonList(child));
     }

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java Tue Jul 27 14:11:45 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java Wed Jul 28 09:52:56 2010
@@ -176,6 +176,10 @@
     private static Logger logger = Logger.getLogger(ArchitectFrame.class);

     public static final double ZOOM_STEP = 0.25;
+
+    public static interface Saver {
+ public boolean save(ArchitectSwingSession session, boolean showChooser);
+    }

     private ArchitectSwingSessionContext context;
     private ArchitectSwingSession currentSession = null;
@@ -265,6 +269,12 @@

private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();

+    private Saver saveBehaviour = new Saver() {
+ public boolean save(ArchitectSwingSession session, boolean showChooser) {
+            return session.saveOrSaveAs(showChooser, true);
+        }
+    };
+
private final EditCriticSettingsAction showCriticsManagerAction = new EditCriticSettingsAction(this);

     /**
@@ -472,6 +482,14 @@

     private JMenuItem enterpriseLinkButton;

+    private JButton saveProjectButton;
+
+    private JMenuItem saveProjectMenu;
+
+    private JMenuItem saveProjectAsMenu;
+
+    private JMenuItem saveAllProjectsMenu;
+
     /**
* Sets up a new ArchitectFrame, which represents a window containing one or * more {...@link ArchitectSwingSession}s. It will not become visible until
@@ -628,7 +646,7 @@
                         JMenuBar mb = newFrame.menuBar;
                         for (int i = 0; i < mb.getMenuCount(); i++) {
if ("TOOLS_MENU".equals(mb.getMenu(i).getName())) { - mb.getMenu(i).add(new InvadersAction(newSession)); + mb.getMenu(i).add(new InvadersAction(newFrame));
                             }
                         }
                     }
@@ -650,7 +668,7 @@
Messages.getString("ArchitectFrame.saveProjectActionIconDescription"), //$NON-NLS-1$ sprefs.getInt(ArchitectSwingUserSettings.ICON_SIZE, ArchitectSwingSessionContext.ICON_SIZE))) {
             public void actionPerformed(ActionEvent e) {
-                currentSession.saveOrSaveAs(false, true);
+                saveBehaviour.save(currentSession, false);
stackedTabPane.setTitleAt(stackedTabPane.getSelectedIndex(), currentSession.getName()); setTitle(Messages.getString("ArchitectSwingSessionImpl.mainFrameTitle", currentSession.getName())); //$NON-NLS-1$
             }
@@ -664,7 +682,7 @@
Messages.getString("ArchitectFrame.saveProjectAsActionIconDescription"), //$NON-NLS-1$ sprefs.getInt(ArchitectSwingUserSettings.ICON_SIZE, ArchitectSwingSessionContext.ICON_SIZE))) {
             public void actionPerformed(ActionEvent e) {
-                currentSession.saveOrSaveAs(true, true);
+                saveBehaviour.save(currentSession, true);
stackedTabPane.setTitleAt(stackedTabPane.getSelectedIndex(), currentSession.getName()); setTitle(Messages.getString("ArchitectSwingSessionImpl.mainFrameTitle", currentSession.getName())); //$NON-NLS-1$
             }
@@ -677,7 +695,7 @@
sprefs.getInt(ArchitectSwingUserSettings.ICON_SIZE, ArchitectSwingSessionContext.ICON_SIZE))) {
             public void actionPerformed(ActionEvent e) {
                 for (ArchitectSwingSession session : sessions) {
-                    session.saveOrSaveAs(false, true);
+                    saveBehaviour.save(session, false);
stackedTabPane.setTitleAt(stackedTabPane.indexOfTab(sessionTabs.get(session)), session.getName());
                 }
setTitle(Messages.getString("ArchitectSwingSessionImpl.mainFrameTitle", currentSession.getName())); //$NON-NLS-1$
@@ -775,7 +793,7 @@

         newProjectButton = projectBar.add(newProjectAction);
         projectBar.add(openProjectAction);
-        projectBar.add(saveProjectAction);
+        saveProjectButton = projectBar.add(saveProjectAction);
         projectBar.addSeparator();

         projectBar.add(refreshProjectAction);
@@ -872,7 +890,7 @@
             public void loadFile(String fileName) throws IOException {
                 File f = new File(fileName);
                 try {
- OpenProjectAction.openAsynchronously(context.createSession(), f, currentSession); + OpenProjectAction.getFileLoader().openAsynchronously(context.createSession(), f, currentSession);
                 } catch (SQLObjectException ex) {
SPSUtils.showExceptionDialogNoReport(ArchitectFrame.this, Messages.getString("ArchitectSwingSessionImpl.openProjectFileFailed"), ex); //$NON-NLS-1$
                 }
@@ -880,9 +898,9 @@
         });
         fileMenu.add(closeProjectAction);
         fileMenu.addSeparator();
-        fileMenu.add(saveProjectAction);
-        fileMenu.add(saveProjectAsAction);
-        fileMenu.add(saveAllProjectsAction);
+        saveProjectMenu = fileMenu.add(saveProjectAction);
+        saveProjectAsMenu = fileMenu.add(saveProjectAsAction);
+        saveAllProjectsMenu = fileMenu.add(saveAllProjectsAction);
         fileMenu.add(printAction);
         fileMenu.add(exportPlaypenToPDFAction);
         fileMenu.add(exportHTMLReportAction);
@@ -1410,7 +1428,11 @@
         this.newWindowAction = newWindowAction;
         newWindowMenu.setAction(newWindowAction);
     }
-
+
+    public void setSaveBehaviour(Saver saveBehaviour) {
+        this.saveBehaviour = saveBehaviour;
+    }
+
     public ZoomToFitAction getZoomToFitAction() {
         return zoomToFitAction;
     }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSession.java Tue Jul 27 14:11:45 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSession.java Wed Jul 28 09:52:56 2010
@@ -20,6 +20,7 @@

 import java.awt.Window;
 import java.util.List;
+import java.util.concurrent.Executor;

 import javax.swing.JComponent;
 import javax.swing.JDialog;
@@ -341,6 +342,8 @@
     public JScrollPane getPlayPenScrollPane();

     void setPlayPenScrollPane(JScrollPane ppScrollPane);
+
+    public Executor getSaveExecutor();

     ArchitectStatusBar getStatusInformation();
 }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Tue Jul 27 14:11:45 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Wed Jul 28 09:52:56 2010
@@ -283,7 +283,7 @@
             public void loadFile(String fileName) throws IOException {
                 File f = new File(fileName);
                 try {
- OpenProjectAction.openAsynchronously(getContext().createSession(), f, ArchitectSwingSessionImpl.this); + OpenProjectAction.getFileLoader().openAsynchronously(getContext().createSession(), f, ArchitectSwingSessionImpl.this);
                 } catch (SQLObjectException ex) {
SPSUtils.showExceptionDialogNoReport(getArchitectFrame(), Messages.getString("ArchitectSwingSessionImpl.openProjectFileFailed"), ex); //$NON-NLS-1$
                 }
@@ -621,6 +621,10 @@
             return saveTask.success;
         }
     }
+
+    public Executor getSaveExecutor() {
+        return saveExecutor;
+    }

     // STUFF BROUGHT IN FROM SwingUIProject

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/action/InvadersAction.java Mon Jul 12 08:21:11 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/action/InvadersAction.java Wed Jul 28 09:52:56 2010
@@ -34,6 +34,7 @@

 import javax.swing.Timer;

+import ca.sqlpower.architect.swingui.ArchitectFrame;
 import ca.sqlpower.architect.swingui.ArchitectSwingSession;
 import ca.sqlpower.architect.swingui.PlayPen;
 import ca.sqlpower.architect.swingui.Relationship;
@@ -49,8 +50,8 @@

 public class InvadersAction extends AbstractArchitectAction {

-    public InvadersAction(ArchitectSwingSession session) {
- super(session, "Architect Invaders", "Defend your data model against interplanetary attack");
+    public InvadersAction(ArchitectFrame frame) {
+ super(frame, "Architect Invaders", "Defend your data model against interplanetary attack");
     }

     public void actionPerformed(ActionEvent e) {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/action/OpenProjectAction.java Mon Jul 12 08:21:11 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/action/OpenProjectAction.java Wed Jul 28 09:52:56 2010
@@ -49,26 +49,9 @@
 public class OpenProjectAction extends AbstractArchitectAction {

private static final Logger logger = Logger.getLogger(OpenProjectAction.class);
-
-    public OpenProjectAction(ArchitectFrame frame) {
- super(frame, Messages.getString("OpenProjectAction.name"), Messages.getString("OpenProjectAction.description"), "folder"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit()
-                .getMenuShortcutKeyMask()));
-    }
-
-    public void actionPerformed(ActionEvent e) {
- JFileChooser chooser = new JFileChooser(getSession().getRecentMenu().getMostRecentFile());
-        chooser.addChoosableFileFilter(SPSUtils.ARCHITECT_FILE_FILTER);
-        int returnVal = chooser.showOpenDialog(frame);
-        if (returnVal == JFileChooser.APPROVE_OPTION) {
-            File f = chooser.getSelectedFile();
-            try {
- OpenProjectAction.openAsynchronously(getSession().getContext().createSession(), f, getSession());
-            } catch (SQLObjectException ex) {
- SPSUtils.showExceptionDialogNoReport(getSession().getArchitectFrame(), - Messages.getString("OpenProjectAction.failedToOpenProjectFile"), ex); //$NON-NLS-1$
-            }
-        }
+
+    public static interface FileLoader {
+ public void openAsynchronously(ArchitectSwingSession newSession, File f, ArchitectSwingSession openingSession);
     }

     /**
@@ -92,21 +75,52 @@
* and unmodified project) then openingSession.close() will be
      *            called once the project is finished loading.
      */
- public static void openAsynchronously(ArchitectSwingSession newSession, File f, ArchitectSwingSession openingSession) {
-        LoadFileWorker worker;
-        try {
-            worker = new LoadFileWorker(f, newSession, openingSession);
-            new Thread(worker).start();
-        } catch (Exception e1) {
- ASUtils.showExceptionDialogNoReport(Messages.getString("OpenProjectAction.errorLoadingFile"), e1); //$NON-NLS-1$
-        }
-
+    private static FileLoader fileLoader = new FileLoader() {
+ public void openAsynchronously(ArchitectSwingSession newSession, File f, ArchitectSwingSession openingSession) {
+            LoadFileWorker worker;
+            try {
+                worker = new LoadFileWorker(f, newSession, openingSession);
+                new Thread(worker).start();
+            } catch (Exception e1) {
+ ASUtils.showExceptionDialogNoReport(Messages.getString("OpenProjectAction.errorLoadingFile"), e1); //$NON-NLS-1$
+            }
+
+        }
+    };
+
+    public static void setFileLoader(FileLoader loader) {
+        fileLoader = loader;
+    }
+
+    public static FileLoader getFileLoader() {
+        return fileLoader;
+    }
+
+    public OpenProjectAction(ArchitectFrame frame) {
+ super(frame, Messages.getString("OpenProjectAction.name"), Messages.getString("OpenProjectAction.description"), "folder"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit()
+                .getMenuShortcutKeyMask()));
     }

+    public void actionPerformed(ActionEvent e) {
+ JFileChooser chooser = new JFileChooser(getSession().getRecentMenu().getMostRecentFile());
+        chooser.addChoosableFileFilter(SPSUtils.ARCHITECT_FILE_FILTER);
+        int returnVal = chooser.showOpenDialog(frame);
+        if (returnVal == JFileChooser.APPROVE_OPTION) {
+            File f = chooser.getSelectedFile();
+            try {
+ fileLoader.openAsynchronously(getSession().getContext().createSession(), f, getSession());
+            } catch (SQLObjectException ex) {
+ SPSUtils.showExceptionDialogNoReport(getSession().getArchitectFrame(), + Messages.getString("OpenProjectAction.failedToOpenProjectFile"), ex); //$NON-NLS-1$
+            }
+        }
+    }
+
     /**
      * A worker for asynchronously loading a new project file.
      */
-    private static class LoadFileWorker extends SPSwingWorker {
+    public static class LoadFileWorker extends SPSwingWorker {
         private final ArchitectSwingSessionContext context;

         private final InputStream in;

Reply via email to