Revision: 3279
Author: ferguson.sebastian
Date: Tue Feb  9 12:57:13 2010
Log: Added GUI for managing projects
http://code.google.com/p/power-architect/source/detail?r=3279

Added:
 /trunk/src/ca/sqlpower/architect/swingui/enterprise
/trunk/src/ca/sqlpower/architect/swingui/enterprise/ServerProjectsManagerPanel.java
Modified:
 /trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
 /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java

=======================================
--- /dev/null
+++ /trunk/src/ca/sqlpower/architect/swingui/enterprise/ServerProjectsManagerPanel.java Tue Feb 9 12:57:13 2010
@@ -0,0 +1,265 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of Power*Architect.
+ *
+ * Power*Architect is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Power*Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.swingui.enterprise;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
+
+import ca.sqlpower.architect.ArchitectSessionContext;
+import ca.sqlpower.architect.enterprise.ArchitectClientSideSession;
+import ca.sqlpower.architect.enterprise.ProjectLocation;
+import ca.sqlpower.architect.swingui.ArchitectSwingSessionContextImpl;
+import ca.sqlpower.enterprise.client.SPServerInfo;
+import ca.sqlpower.enterprise.client.SPServerInfoManager;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+
+public class ServerProjectsManagerPanel {
+
+    private final Component dialogOwner;
+    private final JPanel panel;
+    private final SPServerInfoManager serverInfoManager;
+    private final ArchitectSessionContext context;
+    private JList projects;
+    private JList servers;
+
+    private Action refreshAction = new AbstractAction("Refresh...") {
+        public void actionPerformed(ActionEvent e) {
+            refreshInfoList();
+        }
+    };
+
+    private Action newAction = new AbstractAction("New...") {
+        public void actionPerformed(ActionEvent e) {
+
+            if (getSelectedServerInfo() != null) {
+
+ String name = JOptionPane.showInputDialog(dialogOwner, "Please specify the name of your project", "", JOptionPane.QUESTION_MESSAGE);
+
+                if (name != null) {
+                    try {
+ ArchitectClientSideSession.createNewServerSession(getSelectedServerInfo());
+                    } catch (Exception ex) {
+ throw new RuntimeException("Unable to create new project", ex);
+                    }
+
+                    refreshInfoList();
+                }
+            }
+        }
+    };
+
+    private Action openAction = new AbstractAction("Open...") {
+        public void actionPerformed(ActionEvent e) {
+
+            if (getSelectedServerInfo() != null) {
+
+                int [] indecies = projects.getSelectedIndices();
+
+                if (indecies.length >= 1) {
+
+                    final Object [] objs = new Object[indecies.length];
+                    for (int i = 0; i < indecies.length; i++) {
+ objs[i] = projects.getModel().getElementAt(indecies[i]);
+                    }
+
+                    for (Object obj : objs) {
+                        if (obj instanceof ProjectLocation) {
+ ProjectLocation location = (ProjectLocation) obj;
+                            try {
+ ((ArchitectSwingSessionContextImpl) context).createServerSession(location, true);
+                            } catch (Exception ex) {
+ throw new RuntimeException("Unable to open project", ex);
+                            }
+                        }
+                    }
+
+                    refreshInfoList();
+                }
+            }
+        }
+    };
+
+
+    private Action deleteAction = new AbstractAction("Delete...") {
+        public void actionPerformed(ActionEvent e) {
+
+            if (getSelectedServerInfo() != null) {
+
+                int [] indecies = projects.getSelectedIndices();
+
+                if (indecies.length >= 1) {
+
+                    final Object [] objs = new Object[indecies.length];
+                    for (int i = 0; i < indecies.length; i++) {
+ objs[i] = projects.getModel().getElementAt(indecies[i]);
+                    }
+
+                    String promptMessage;
+                    if (indecies.length == 1) {
+ promptMessage = "Are you sure you want to delete the selected project?" +
+                                        "\nThis action cannot be undone.";
+                    } else {
+ promptMessage = "Are you sure you want to delete these " + indecies.length + " selected projects?" +
+                                        "\nThis action cannot be undone.";
+                    }
+
+ if (JOptionPane.showConfirmDialog(dialogOwner, promptMessage, "Confirm Delete Projects", + JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
+                        for (Object obj : objs) {
+                            if (obj instanceof ProjectLocation) {
+ ProjectLocation location = (ProjectLocation) obj;
+                                try {
+ ArchitectClientSideSession.deleteServerWorkspace(location);
+                                } catch (Exception ex) {
+ throw new RuntimeException("Unable to delete project", ex);
+                                }
+                            }
+                        }
+
+                        refreshInfoList();
+                    }
+                }
+            }
+        }
+    };
+
+ public ServerProjectsManagerPanel(ArchitectSessionContext context, SPServerInfoManager serverInfoManager, Component dialogOwner, Action closeAction) {
+        this.dialogOwner = dialogOwner;
+        this.serverInfoManager = serverInfoManager;
+        this.context = context;
+
+        DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(
+                "pref:grow, 5dlu, pref:grow, 5dlu, pref",
+                "pref, pref, pref"));
+
+        servers = new JList(new DefaultListModel());
+        servers.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseClicked(MouseEvent e) {
+                if (SwingUtilities.isLeftMouseButton(e)) {
+                    refreshInfoList();
+                }
+            }
+        });
+
+ DefaultListModel serversModel = (DefaultListModel) servers.getModel();
+        serversModel.removeAllElements();
+        if (serverInfoManager.getServers(false).size() > 0) {
+ for (SPServerInfo serverInfo : serverInfoManager.getServers(false)) {
+                serversModel.addElement(serverInfo);
+            }
+        } else {
+            serversModel.addElement("No Servers");
+        }
+
+        projects = new JList(new DefaultListModel());
+        projects.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
+                    openSelectedProject();
+                }
+            }
+        });
+
+        JScrollPane projectsPane = new JScrollPane(projects);
+        projectsPane.setPreferredSize(new Dimension(250, 300));
+
+        JScrollPane serverPane = new JScrollPane(servers);
+        serverPane.setPreferredSize(new Dimension(250, 300));
+
+        refreshInfoList();
+        CellConstraints cc = new CellConstraints();
+        builder.add(new JLabel("Servers:"), cc.xyw(1, 1, 2));
+        builder.add(new JLabel("Projects:"), cc.xyw(3, 1, 2));
+        builder.nextLine();
+        builder.add(serverPane, cc.xywh(1, 2, 1, 2));
+        builder.add(projectsPane, cc.xywh(3, 2, 1, 2));
+
+ DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
+        buttonBarBuilder.append(new JButton(refreshAction));
+        buttonBarBuilder.append(new JButton(newAction));
+        buttonBarBuilder.append(new JButton(openAction));
+        buttonBarBuilder.append(new JButton(deleteAction));
+        buttonBarBuilder.append(new JButton(closeAction));
+        builder.add(buttonBarBuilder.getPanel(), cc.xy(5, 2));
+        builder.setDefaultDialogBorder();
+        panel = builder.getPanel();
+    }
+
+    public JPanel getPanel() {
+        return panel;
+    }
+
+    private void refreshInfoList() {
+        DefaultListModel model = (DefaultListModel) projects.getModel();
+        model.removeAllElements();
+
+        SPServerInfo serviceInfo = getSelectedServerInfo();
+        if (serviceInfo != null) {
+            try {
+ for (ProjectLocation pl : ArchitectClientSideSession.getWorkspaceNames(serviceInfo)) {
+                    model.addElement(pl);
+                }
+            } catch (Exception ex) {
+                model.removeAllElements();
+ model.addElement("There has been a problem retrieving projects from the selected server");
+            }
+        } else {
+            model.addElement("No Server Selected");
+        }
+    }
+
+    private SPServerInfo getSelectedServerInfo() {
+        int index = servers.getSelectedIndex();
+        Object obj;
+
+        if (index >= 0) {
+            obj = servers.getModel().getElementAt(index);
+
+            if (obj instanceof SPServerInfo) {
+                return (SPServerInfo) obj;
+            }
+        }
+
+        return null;
+    }
+
+    private void openSelectedProject() {
+
+    }
+}
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java Mon Feb 8 14:34:01 2010 +++ /trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java Tue Feb 9 12:57:13 2010
@@ -115,6 +115,7 @@
 import ca.sqlpower.architect.swingui.action.ZoomAction;
 import ca.sqlpower.architect.swingui.action.ZoomResetAction;
 import ca.sqlpower.architect.swingui.action.ZoomToFitAction;
+import ca.sqlpower.architect.swingui.enterprise.ServerProjectsManagerPanel;
 import ca.sqlpower.architect.swingui.olap.action.ImportSchemaAction;
 import ca.sqlpower.architect.swingui.olap.action.OLAPEditAction;
 import ca.sqlpower.architect.swingui.olap.action.OLAPSchemaManagerAction;
@@ -240,6 +241,29 @@
             d.setLocationRelativeTo(ArchitectFrame.this);
             d.setVisible(true);
         }
+    };
+
+ private Action openProjectManagerAction = new AbstractAction("Projects...") {
+        public void actionPerformed(ActionEvent e) {
+
+ final JDialog d = SPSUtils.makeOwnedDialog(ArchitectFrame.this, "Projects");
+            Action closeAction = new AbstractAction("Close") {
+                public void actionPerformed(ActionEvent e) {
+                    d.dispose();
+                }
+            };
+
+ ServerProjectsManagerPanel spm = new ServerProjectsManagerPanel(session.getContext(),
+                    session.getContext().getServerManager(),
+                    ArchitectFrame.this, closeAction);
+            d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+            d.setContentPane(spm.getPanel());
+
+            SPSUtils.makeJDialogCancellable(d, null);
+            d.pack();
+            d.setLocationRelativeTo(ArchitectFrame.this);
+            d.setVisible(true);
+        }
     };

     /**
@@ -660,6 +684,7 @@

         JMenu enterpriseMenu = new JMenu("Enterprise");
         enterpriseMenu.add(openServerManagerAction);
+        enterpriseMenu.add(openProjectManagerAction);
         menuBar.add(enterpriseMenu);

JMenu toolsMenu = new JMenu(Messages.getString("ArchitectFrame.toolsMenu")); //$NON-NLS-1$
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java Mon Feb 8 14:34:01 2010 +++ /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java Tue Feb 9 12:57:13 2010
@@ -28,6 +28,7 @@
 import java.awt.datatransfer.UnsupportedFlavorException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -37,12 +38,18 @@
 import javax.swing.ImageIcon;
 import javax.swing.JDialog;

+import org.apache.http.client.ClientProtocolException;
 import org.apache.log4j.Logger;
+import org.json.JSONException;

 import ca.sqlpower.architect.ArchitectSession;
 import ca.sqlpower.architect.ArchitectSessionContext;
 import ca.sqlpower.architect.ArchitectSessionContextImpl;
 import ca.sqlpower.architect.CoreUserSettings;
+
+import ca.sqlpower.architect.enterprise.ArchitectClientSideSession;
+import ca.sqlpower.architect.enterprise.ProjectLocation;
+import ca.sqlpower.enterprise.client.SPServerInfo;
 import ca.sqlpower.enterprise.client.SPServerInfoManager;
 import ca.sqlpower.sql.DataSourceCollection;
 import ca.sqlpower.sql.JDBCDataSource;
@@ -260,7 +267,47 @@
public ArchitectSwingSession createSession(ArchitectSwingSession openingSession) throws SQLObjectException { return createSessionImpl(Messages.getString("ArchitectSwingSessionContextImpl.defaultNewProjectName"), true, openingSession); //$NON-NLS-1$
     }
-
+
+ public ArchitectSwingSession createNewServerSession(SPServerInfo serverInfo, boolean initGUI) throws SQLObjectException, ClientProtocolException, URISyntaxException, IOException, JSONException {
+        return createNewServerSession(serverInfo, "", initGUI);
+    }
+
+ public ArchitectSwingSession createNewServerSession(SPServerInfo serverInfo, String name, boolean initGUI) throws SQLObjectException, ClientProtocolException, URISyntaxException, IOException, JSONException {
+
+ ProjectLocation projectLocation = ArchitectClientSideSession.createNewServerSession(serverInfo); + ArchitectSession clientSession = new ArchitectClientSideSession(this, name, projectLocation);
+
+ ArchitectSwingSession swingSession = new ArchitectSwingSessionImpl(this, clientSession);
+
+        if (initGUI) {
+            swingSession.initGUI();
+        }
+
+        return swingSession;
+    }
+
+
+
+ public ArchitectSwingSession createServerSession(ProjectLocation projectLocation, boolean initGUI) throws SQLObjectException {
+        return createServerSession(projectLocation, "", initGUI);
+    }
+
+ public ArchitectSwingSession createServerSession(ProjectLocation projectLocation, String name, boolean initGUI) throws SQLObjectException {
+
+ ArchitectClientSideSession clientSession = new ArchitectClientSideSession(this, name, projectLocation);
+        clientSession.startUpdaterThread();
+
+ ArchitectSwingSession swingSession = new ArchitectSwingSessionImpl(this, clientSession);
+
+        if (initGUI) {
+            swingSession.initGUI();
+        }
+
+        return swingSession;
+    }
+
+
+
     /**
      * This is the one createSession() implementation to which all other
      * overloads of createSession() actually delegate their work.
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Tue Jan 26 10:49:55 2010 +++ /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Tue Feb 9 12:57:13 2010
@@ -226,6 +226,81 @@
             }
         };

+ // Make sure we can load the pl.ini file so we can handle exceptions + // XXX this is probably redundant now, since the context owns the pl.ini
+        getContext().getPlDotIni();
+
+        setProjectLoader(new SwingUIProjectLoader(this));
+
+        compareDMSettings = new CompareDMSettings();
+
+        kettleJob = new KettleJob(this);
+
+        olapSchemaManager = new OLAPSchemaManager(this);
+
+        delegateSession.getRootObject().addChild(getTargetDatabase());
+        this.sourceDatabases = new DBTree(this);
+
+ playPen = RelationalPlayPenFactory.createPlayPen(this, sourceDatabases);
+        UserSettings sprefs = getUserSettings().getSwingSettings();
+        if (sprefs != null) {
+ playPen.setRenderingAntialiased(sprefs.getBoolean(ArchitectSwingUserSettings.PLAYPEN_RENDER_ANTIALIASED, false));
+        }
+ projectModificationWatcher = new ProjectModificationWatcher(playPen);
+
+        getRootObject().addSPListener(new AbstractSPListener() {
+            @Override
+            public void propertyChangeImpl(PropertyChangeEvent e) {
+                isNew = false;
+            }
+            @Override
+            public void childRemovedImpl(SPChildEvent e) {
+                isNew = false;
+            }
+            @Override
+            public void childAddedImpl(SPChildEvent e) {
+                isNew = false;
+            }
+        });
+        undoManager = new ArchitectUndoManager(playPen);
+ playPen.getPlayPenContentPane().addPropertyChangeListener("location", undoManager.getEventAdapter()); //$NON-NLS-1$ + playPen.getPlayPenContentPane().addPropertyChangeListener("connectionPoints", undoManager.getEventAdapter()); //$NON-NLS-1$ + playPen.getPlayPenContentPane().addPropertyChangeListener("backgroundColor", undoManager.getEventAdapter()); //$NON-NLS-1$ + playPen.getPlayPenContentPane().addPropertyChangeListener("foregroundColor", undoManager.getEventAdapter()); //$NON-NLS-1$ + playPen.getPlayPenContentPane().addPropertyChangeListener("dashed", undoManager.getEventAdapter()); //$NON-NLS-1$ + playPen.getPlayPenContentPane().addPropertyChangeListener("rounded", undoManager.getEventAdapter()); //$NON-NLS-1$
+
+ lifecycleListeners = new ArrayList<SessionLifecycleListener<ArchitectSession>>();
+
+        swingWorkers = new HashSet<SPSwingWorker>();
+
+        olapEditSessions = new ArrayList<OLAPEditSession>();
+
+        printSettings = new PrintSettings();
+    }
+
+ ArchitectSwingSessionImpl(final ArchitectSwingSessionContext context, ArchitectSession delegateSession)
+    throws SQLObjectException {
+
+        swinguiUserPrompterFactory = new SwingUIUserPrompterFactory(frame);
+        this.isNew = true;
+        this.context = context;
+        this.delegateSession = delegateSession;
+        this.olapRootObject = new OLAPRootObject(delegateSession);
+ ((ArchitectSessionImpl)delegateSession).setProfileManager(new ProfileManagerImpl(this)); + ((ArchitectSessionImpl)delegateSession).setUserPrompterFactory(this);
+        this.recent = new RecentMenu(this.getClass()) {
+            @Override
+            public void loadFile(String fileName) throws IOException {
+                File f = new File(fileName);
+                try {
+ OpenProjectAction.openAsynchronously(getContext().createSession(false), f, ArchitectSwingSessionImpl.this);
+                } catch (SQLObjectException ex) {
+ SPSUtils.showExceptionDialogNoReport(getArchitectFrame(), Messages.getString("ArchitectSwingSessionImpl.openProjectFileFailed"), ex); //$NON-NLS-1$
+                }
+            }
+        };
+
// Make sure we can load the pl.ini file so we can handle exceptions // XXX this is probably redundant now, since the context owns the pl.ini
         getContext().getPlDotIni();

Reply via email to