[Mongobrowser-commit] SF.net SVN: mongobrowser:[30] trunk/mongobrowser/src/com/mebigfatguy/ mongobr
Status: Pre-Alpha
Brought to you by:
dbrosius
From: <dbr...@us...> - 2009-12-25 06:04:02
|
Revision: 30 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=30&view=rev Author: dbrosius Date: 2009-12-25 06:03:50 +0000 (Fri, 25 Dec 2009) Log Message: ----------- add new collection button on control panel, and move tree to the context Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.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 Added Paths: ----------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoActions.java Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java 2009-12-25 05:48:34 UTC (rev 29) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java 2009-12-25 06:03:50 UTC (rev 30) @@ -18,11 +18,16 @@ */ package com.mebigfatguy.mongobrowser; +import javax.swing.JTree; + import com.mongodb.DB; import com.mongodb.Mongo; public interface MongoContext { + void setTree(JTree tree); + JTree getTree(); + void setServer(Mongo server); Mongo getServer(); Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoActions.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoActions.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoActions.java 2009-12-25 06:03:50 UTC (rev 30) @@ -0,0 +1,49 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * Copyright 2009 MeBigFatGuy.com + * Copyright 2009 Dave Brosius + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations + * under the License. + */ +package com.mebigfatguy.mongobrowser.dialogs; + +import javax.swing.JOptionPane; +import javax.swing.tree.DefaultTreeModel; + +import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.MongoContext; +import com.mongodb.DB; +import com.mongodb.DBCollection; + +public class MongoActions { + + private MongoContext context; + + public MongoActions(MongoContext ctxt) { + context = ctxt; + } + + public void createNewCollection() { + String collectionName = JOptionPane.showInputDialog(context.getTree(), MongoBundle.getString(MongoBundle.Key.NewCollection)); + if (collectionName != null) { + DB db = context.getDatabase(); + DBCollection dbCollection = db.getCollection(collectionName); + DefaultTreeModel model = (DefaultTreeModel)context.getTree().getModel(); + MongoTreeNode root = (MongoTreeNode)model.getRoot(); + MongoTreeNode collectionNode = new MongoTreeNode(MongoTreeNode.Type.Collection, dbCollection); + root.add(collectionNode); + model.nodeStructureChanged(root); + } + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoActions.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java 2009-12-25 05:48:34 UTC (rev 29) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java 2009-12-25 06:03:50 UTC (rev 30) @@ -27,6 +27,7 @@ import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; +import javax.swing.JTree; import com.mebigfatguy.mongobrowser.MongoBundle; import com.mebigfatguy.mongobrowser.MongoContext; @@ -85,10 +86,22 @@ class Mediator implements MongoContext { + private JTree activeTree; private Mongo activeServer; private DB activeDatabase; + @Override + public JTree getTree() { + return activeTree; + } + + @Override + public void setTree(JTree tree) { + activeTree = tree; + } + + @Override public Mongo getServer() { return activeServer; } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2009-12-25 05:48:34 UTC (rev 29) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2009-12-25 06:03:50 UTC (rev 30) @@ -19,12 +19,15 @@ package com.mebigfatguy.mongobrowser.dialogs; import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.List; import javax.swing.BorderFactory; import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -42,6 +45,7 @@ private static final long serialVersionUID = 1439280424726915624L; private MongoContext context; private JComboBox dbComboBox; + private JButton dbNewCollectionButton; public MongoControlPanel(MongoContext ctxt) { context = ctxt; @@ -65,6 +69,7 @@ } }); dbComboBox.setEnabled(true); + dbNewCollectionButton.setEnabled(true); } }); @@ -77,13 +82,14 @@ DefaultComboBoxModel model = (DefaultComboBoxModel)dbComboBox.getModel(); model.removeAllElements(); dbComboBox.setEnabled(false); + dbNewCollectionButton.setEnabled(false); } }); } private void initComponents() { setBorder(BorderFactory.createLineBorder(Color.BLACK)); - setLayout(new FormLayout("3dlu, pref, 1dlu, 150px, pref", "pref")); + setLayout(new FormLayout("3dlu, pref, 1dlu, 150px, pref, pref", "pref")); CellConstraints cc = new CellConstraints(); JLabel dbLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Database)); @@ -92,6 +98,10 @@ dbLabel.setLabelFor(dbComboBox); add(dbLabel, cc.xy(2, 1)); add(dbComboBox, cc.xy(4, 1)); + + dbNewCollectionButton = new JButton(MongoBundle.getString(MongoBundle.Key.NewCollection)); + add(dbNewCollectionButton, cc.xy(6, 1)); + dbNewCollectionButton.setEnabled(false); } private void initListeners() { @@ -117,6 +127,14 @@ } }); + + dbNewCollectionButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + MongoActions actions = new MongoActions(context); + actions.createNewCollection(); + } + }); } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2009-12-25 05:48:34 UTC (rev 29) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2009-12-25 06:03:50 UTC (rev 30) @@ -26,7 +26,6 @@ import java.util.Set; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; @@ -97,6 +96,7 @@ tree.setRootVisible(false); tree.setShowsRootHandles(true); add(new JScrollPane(tree), BorderLayout.CENTER); + context.setTree(tree); newCollectionItem = new JMenuItem(MongoBundle.getString(MongoBundle.Key.NewCollection)); newObjectItem = new JMenuItem(MongoBundle.getString(MongoBundle.Key.NewObject)); @@ -186,16 +186,8 @@ newCollectionItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { - String collectionName = JOptionPane.showInputDialog(tree, MongoBundle.getString(MongoBundle.Key.NewCollection)); - if (collectionName != null) { - DB db = context.getDatabase(); - DBCollection dbCollection = db.getCollection(collectionName); - DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); - MongoTreeNode root = (MongoTreeNode)model.getRoot(); - MongoTreeNode collectionNode = new MongoTreeNode(MongoTreeNode.Type.Collection, dbCollection); - root.add(collectionNode); - model.nodeStructureChanged(root); - } + MongoActions actions = new MongoActions(context); + actions.createNewCollection(); } }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |