Revision: 6554
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6554&view=rev
Author: gerdwagner
Date: 2012-01-04 20:36:28 +0000 (Wed, 04 Jan 2012)
Log Message:
-----------
Graphs can be copied and pasted
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/action/ActionCollection.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/session/MainPanel.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/session/SessionPanel.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/ISession.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/Session.java
trunk/sql12/doc/src/main/resources/changes.txt
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/xml/XMLBeanWriter.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphController.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopController.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopListener.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphMainPanelTab.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphPlugin.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphPluginResources.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/LinkGraphController.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/LinkGraphDialog.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/window/GraphWindowController.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/window/TabToWindowHandler.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/xmlbeans/GraphXmlSerializer.java
trunk/sql12/plugins/graph/src/main/resources/net/sourceforge/squirrel_sql/plugins/graph/GraphPluginResources.properties
trunk/sql12/plugins/graph/src/main/resources/net/sourceforge/squirrel_sql/plugins/graph/I18NStrings.properties
trunk/sql12/plugins/graph/src/main/resources/net/sourceforge/squirrel_sql/plugins/graph/graph.properties
trunk/sql12/plugins/graph/src/main/resources/net/sourceforge/squirrel_sql/plugins/graph/window/I18NStrings.properties
trunk/sql12/plugins/graph/src/main/resources/net/sourceforge/squirrel_sql/plugins/graph/xmlbeans/I18NStrings.properties
Added Paths:
-----------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/IMainPanelTabAction.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/CopyGraphAction.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/PasteGraphAction.java
trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/xmlbeans/DefaultGraphXmlSerializerConfig.java
trunk/sql12/plugins/graph/src/main/resources/net/sourceforge/squirrel_sql/plugins/graph/images/copyGraph.png
trunk/sql12/plugins/graph/src/main/resources/net/sourceforge/squirrel_sql/plugins/graph/images/cutGraph.png
trunk/sql12/plugins/graph/src/main/resources/net/sourceforge/squirrel_sql/plugins/graph/images/pasteGraph.png
trunk/sql12/plugins/graph/src/main/resources/net/sourceforge/squirrel_sql/plugins/graph/images/pasteGraphLink.png
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/action/ActionCollection.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/action/ActionCollection.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/action/ActionCollection.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -244,8 +244,6 @@
* This function should be called whenever an internal frame is
* activated.
*
- * JASON: Should this be in Sessionmanager or SessionWindowmanager?
- *
* @param frame The <TT>JInternalFrame</TT> activated.
*/
public synchronized void activationChanged(IWidget frame)
@@ -275,6 +273,12 @@
{
((IObjectTreeAction)act).setObjectTree(((ObjectTreeInternalFrame)frame).getObjectTreePanel());
}
+
+ if(isSessionInternalFrame && act instanceof IMainPanelTabAction)
+ {
+ ((IMainPanelTabAction)act).setSelectedMainPanelTab(session.getSelectedMainTab());
+ }
+
if ((isSessionInternalFrame) && (act instanceof ISQLPanelAction))
{
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/session/MainPanel.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/session/MainPanel.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/session/MainPanel.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -19,7 +19,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-import java.awt.BorderLayout;
+import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
@@ -51,9 +51,7 @@
*/
public class MainPanel extends JPanel
{
- private static final long serialVersionUID = 1L;
-
- /**
+ /**
* IDs of tabs.
*/
public interface ITabIndexes
@@ -305,9 +303,26 @@
private void updateState()
{
+ int idx = _tabPnl.getSelectedIndex();
+ if (idx != -1)
+ {
+ (_tabs.get(idx)).select();
+ }
_session.getApplication().getActionCollection().activationChanged(_session.getSessionInternalFrame());
}
+ public IMainPanelTab getSelectedMainTab()
+ {
+ int idx = _tabPnl.getSelectedIndex();
+ if (idx == -1)
+ {
+ return null;
+ }
+
+ return _tabs.get(idx);
+ }
+
+
/**
* The passed session is closing so tell each tab.
*
@@ -367,11 +382,6 @@
_tabPnl.requestFocusInWindow();
updateState();
- int idx = _tabPnl.getSelectedIndex();
- if (idx != -1)
- {
- (_tabs.get(idx)).select();
- }
}
ObjectTreePanel getObjectTreePanel()
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/session/SessionPanel.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/session/SessionPanel.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/session/SessionPanel.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -242,7 +242,13 @@
return _mainTabPane.getTabbedPane().getSelectedIndex();
}
+ public IMainPanelTab getSelectedMainTab()
+ {
+ return _mainTabPane.getSelectedMainTab();
+ }
+
+
/**
* Add a tab to the main tabbed panel.
*
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/ISession.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/ISession.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/ISession.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -390,4 +390,8 @@
* @return A new connection for the alias of the current session.
*/
public SQLConnection createUnmanagedConnection();
+
+ boolean isSessionWidgetActive();
+
+ IMainPanelTab getSelectedMainTab();
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/Session.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/Session.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/Session.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -651,7 +651,14 @@
return _sessionSheet.getSelectedMainTabIndex();
}
+ @Override
+ public IMainPanelTab getSelectedMainTab()
+ {
+ return _sessionSheet.getSelectedMainTab();
+ }
+
+
/**
* Add a tab to the main tabbed panel.
*
@@ -865,7 +872,7 @@
public ISQLPanelAPI getSQLPanelAPIOfActiveSessionWindow()
{
ISQLPanelAPI sqlPanelAPI;
- if(_activeActiveSessionWindow instanceof SessionInternalFrame)
+ if(isSessionWidgetActive())
{
sqlPanelAPI = ((SessionInternalFrame)_activeActiveSessionWindow).getSQLPanelAPI();
}
@@ -881,6 +888,11 @@
return sqlPanelAPI;
}
+ public boolean isSessionWidgetActive()
+ {
+ return _activeActiveSessionWindow instanceof SessionInternalFrame;
+ }
+
/**
*
* @throws IllegalStateException if ActiveSessionWindow doesn't provide an IObjectTreeAPI
@@ -889,7 +901,7 @@
public IObjectTreeAPI getObjectTreeAPIOfActiveSessionWindow()
{
IObjectTreeAPI objectTreeAPI;
- if(_activeActiveSessionWindow instanceof SessionInternalFrame)
+ if(isSessionWidgetActive())
{
objectTreeAPI = ((SessionInternalFrame)_activeActiveSessionWindow).getObjectTreeAPI();
}
Copied: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/IMainPanelTabAction.java (from rev 6549, trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/ISQLPanelAction.java)
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/IMainPanelTabAction.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/IMainPanelTabAction.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -0,0 +1,9 @@
+package net.sourceforge.squirrel_sql.client.session.action;
+
+
+import net.sourceforge.squirrel_sql.client.session.mainpanel.IMainPanelTab;
+
+public interface IMainPanelTabAction extends ISessionAction
+{
+ void setSelectedMainPanelTab(IMainPanelTab selectedMainTab);
+}
Modified: trunk/sql12/doc/src/main/resources/changes.txt
===================================================================
--- trunk/sql12/doc/src/main/resources/changes.txt 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/doc/src/main/resources/changes.txt 2012-01-04 20:36:28 UTC (rev 6554)
@@ -7,6 +7,9 @@
Enhancements:
Graph Plugin:
+ Graphs can be copied and pasted.
+
+Graph Plugin:
New Session toolbar button to create links to Graphs of other JDBC-URLs or to Graphs that are placed arbitrary directories.
With this feature it is possible to work with shared repositories of Graphs.
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/xml/XMLBeanWriter.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/xml/XMLBeanWriter.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/xml/XMLBeanWriter.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -18,24 +18,21 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
+import net.n3.nanoxml.IXMLElement;
+import net.n3.nanoxml.XMLElement;
+import net.n3.nanoxml.XMLWriter;
+import net.sourceforge.squirrel_sql.fw.util.FileWrapper;
+import net.sourceforge.squirrel_sql.fw.util.beanwrapper.StringWrapper;
+
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
import java.lang.reflect.Method;
import java.util.Iterator;
-import net.n3.nanoxml.IXMLElement;
-import net.n3.nanoxml.XMLElement;
-import net.n3.nanoxml.XMLWriter;
-
-import net.sourceforge.squirrel_sql.fw.util.FileWrapper;
-import net.sourceforge.squirrel_sql.fw.util.beanwrapper.StringWrapper;
-
public final class XMLBeanWriter
{
private IXMLElement _rootElement;
@@ -111,6 +108,24 @@
}
}
+ public String getAsString() throws IOException
+ {
+ StringWriter sw = new StringWriter();
+ BufferedWriter bw = new BufferedWriter(sw);
+
+ new XMLWriter(bw).write(_rootElement, true);
+
+ bw.flush();
+ sw.flush();
+
+ bw.close();
+
+ sw.close();
+
+ return sw.toString();
+ }
+
+
private IXMLElement createElement(Object bean, String name) throws XMLException
{
IXMLElement elem = null;
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphController.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphController.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphController.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -6,6 +6,7 @@
import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.plugins.graph.link.CopyGraphAction;
import net.sourceforge.squirrel_sql.plugins.graph.link.LinkManager;
import net.sourceforge.squirrel_sql.plugins.graph.querybuilder.WhereTreeNodeStructure;
import net.sourceforge.squirrel_sql.plugins.graph.window.TabToWindowHandler;
@@ -36,7 +37,7 @@
private GraphXmlSerializer _xmlSerializer;
private boolean _lazyLoadDone;
- public GraphController(ISession session, GraphPlugin plugin, final GraphXmlSerializer xmlSerializer, boolean showDndDesktopImageAtStartup)
+ public GraphController(ISession session, GraphPlugin plugin, final GraphXmlSerializer xmlSerializer, boolean showDndDesktopImageAtStartup, boolean selectTab)
{
_session = session;
_plugin = plugin;
@@ -135,12 +136,18 @@
{
onShowLinkDetails();
}
+
+ @Override
+ public void copyGraph()
+ {
+ onCopyGraph();
+ }
};
if(null == xmlSerializer)
{
- _xmlSerializer = new GraphXmlSerializer(_plugin, _session, _tabToWindowHandler.getTitle(), null);
+ _xmlSerializer = new GraphXmlSerializer(_plugin, _session, null);
}
else
{
@@ -161,7 +168,7 @@
};
GraphControllerXmlBean graphControllerXmlBean = null;
- if(null != xmlSerializer)
+ if(_xmlSerializer.isLoadable())
{
graphControllerXmlBean = _xmlSerializer.read();
_tabToWindowHandler.setTitle(graphControllerXmlBean.getTitle());
@@ -181,7 +188,7 @@
}
else
{
- _tabToWindowHandler.setTitle(_plugin.patchName(_tabToWindowHandler.getTitle(), _session));
+ _tabToWindowHandler.setTitle(_xmlSerializer.getTitle());
_panelController.initMode(Mode.DEFAULT, null, null, false, null, null, null);
}
@@ -196,9 +203,14 @@
onLazyLoadTables(finalGraphControllerXmlBean);
}
};
- _tabToWindowHandler.showGraph(lazyLoadListener);
+ _tabToWindowHandler.showGraph(lazyLoadListener, selectTab);
}
+ private void onCopyGraph()
+ {
+ CopyGraphAction.copyGraph(this);
+ }
+
private void onShowLinkDetails()
{
JPanel pnl = new JPanel(new GridBagLayout());
@@ -213,10 +225,23 @@
gbc = new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0);
pnl.add(new JLabel(msg), gbc);
- gbc = new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0);
+ gbc = new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,0,0,0),0,0);
JTextField textField = new JTextField(_xmlSerializer.getLinkXmlBean().getFilePathOfLinkedGraph());
textField.setEditable(false);
pnl.add(textField, gbc);
+
+
+ String msg2 = s_stringMgr.getString("graph.link.linkDetailsMsg2");
+ gbc = new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(15,0,0,0),0,0);
+ pnl.add(new JLabel(msg2), gbc);
+
+ gbc = new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,0,0,0),0,0);
+ JTextField textField2 = new JTextField(_xmlSerializer.getLinkFile());
+ textField2.setEditable(false);
+ pnl.add(textField2, gbc);
+
+
+
JOptionPane.showMessageDialog(GUIUtils.getOwningFrame(_tabToWindowHandler.getComponent()), pnl);
}
@@ -318,7 +343,7 @@
_xmlSerializer.write(xmlBean);
}
- private GraphControllerXmlBean createXmlBean()
+ public GraphControllerXmlBean createXmlBean()
{
GraphControllerXmlBean xmlBean = new GraphControllerXmlBean();
xmlBean.setTitle(_tabToWindowHandler.getTitle());
@@ -541,5 +566,10 @@
_panelController.getModeManager().setMode(Mode.QUERY_BUILDER);
_tabToWindowHandler.showInWindowBesidesObjectTree();
}
+
+ public boolean isMyGraphMainPanelTab(GraphMainPanelTab graphMainPanelTab)
+ {
+ return _tabToWindowHandler.isMyGraphMainPanelTab(graphMainPanelTab);
+ }
}
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopController.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopController.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopController.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -45,7 +45,9 @@
//
////////////////////////////////////
+ private JMenuItem _mnuCopyGraph;
+
private JMenuItem _mnuRefreshAllTables;
private JMenuItem _mnuScriptAllTables;
private JMenuItem _mnuSelectAllTables;
@@ -202,7 +204,17 @@
createGraphSavingMenus();
}
+ _mnuCopyGraph= new JMenuItem(s_stringMgr.getString("graph.copyGraph"));
+ _mnuCopyGraph.setIcon(_graphPluginResources.getIcon(GraphPluginResources.IKeys.COPY_GRAPH));
+ _mnuCopyGraph.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ onCopyGraph();
+ }
+ });
+
// i18n[graph.refreshAllTables=Refresh all tables]
_mnuRefreshAllTables = new JMenuItem(s_stringMgr.getString("graph.refreshAllTables"));
_mnuRefreshAllTables.addActionListener(new ActionListener()
@@ -328,6 +340,8 @@
_popUp.add(_mnuRemoveGraph);
}
_popUp.add(new JSeparator());
+ _popUp.add(_mnuCopyGraph);
+ _popUp.add(new JSeparator());
_popUp.add(_mnuRefreshAllTables);
_popUp.add(_mnuScriptAllTables);
_popUp.add(new JSeparator());
@@ -587,8 +601,14 @@
_listener.showLinkDetails();
}
+ private void onCopyGraph()
+ {
+ _listener.copyGraph();
+ }
+
+
private void maybeShowPopup(MouseEvent e)
{
if (e.isPopupTrigger())
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopListener.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopListener.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphDesktopListener.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -38,4 +38,6 @@
void removeLink();
void showLinkDetails();
+
+ void copyGraph();
}
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphMainPanelTab.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphMainPanelTab.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphMainPanelTab.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -28,7 +28,7 @@
_tabComponent = new JPanel(new BorderLayout(3,0));
_tabComponent.setOpaque(false);
- _lblTitle = new JLabel(s_stringMgr.getString("graph.newGraph"));
+ _lblTitle = new JLabel();
_lblTitle.setOpaque(false);
if(isLink)
{
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphPlugin.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphPlugin.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphPlugin.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -27,7 +27,7 @@
import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
-import net.sourceforge.squirrel_sql.plugins.graph.link.LinkGraphAction;
+import net.sourceforge.squirrel_sql.plugins.graph.link.*;
import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.GraphXmlSerializer;
import java.util.ArrayList;
@@ -148,6 +148,8 @@
coll.add(new AddToGraphAction(app, _resources, this));
coll.add(new NewQueryBuilderWindowAction(app, _resources, this));
coll.add(new LinkGraphAction(app, _resources, this));
+ coll.add(new CopyGraphAction(app, _resources, this));
+ coll.add(new PasteGraphAction(app, _resources, this));
}
/**
@@ -173,14 +175,14 @@
for (int i = 0; i < serializers.length; i++)
{
- controllers.add(new GraphController(session, this, serializers[i], false));
+ controllers.add(new GraphController(session, this, serializers[i], false, false));
}
GraphXmlSerializer[] linkedSerializers = GraphXmlSerializer.getLinkedGraphXmSerializers(this, session);
for (int i = 0; i < linkedSerializers.length; i++)
{
- controllers.add(new GraphController(session, this, linkedSerializers[i], false));
+ controllers.add(new GraphController(session, this, linkedSerializers[i], false, false));
}
@@ -195,6 +197,8 @@
session.addSeparatorToToolbar();
session.addToToolbar(coll.get(NewQueryBuilderWindowAction.class));
session.addToToolbar(coll.get(LinkGraphAction.class));
+ session.addToToolbar(coll.get(CopyGraphAction.class));
+ session.addToToolbar(coll.get(PasteGraphAction.class));
return new PluginSessionCallbackAdaptor(this);
@@ -216,6 +220,24 @@
return _grapControllersBySessionID.get(session.getIdentifier()).toArray(new GraphController[0]);
}
+ public GraphController getGraphControllerForMainTab(GraphMainPanelTab mainTab, ISession session)
+ {
+ GraphController[] graphControllers = getGraphControllers(session);
+
+
+ GraphController graphController = null;
+ for (GraphController g : graphControllers)
+ {
+ if(g.isMyGraphMainPanelTab(mainTab))
+ {
+ graphController = g;
+ break;
+ }
+ }
+ return graphController;
+ }
+
+
public String patchName(String name, ISession session)
{
@@ -235,7 +257,7 @@
while(true)
{
boolean incremented = false;
- for (int i = 0; i < controllers.size(); i++)
+ for (int i = 0; null != controllers && i < controllers.size(); i++)
{
if(0 == postfix)
{
@@ -273,15 +295,18 @@
public GraphController createNewGraphControllerForSession(ISession session, boolean showDndDesktopImageAtStartup)
{
- return _createNewGraphControllerForSession(session, null, showDndDesktopImageAtStartup);
+ return _createNewGraphControllerForSession(session, null, showDndDesktopImageAtStartup, false);
}
- public void createNewGraphControllerForSession(ISession session, GraphXmlSerializer graphXmlSerializer)
+ public void createNewGraphControllerForSession(ISession session, GraphXmlSerializer graphXmlSerializer, boolean selectTab)
{
- _createNewGraphControllerForSession(session, graphXmlSerializer, false);
+ _createNewGraphControllerForSession(session, graphXmlSerializer, false, selectTab);
}
- private GraphController _createNewGraphControllerForSession(ISession session, GraphXmlSerializer graphXmlSerializer, boolean showDndDesktopImageAtStartup)
+ private GraphController _createNewGraphControllerForSession(ISession session,
+ GraphXmlSerializer graphXmlSerializer,
+ boolean showDndDesktopImageAtStartup,
+ boolean selectTab)
{
ArrayList<GraphController> controllers = _grapControllersBySessionID.get(session.getIdentifier());
@@ -290,7 +315,7 @@
controllers = new ArrayList<GraphController>();
_grapControllersBySessionID.put(session.getIdentifier(), controllers);
}
- GraphController ret = new GraphController(session, this, graphXmlSerializer, showDndDesktopImageAtStartup);
+ GraphController ret = new GraphController(session, this, graphXmlSerializer, showDndDesktopImageAtStartup, selectTab);
controllers.add(ret);
_grapControllersBySessionID.put(session.getIdentifier(), controllers);
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphPluginResources.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphPluginResources.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/GraphPluginResources.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -48,5 +48,7 @@
String DND = "dnd";
String ESCAPE_DATE = "escapedate";
String LINK = "link";
+ String COPY_GRAPH = "copyGraph";
+ String PASTE_GRAPH = "pasteGraph";
}
}
Copied: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/CopyGraphAction.java (from rev 6550, trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/LinkGraphAction.java)
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/CopyGraphAction.java (rev 0)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/CopyGraphAction.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -0,0 +1,80 @@
+package net.sourceforge.squirrel_sql.plugins.graph.link;
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
+import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.client.session.action.IMainPanelTabAction;
+import net.sourceforge.squirrel_sql.client.session.mainpanel.IMainPanelTab;
+import net.sourceforge.squirrel_sql.fw.xml.XMLBeanWriter;
+import net.sourceforge.squirrel_sql.plugins.graph.GraphController;
+import net.sourceforge.squirrel_sql.plugins.graph.GraphMainPanelTab;
+import net.sourceforge.squirrel_sql.plugins.graph.GraphPlugin;
+import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.GraphControllerXmlBean;
+
+import java.awt.*;
+import java.awt.datatransfer.StringSelection;
+import java.awt.event.ActionEvent;
+
+public class CopyGraphAction extends SquirrelAction implements IMainPanelTabAction
+{
+ private GraphPlugin _graphPlugin;
+ private ISession _session;
+ private GraphMainPanelTab _selectedMainTab;
+
+ public CopyGraphAction(IApplication app, PluginResources resources, GraphPlugin graphPlugin)
+ {
+ super(app, resources);
+ _graphPlugin = graphPlugin;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (null == _session || null == _selectedMainTab)
+ {
+ return;
+ }
+
+ GraphController graphController = _graphPlugin.getGraphControllerForMainTab(_selectedMainTab, _session);
+
+ copyGraph(graphController);
+ }
+
+ public static void copyGraph(GraphController graphController)
+ {
+ try
+ {
+ GraphControllerXmlBean xmlBean = graphController.createXmlBean();
+ xmlBean.set32Converted(true);
+
+ final StringSelection ss = new StringSelection(new XMLBeanWriter(xmlBean).getAsString());
+ Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, ss);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void setSession(ISession session)
+ {
+ _session = session;
+ }
+
+ @Override
+ public void setSelectedMainPanelTab(IMainPanelTab selectedMainTab)
+ {
+ if (selectedMainTab instanceof GraphMainPanelTab)
+ {
+ _selectedMainTab = (GraphMainPanelTab) selectedMainTab;
+ setEnabled(true);
+ }
+ else
+ {
+ _selectedMainTab = null;
+ setEnabled(false);
+ }
+ }
+}
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/LinkGraphController.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/LinkGraphController.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/LinkGraphController.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -5,12 +5,12 @@
import net.sourceforge.squirrel_sql.client.session.event.SessionEvent;
import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetException;
import net.sourceforge.squirrel_sql.fw.datasetviewer.JavabeanArrayDataSet;
-import net.sourceforge.squirrel_sql.fw.sql.ISQLAlias;
import net.sourceforge.squirrel_sql.fw.util.*;
import net.sourceforge.squirrel_sql.fw.xml.XMLBeanReader;
import net.sourceforge.squirrel_sql.fw.xml.XMLBeanWriter;
import net.sourceforge.squirrel_sql.plugins.graph.GraphPlugin;
import net.sourceforge.squirrel_sql.plugins.graph.GraphUtil;
+import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.DefaultGraphXmlSerializerConfig;
import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.GraphXmlSerializer;
import javax.swing.*;
@@ -23,17 +23,10 @@
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.prefs.Preferences;
-/**
- * Created by IntelliJ IDEA.
- * User: gerd
- * Date: 27.11.11
- * Time: 11:55
- */
public class LinkGraphController
{
private static final StringManager s_stringMgr = StringManagerFactory.getStringManager(LinkGraphDialog.class);
@@ -146,7 +139,7 @@
@Override
public boolean accept(File dir, String name)
{
- if (name.startsWith(GraphXmlSerializer.LINK_PREFIX))
+ if (name.startsWith(DefaultGraphXmlSerializerConfig.LINK_PREFIX))
{
return true;
}
@@ -193,8 +186,11 @@
bw.save(pathOfLinkXmlFile.getAbsolutePath());
- _plugin.createNewGraphControllerForSession(_session, new GraphXmlSerializer(_plugin, _session, linkXmlBean, pathOfLinkXmlFile.getAbsolutePath()));
+ GraphXmlSerializer graphXmlSerializer =
+ new GraphXmlSerializer(_plugin, _session, linkXmlBean, pathOfLinkXmlFile.getAbsolutePath());
+ _plugin.createNewGraphControllerForSession(_session, graphXmlSerializer, false);
+
}
onWindowClosing();
@@ -210,8 +206,9 @@
private String createLinkFileName(GraphFileDisplayBean gdb)
{
return
- GraphXmlSerializer.LINK_PREFIX +
- GraphUtil.createGraphFileName(_session.getAlias().getUrl(), _plugin.patchName(gdb.getLoadedName(), _session));
+ DefaultGraphXmlSerializerConfig.LINK_PREFIX +
+ GraphUtil.createGraphFileName(_session.getAlias().getUrl(), _plugin.patchName(gdb.getLoadedName(), _session)) +
+ DefaultGraphXmlSerializerConfig.XML_BEAN_POSTFIX;
}
private void onHomeDir()
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/LinkGraphDialog.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/LinkGraphDialog.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/LinkGraphDialog.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -116,18 +116,18 @@
GridBagConstraints gbc;
+
gbc = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0);
- btnExplore = new JButton(s_stringMgr.getString("linkGraph.dialog.openFolderInExplorer"));
- pnl.add(btnExplore, gbc);
-
- gbc = new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0);
btnChangeDir = new JButton(s_stringMgr.getString("linkGraph.dialog.changeFolder"));
pnl.add(btnChangeDir, gbc);
- gbc = new GridBagConstraints(2, 0, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0);
+ gbc = new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0);
btnHomeDir = new JButton(s_stringMgr.getString("linkGraph.dialog.toHomeDir"));
pnl.add(btnHomeDir, gbc);
+ gbc = new GridBagConstraints(2, 0, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0);
+ btnExplore = new JButton(s_stringMgr.getString("linkGraph.dialog.openFolderInExplorer"));
+ pnl.add(btnExplore, gbc);
return pnl;
Added: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/PasteGraphAction.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/PasteGraphAction.java (rev 0)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/link/PasteGraphAction.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -0,0 +1,99 @@
+package net.sourceforge.squirrel_sql.plugins.graph.link;
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
+import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+import net.sourceforge.squirrel_sql.fw.xml.XMLBeanReader;
+import net.sourceforge.squirrel_sql.fw.xml.XMLBeanWriter;
+import net.sourceforge.squirrel_sql.plugins.graph.GraphPlugin;
+import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.GraphControllerXmlBean;
+import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.GraphXmlSerializer;
+
+import java.awt.*;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.io.FileWriter;
+
+public class PasteGraphAction extends SquirrelAction implements ISessionAction
+{
+ private final static ILogger s_log = LoggerController.createLogger(PasteGraphAction.class);
+
+ private GraphPlugin _plugin;
+ private ISession _session;
+
+ public PasteGraphAction(IApplication app, PluginResources resources, GraphPlugin plugin)
+ {
+ super(app, resources);
+ _plugin = plugin;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ if(null == _session)
+ {
+ return;
+ }
+
+ String data = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
+
+
+ File graphTmp = File.createTempFile("graphTmp_", "_.xml");
+
+ FileWriter fw = new FileWriter(graphTmp);
+ fw.write(data);
+ fw.flush();
+ fw.close();
+
+
+ XMLBeanReader br = new XMLBeanReader();
+ try
+ {
+ br.load(graphTmp, this.getClass().getClassLoader());
+ }
+ catch (Exception exc)
+ {
+ _session.showWarningMessage("Could not interpret clipboard as Graph: " + exc.getMessage());
+ s_log.warn("Could not interpret clipboard as Graph: ", exc);
+ return;
+ }
+
+
+ GraphControllerXmlBean bean = (GraphControllerXmlBean) br.iterator().next();
+
+ String title = _plugin.patchName(bean.getTitle(), _session);
+
+ if(false == title.equals(bean.getTitle()))
+ {
+ bean.setTitle(title);
+
+ XMLBeanWriter xbw = new XMLBeanWriter(bean);
+ xbw.save(graphTmp);
+ }
+
+ String graphFile = graphTmp.getAbsolutePath();
+ GraphXmlSerializer graphXmlSerializer = new GraphXmlSerializer(_plugin, _session, graphFile);
+
+ _plugin.createNewGraphControllerForSession(_session, graphXmlSerializer, true);
+ }
+ catch (Exception exc)
+ {
+ throw new RuntimeException(exc);
+ }
+
+ }
+
+ @Override
+ public void setSession(ISession session)
+ {
+ _session = session;
+ }
+
+}
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/window/GraphWindowController.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/window/GraphWindowController.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/window/GraphWindowController.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -4,10 +4,12 @@
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.event.SessionAdapter;
import net.sourceforge.squirrel_sql.client.session.event.SessionEvent;
-import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
import net.sourceforge.squirrel_sql.plugins.graph.GraphMainPanelTab;
+import net.sourceforge.squirrel_sql.plugins.graph.GraphPlugin;
+import net.sourceforge.squirrel_sql.plugins.graph.GraphPluginResources;
+import net.sourceforge.squirrel_sql.plugins.graph.link.CopyGraphAction;
import javax.swing.*;
import java.awt.*;
@@ -23,6 +25,7 @@
private ISession _session;
+ private GraphPlugin _plugin;
private GraphMainPanelTab _graphMainPanelTab;
private int _tabIdx;
private GraphWindowControllerListener _listener;
@@ -30,6 +33,7 @@
private JCheckBox _chkStayOnTop;
private JButton _btnReturn;
private JButton _btnRemove;
+ private JButton _btnCopyGraph;
private JPanel _contentPanel;
private JDialog _dlgWindow;
@@ -38,14 +42,16 @@
private WindowAdapter _windowAdapter;
- public GraphWindowController(ISession session,
- GraphMainPanelTab graphMainPanelTab,
- int tabIdx,
- Rectangle tabBoundsOnScreen,
- GraphWindowControllerListener listener,
+ public GraphWindowController(ISession session,
+ GraphPlugin plugin,
+ GraphMainPanelTab graphMainPanelTab,
+ int tabIdx,
+ Rectangle tabBoundsOnScreen,
+ GraphWindowControllerListener listener,
boolean link)
{
_session = session;
+ _plugin = plugin;
_graphMainPanelTab = graphMainPanelTab;
_tabIdx = tabIdx;
_listener = listener;
@@ -107,8 +113,22 @@
onRemove();
}
});
+
+ _btnCopyGraph.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ onCopyGraph();
+ }
+ });
}
+ private void onCopyGraph()
+ {
+ CopyGraphAction.copyGraph(_plugin.getGraphControllerForMainTab(_graphMainPanelTab, _session));
+ }
+
private String createTitle(GraphMainPanelTab graphMainPanelTab)
{
String ret = graphMainPanelTab.getTitle();
@@ -242,7 +262,14 @@
_btnRemove = new JButton(s_stringMgr.getString("graph.window.removeGraph"));
ret.add(_btnRemove, gbc);
- gbc = new GridBagConstraints(3,0,1,1,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5),0,0);
+ gbc = new GridBagConstraints(3,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5),0,0);
+ _btnCopyGraph = new JButton(s_stringMgr.getString("graph.window.copyGraph"));
+ _btnCopyGraph.setToolTipText(s_stringMgr.getString("graph.window.copyGraphToolTip"));
+ _btnCopyGraph.setIcon(new GraphPluginResources(_plugin).getIcon(GraphPluginResources.IKeys.COPY_GRAPH));
+
+ ret.add(_btnCopyGraph, gbc);
+
+ gbc = new GridBagConstraints(4,0,1,1,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5),0,0);
ret.add(new JPanel(), gbc);
return ret;
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/window/TabToWindowHandler.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/window/TabToWindowHandler.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/window/TabToWindowHandler.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -15,6 +15,7 @@
{
private GraphMainPanelTab _graphMainPanelTab;
private ISession _session;
+ private GraphPlugin _plugin;
private boolean _link;
private GraphWindowController _graphWindowController;
private LazyLoadListener _lazyLoadListener;
@@ -22,6 +23,7 @@
public TabToWindowHandler(GraphPanelController panelController, ISession session, GraphPlugin plugin, boolean isLink)
{
_session = session;
+ _plugin = plugin;
_link = isLink;
_graphMainPanelTab = new GraphMainPanelTab(panelController, plugin, _link);
_graphMainPanelTab.getToWindowButton().addActionListener(new ActionListener()
@@ -64,7 +66,14 @@
}
};
- _graphWindowController = new GraphWindowController(_session, _graphMainPanelTab, tabIdx, tabBoundsOnScreen, listener, _link);
+ _graphWindowController =
+ new GraphWindowController(_session,
+ _plugin,
+ _graphMainPanelTab,
+ tabIdx,
+ tabBoundsOnScreen,
+ listener,
+ _link);
}
private void onWindowClosing(int tabIdx)
@@ -83,11 +92,16 @@
}
- public void showGraph(LazyLoadListener lazyLoadListener)
+ public void showGraph(LazyLoadListener lazyLoadListener, boolean selectTab)
{
_lazyLoadListener = lazyLoadListener;
_graphMainPanelTab.setLazyLoadListener(_lazyLoadListener);
- _session.getSessionSheet().addMainTab(_graphMainPanelTab);
+ int tabIdx = _session.getSessionSheet().addMainTab(_graphMainPanelTab);
+
+ if (selectTab)
+ {
+ _session.getSessionSheet().selectMainTab(tabIdx);
+ }
}
public void removeGraph()
@@ -176,4 +190,9 @@
return _graphWindowController.getComponent();
}
}
+
+ public boolean isMyGraphMainPanelTab(GraphMainPanelTab graphMainPanelTab)
+ {
+ return _graphMainPanelTab == graphMainPanelTab;
+ }
}
Added: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/xmlbeans/DefaultGraphXmlSerializerConfig.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/xmlbeans/DefaultGraphXmlSerializerConfig.java (rev 0)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/xmlbeans/DefaultGraphXmlSerializerConfig.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -0,0 +1,241 @@
+package net.sourceforge.squirrel_sql.plugins.graph.xmlbeans;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.plugins.graph.GraphPlugin;
+import net.sourceforge.squirrel_sql.plugins.graph.GraphUtil;
+import net.sourceforge.squirrel_sql.plugins.graph.link.LinkXmlBean;
+
+import java.io.File;
+import java.io.IOException;
+
+public class DefaultGraphXmlSerializerConfig
+{
+ private static final StringManager s_stringMgr = StringManagerFactory.getStringManager(DefaultGraphXmlSerializerConfig.class);
+
+
+ public static final String XML_BEAN_POSTFIX = ".graph.xml";
+ public static final String LINK_PREFIX = "lnk_";
+
+ GraphPlugin _plugin;
+ private ISession _session;
+
+
+ private String _graphFilePath;
+ private LinkXmlBean _linkXmlBean;
+ private String _pathOfLinkXmlFile;
+ private String _title;
+
+
+ public DefaultGraphXmlSerializerConfig(GraphPlugin plugin, ISession session, LinkXmlBean linkXmlBean, String pathOfLinkXmlFile)
+ {
+
+ _linkXmlBean = linkXmlBean;
+ _pathOfLinkXmlFile = pathOfLinkXmlFile;
+ _init(plugin, session, _linkXmlBean.getFilePathOfLinkedGraph());
+ }
+
+ public DefaultGraphXmlSerializerConfig(GraphPlugin plugin, ISession session, String graphFileName)
+ {
+ _init(plugin, session, graphFileName);
+ }
+
+ private void _init(GraphPlugin plugin, ISession session, String graphFileName)
+ {
+ _plugin = plugin;
+ _session = session;
+
+ _title = _plugin.patchName(s_stringMgr.getString("graph.newGraph"), _session);
+
+
+ if (null == graphFileName)
+ {
+ _graphFilePath = generateGraphFilePath(_title);
+ }
+ else
+ {
+ _graphFilePath = graphFileName;
+ }
+ }
+
+ private String generateGraphFilePath(String title)
+ {
+ try
+ {
+ String url = _session.getAlias().getUrl();
+ return getFileName(_plugin.getPluginUserSettingsFolder().getPath(), url, title);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ public boolean isLink()
+ {
+ return null != _linkXmlBean;
+ }
+
+ public String getGraphFilePath()
+ {
+ return _graphFilePath;
+ }
+
+ public LinkXmlBean getLinkXmlBean()
+ {
+ return _linkXmlBean;
+ }
+
+ public void renameGraph(String newGraphName)
+ {
+ try
+ {
+ String url = _session.getAlias().getUrl();
+ String newGraphFile = getFileName(_plugin.getPluginUserSettingsFolder().getPath(), url, newGraphName);
+
+ if (new File(_graphFilePath).exists())
+ {
+ if(false == new File(_graphFilePath).renameTo(new File(newGraphFile)))
+ {
+ String msg = "Failed to rename file: " + _graphFilePath;
+ _session.showErrorMessage(msg);
+ throw new IllegalStateException(msg);
+ }
+
+ String[] params = {_graphFilePath, newGraphFile};
+ // i18n[graph.graphRenamed=Renamed "{0}" to "{1}"]
+ _session.showMessage(s_stringMgr.getString("graph.graphRenamed", params));
+ }
+
+ _graphFilePath = newGraphFile;
+ _title = newGraphName;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static String getLinkPrefix(ISession session)
+ {
+ return LINK_PREFIX + GraphUtil.javaNormalize(session.getAlias().getUrl()) + ".";
+ }
+
+ private String getFileName(String path, String url, String title)
+ {
+ String graphFileName = GraphUtil.createGraphFileName(url, _plugin.patchName(title, _session));
+ return path + File.separator + graphFileName + XML_BEAN_POSTFIX;
+ }
+
+ public String getTitle()
+ {
+ if (isLink())
+ {
+ return _linkXmlBean.getLinkName();
+ }
+ else
+ {
+ return _title;
+ }
+ }
+
+ public void transformToLocalCopy()
+ {
+ try
+ {
+ String linkName = new File(_pathOfLinkXmlFile).getName();
+ String newGraphsName = linkName.substring(LINK_PREFIX.length(), linkName.length());
+ _graphFilePath = new File(_plugin.getPluginUserSettingsFolder().getPath(), newGraphsName).getAbsolutePath();
+ _linkXmlBean = null;
+ new File(_pathOfLinkXmlFile).delete();
+ _pathOfLinkXmlFile = null;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void checkTargetWritable()
+ {
+ if(isLink())
+ {
+ if(false == new File(_graphFilePath).canWrite())
+ {
+ String msg =
+ s_stringMgr.getString("graph.link.cannotWrite",
+ _linkXmlBean.getNameOfLinkedGraph(),
+ _graphFilePath,
+ _pathOfLinkXmlFile);
+
+ _session.getApplication().getMessageHandler().showErrorMessage(msg);
+ throw new IllegalStateException(msg);
+ }
+ }
+ }
+
+ public void removeLink()
+ {
+ if(false == isLink())
+ {
+ throw new IllegalStateException("Not a link");
+ }
+
+
+ if(false == new File(_pathOfLinkXmlFile).delete())
+ {
+ String msg = "Failed to remove link file: " + _pathOfLinkXmlFile;
+ _session.showErrorMessage(msg);
+ throw new IllegalStateException(msg);
+ }
+
+
+ _session.showMessage(s_stringMgr.getString("graph.graphLinkRemoved", _pathOfLinkXmlFile));
+ }
+
+ public void setTitle(String title)
+ {
+ _title = title;
+ _graphFilePath = generateGraphFilePath(title);
+ }
+
+ public boolean isLoadable()
+ {
+ if(isLink() || (null != _graphFilePath && new File(_graphFilePath).exists()))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public void removeGraphFile()
+ {
+ if (new File(_graphFilePath).exists())
+ {
+ if(false == new File(_graphFilePath).delete())
+ {
+ String msg = "Failed to remove file: " + _graphFilePath;
+ _session.showErrorMessage(msg);
+ throw new IllegalStateException(msg);
+ }
+
+ String[] params = {_graphFilePath};
+ // i18n[graph.graphRemoved=Removed graph file "{0}"]
+ _session.showMessage(s_stringMgr.getString("graph.graphRemoved", params));
+ }
+ }
+
+ public String getPathOfLinkXmlFile()
+ {
+ if(false == isLink())
+ {
+ throw new IllegalStateException("Not a link");
+ }
+ return _pathOfLinkXmlFile;
+ }
+}
\ No newline at end of file
Modified: trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/xmlbeans/GraphXmlSerializer.java
===================================================================
--- trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/xmlbeans/GraphXmlSerializer.java 2012-01-03 11:42:05 UTC (rev 6553)
+++ trunk/sql12/plugins/graph/src/main/java/net/sourceforge/squirrel_sql/plugins/graph/xmlbeans/GraphXmlSerializer.java 2012-01-04 20:36:28 UTC (rev 6554)
@@ -24,71 +24,33 @@
private final static ILogger s_log = LoggerController.createLogger(GraphXmlSerializer.class);
-
- private static final String XML_BEAN_POSTFIX = ".graph.xml";
- public static final String LINK_PREFIX = "lnk_";
-
- private GraphPlugin _plugin;
+ private DefaultGraphXmlSerializerConfig _cfg;
private ISession _session;
- private String _graphFile;
- private LinkXmlBean _linkXmlBean;
- private String _pathOfLinkXmlFile;
- public GraphXmlSerializer(GraphPlugin plugin, ISession session, String title, String graphFileName)
+ public GraphXmlSerializer(GraphPlugin plugin, ISession session, String graphFileName)
{
- _init(plugin, session, title, graphFileName);
+ _session = session;
+ _cfg = new DefaultGraphXmlSerializerConfig(plugin, session, graphFileName);
}
public GraphXmlSerializer(GraphPlugin plugin, ISession session, LinkXmlBean linkXmlBean, String pathOfLinkXmlFile)
{
- _linkXmlBean = linkXmlBean;
- _pathOfLinkXmlFile = pathOfLinkXmlFile;
- _init(plugin, session, _linkXmlBean.getLinkName(), _linkXmlBean.getFilePathOfLinkedGraph());
+ _session = session;
+ _cfg = new DefaultGraphXmlSerializerConfig(plugin, session, linkXmlBean, pathOfLinkXmlFile);
}
- private void _init(GraphPlugin plugin, ISession session, String title, String graphFileName)
- {
- try
- {
- _plugin = plugin;
- _session = session;
- String url = _session.getAlias().getUrl();
-
- if(null == graphFileName)
- {
- _graphFile = getFileName(plugin.getPluginUserSettingsFolder().getPath(), url, title);
- }
- else
- {
- _graphFile = graphFileName;
- }
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
public void write(GraphControllerXmlBean xmlBean)
{
try
{
- if(null != _linkXmlBean)
- {
- if(false == new File(_graphFile).canWrite())
- {
- String msg = s_stringMgr.getString("graph.link.cannotWrite", _linkXmlBean.getNameOfLinkedGraph(), _graphFile);
- _session.getApplication().getMessageHandler().showErrorMessage(msg);
- throw new IllegalStateException(msg);
- }
- }
+ _cfg.checkTargetWritable();
Version32Converter.markConverted(xmlBean);
XMLBeanWriter bw = new XMLBeanWriter(xmlBean);
- bw.save(_graphFile);
+ bw.save(_cfg.getGraphFilePath());
- String[] params = {xmlBean.getTitle(), _graphFile};
+ String[] params = {xmlBean.getTitle(), _cfg.getGraphFilePath()};
// i18n[graph.graphSaved=Graph "{0}" saved to "{1}"]
String msg = s_stringMgr.getString("graph.graphSaved", params);
@@ -100,6 +62,7 @@
}
}
+
public void saveLinkAsLocalCopy(GraphControllerXmlBean xmlBean)
{
if(false == isLink())
@@ -107,41 +70,28 @@
throw new IllegalStateException("Not a link");
}
- transformMeFromLinkToLocalCopy();
+ _cfg.transformToLocalCopy();
write(xmlBean);
}
- private void transformMeFromLinkToLocalCopy()
- {
- try
- {
- String linkName = new File(_pathOfLinkXmlFile).getName();
- String newGraphsName = linkName.substring(LINK_PREFIX.length(), linkName.length());
- _graphFile = new File(_plugin.getPluginUserSettingsFolder().getPath(), newGraphsName).getAbsolutePath();
- _linkXmlBean = null;
- new File(_pathOfLinkXmlFile).delete();
- _pathOfLinkXmlFile = null;
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- }
-
public GraphControllerXmlBean read()
{
try
{
XMLBeanReader br = new XMLBeanReader();
- br.load(_graphFile, this.getClass().getClassLoader());
+ br.load(_cfg.getGraphFilePath(), this.getClass().getClassLoader());
GraphControllerXmlBean ret = (GraphControllerXmlBean) br.iterator().next();
Version32Converter.convert(ret);
- if(null != _linkXmlBean)
+ if(_cfg.isLink())
{
- ret.setTitle(_linkXmlBean.getLinkName());
+ ret.setTitle(_cfg.getTitle());
}
+ else
+ {
+ _cfg.setTitle(ret.getTitle());
+ }
return ret;
}
@@ -152,36 +102,7 @@
}
- private String getFileName(String path, String url, String title)
- {
- final String filePrefix = GraphUtil.createGraphFileName(url, title);
- File p = new File(path);
- String buf = filePrefix;
- for(int i=1; prefixExists(p, buf); ++i)
- {
- buf = filePrefix + "_" + i ;
- }
-
- return path + File.separator + buf + XML_BEAN_POSTFIX;
- }
-
- private boolean prefixExists(File path, final String filePrefix)
- {
- File[] files = path.listFiles(new FilenameFilter()
- {
- public boolean accept(File dir, String name)
- {
- if(name.toLowerCase().equals(filePrefix.toLowerCase() + XML_BEAN_POSTFIX))
- {
- return true;
- }
- return false;
- }
- });
- return 0 < files.length;
- }
-
public static GraphXmlSerializer[] getGraphXmSerializers(GraphPlugin plugin, ISession session)
{
try
@@ -212,7 +133,7 @@
{
try
{
- final String linkPrefix = LINK_PREFIX + GraphUtil.javaNormalize(session.getAlias().getUrl()) + ".";
+ final String linkPrefix = DefaultGraphXmlSerializerConfig.getLinkPrefix(session);
FileWrapper[] linkXmlFiles = plugin.getPluginUserSettingsFolder().listFiles(new FilenameFilter()
{
@@ -239,7 +160,12 @@
}
else
{
- String msg = s_stringMgr.getString("graph.link.cannotRead", linkXmlBean.getNameOfLinkedGraph(), linkXmlBean.getFilePathOfLinkedGraph());
+ String msg =
+ s_stringMgr.getString("graph.link.cannotRead",
+ linkXmlBean.getNameOfLinkedGraph(),
+ linkXmlBean.getFilePathOfLinkedGraph(),
+ linkXmlFile.getAbsolutePath());
+
session.getApplication().getMessageHandler().showErrorMessage(msg);
s_log.error(msg, new IllegalStateException(msg));
}
@@ -260,7 +186,7 @@
GraphXmlSerializer[] ret = new GraphXmlSerializer[graphXmlFiles.length];
for (int i = 0; i < graphXmlFiles.length; i++)
{
- ret[i] = new GraphXmlSerializer(plugin, session, (String)null, graphXmlFiles[i].getPath());
+ ret[i] = new GraphXmlSerializer(plugin, session, graphXmlFiles[i].getPath());
}
return ret;
@@ -314,15 +240,7 @@
{
try
{
- String url = _session.getAlias().getUrl();
- String newGraphFile = getFileName(_plugin.getPluginUserSettingsFolder().getPath(), url, newName);
...
[truncated message content] |