[Mongobrowser-commit] SF.net SVN: mongobrowser:[131] trunk/mongobrowser
Status: Pre-Alpha
Brought to you by:
dbrosius
From: <dbr...@us...> - 2011-06-19 07:14:50
|
Revision: 131 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=131&view=rev Author: dbrosius Date: 2011-06-19 07:14:41 +0000 (Sun, 19 Jun 2011) Log Message: ----------- periodic checkin from git Modified Paths: -------------- trunk/mongobrowser/.classpath trunk/mongobrowser/.gitignore trunk/mongobrowser/build.xml trunk/mongobrowser/etc/mongobrowser.jnlp trunk/mongobrowser/mongobrowser.fb trunk/mongobrowser/mongobrowser.store trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBrowser.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/TreeUtils.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ConnectAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DeleteAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DisconnectAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/DoubleDocument.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/FloatDocument.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IntegerDocument.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoPanel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties Modified: trunk/mongobrowser/.classpath =================================================================== --- trunk/mongobrowser/.classpath 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/.classpath 2011-06-19 07:14:41 UTC (rev 131) @@ -4,6 +4,6 @@ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="lib" path="lib/forms-1.2.1.jar"/> <classpathentry kind="lib" path="lib/commons-io-1.3.2.jar"/> - <classpathentry kind="lib" path="lib/mongo-java-driver-1.2.jar"/> + <classpathentry kind="lib" path="lib/mongo-java-driver-2.6.2.jar"/> <classpathentry kind="output" path="classes"/> </classpath> Modified: trunk/mongobrowser/.gitignore =================================================================== --- trunk/mongobrowser/.gitignore 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/.gitignore 2011-06-19 07:14:41 UTC (rev 131) @@ -8,3 +8,4 @@ .settings javadoc jnlp +/lib Modified: trunk/mongobrowser/build.xml =================================================================== --- trunk/mongobrowser/build.xml 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/build.xml 2011-06-19 07:14:41 UTC (rev 131) @@ -2,8 +2,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,10 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> + <property name="forms.version" value="1.2.1"/> + <property name="mongo-java-driver.version" value="2.6.2"/> + <property name="commons-io.version" value="1.3.2"/> + <property name="mongobrowser.version" value="0.1.0"/> <target name="clean" description="removes all generated collateral"> @@ -55,38 +59,38 @@ <mkdir dir="${classes.dir}"/> <mkdir dir="${javadoc.dir}"/> <path id="mongobrowser.classpath"> - <pathelement location="${lib.dir}/mongo-java-driver-1.2.jar"/> - <pathelement location="${lib.dir}/forms-1.2.1.jar"/> - <pathelement location="${lib.dir}/commons-io-2.3.2.jar"/> + <pathelement location="${lib.dir}/mongo-java-driver-${mongo-java-driver.version}.jar"/> + <pathelement location="${lib.dir}/forms-${forms.version}.jar"/> + <pathelement location="${lib.dir}/commons-io-${commons-io.version}.jar"/> </path> </target> - <property name="forms_url" value="http://repo1.maven.org/maven2/com/jgoodies/forms/1.2.1/forms-1.2.1.jar"/> - <property name="mongodriver_url" value="http://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/1.2/mongo-java-driver-1.2.jar"/> - <property name="commonsio_url" value="http://repo1.maven.org/maven2/org/apache/commons/commons-io/1.3.2/commons-io-1.3.2.jar"/> + <property name="forms_url" value="http://repo1.maven.org/maven2/com/jgoodies/forms/${forms.version}/forms-${forms.version}.jar"/> + <property name="mongodriver_url" value="http://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/${mongo-java-driver.version}/mongo-java-driver-${mongo-java-driver.version}.jar"/> + <property name="commonsio_url" value="http://repo1.maven.org/maven2/org/apache/commons/commons-io/${commons-io.version}/commons-io-${commons-io.version}.jar"/> <target name="forms_check"> - <available file="${basedir}/lib/forms-1.2.1.jar" property="forms_exists"/> + <available file="${basedir}/lib/forms-${forms.version}.jar" property="forms_exists"/> </target> <target name="mongodriver_check"> - <available file="${basedir}/lib/mongo-java-driver-1.2.jar" property="mongodriver.exists"/> + <available file="${basedir}/lib/mongo-java-driver-${mongo-java-driver.version}.jar" property="mongodriver.exists"/> </target> <target name="commonsio_check"> - <available file="${basedir}/lib/commons-io-1.3.2.jar" property="commonsio.exists"/> + <available file="${basedir}/lib/commons-io-${commons-io.version}.jar" property="commonsio.exists"/> </target> <target name="install_forms" depends="forms_check" unless="forms_exists" description="installs forms.jar into lib"> - <get src="${forms_url}" dest="${basedir}/lib/forms-1.2.1.jar" verbose="true" ignoreerrors="true"/> + <get src="${forms_url}" dest="${basedir}/lib/forms-${forms.version}.jar" verbose="true" ignoreerrors="true"/> </target> <target name="install_mongodriver" depends="mongodriver_check" unless="mongodriver.exists" description="installs mongodriver.jar into lib"> - <get src="${mongodriver_url}" dest="${basedir}/lib/mongo-java-driver-1.2.jar" verbose="true" ignoreerrors="true"/> + <get src="${mongodriver_url}" dest="${basedir}/lib/mongo-java-driver-${mongo-java-driver.version}.jar" verbose="true" ignoreerrors="true"/> </target> <target name="install_commonsio" depends="commonsio_check" unless="commonsio.exists" description="installs commons-io.jar into lib"> - <get src="${commonsio_url}" dest="${basedir}/lib/commons-io-1.3.2.jar" verbose="true" ignoreerrors="true"/> + <get src="${commonsio_url}" dest="${basedir}/lib/commons-io-${commons-io.version}.jar" verbose="true" ignoreerrors="true"/> </target> <target name="pull" depends="install_forms, install_mongodriver, install_commonsio" description="pulls in the 3rd party jars"> @@ -98,7 +102,8 @@ source="${javac.source}" target="${javac.target}" deprecation="${javac.deprecation}" - debug="${javac.debug}"> + debug="${javac.debug}" + includeantruntime="false"> <classpath refid="mongobrowser.classpath"/> </javac> </target> @@ -139,7 +144,7 @@ <manifest> <attribute name="mongobrowser-version" value="${mongobrowser.version}"/> <attribute name="Main-Class" value="com.mebigfatguy.mongobrowser.MongoBrowser"/> - <attribute name="Class-Path" value="commons-io-1.3.2.jar forms-1.2.1.jar"/> + <attribute name="Class-Path" value="commons-io-${commons-io.version}.jar forms-${forms.version}.jar"/> </manifest> </jar> </target> @@ -157,7 +162,7 @@ destdir="${javadoc.dir}" windowtitle="mongobrowser api"> <doctitle><![CDATA[<h1>mongobrowser javadoc</h1>]]></doctitle> - <bottom><![CDATA[<i>Copyright © 2009-2010 MeBigFatGuy.com. All Rights Reserved.</i>]]></bottom> + <bottom><![CDATA[<i>Copyright © 2009-2011 MeBigFatGuy.com. All Rights Reserved.</i>]]></bottom> </javadoc> </target> @@ -206,7 +211,7 @@ <target name="binzip" depends="build" description="zips up all jars"> <zip destfile="${basedir}/mongobrowser-bin-${mongobrowser.version}.zip" basedir="${jnlp.dir}" - includes="mongobrowser-${mongobrowser.version}.jar commons-io-1.3.2.jar forms-1.2.1.jar"/> + includes="mongobrowser-${mongobrowser.version}.jar commons-io-${commons-io.version}.jar forms-${forms.version}.jar"/> </target> <target name="release" depends="build, jnlp, binzip, srczip, javadoc" description="prepares everything for a release"/> Modified: trunk/mongobrowser/etc/mongobrowser.jnlp =================================================================== --- trunk/mongobrowser/etc/mongobrowser.jnlp 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/etc/mongobrowser.jnlp 2011-06-19 07:14:41 UTC (rev 131) @@ -16,7 +16,7 @@ <resources> <j2se version="1.6+" initial-heap-size="400m" max-heap-size="800m"/> <jar href="mongobrowser-$VERSION.jar"/> - <jar href="mongo-1.2.jar"/> + <jar href="mongo-java-driver-2.6.2.jar"/> <jar href="forms-1.2.1.jar"/> </resources> <application-desc main-class="com.mebigfatguy.mongobrowser.MongoBrowser"/> Modified: trunk/mongobrowser/mongobrowser.fb =================================================================== --- trunk/mongobrowser/mongobrowser.fb 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/mongobrowser.fb 2011-06-19 07:14:41 UTC (rev 131) @@ -4,6 +4,7 @@ ./src [Aux classpath entries] ./lib/forms-1.2.1.jar -./lib/mongo-1.2.jar +./lib/commons-io-1.3.2.jar +./lib/mongo-java-driver-2.6.2.jar [Options] relative_paths=true Modified: trunk/mongobrowser/mongobrowser.store =================================================================== (Binary files differ) Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBrowser.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBrowser.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBrowser.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,9 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius + * Copyright 2009-2011 Rodrigo Hjort * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,20 +19,40 @@ */ package com.mebigfatguy.mongobrowser; +import java.net.UnknownHostException; + import com.mebigfatguy.mongobrowser.dialogs.MongoBrowserFrame; +import com.mongodb.MongoException; /** * main application class */ public class MongoBrowser { + public static final String DEFAULT_SERVER = "localhost"; + public static final int DEFAULT_PORT = 27017; + /** - * - * @param args the command line arguments (unused) + * @param args + * the command line arguments */ public static void main(String[] args) { + + final String host = (args.length > 0 ? args[0] : null); + MongoBrowserFrame frame = new MongoBrowserFrame(); frame.setLocationRelativeTo(null); frame.setVisible(true); + + if (host != null) { + final int port = (args.length > 1 ? Integer.parseInt(args[1]) : DEFAULT_PORT); + try { + frame.startupConnection(host, port); + } catch (UnknownHostException e) { + System.err.println("Unknown host specified: " + host); + } catch (MongoException e) { + System.err.println("An error has occurred: " + e.getMessage()); + } + } } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import java.util.ResourceBundle; -/** +/** * manages the resource bundle properties file for this application */ public class MongoBundle { @@ -29,40 +29,25 @@ * an enumeration of all the possible entries in the bundle */ public enum Key { - OK("mongo.ok"), - Cancel("mongo.cancel"), - Title("mongo.title"), - Servers("mongo.servers"), - Connect("mongo.connect"), - Disconnect("mongo.disconnect"), - ConnectToServer("mongo.connecttoserver"), - Server("mongo.server"), - Port("mongo.port"), - Database("mongo.database"), - NewDatabase("mongo.newdatabase"), - NewCollection("mongo.newcollection"), - NewObject("mongo.newobject"), - NewKeyValue("mongo.newkeyvalue"), - Key("mongo.key"), - Value("mongo.value"), - Integer("mongo.integer"), - Double("mongo.double"), - Float("mongo.float"), - String("mongo.string"), - Object("mongo.object"), - Delete("mongo.delete"); - + OK("mongo.ok"), Cancel("mongo.cancel"), Title("mongo.title"), Servers("mongo.servers"), Connect("mongo.connect"), Disconnect( + "mongo.disconnect"), ConnectToServer("mongo.connecttoserver"), Server("mongo.server"), Port( + "mongo.port"), Database("mongo.database"), NewDatabase("mongo.newdatabase"), NewCollection( + "mongo.newcollection"), NewObject("mongo.newobject"), NewKeyValue("mongo.newkeyvalue"), Key("mongo.key"), Value( + "mongo.value"), Integer("mongo.integer"), Double("mongo.double"), Float("mongo.float"), String( + "mongo.string"), Object("mongo.object"), Delete("mongo.delete"); + String id; - + /** * creates a key given the properties file name * - * @param id the properties file entry name + * @param id + * the properties file entry name */ Key(String id) { this.id = id; } - + /** * retrieves the properties file entry name for this Key * @@ -72,20 +57,22 @@ return id; } }; - + private static ResourceBundle bundle = ResourceBundle.getBundle("com/mebigfatguy/mongobrowser/resources/resource"); - + /** - * protects this class from being instantiated as it is meant to be accessed as a static class + * protects this class from being instantiated as it is meant to be accessed + * as a static class */ private MongoBundle() { - + } - + /** * retrieves a string from a resource bundle given a key * - * @param key the key of the property item that is to be retrieved + * @param key + * the key of the property item that is to be retrieved * @return the string representing the localized name */ public static String getString(Key key) { Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,14 +30,18 @@ public interface MongoContext { void setTree(JTree tree); + JTree getTree(); - - void setSelectedNode(MongoTreeNode node); - MongoTreeNode getSelectedNode(); - + + void setSelectedNodes(MongoTreeNode... node); + + MongoTreeNode[] getSelectedNodes(); + void setServer(Mongo server); + Mongo getServer(); - + void setDatabase(DB db); + DB getDatabase(); } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/TreeUtils.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/TreeUtils.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/TreeUtils.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,27 +18,54 @@ */ package com.mebigfatguy.mongobrowser; +import javax.swing.JTree; +import javax.swing.tree.TreePath; + import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode; /** * a collection of utility methods used in a static context */ public class TreeUtils { - - private TreeUtils() { + + private TreeUtils() { } - + /** * retrieves the collection node that owns the requested node * - * @param fromNode the node to find the collection for + * @param fromNode + * the node to find the collection for * @return the collection node that owns this node */ public static MongoTreeNode findCollectionNode(MongoTreeNode fromNode) { while (fromNode.getType() != MongoTreeNode.Type.Collection) { - fromNode = (MongoTreeNode)fromNode.getParent(); + fromNode = (MongoTreeNode) fromNode.getParent(); } - + return fromNode; } + + /** + * retrieves all the MongoTreeNodes from the current selection + * + * @param tree + * the tree to fetch the nodes from + * @return the selected MongoTreeNodes + */ + public static MongoTreeNode[] getSelectedNodes(JTree tree) { + TreePath[] paths = tree.getSelectionPaths(); + + if (paths != null) { + MongoTreeNode[] nodes = new MongoTreeNode[paths.length]; + + for (int i = 0; i < nodes.length; i++) { + nodes[i] = (MongoTreeNode) paths[i].getLastPathComponent(); + } + + return nodes; + } else { + return new MongoTreeNode[0]; + } + } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ConnectAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ConnectAction.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ConnectAction.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,12 +36,12 @@ private static final long serialVersionUID = -4704951174439411332L; private MongoContext context; - + public ConnectAction(MongoContext ctxt) { super(MongoBundle.getString(MongoBundle.Key.Connect)); context = ctxt; } - + @Override public void actionPerformed(ActionEvent e) { try { Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DeleteAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DeleteAction.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DeleteAction.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import com.mebigfatguy.mongobrowser.MongoContext; import com.mebigfatguy.mongobrowser.TreeUtils; import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode; +import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode.Type; import com.mongodb.DBCollection; import com.mongodb.DBObject; @@ -36,54 +37,68 @@ public class DeleteAction extends AbstractAction { private static final long serialVersionUID = 9057255369669193765L; - private MongoContext context; - + private final MongoContext context; + public DeleteAction(MongoContext ctxt) { super(MongoBundle.getString(MongoBundle.Key.Delete)); context = ctxt; } - + @Override public void actionPerformed(ActionEvent e) { - MongoTreeNode node = context.getSelectedNode(); - switch (node.getType()) { - case Collection: { - DBCollection collection = (DBCollection)node.getUserObject(); - collection.drop(); - MongoTreeNode dbNode = (MongoTreeNode)node.getParent(); - dbNode.remove(node); - DefaultTreeModel model = (DefaultTreeModel)context.getTree().getModel(); - model.nodeStructureChanged(dbNode); - } - break; - - case Object: { - DBObject object = (DBObject)node.getUserObject(); - MongoTreeNode collectionNode = TreeUtils.findCollectionNode(node); - DBCollection collection = (DBCollection)collectionNode.getUserObject(); - collection.remove(object); - collectionNode.remove(node); - DefaultTreeModel model = (DefaultTreeModel)context.getTree().getModel(); - model.nodeStructureChanged(collectionNode); - } - break; - - case KeyValue: { - MongoTreeNode.KV kv = (MongoTreeNode.KV)node.getUserObject(); - String key = kv.getKey(); - if (!key.startsWith("_")) { - MongoTreeNode objectNode = (MongoTreeNode)node.getParent(); - DBObject object = (DBObject)objectNode.getUserObject(); - object.removeField(key); - MongoTreeNode collectionNode = TreeUtils.findCollectionNode(objectNode); - DBCollection collection = (DBCollection)collectionNode.getUserObject(); - collection.save(object); - objectNode.remove(node); - DefaultTreeModel model = (DefaultTreeModel)context.getTree().getModel(); - model.nodeStructureChanged(objectNode); + MongoTreeNode[] nodes = context.getSelectedNodes(); + + deleteNodesOfType(nodes, Type.KeyValue); + deleteNodesOfType(nodes, Type.Object); + deleteNodesOfType(nodes, Type.Collection); + } + + private void deleteNodesOfType(MongoTreeNode[] nodes, Type type) { + for (int i = nodes.length - 1; i >= 0; i--) { + MongoTreeNode node = nodes[i]; + + Type nodeType = node.getType(); + if (nodeType == type) { + switch (nodeType) { + case Collection: { + DBCollection collection = (DBCollection) node.getUserObject(); + collection.drop(); + MongoTreeNode dbNode = (MongoTreeNode) node.getParent(); + dbNode.remove(node); + DefaultTreeModel model = (DefaultTreeModel) context.getTree().getModel(); + model.nodeStructureChanged(dbNode); + } + break; + + case Object: { + DBObject object = (DBObject) node.getUserObject(); + MongoTreeNode collectionNode = TreeUtils.findCollectionNode(node); + DBCollection collection = (DBCollection) collectionNode.getUserObject(); + collection.remove(object); + collectionNode.remove(node); + DefaultTreeModel model = (DefaultTreeModel) context.getTree().getModel(); + model.nodeStructureChanged(collectionNode); + } + break; + + case KeyValue: { + MongoTreeNode.KV kv = (MongoTreeNode.KV) node.getUserObject(); + String key = kv.getKey(); + if (!key.startsWith("_")) { + MongoTreeNode objectNode = (MongoTreeNode) node.getParent(); + DBObject object = (DBObject) objectNode.getUserObject(); + object.removeField(key); + MongoTreeNode collectionNode = TreeUtils.findCollectionNode(objectNode); + DBCollection collection = (DBCollection) collectionNode.getUserObject(); + collection.save(object); + objectNode.remove(node); + DefaultTreeModel model = (DefaultTreeModel) context.getTree().getModel(); + model.nodeStructureChanged(objectNode); + } + } + break; } } - break; } } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DisconnectAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DisconnectAction.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DisconnectAction.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,12 +32,12 @@ private static final long serialVersionUID = -5795316226405751888L; private MongoContext context; - + public DisconnectAction(MongoContext ctxt) { super(MongoBundle.getString(MongoBundle.Key.Disconnect)); context = ctxt; } - + @Override public void actionPerformed(ActionEvent e) { context.setDatabase(null); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,14 +38,14 @@ public class NewCollectionAction extends AbstractAction { private static final long serialVersionUID = 9090870672875251498L; - + private MongoContext context; - + public NewCollectionAction(MongoContext ctxt) { super(MongoBundle.getString(MongoBundle.Key.NewCollection)); context = ctxt; } - + @Override public void actionPerformed(ActionEvent e) { JTree tree = context.getTree(); @@ -53,8 +53,8 @@ if (collectionName != null) { DB db = context.getDatabase(); DBCollection dbCollection = db.getCollection(collectionName); - DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); - MongoTreeNode root = (MongoTreeNode)model.getRoot(); + DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); + MongoTreeNode root = (MongoTreeNode) model.getRoot(); MongoTreeNode collectionNode = new MongoTreeNode(dbCollection, false); root.add(collectionNode); MongoTreeNode slug = new MongoTreeNode(); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,13 +39,13 @@ public class NewKeyValueAction extends AbstractAction { private static final long serialVersionUID = -500965537578361564L; - private MongoContext context; - + private final MongoContext context; + public NewKeyValueAction(MongoContext ctxt) { super(MongoBundle.getString(MongoBundle.Key.NewKeyValue)); context = ctxt; } - + @Override public void actionPerformed(ActionEvent e) { JTree tree = context.getTree(); @@ -53,34 +53,45 @@ dialog.setLocationRelativeTo(tree); dialog.setModal(true); dialog.setVisible(true); + if (dialog.isOK()) { String key = dialog.getKey(); Object value = dialog.getValue(); - TreePath path = tree.getSelectionPath(); - MongoTreeNode selectedNode = (MongoTreeNode)path.getLastPathComponent(); - DBObject object; - - if (selectedNode.getType() == MongoTreeNode.Type.KeyValue) { - object = (DBObject) ((MongoTreeNode.KV)selectedNode.getUserObject()).getValue(); - } else { - object = (DBObject) selectedNode.getUserObject(); + + boolean didScrollToView = false; + MongoTreeNode[] selectedNodes = TreeUtils.getSelectedNodes(tree); + + for (MongoTreeNode selectedNode : selectedNodes) { + DBObject object; + + if (selectedNode.getType() == MongoTreeNode.Type.KeyValue) { + object = (DBObject) ((MongoTreeNode.KV) selectedNode.getUserObject()).getValue(); + } else { + object = (DBObject) selectedNode.getUserObject(); + } + + object.put(key, value); + MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key)), false); + selectedNode.add(kv); + if (value instanceof DBObject) { + MongoTreeNode slug = new MongoTreeNode(); + kv.add(slug); + } + MongoTreeNode collectionNode = TreeUtils.findCollectionNode(selectedNode); + DBCollection collection = (DBCollection) collectionNode.getUserObject(); + collection.save(object); + + DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); + model.nodeStructureChanged((MongoTreeNode) model.getRoot()); + + if (!didScrollToView) { + TreePath selection = new TreePath(kv.getPath()); + tree.scrollPathToVisible(selection); + tree.setSelectionPath(selection); + didScrollToView = true; + } } - - object.put(key, value); - MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key)), false); - selectedNode.add(kv); - if (value instanceof DBObject) { - MongoTreeNode slug = new MongoTreeNode(); - kv.add(slug); - } - MongoTreeNode collectionNode = TreeUtils.findCollectionNode(selectedNode); - DBCollection collection = (DBCollection)collectionNode.getUserObject(); - collection.save(object); - DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); - model.nodeStructureChanged((MongoTreeNode)model.getRoot()); - TreePath selection = new TreePath(kv.getPath()); - tree.scrollPathToVisible(selection); - tree.setSelectionPath(selection); + } } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import com.mebigfatguy.mongobrowser.MongoBundle; import com.mebigfatguy.mongobrowser.MongoContext; +import com.mebigfatguy.mongobrowser.TreeUtils; import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode; import com.mongodb.BasicDBObject; import com.mongodb.DBCollection; @@ -37,30 +38,36 @@ public class NewObjectAction extends AbstractAction { private static final long serialVersionUID = 5752147095730092598L; - private MongoContext context; - + private final MongoContext context; + public NewObjectAction(MongoContext ctxt) { super(MongoBundle.getString(MongoBundle.Key.NewObject)); context = ctxt; } - + @Override public void actionPerformed(ActionEvent e) { JTree tree = context.getTree(); - TreePath path = tree.getSelectionPath(); - MongoTreeNode collectionNode = (MongoTreeNode)path.getLastPathComponent(); - DBCollection dbCollection = (DBCollection) collectionNode.getUserObject(); - BasicDBObject dbObj = new BasicDBObject(); - dbCollection.insert(dbObj); - DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); - MongoTreeNode objectNode = new MongoTreeNode(dbObj, false); - collectionNode.add(objectNode); - MongoTreeNode slug = new MongoTreeNode(); - objectNode.add(slug); - model.nodeStructureChanged((MongoTreeNode)model.getRoot()); - TreePath selection = new TreePath(objectNode.getPath()); - tree.scrollPathToVisible(selection); - tree.setSelectionPath(selection); + + MongoTreeNode[] selectedNodes = TreeUtils.getSelectedNodes(tree); + boolean didScrollToVisible = false; + for (MongoTreeNode selectedNode : selectedNodes) { + DBCollection dbCollection = (DBCollection) selectedNode.getUserObject(); + BasicDBObject dbObj = new BasicDBObject(); + dbCollection.insert(dbObj); + DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); + MongoTreeNode objectNode = new MongoTreeNode(dbObj, false); + selectedNode.add(objectNode); + MongoTreeNode slug = new MongoTreeNode(); + objectNode.add(slug); + model.nodeStructureChanged((MongoTreeNode) model.getRoot()); + + if (!didScrollToVisible) { + TreePath selection = new TreePath(objectNode.getPath()); + tree.scrollPathToVisible(selection); + tree.setSelectionPath(selection); + didScrollToVisible = false; + } + } } - } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ private JButton okButton; private JButton cancelButton; private boolean ok = false; - + /** * constructs the dialog */ @@ -67,7 +67,7 @@ cp.add(createFormPanel(), BorderLayout.CENTER); cp.add(createCtrlPanel(), BorderLayout.SOUTH); } - + /** * create the panel that houses the input form * @@ -77,29 +77,29 @@ JPanel p = new JPanel(); p.setLayout(new FormLayout("6dlu, pref, 5dlu, 200px, 6dlu", "6dlu, pref, 2dlu, pref, 6dlu")); CellConstraints cc = new CellConstraints(); - + JLabel serverLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Server)); p.add(serverLabel, cc.xy(2, 2)); - + serverField = new JTextField(); p.add(serverField, cc.xy(4, 2)); serverField.setText("localhost"); - + serverLabel.setLabelFor(serverField); - + JLabel portLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Port)); p.add(portLabel, cc.xy(2, 4)); - + portField = new JTextField(); portField.setDocument(new IntegerDocument()); p.add(portField, cc.xy(4, 4)); portField.setText("27017"); - + portLabel.setLabelFor(portField); - + return p; } - + /** * creates the panel that houses the ok and cancel buttons * @@ -110,15 +110,15 @@ p.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(Box.createHorizontalGlue()); - + okButton = new JButton(MongoBundle.getString(MongoBundle.Key.OK)); p.add(okButton); p.add(Box.createHorizontalStrut(10)); - + cancelButton = new JButton(MongoBundle.getString(MongoBundle.Key.Cancel)); p.add(cancelButton); p.add(Box.createHorizontalStrut(10)); - + return p; } @@ -127,17 +127,21 @@ */ private void initListeners() { okButton.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent ae) { ok = true; dispose(); } }); - + cancelButton.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent ae) { dispose(); } }); + + getRootPane().setDefaultButton(okButton); } /** @@ -148,7 +152,7 @@ public boolean isOK() { return ok; } - + /** * get the user supplied host name of the server * @@ -167,5 +171,4 @@ return Integer.parseInt(portField.getText()); } - } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/DoubleDocument.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/DoubleDocument.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/DoubleDocument.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,12 @@ * intercepts string insertions to make sure that the values to be put into * a text component is only an double value * - * @param pos where the text is being inserted - * @param insertStr the new text that was typed - * @param atts the attributes for the text (unused) + * @param pos + * where the text is being inserted + * @param insertStr + * the new text that was typed + * @param atts + * the attributes for the text (unused) */ @Override public void insertString(int pos, String insertStr, AttributeSet atts) throws BadLocationException { @@ -47,7 +50,7 @@ Double.parseDouble(text.toString()); super.insertString(pos, insertStr, atts); } catch (Exception e) { - Toolkit.getDefaultToolkit().beep(); + Toolkit.getDefaultToolkit().beep(); } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/FloatDocument.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/FloatDocument.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/FloatDocument.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; + /** * a JTextComponent model object that only allows float value input */ @@ -34,9 +35,12 @@ * intercepts string insertions to make sure that the values to be put into * a text component is only an float value * - * @param pos where the text is being inserted - * @param insertStr the new text that was typed - * @param atts the attributes for the text (unused) + * @param pos + * where the text is being inserted + * @param insertStr + * the new text that was typed + * @param atts + * the attributes for the text (unused) */ @Override public void insertString(int pos, String insertStr, AttributeSet atts) throws BadLocationException { @@ -46,7 +50,7 @@ Float.parseFloat(text.toString()); super.insertString(pos, insertStr, atts); } catch (Exception e) { - Toolkit.getDefaultToolkit().beep(); + Toolkit.getDefaultToolkit().beep(); } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IntegerDocument.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IntegerDocument.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IntegerDocument.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,12 @@ * intercepts string insertions to make sure that the values to be put into * a text component is only an integer value * - * @param pos where the text is being inserted - * @param insertStr the new text that was typed - * @param atts the attributes for the text (unused) + * @param pos + * where the text is being inserted + * @param insertStr + * the new text that was typed + * @param atts + * the attributes for the text (unused) */ @Override public void insertString(int pos, String insertStr, AttributeSet atts) throws BadLocationException { @@ -47,7 +50,7 @@ Integer.parseInt(text.toString()); super.insertString(pos, insertStr, atts); } catch (Exception e) { - Toolkit.getDefaultToolkit().beep(); + Toolkit.getDefaultToolkit().beep(); } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2011-06-19 07:14:41 UTC (rev 131) @@ -29,16 +29,16 @@ * a dialog for collecting key/value pairs for a mongo object property */ public class KeyValueDialog extends JDialog { - + private static final long serialVersionUID = 4909101478144542212L; - + private JTextField keyField; private JComboBox valueTypeBox; private JTextField valueField; private JButton okButton; private JButton cancelButton; private boolean ok = false; - + /** * constructs a dialog to collect a key value for a mongo object's property */ @@ -48,7 +48,7 @@ initListeners(); pack(); } - + /** * adds and lays out the components in the dialog */ @@ -58,7 +58,7 @@ cp.add(createFormPanel(), BorderLayout.CENTER); cp.add(createCtrlPanel(), BorderLayout.SOUTH); } - + /** * creates the panel for collecting the key and value * @@ -68,36 +68,36 @@ JPanel p = new JPanel(); p.setLayout(new FormLayout("6dlu, pref, 5dlu, 200px, 5dlu, pref, 6dlu", "6dlu, pref, 2dlu, pref, 6dlu")); CellConstraints cc = new CellConstraints(); - + JLabel keyLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Key)); p.add(keyLabel, cc.xy(2, 2)); - + keyField = new JTextField(); p.add(keyField, cc.xy(4, 2)); - + keyLabel.setLabelFor(keyField); - + JLabel valueLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Value)); p.add(valueLabel, cc.xy(2, 4)); valueField = new JTextField(); p.add(valueField, cc.xy(4, 4)); - + valueTypeBox = new JComboBox(); - DefaultComboBoxModel model = (DefaultComboBoxModel)valueTypeBox.getModel(); + DefaultComboBoxModel model = (DefaultComboBoxModel) valueTypeBox.getModel(); model.addElement(new IntegerValueType()); model.addElement(new DoubleValueType()); model.addElement(new FloatValueType()); model.addElement(new StringValueType()); model.addElement(new ObjectValueType()); - valueTypeBox.setSelectedIndex(2); + valueTypeBox.setSelectedIndex(3); p.add(valueTypeBox, cc.xy(6, 4)); - + valueLabel.setLabelFor(valueField); - + return p; } - + /** * creates a panel holding the ok and cancel buttons * @@ -108,45 +108,49 @@ p.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(Box.createHorizontalGlue()); - + okButton = new JButton(MongoBundle.getString(MongoBundle.Key.OK)); p.add(okButton); p.add(Box.createHorizontalStrut(10)); - + cancelButton = new JButton(MongoBundle.getString(MongoBundle.Key.Cancel)); p.add(cancelButton); p.add(Box.createHorizontalStrut(10)); - + return p; } - + /** * installs the listeners */ private void initListeners() { okButton.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent ae) { ok = true; dispose(); } }); - + cancelButton.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent ae) { dispose(); } }); - + valueTypeBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent ie) { if (ie.getStateChange() == ItemEvent.SELECTED) { - ValueType vt = (ValueType)ie.getItem(); + ValueType vt = (ValueType) ie.getItem(); vt.installDocument(valueField); } } }); + + getRootPane().setDefaultButton(okButton); } /** @@ -157,7 +161,7 @@ public boolean isOK() { return ok; } - + /** * gets the key value from the form * @@ -166,16 +170,16 @@ public String getKey() { return keyField.getText(); } - + /** * gets the typed value from the dialog * * @return the typed value */ public Object getValue() { - return ((ValueType)valueTypeBox.getSelectedItem()).getValue(valueField); + return ((ValueType) valueTypeBox.getSelectedItem()).getValue(valueField); } - + /** * interface for items that are put into the Value type combobox */ @@ -183,27 +187,31 @@ /** * switch the JTextField's model based on the type of value * - * @param field the component who's document should be modified + * @param field + * the component who's document should be modified */ void installDocument(JTextField field); + /** * get the value object of the field, based on the type of this value * - * @param field the component to get the value from + * @param field + * the component to get the value from * @return a value object */ Object getValue(JTextField field); } - + /** * a value type representing an Integer object */ static class IntegerValueType implements ValueType { - + /** * installs an IntegerDocument as the field's model * - * @param field the text edit field to install the model + * @param field + * the text edit field to install the model */ @Override public void installDocument(JTextField field) { @@ -216,18 +224,19 @@ } catch (BadLocationException ble) { } } - + /** * get the field's values as an Integer * - * @param field the component that holds the integer value + * @param field + * the component that holds the integer value * @return an Integer that is the value of the text field */ @Override public Object getValue(JTextField field) { return Integer.valueOf(field.getText()); } - + /** * returns the display value shown in the combo box * @@ -238,16 +247,17 @@ return MongoBundle.getString(MongoBundle.Key.Integer); } } - + /** * a value type representing an Double object */ static class DoubleValueType implements ValueType { - + /** * installs an DoubleDocument as the field's model * - * @param field the text edit field to install the model + * @param field + * the text edit field to install the model */ @Override public void installDocument(JTextField field) { @@ -260,18 +270,19 @@ } catch (BadLocationException ble) { } } - + /** * get the field's values as an Double * - * @param field the component that holds the double value + * @param field + * the component that holds the double value * @return an Double that is the value of the text field */ @Override public Object getValue(JTextField field) { return Double.valueOf(field.getText()); } - + /** * returns the display value shown in the combo box * @@ -280,18 +291,19 @@ @Override public String toString() { return MongoBundle.getString(MongoBundle.Key.Double); - } + } } - + /** * a value type representing an Float object */ static class FloatValueType implements ValueType { - + /** * installs an FloatDocument as the field's model * - * @param field the text edit field to install the model + * @param field + * the text edit field to install the model */ @Override public void installDocument(JTextField field) { @@ -304,18 +316,19 @@ } catch (BadLocationException ble) { } } - + /** * get the field's values as an Float * - * @param field the component that holds the float value + * @param field + * the component that holds the float value * @return an Float that is the value of the text field */ @Override public Object getValue(JTextField field) { return Float.valueOf(field.getText()); } - + /** * returns the display value shown in the combo box * @@ -324,19 +337,19 @@ @Override public String toString() { return MongoBundle.getString(MongoBundle.Key.Float); - } + } } - /** * a value type representing an String object */ static class StringValueType implements ValueType { - + /** * installs an PlainDocument as the field's model * - * @param field the text edit field to install the model + * @param field + * the text edit field to install the model */ @Override public void installDocument(JTextField field) { @@ -349,18 +362,19 @@ } catch (BadLocationException ble) { } } - + /** * get the field's values as an String * - * @param field the component that holds the string value + * @param field + * the component that holds the string value * @return an String that is the value of the text field */ @Override public Object getValue(JTextField field) { return field.getText(); } - + /** * returns the display value shown in the combo box * @@ -369,19 +383,19 @@ @Override public String toString() { return MongoBundle.getString(MongoBundle.Key.String); - } + } } - + /** * a value type representing an BasicDBObject object */ static class ObjectValueType implements ValueType { - + /** - * installs an PlainDocument as the field's model - * and disables the field + * installs an PlainDocument as the field's model and disables the field * - * @param field the text edit field to install the model + * @param field + * the text edit field to install the model */ @Override public void installDocument(JTextField field) { @@ -389,18 +403,19 @@ field.setDocument(new PlainDocument()); field.setEnabled(false); } - + /** * get the field's values as an BasicDBObject * - * @param field the component that holds the string value + * @param field + * the component that holds the string value * @return an String that is the value of the text field */ @Override public Object getValue(JTextField field) { return new BasicDBObject(); } - + /** * returns the display value shown in the combo box * Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import java.awt.Container; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.net.UnknownHostException; import javax.swing.JFrame; import javax.swing.JMenu; @@ -35,6 +36,7 @@ import com.mebigfatguy.mongobrowser.actions.DisconnectAction; import com.mongodb.DB; import com.mongodb.Mongo; +import com.mongodb.MongoException; /** * the main frame of the browser @@ -46,8 +48,8 @@ private JMenuItem disconnectItem; private MongoControlPanel ctrlPanel; private MongoDataPanel dataPanel; - private Mediator mediator = new Mediator(); - + private final Mediator mediator = new Mediator(); + /** * constructs the main frame */ @@ -67,20 +69,21 @@ dataPanel = new MongoDataPanel(mediator); cp.add(dataPanel, BorderLayout.CENTER); } - + private void initMenus() { - + JMenuBar mb = new JMenuBar(); JMenu databasesMenu = new JMenu(MongoBundle.getString(MongoBundle.Key.Servers)); connectItem = new JMenuItem(new ConnectAction(mediator)); databasesMenu.add(connectItem); disconnectItem = new JMenuItem(new DisconnectAction(mediator)); - mb.add(databasesMenu); + disconnectItem.setEnabled(false); + mb.add(databasesMenu); databasesMenu.add(disconnectItem); - + setJMenuBar(mb); } - + private void initListeners() { addWindowListener(new WindowAdapter() { @Override @@ -90,18 +93,17 @@ } }); } - + /** * a mediator for all the actions that occur in the frame */ class Mediator implements MongoContext { - + private JTree activeTree; - private MongoTreeNode activeNode; + private MongoTreeNode[] activeNodes; private Mongo activeServer; private DB activeDatabase; - - + @Override public JTree getTree() { return activeTree; @@ -111,23 +113,23 @@ public void setTree(JTree tree) { activeTree = tree; } - + @Override - public MongoTreeNode getSelectedNode() { - return activeNode; + public MongoTreeNode[] getSelectedNodes() { + return activeNodes; } - + @Override - public void setSelectedNode(MongoTreeNode node) { - activeNode = node; - ctrlPanel.adjustEnabled(node); + public void setSelectedNodes(MongoTreeNode... nodes) { + activeNodes = nodes; + ctrlPanel.adjustEnabled(nodes); } @Override public Mongo getServer() { return activeServer; } - + @Override public void setServer(Mongo server) { activeServer = server; @@ -141,17 +143,40 @@ dataPanel.term(); } } - + + @Override public DB getDatabase() { return activeDatabase; } - + + @Override public void setDatabase(DB database) { activeDatabase = database; - if (activeDatabase != null) + if (activeDatabase != null) { dataPanel.init(); - else + } else { dataPanel.term(); + } } } + + public void startupConnection(final String host, final int port) throws UnknownHostException, MongoException { + + try { + mediator.setServer(new Mongo(host, port)); + } catch (Exception e) { + + connectItem.setEnabled(true); + disconnectItem.setEnabled(false); + ctrlPanel.term(); + dataPanel.term(); + + if (e instanceof UnknownHostException) { + throw (UnknownHostException) e; + } else if (e instanceof MongoException) { + throw (MongoException) e; + } + } + } + } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2011-06-16 19:41:58 UTC (rev 130) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2011-06-19 07:14:41 UTC (rev 131) @@ -1,8 +1,8 @@ /* * mongobrowser - a webstart gui application for viewing, * editing and administering a Mongo Database - * Copyright 2009-2010 MeBigFatGuy.com - * Copyright 2009-2010 Dave Brosius + * Copyright 2009-2011 MeBigFatGuy.com + * Copyright 2009-2011 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,10 @@ import java.awt.Color; import java.awt.Dimension; +import java.awt.GradientPaint; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Paint; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.List; @@ -51,154 +55,175 @@ public class MongoControlPanel extends JPanel implements MongoPanel { private static final long serialVersionUID = 1439280424726915624L; - private MongoContext context; + private final MongoContext context; private JComboBox dbComboBox; private JButton dbNewCollectionButton; private JButton dbNewObjectButton; private JButton dbNewKeyValueButton; private JButton dbDeleteButton; - + /** * constructs the button bar panel * - * @param ctxt the mediator object for the dialog + * @param ctxt + * the mediator object for the dialog */ public MongoControlPanel(MongoContext ctxt) { context = ctxt; initComponents(); initListeners(); } - + @Override public void init() { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { Mongo db = context.getServer(); List<String> databases = db.getDatabaseNames(); - DefaultComboBoxModel model = (Def... [truncated message content] |