Thread: [Mongobrowser-commit] SF.net SVN: mongobrowser:[7] trunk/mongobrowser/src/com/mebigfatguy/ mongobro
Status: Pre-Alpha
Brought to you by:
dbrosius
From: <dbr...@us...> - 2009-12-24 00:11:26
|
Revision: 7 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=7&view=rev Author: dbrosius Date: 2009-12-24 00:11:18 +0000 (Thu, 24 Dec 2009) Log Message: ----------- Initial Checkin Added Paths: ----------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ConnectAction.java Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ConnectAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ConnectAction.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ConnectAction.java 2009-12-24 00:11:18 UTC (rev 7) @@ -0,0 +1,39 @@ +package com.mebigfatguy.mongobrowser.actions; + +import java.awt.event.ActionEvent; +import java.net.UnknownHostException; + +import javax.swing.AbstractAction; +import javax.swing.JOptionPane; + +import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.MongoContext; +import com.mebigfatguy.mongobrowser.dialogs.ConnectionDialog; +import com.mongodb.Mongo; + +public class ConnectAction extends AbstractAction { + + private MongoContext context; + + public ConnectAction(MongoContext ctxt) { + super(MongoBundle.getString(MongoBundle.Key.Connect)); + context = ctxt; + } + + @Override + public void actionPerformed(ActionEvent e) { + try { + ConnectionDialog cd = new ConnectionDialog(); + cd.setLocationRelativeTo(null); + cd.setModal(true); + cd.setVisible(true); + if (cd.isOK()) { + String host = cd.getHost(); + int port = cd.getPort(); + context.setServer(new Mongo(host, port)); + } + } catch (UnknownHostException uhe) { + JOptionPane.showMessageDialog(null, uhe.getMessage()); + } + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ConnectAction.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-12-24 01:24:06
|
Revision: 10 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=10&view=rev Author: dbrosius Date: 2009-12-24 00:12:57 +0000 (Thu, 24 Dec 2009) Log Message: ----------- Initial Checkin Added Paths: ----------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties 2009-12-24 00:12:57 UTC (rev 10) @@ -0,0 +1,14 @@ +mongo.ok = OK +mongo.cancel = Cancel +mongo.title = Mongo Browser +mongo.servers = Servers +mongo.connect = Connect... +mongo.disconnect = Disconnect +mongo.connecttoserver = Connect to Server +mongo.server = Server +mongo.port = Port +mongo.database = Database +mongo.newdatabase = New Database... +mongo.newcollection = New Collection... +mongo.newobject = New Object... +mongo.newkeyvalue = New Key/Value... \ No newline at end of file Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-12-24 02:03:17
|
Revision: 13 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=13&view=rev Author: dbrosius Date: 2009-12-24 00:26:39 +0000 (Thu, 24 Dec 2009) Log Message: ----------- Initial Checkin Added Paths: ----------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IntegerDocument.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 Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java 2009-12-24 00:26:39 UTC (rev 13) @@ -0,0 +1,115 @@ +package com.mebigfatguy.mongobrowser.dialogs; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import com.jgoodies.forms.layout.CellConstraints; +import com.jgoodies.forms.layout.FormLayout; +import com.mebigfatguy.mongobrowser.MongoBundle; + +public class ConnectionDialog extends JDialog { + + private JTextField serverField; + private JTextField portField; + private JButton okButton; + private JButton cancelButton; + private boolean ok = false; + + public ConnectionDialog() { + setTitle(MongoBundle.getString(MongoBundle.Key.ConnectToServer)); + initComponents(); + initListeners(); + pack(); + } + + private void initComponents() { + Container cp = getContentPane(); + cp.setLayout(new BorderLayout(4, 4)); + cp.add(createFormPanel(), BorderLayout.CENTER); + cp.add(createCtrlPanel(), BorderLayout.SOUTH); + + } + + private JPanel createFormPanel() { + JPanel p = new JPanel(); + p.setLayout(new FormLayout("3dlu, 100px, 5dlu, 200px, 3dlu", "3dlu, pref, 2dlu, pref, 3dlu")); + 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; + } + + private JPanel createCtrlPanel() { + JPanel p = new JPanel(); + 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; + } + + private void initListeners() { + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + ok = true; + dispose(); + } + }); + + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + dispose(); + } + }); + + } + + public boolean isOK() { + return ok; + } + + public String getHost() { + return serverField.getText(); + } + + public int getPort() { + return Integer.parseInt(portField.getText()); + } + + +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IntegerDocument.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IntegerDocument.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IntegerDocument.java 2009-12-24 00:26:39 UTC (rev 13) @@ -0,0 +1,33 @@ +package com.mebigfatguy.mongobrowser.dialogs; + +import java.awt.Toolkit; + +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; + +public class IntegerDocument extends PlainDocument { + + private static final long serialVersionUID = -6755728406523769124L; + + /** + * 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) + */ + @Override + public void insertString(int pos, String insertStr, AttributeSet atts) throws BadLocationException { + StringBuilder text = new StringBuilder(getText(0, getLength())); + try { + text.insert(pos, insertStr); + Integer.parseInt(text.toString()); + super.insertString(pos, insertStr, atts); + } catch (Exception e) { + Toolkit.getDefaultToolkit().beep(); + } + } + +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IntegerDocument.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java 2009-12-24 00:26:39 UTC (rev 13) @@ -0,0 +1,106 @@ +package com.mebigfatguy.mongobrowser.dialogs; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; + +import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.MongoContext; +import com.mebigfatguy.mongobrowser.actions.ConnectAction; +import com.mebigfatguy.mongobrowser.actions.DisconnectAction; +import com.mongodb.DB; +import com.mongodb.Mongo; + +public class MongoBrowserFrame extends JFrame { + + private JMenuItem connectItem; + private JMenuItem disconnectItem; + private MongoControlPanel ctrlPanel; + private MongoDataPanel dataPanel; + private Mediator mediator = new Mediator(); + + private Mongo activeServer; + private DB database; + + public MongoBrowserFrame() { + super(MongoBundle.getString(MongoBundle.Key.Title)); + initComponents(); + initMenus(); + initListeners(); + pack(); + } + + private void initComponents() { + Container cp = getContentPane(); + cp.setLayout(new BorderLayout(4, 4)); + ctrlPanel = new MongoControlPanel(mediator); + cp.add(ctrlPanel, BorderLayout.NORTH); + 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); + databasesMenu.add(disconnectItem); + + setJMenuBar(mb); + } + + private void initListeners() { + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent we) { + dispose(); + System.exit(0); + } + }); + } + + class Mediator implements MongoContext { + + private Mongo activeServer; + private DB activeDatabase; + + @Override + public Mongo getServer() { + return activeServer; + } + + @Override + public void setServer(Mongo server) { + activeServer = server; + connectItem.setEnabled(server == null); + disconnectItem.setEnabled(server != null); + if (server != null) { + ctrlPanel.init(); + dataPanel.init(); + } else { + ctrlPanel.term(); + dataPanel.term(); + } + } + + public DB getDatabase() { + return activeDatabase; + } + + public void setDatabase(DB database) { + activeDatabase = database; + if (activeDatabase != null) + dataPanel.init(); + else + dataPanel.term(); + } + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2009-12-24 00:26:39 UTC (rev 13) @@ -0,0 +1,105 @@ +package com.mebigfatguy.mongobrowser.dialogs; + +import java.awt.Color; +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.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import com.jgoodies.forms.layout.CellConstraints; +import com.jgoodies.forms.layout.FormLayout; +import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.MongoContext; +import com.mongodb.Mongo; + +public class MongoControlPanel extends JPanel implements MongoPanel { + + private MongoContext context; + private JLabel dbLabel; + private JComboBox dbComboBox; + + public MongoControlPanel(MongoContext ctxt) { + context = ctxt; + initComponents(); + initListeners(); + } + + @Override + public void init() { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + Mongo db = context.getServer(); + List<String> databases = db.getDatabaseNames(); + DefaultComboBoxModel model = (DefaultComboBoxModel)dbComboBox.getModel(); + for (String database : databases) { + model.addElement(database); + } + model.addElement(new Object() { + public String toString() { + return "New Database..."; + } + }); + dbComboBox.setEnabled(true); + } + }); + + } + + @Override + public void term() { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + Mongo db = context.getServer(); + DefaultComboBoxModel model = (DefaultComboBoxModel)dbComboBox.getModel(); + model.removeAllElements(); + dbComboBox.setEnabled(false); + } + }); + } + + private void initComponents() { + setBorder(BorderFactory.createLineBorder(Color.BLACK)); + setLayout(new FormLayout("3dlu, pref, 1dlu, 150px, pref", "pref")); + CellConstraints cc = new CellConstraints(); + + JLabel dbLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Database)); + dbComboBox = new JComboBox(new DefaultComboBoxModel()); + dbComboBox.setEnabled(false); + dbLabel.setLabelFor(dbComboBox); + add(dbLabel, cc.xy(2, 1)); + add(dbComboBox, cc.xy(4, 1)); + } + + private void initListeners() { + dbComboBox.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent ie) { + if (ie.getStateChange() == ItemEvent.SELECTED) { + Object sel = dbComboBox.getSelectedItem(); + if (sel instanceof String) { + context.setDatabase(context.getServer().getDB((String)sel)); + } else { + String dbName = JOptionPane.showInputDialog(MongoBundle.getString(MongoBundle.Key.NewDatabase)); + if (dbName != null) { + context.setDatabase(context.getServer().getDB(dbName)); + DefaultComboBoxModel model = (DefaultComboBoxModel) dbComboBox.getModel(); + model.insertElementAt(dbName, model.getSize() - 1); + } + } + } else { + context.setDatabase(null); + } + } + + }); + } + +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2009-12-24 00:26:39 UTC (rev 13) @@ -0,0 +1,148 @@ +package com.mebigfatguy.mongobrowser.dialogs; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Set; + +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; + +import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.MongoContext; +import com.mongodb.BasicDBObject; +import com.mongodb.DB; +import com.mongodb.DBCollection; + +public class MongoDataPanel extends JPanel implements MongoPanel { + + private MongoContext context; + private JTree tree; + private JMenuItem newCollectionItem; + private JMenuItem newObjectItem; + private JMenuItem newKeyValueItem; + + public MongoDataPanel(MongoContext ctxt) { + context = ctxt; + initComponents(); + initListeners(); + } + + @Override + public void init() { + DB db = context.getDatabase(); + DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); + MongoTreeNode root = (MongoTreeNode)model.getRoot(); + + if (db != null) { + Set<String> collections = db.getCollectionNames(); + for (String collection : collections) { + MongoTreeNode col = new MongoTreeNode(MongoTreeNode.Type.Collection, collection); + root.add(col); + } + } else { + root.removeAllChildren(); + } + model.nodeStructureChanged(root); + } + + @Override + public void term() { + } + + private void initComponents() { + setLayout(new BorderLayout(4, 4)); + + MongoTreeNode root = new MongoTreeNode(MongoTreeNode.Type.Root, "root"); + tree = new JTree(root); + tree.setRootVisible(false); + DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); + add(new JScrollPane(tree), BorderLayout.CENTER); + + newCollectionItem = new JMenuItem(MongoBundle.getString(MongoBundle.Key.NewCollection)); + newObjectItem = new JMenuItem(MongoBundle.getString(MongoBundle.Key.NewObject)); + newKeyValueItem = new JMenuItem(MongoBundle.getString(MongoBundle.Key.NewKeyValue)); + } + + private void initListeners() { + final JPopupMenu menu = new JPopupMenu(); + + tree.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + showPopup(e); + } + + @Override + public void mousePressed(MouseEvent e) { + showPopup(e); } + + @Override + public void mouseReleased(MouseEvent e) { + showPopup(e); } + + private void showPopup(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + if (e.isPopupTrigger()) { + menu.removeAll(); + TreePath path = tree.getPathForLocation(x, y); + if (path == null) { + menu.add(newCollectionItem); + menu.show(tree, x, y); + } else { + MongoTreeNode node = (MongoTreeNode)path.getLastPathComponent(); + if (node.getType() == MongoTreeNode.Type.Collection) { + menu.add(newObjectItem); + menu.show(tree, x, y); + } + } + } + } + }); + + 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, collectionName); + collectionNode.setUserObject(dbCollection); + root.add(collectionNode); + model.nodeStructureChanged(root); + } + } + }); + + newObjectItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + String objectName = JOptionPane.showInputDialog(tree, MongoBundle.getString(MongoBundle.Key.NewCollection)); + if (objectName != null) { + 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(MongoTreeNode.Type.Object, objectName); + objectNode.setUserObject(dbObj); + collectionNode.add(objectNode); + model.nodeStructureChanged((MongoTreeNode)model.getRoot()); + } + } + }); + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoPanel.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoPanel.java 2009-12-24 00:26:39 UTC (rev 13) @@ -0,0 +1,6 @@ +package com.mebigfatguy.mongobrowser.dialogs; + +public interface MongoPanel { + void init(); + void term(); +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoPanel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2009-12-24 00:26:39 UTC (rev 13) @@ -0,0 +1,22 @@ +package com.mebigfatguy.mongobrowser.dialogs; + +import javax.swing.tree.DefaultMutableTreeNode; + +public class MongoTreeNode extends DefaultMutableTreeNode { + enum Type {Root, Collection, Object, KeyValue}; + + Type nodeType; + + public MongoTreeNode(Type type, String name) { + super(name); + nodeType = type; + } + + public boolean isLeaf() { + return nodeType == Type.KeyValue; + } + + public Type getType() { + return nodeType; + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-12-25 05:14:51
|
Revision: 26 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=26&view=rev Author: dbrosius Date: 2009-12-25 05:14:31 +0000 (Fri, 25 Dec 2009) Log Message: ----------- add slugs and tree expansion listeners for collections Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2009-12-24 03:51:00 UTC (rev 25) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2009-12-25 05:14:31 UTC (rev 26) @@ -42,7 +42,8 @@ NewDatabase("mongo.newdatabase"), NewCollection("mongo.newcollection"), NewObject("mongo.newobject"), - NewKeyValue("mongo.newkeyvalue"); + NewKeyValue("mongo.newkeyvalue"), + Object("mongo.object"); String id; Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2009-12-24 03:51:00 UTC (rev 25) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2009-12-25 05:14:31 UTC (rev 26) @@ -31,7 +31,10 @@ import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTree; +import javax.swing.event.TreeExpansionEvent; +import javax.swing.event.TreeWillExpandListener; import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.ExpandVetoException; import javax.swing.tree.TreePath; import com.mebigfatguy.mongobrowser.MongoBundle; @@ -39,6 +42,8 @@ import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; +import com.mongodb.DBCursor; +import com.mongodb.DBObject; public class MongoDataPanel extends JPanel implements MongoPanel { @@ -62,10 +67,14 @@ MongoTreeNode root = (MongoTreeNode)model.getRoot(); if (db != null) { - Set<String> collections = db.getCollectionNames(); - for (String collection : collections) { - MongoTreeNode col = new MongoTreeNode(MongoTreeNode.Type.Collection, collection); + Set<String> collectionNames = db.getCollectionNames(); + for (String collectionName : collectionNames) { + MongoTreeNode col = new MongoTreeNode(MongoTreeNode.Type.Collection, collectionName); + DBCollection collection = db.getCollection(collectionName); + col.setUserObject(collection); root.add(col); + MongoTreeNode slug = new MongoTreeNode(MongoTreeNode.Type.ExpansionSlug, ""); + col.add(slug); } } else { root.removeAllChildren(); @@ -87,6 +96,7 @@ MongoTreeNode root = new MongoTreeNode(MongoTreeNode.Type.Root, "root"); tree = new JTree(root); tree.setRootVisible(false); + tree.setShowsRootHandles(true); add(new JScrollPane(tree), BorderLayout.CENTER); newCollectionItem = new JMenuItem(MongoBundle.getString(MongoBundle.Key.NewCollection)); @@ -131,6 +141,41 @@ } }); + tree.addTreeWillExpandListener(new TreeWillExpandListener() { + @Override + public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { + MongoTreeNode node = (MongoTreeNode)event.getPath().getLastPathComponent(); + MongoTreeNode slug = (MongoTreeNode)node.getFirstChild(); + if (slug.getType() == MongoTreeNode.Type.ExpansionSlug) { + node.removeAllChildren(); + String objectName = MongoBundle.getString(MongoBundle.Key.Object); + switch (node.getType()) { + case Collection: { + DBCollection collection = (DBCollection)node.getUserObject(); + DBCursor cursor = collection.find(); + while (cursor.hasNext()) { + DBObject obj = cursor.next(); + MongoTreeNode objNode = new MongoTreeNode(MongoTreeNode.Type.Object, objectName); + objNode.setUserObject(obj); + node.add(objNode); + slug = new MongoTreeNode(MongoTreeNode.Type.ExpansionSlug, ""); + objNode.add(slug); + } + } + break; + } + } + + DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); + model.nodeStructureChanged(node); + } + + @Override + public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { + } + + }); + newCollectionItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2009-12-24 03:51:00 UTC (rev 25) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2009-12-25 05:14:31 UTC (rev 26) @@ -23,7 +23,7 @@ public class MongoTreeNode extends DefaultMutableTreeNode { private static final long serialVersionUID = -1710144820086785938L; - enum Type {Root, Collection, Object, KeyValue}; + enum Type {Root, Collection, Object, KeyValue, ExpansionSlug}; Type nodeType; @@ -31,10 +31,6 @@ super(name); nodeType = type; } - - public boolean isLeaf() { - return nodeType == Type.KeyValue; - } public Type getType() { return nodeType; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <dbr...@us...> - 2009-12-27 04:28:57
|
Revision: 35 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=35&view=rev Author: dbrosius Date: 2009-12-27 04:28:49 +0000 (Sun, 27 Dec 2009) Log Message: ----------- make the Object name the toString value Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2009-12-27 04:23:27 UTC (rev 34) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2009-12-27 04:28:49 UTC (rev 35) @@ -42,8 +42,7 @@ NewDatabase("mongo.newdatabase"), NewCollection("mongo.newcollection"), NewObject("mongo.newobject"), - NewKeyValue("mongo.newkeyvalue"), - Object("mongo.object"); + NewKeyValue("mongo.newkeyvalue"); String id; Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2009-12-27 04:23:27 UTC (rev 34) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2009-12-27 04:28:49 UTC (rev 35) @@ -148,7 +148,6 @@ node.removeAllChildren(); switch (node.getType()) { case Collection: { - String objectName = MongoBundle.getString(MongoBundle.Key.Object); DBCollection collection = (DBCollection)node.getUserObject(); DBCursor cursor = collection.find(); while (cursor.hasNext()) { Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2009-12-27 04:23:27 UTC (rev 34) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2009-12-27 04:28:49 UTC (rev 35) @@ -20,8 +20,8 @@ import javax.swing.tree.DefaultMutableTreeNode; -import com.mebigfatguy.mongobrowser.MongoBundle; import com.mongodb.DBCollection; +import com.mongodb.DBObject; public class MongoTreeNode extends DefaultMutableTreeNode { private static final long serialVersionUID = -1710144820086785938L; @@ -45,8 +45,9 @@ case Collection: return ((DBCollection)getUserObject()).getName(); - case Object: - return MongoBundle.getString(MongoBundle.Key.Object); + case Object: { + return ((DBObject)getUserObject()).toString(); + } case KeyValue: return (String)getUserObject(); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties 2009-12-27 04:23:27 UTC (rev 34) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties 2009-12-27 04:28:49 UTC (rev 35) @@ -30,5 +30,4 @@ mongo.newdatabase = New Database... mongo.newcollection = New Collection... mongo.newobject = New Object... -mongo.newkeyvalue = New Key/Value... -mongo.object = Object \ No newline at end of file +mongo.newkeyvalue = New Key/Value... \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-12-27 05:07:41
|
Revision: 38 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=38&view=rev Author: dbrosius Date: 2009-12-27 05:07:35 +0000 (Sun, 27 Dec 2009) Log Message: ----------- add keyvalue menu/button, and fix enabling of buttons Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoActions.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 Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java 2009-12-27 04:40:15 UTC (rev 37) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoContext.java 2009-12-27 05:07:35 UTC (rev 38) @@ -20,6 +20,7 @@ import javax.swing.JTree; +import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode; import com.mongodb.DB; import com.mongodb.Mongo; @@ -28,6 +29,9 @@ void setTree(JTree tree); JTree getTree(); + void setSelectedNode(MongoTreeNode node); + MongoTreeNode getSelectedNode(); + void setServer(Mongo server); Mongo getServer(); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoActions.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoActions.java 2009-12-27 04:40:15 UTC (rev 37) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoActions.java 2009-12-27 05:07:35 UTC (rev 38) @@ -67,4 +67,7 @@ objectNode.add(slug); model.nodeStructureChanged((MongoTreeNode)model.getRoot()); } + + public void createNewKeyValue() { + } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java 2009-12-27 04:40:15 UTC (rev 37) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoBrowserFrame.java 2009-12-27 05:07:35 UTC (rev 38) @@ -87,6 +87,7 @@ class Mediator implements MongoContext { private JTree activeTree; + private MongoTreeNode activeNode; private Mongo activeServer; private DB activeDatabase; @@ -100,6 +101,17 @@ public void setTree(JTree tree) { activeTree = tree; } + + @Override + public MongoTreeNode getSelectedNode() { + return activeNode; + } + + @Override + public void setSelectedNode(MongoTreeNode node) { + activeNode = node; + ctrlPanel.adjustEnabled(node); + } @Override public Mongo getServer() { Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2009-12-27 04:40:15 UTC (rev 37) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2009-12-27 05:07:35 UTC (rev 38) @@ -49,6 +49,7 @@ private JComboBox dbComboBox; private JButton dbNewCollectionButton; private JButton dbNewObjectButton; + private JButton dbNewKeyValueButton; public MongoControlPanel(MongoContext ctxt) { context = ctxt; @@ -72,8 +73,7 @@ } }); dbComboBox.setEnabled(true); - dbNewCollectionButton.setEnabled(true); - dbNewObjectButton.setEnabled(true); + context.setSelectedNode(null); } }); @@ -86,15 +86,43 @@ DefaultComboBoxModel model = (DefaultComboBoxModel)dbComboBox.getModel(); model.removeAllElements(); dbComboBox.setEnabled(false); - dbNewCollectionButton.setEnabled(false); - dbNewObjectButton.setEnabled(false); + context.setSelectedNode(null); } }); } + + public void adjustEnabled(MongoTreeNode selectedNode) { + if (selectedNode == null) { + dbNewCollectionButton.setEnabled(true); + dbNewObjectButton.setEnabled(false); + dbNewKeyValueButton.setEnabled(false); + } else { + switch (selectedNode.getType()) { + case Collection: + dbNewCollectionButton.setEnabled(true); + dbNewObjectButton.setEnabled(true); + dbNewKeyValueButton.setEnabled(false); + break; + + case Object: + dbNewCollectionButton.setEnabled(true); + dbNewObjectButton.setEnabled(false); + dbNewKeyValueButton.setEnabled(true); + break; + + case KeyValue: + dbNewCollectionButton.setEnabled(true); + dbNewObjectButton.setEnabled(false); + dbNewKeyValueButton.setEnabled(false); + break; + } + } + } + private void initComponents() { setBorder(BorderFactory.createLineBorder(Color.BLACK)); - setLayout(new FormLayout("3dlu, pref, 1dlu, 150px, 3dlu, pref, 3dlu, pref", "pref")); + setLayout(new FormLayout("3dlu, pref, 1dlu, 150px, 3dlu, pref, 3dlu, pref, 3dlu, pref", "pref")); CellConstraints cc = new CellConstraints(); JLabel dbLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Database)); @@ -117,6 +145,13 @@ dbNewObjectButton.setToolTipText(MongoBundle.getString(MongoBundle.Key.NewObject)); add(dbNewObjectButton, cc.xy(8, 1)); dbNewObjectButton.setEnabled(false); + + icon = new ImageIcon(MongoControlPanel.class.getResource("/com/mebigfatguy/mongobrowser/resources/newkeyvalue.png")); + dbNewKeyValueButton = new JButton(icon); + dbNewKeyValueButton.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); + dbNewKeyValueButton.setToolTipText(MongoBundle.getString(MongoBundle.Key.NewKeyValue)); + add(dbNewKeyValueButton, cc.xy(10, 1)); + dbNewKeyValueButton.setEnabled(false); } private void initListeners() { Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2009-12-27 04:40:15 UTC (rev 37) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2009-12-27 05:07:35 UTC (rev 38) @@ -31,6 +31,8 @@ import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.event.TreeExpansionEvent; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; import javax.swing.event.TreeWillExpandListener; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.ExpandVetoException; @@ -77,6 +79,7 @@ root.removeAllChildren(); } model.nodeStructureChanged(root); + context.setSelectedNode(null); } @Override @@ -85,6 +88,7 @@ MongoTreeNode root = (MongoTreeNode)model.getRoot(); root.removeAllChildren(); model.nodeStructureChanged(root); + context.setSelectedNode(null); } private void initComponents() { @@ -130,9 +134,13 @@ menu.show(tree, x, y); } else { MongoTreeNode node = (MongoTreeNode)path.getLastPathComponent(); + context.setSelectedNode(node); if (node.getType() == MongoTreeNode.Type.Collection) { menu.add(newObjectItem); menu.show(tree, x, y); + } else if (node.getType() == MongoTreeNode.Type.Object){ + menu.add(newKeyValueItem); + menu.show(tree, x, y); } } } @@ -187,6 +195,19 @@ }); + tree.addTreeSelectionListener(new TreeSelectionListener() { + @Override + public void valueChanged(TreeSelectionEvent tse) { + TreePath path = tse.getNewLeadSelectionPath(); + if (path != null) { + MongoTreeNode node = (MongoTreeNode)path.getLastPathComponent(); + context.setSelectedNode(node); + } else { + context.setSelectedNode(null); + } + } + }); + newCollectionItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { @@ -202,5 +223,13 @@ actions.createNewObject(); } }); + + newKeyValueItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + MongoActions actions = new MongoActions(context); + actions.createNewKeyValue(); + } + }); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-01 02:48:16
|
Revision: 71 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=71&view=rev Author: dbrosius Date: 2010-01-01 02:48:10 +0000 (Fri, 01 Jan 2010) Log Message: ----------- add ability to add key/values Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2010-01-01 02:33:21 UTC (rev 70) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2010-01-01 02:48:10 UTC (rev 71) @@ -22,10 +22,14 @@ import javax.swing.AbstractAction; import javax.swing.JTree; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; import com.mebigfatguy.mongobrowser.MongoBundle; import com.mebigfatguy.mongobrowser.MongoContext; import com.mebigfatguy.mongobrowser.dialogs.KeyValueDialog; +import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode; +import com.mongodb.DBObject; public class NewKeyValueAction extends AbstractAction { @@ -45,7 +49,19 @@ dialog.setModal(true); dialog.setVisible(true); if (dialog.isOK()) { - + String key = dialog.getKey(); + Object value = dialog.getValue(); + TreePath path = tree.getSelectionPath(); + MongoTreeNode objectNode = (MongoTreeNode)path.getLastPathComponent(); + DBObject object = (DBObject) objectNode.getUserObject(); + object.put(key, value); + MongoTreeNode kv = new MongoTreeNode(MongoTreeNode.Type.KeyValue, key + " : " + object.get(key)); + objectNode.add(kv); + 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/dialogs/KeyValueDialog.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2010-01-01 02:33:21 UTC (rev 70) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2010-01-01 02:48:10 UTC (rev 71) @@ -4,6 +4,8 @@ import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import javax.swing.BorderFactory; import javax.swing.Box; @@ -15,16 +17,19 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mongodb.BasicDBObject; public class KeyValueDialog extends JDialog { private static final long serialVersionUID = 4909101478144542212L; - private JTextField keyName; + private JTextField keyField; private JComboBox valueTypeBox; private JTextField valueField; private JButton okButton; @@ -53,10 +58,10 @@ JLabel keyLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Key)); p.add(keyLabel, cc.xy(2, 2)); - keyName = new JTextField(); - p.add(keyName, cc.xy(4, 2)); + keyField = new JTextField(); + p.add(keyField, cc.xy(4, 2)); - keyLabel.setLabelFor(keyName); + keyLabel.setLabelFor(keyField); JLabel valueLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Value)); p.add(valueLabel, cc.xy(2, 4)); @@ -70,6 +75,7 @@ model.addElement(new DoubleValueType()); model.addElement(new StringValueType()); model.addElement(new ObjectValueType()); + valueTypeBox.setSelectedIndex(2); p.add(valueTypeBox, cc.xy(6, 4)); valueLabel.setLabelFor(valueField); @@ -107,19 +113,56 @@ dispose(); } }); + + valueTypeBox.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent ie) { + if (ie.getStateChange() == ItemEvent.SELECTED) { + ValueType vt = (ValueType)ie.getItem(); + vt.installDocument(valueField); + } + } + }); } public boolean isOK() { return ok; } + public String getKey() { + return keyField.getText(); + } + + public Object getValue() { + return ((ValueType)valueTypeBox.getSelectedItem()).getValue(valueField); + } + interface ValueType { - + void installDocument(JTextField field); + Object getValue(JTextField field); } class IntegerValueType implements ValueType { @Override + public void installDocument(JTextField field) { + try { + String val = field.getText(); + field.setText(""); + field.setDocument(new IntegerDocument()); + field.getDocument().insertString(0, val, null); + field.setEnabled(true); + } catch (BadLocationException ble) { + } + } + + @Override + public Object getValue(JTextField field) { + return Integer.valueOf(field.getText()); + } + + @Override public String toString() { return MongoBundle.getString(MongoBundle.Key.Integer); } @@ -128,6 +171,22 @@ class DoubleValueType implements ValueType { @Override + public void installDocument(JTextField field) { + try { + String val = field.getText(); + field.setText(""); + field.setDocument(new IntegerDocument()); + field.getDocument().insertString(0, val, null); + field.setEnabled(true); + } catch (BadLocationException ble) { + } + } + + @Override + public Object getValue(JTextField field) { + return Double.valueOf(field.getText()); + } + @Override public String toString() { return MongoBundle.getString(MongoBundle.Key.Double); } @@ -136,6 +195,23 @@ class StringValueType implements ValueType { @Override + public void installDocument(JTextField field) { + try { + String val = field.getText(); + field.setText(""); + field.setDocument(new PlainDocument()); + field.getDocument().insertString(0, val, null); + field.setEnabled(true); + } catch (BadLocationException ble) { + } + } + + @Override + public Object getValue(JTextField field) { + return field.getText(); + } + + @Override public String toString() { return MongoBundle.getString(MongoBundle.Key.String); } @@ -144,6 +220,18 @@ class ObjectValueType implements ValueType { @Override + public void installDocument(JTextField field) { + field.setText(""); + field.setDocument(new PlainDocument()); + field.setEnabled(false); + } + + @Override + public Object getValue(JTextField field) { + return new BasicDBObject(); + } + + @Override public String toString() { return MongoBundle.getString(MongoBundle.Key.Object); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-03 00:50:11
|
Revision: 90 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=90&view=rev Author: dbrosius Date: 2010-01-03 00:50:02 +0000 (Sun, 03 Jan 2010) Log Message: ----------- rework mongotreenode to have multiple ctors that pick types from parm types. add Delete menu items Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DeleteAction.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/MongoDataPanel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DeleteAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DeleteAction.java 2010-01-03 00:28:05 UTC (rev 89) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/DeleteAction.java 2010-01-03 00:50:02 UTC (rev 90) @@ -66,15 +66,19 @@ break; case KeyValue: { - String key = (String)node.getUserObject(); - 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); - DefaultTreeModel model = (DefaultTreeModel)context.getTree().getModel(); - model.nodeStructureChanged(objectNode); + 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; } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java 2010-01-03 00:28:05 UTC (rev 89) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java 2010-01-03 00:50:02 UTC (rev 90) @@ -52,9 +52,9 @@ DBCollection dbCollection = db.getCollection(collectionName); DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); MongoTreeNode root = (MongoTreeNode)model.getRoot(); - MongoTreeNode collectionNode = new MongoTreeNode(MongoTreeNode.Type.Collection, dbCollection); + MongoTreeNode collectionNode = new MongoTreeNode(dbCollection); root.add(collectionNode); - MongoTreeNode slug = new MongoTreeNode(MongoTreeNode.Type.ExpansionSlug, null); + MongoTreeNode slug = new MongoTreeNode(); collectionNode.add(slug); model.nodeStructureChanged(root); TreePath selection = new TreePath(collectionNode.getPath()); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2010-01-03 00:28:05 UTC (rev 89) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2010-01-03 00:50:02 UTC (rev 90) @@ -57,7 +57,7 @@ MongoTreeNode objectNode = (MongoTreeNode)path.getLastPathComponent(); DBObject object = (DBObject) objectNode.getUserObject(); object.put(key, value); - MongoTreeNode kv = new MongoTreeNode(MongoTreeNode.Type.KeyValue, key + " : " + object.get(key)); + MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key))); objectNode.add(kv); MongoTreeNode collectionNode = TreeUtils.findCollectionNode(objectNode); DBCollection collection = (DBCollection)collectionNode.getUserObject(); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java 2010-01-03 00:28:05 UTC (rev 89) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java 2010-01-03 00:50:02 UTC (rev 90) @@ -50,9 +50,9 @@ BasicDBObject dbObj = new BasicDBObject(); dbCollection.insert(dbObj); DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); - MongoTreeNode objectNode = new MongoTreeNode(MongoTreeNode.Type.Object, dbObj); + MongoTreeNode objectNode = new MongoTreeNode(dbObj); collectionNode.add(objectNode); - MongoTreeNode slug = new MongoTreeNode(MongoTreeNode.Type.ExpansionSlug, null); + MongoTreeNode slug = new MongoTreeNode(); objectNode.add(slug); model.nodeStructureChanged((MongoTreeNode)model.getRoot()); TreePath selection = new TreePath(objectNode.getPath()); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2010-01-03 00:28:05 UTC (rev 89) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2010-01-03 00:50:02 UTC (rev 90) @@ -37,6 +37,7 @@ import javax.swing.tree.TreePath; import com.mebigfatguy.mongobrowser.MongoContext; +import com.mebigfatguy.mongobrowser.actions.DeleteAction; import com.mebigfatguy.mongobrowser.actions.NewCollectionAction; import com.mebigfatguy.mongobrowser.actions.NewKeyValueAction; import com.mebigfatguy.mongobrowser.actions.NewObjectAction; @@ -53,6 +54,7 @@ private JMenuItem newCollectionItem; private JMenuItem newObjectItem; private JMenuItem newKeyValueItem; + private JMenuItem deleteItem; public MongoDataPanel(MongoContext ctxt) { context = ctxt; @@ -70,9 +72,9 @@ Set<String> collectionNames = db.getCollectionNames(); for (String collectionName : collectionNames) { DBCollection collection = db.getCollection(collectionName); - MongoTreeNode col = new MongoTreeNode(MongoTreeNode.Type.Collection, collection); + MongoTreeNode col = new MongoTreeNode(collection); root.add(col); - MongoTreeNode slug = new MongoTreeNode(MongoTreeNode.Type.ExpansionSlug, null); + MongoTreeNode slug = new MongoTreeNode(); col.add(slug); } } else { @@ -94,7 +96,7 @@ private void initComponents() { setLayout(new BorderLayout(4, 4)); - MongoTreeNode root = new MongoTreeNode(MongoTreeNode.Type.Root, null); + MongoTreeNode root = new MongoTreeNode(new MongoTreeNode.Root()); tree = new JTree(root); tree.setRootVisible(false); tree.setShowsRootHandles(true); @@ -104,6 +106,7 @@ newCollectionItem = new JMenuItem(new NewCollectionAction(context)); newObjectItem = new JMenuItem(new NewObjectAction(context)); newKeyValueItem = new JMenuItem(new NewKeyValueAction(context)); + deleteItem = new JMenuItem(new DeleteAction(context)); } private void initListeners() { @@ -137,10 +140,17 @@ context.setSelectedNode(node); if (node.getType() == MongoTreeNode.Type.Collection) { menu.add(newObjectItem); + menu.addSeparator(); + menu.add(deleteItem); menu.show(tree, x, y); } else if (node.getType() == MongoTreeNode.Type.Object){ menu.add(newKeyValueItem); + menu.addSeparator(); + menu.add(deleteItem); menu.show(tree, x, y); + } else if (node.getType() == MongoTreeNode.Type.KeyValue) { + menu.add(deleteItem); + menu.show(tree, x, y); } } } @@ -160,9 +170,9 @@ DBCursor cursor = collection.find(); while (cursor.hasNext()) { DBObject obj = cursor.next(); - MongoTreeNode objNode = new MongoTreeNode(MongoTreeNode.Type.Object, obj); + MongoTreeNode objNode = new MongoTreeNode(obj); node.add(objNode); - slug = new MongoTreeNode(MongoTreeNode.Type.ExpansionSlug, ""); + slug = new MongoTreeNode(); objNode.add(slug); } } @@ -171,7 +181,7 @@ case Object: { DBObject object = (DBObject)node.getUserObject(); for (String key : object.keySet()) { - MongoTreeNode kv = new MongoTreeNode(MongoTreeNode.Type.KeyValue, key + " : " + object.get(key)); + MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key))); node.add(kv); } } @@ -187,7 +197,7 @@ public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { MongoTreeNode node = (MongoTreeNode)event.getPath().getLastPathComponent(); node.removeAllChildren(); - MongoTreeNode slug = new MongoTreeNode(MongoTreeNode.Type.ExpansionSlug, null); + MongoTreeNode slug = new MongoTreeNode(); node.add(slug); DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); model.nodeStructureChanged(node); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2010-01-03 00:28:05 UTC (rev 89) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2010-01-03 00:50:02 UTC (rev 90) @@ -28,11 +28,52 @@ public enum Type {Root, Collection, Object, KeyValue, ExpansionSlug}; + public static class Root {} + + public static class KV { + private String key; + private Object value; + + public KV(String k, Object v) { + key = k; + value = v; + } + + public String getKey() { + return key; + } + + @Override + public String toString() { + return key + " : " + value; + } + } + Type nodeType; - public MongoTreeNode(Type type, Object dbObject) { + public MongoTreeNode() { + super(null); + nodeType = Type.ExpansionSlug; + } + + public MongoTreeNode(Root root) { + super(null); + nodeType = Type.Root; + } + + public MongoTreeNode(DBCollection dbCollection) { + super(dbCollection); + nodeType = Type.Collection; + } + + public MongoTreeNode(DBObject dbObject) { super(dbObject); - nodeType = type; + nodeType = Type.Object; + } + + public MongoTreeNode(KV dbKV) { + super(dbKV); + nodeType = Type.KeyValue; } public Type getType() { @@ -43,14 +84,9 @@ public String toString() { switch (nodeType) { case Collection: - return ((DBCollection)getUserObject()).getName(); - - case Object: { - return ((DBObject)getUserObject()).toString(); - } - + case Object: case KeyValue: - return (String)getUserObject(); + return getUserObject().toString(); case Root: case ExpansionSlug: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-03 01:32:54
|
Revision: 94 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=94&view=rev Author: dbrosius Date: 2010-01-03 01:32:47 +0000 (Sun, 03 Jan 2010) Log Message: ----------- treat system nodes as readonly, and only enable action items for non readonly nodes Modified Paths: -------------- 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/MongoControlPanel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java 2010-01-03 01:07:45 UTC (rev 93) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewCollectionAction.java 2010-01-03 01:32:47 UTC (rev 94) @@ -52,7 +52,7 @@ DBCollection dbCollection = db.getCollection(collectionName); DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); MongoTreeNode root = (MongoTreeNode)model.getRoot(); - MongoTreeNode collectionNode = new MongoTreeNode(dbCollection); + MongoTreeNode collectionNode = new MongoTreeNode(dbCollection, false); root.add(collectionNode); MongoTreeNode slug = new MongoTreeNode(); collectionNode.add(slug); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2010-01-03 01:07:45 UTC (rev 93) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2010-01-03 01:32:47 UTC (rev 94) @@ -57,7 +57,7 @@ MongoTreeNode objectNode = (MongoTreeNode)path.getLastPathComponent(); DBObject object = (DBObject) objectNode.getUserObject(); object.put(key, value); - MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key))); + MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key)), false); objectNode.add(kv); MongoTreeNode collectionNode = TreeUtils.findCollectionNode(objectNode); DBCollection collection = (DBCollection)collectionNode.getUserObject(); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java 2010-01-03 01:07:45 UTC (rev 93) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewObjectAction.java 2010-01-03 01:32:47 UTC (rev 94) @@ -50,7 +50,7 @@ BasicDBObject dbObj = new BasicDBObject(); dbCollection.insert(dbObj); DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); - MongoTreeNode objectNode = new MongoTreeNode(dbObj); + MongoTreeNode objectNode = new MongoTreeNode(dbObj, false); collectionNode.add(objectNode); MongoTreeNode slug = new MongoTreeNode(); objectNode.add(slug); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2010-01-03 01:07:45 UTC (rev 93) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2010-01-03 01:32:47 UTC (rev 94) @@ -42,7 +42,6 @@ import com.mebigfatguy.mongobrowser.actions.NewCollectionAction; import com.mebigfatguy.mongobrowser.actions.NewKeyValueAction; import com.mebigfatguy.mongobrowser.actions.NewObjectAction; -import com.mongodb.DBCollection; import com.mongodb.Mongo; public class MongoControlPanel extends JPanel implements MongoPanel { @@ -106,29 +105,39 @@ switch (selectedNode.getType()) { case Collection: dbNewCollectionButton.setEnabled(true); - dbNewObjectButton.setEnabled(true); dbNewKeyValueButton.setEnabled(false); - DBCollection collection = (DBCollection)selectedNode.getUserObject(); - String collectionName = collection.getName(); - if (!(collectionName.startsWith("system.") || collectionName.startsWith("local."))) { + if (selectedNode.isReadOnly()) { + dbNewObjectButton.setEnabled(false); + dbDeleteButton.setEnabled(false); + } else { + dbNewObjectButton.setEnabled(true); dbDeleteButton.setEnabled(true); } + break; case Object: dbNewCollectionButton.setEnabled(true); dbNewObjectButton.setEnabled(false); - dbNewKeyValueButton.setEnabled(true); - dbDeleteButton.setEnabled(true); + if (selectedNode.isReadOnly()) { + dbNewKeyValueButton.setEnabled(false); + dbDeleteButton.setEnabled(false); + } else { + dbNewKeyValueButton.setEnabled(true); + dbDeleteButton.setEnabled(true); + } break; case KeyValue: dbNewCollectionButton.setEnabled(true); dbNewObjectButton.setEnabled(false); dbNewKeyValueButton.setEnabled(false); - MongoTreeNode.KV kv = (MongoTreeNode.KV)selectedNode.getUserObject(); - if (!kv.getKey().startsWith("_")) { - dbDeleteButton.setEnabled(true); + + if (selectedNode.isReadOnly()) { + dbDeleteButton.setEnabled(false); + } else { + MongoTreeNode.KV kv = (MongoTreeNode.KV)selectedNode.getUserObject(); + dbDeleteButton.setEnabled(!kv.getKey().startsWith("_")); } break; } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2010-01-03 01:07:45 UTC (rev 93) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2010-01-03 01:32:47 UTC (rev 94) @@ -72,7 +72,8 @@ Set<String> collectionNames = db.getCollectionNames(); for (String collectionName : collectionNames) { DBCollection collection = db.getCollection(collectionName); - MongoTreeNode col = new MongoTreeNode(collection); + boolean readOnly = collectionName.startsWith("system."); + MongoTreeNode col = new MongoTreeNode(collection, readOnly); root.add(col); MongoTreeNode slug = new MongoTreeNode(); col.add(slug); @@ -139,24 +140,24 @@ MongoTreeNode node = (MongoTreeNode)path.getLastPathComponent(); context.setSelectedNode(node); if (node.getType() == MongoTreeNode.Type.Collection) { - menu.add(newObjectItem); - DBCollection collection = (DBCollection)node.getUserObject(); - String collectionName = collection.getName(); - if (!(collectionName.startsWith("system.") || collectionName.startsWith("local."))) { + if (!node.isReadOnly()) { + menu.add(newObjectItem); + menu.show(tree, x, y); + } + } else if (node.getType() == MongoTreeNode.Type.Object) { + if (!node.isReadOnly()) { + menu.add(newKeyValueItem); menu.addSeparator(); menu.add(deleteItem); + menu.show(tree, x, y); } - menu.show(tree, x, y); - } else if (node.getType() == MongoTreeNode.Type.Object){ - menu.add(newKeyValueItem); - menu.addSeparator(); - menu.add(deleteItem); - menu.show(tree, x, y); } else if (node.getType() == MongoTreeNode.Type.KeyValue) { - MongoTreeNode.KV kv = (MongoTreeNode.KV)node.getUserObject(); - if (!kv.getKey().startsWith("_")) { - menu.add(deleteItem); - menu.show(tree, x, y); + if (!node.isReadOnly()) { + MongoTreeNode.KV kv = (MongoTreeNode.KV)node.getUserObject(); + if (!kv.getKey().startsWith("_")) { + menu.add(deleteItem); + menu.show(tree, x, y); + } } } } @@ -177,7 +178,7 @@ DBCursor cursor = collection.find(); while (cursor.hasNext()) { DBObject obj = cursor.next(); - MongoTreeNode objNode = new MongoTreeNode(obj); + MongoTreeNode objNode = new MongoTreeNode(obj, node.isReadOnly()); node.add(objNode); slug = new MongoTreeNode(); objNode.add(slug); @@ -188,7 +189,7 @@ case Object: { DBObject object = (DBObject)node.getUserObject(); for (String key : object.keySet()) { - MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key))); + MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key)), node.isReadOnly()); node.add(kv); } } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2010-01-03 01:07:45 UTC (rev 93) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2010-01-03 01:32:47 UTC (rev 94) @@ -50,36 +50,46 @@ } Type nodeType; + boolean readOnly; public MongoTreeNode() { super(null); nodeType = Type.ExpansionSlug; + readOnly = false; } public MongoTreeNode(Root root) { super(null); nodeType = Type.Root; + readOnly = false; } - public MongoTreeNode(DBCollection dbCollection) { + public MongoTreeNode(DBCollection dbCollection, boolean rdOnly) { super(dbCollection); nodeType = Type.Collection; + readOnly = rdOnly; } - public MongoTreeNode(DBObject dbObject) { + public MongoTreeNode(DBObject dbObject, boolean rdOnly) { super(dbObject); nodeType = Type.Object; + readOnly = rdOnly; } - public MongoTreeNode(KV dbKV) { + public MongoTreeNode(KV dbKV, boolean rdOnly) { super(dbKV); nodeType = Type.KeyValue; + readOnly = rdOnly; } public Type getType() { return nodeType; } + public boolean isReadOnly() { + return readOnly; + } + @Override public String toString() { switch (nodeType) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-03 01:54:41
|
Revision: 95 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=95&view=rev Author: dbrosius Date: 2010-01-03 01:54:30 +0000 (Sun, 03 Jan 2010) Log Message: ----------- if a key/value's value is a DBObject, add a slug Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2010-01-03 01:32:47 UTC (rev 94) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2010-01-03 01:54:30 UTC (rev 95) @@ -59,6 +59,10 @@ object.put(key, value); MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key)), false); objectNode.add(kv); + if (value instanceof DBObject) { + MongoTreeNode slug = new MongoTreeNode(); + kv.add(slug); + } MongoTreeNode collectionNode = TreeUtils.findCollectionNode(objectNode); DBCollection collection = (DBCollection)collectionNode.getUserObject(); collection.save(object); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2010-01-03 01:32:47 UTC (rev 94) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2010-01-03 01:54:30 UTC (rev 95) @@ -189,8 +189,13 @@ case Object: { DBObject object = (DBObject)node.getUserObject(); for (String key : object.keySet()) { - MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, object.get(key)), node.isReadOnly()); + Object value = object.get(key); + MongoTreeNode kv = new MongoTreeNode(new MongoTreeNode.KV(key, value), node.isReadOnly()); node.add(kv); + if (value instanceof DBObject) { + slug = new MongoTreeNode(); + kv.add(slug); + } } } break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-03 03:08:33
|
Revision: 106 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=106&view=rev Author: dbrosius Date: 2010-01-03 03:08:22 +0000 (Sun, 03 Jan 2010) Log Message: ----------- add a FloatValueType Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2010-01-03 03:04:48 UTC (rev 105) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2010-01-03 03:08:22 UTC (rev 106) @@ -47,6 +47,7 @@ Value("mongo.value"), Integer("mongo.integer"), Double("mongo.double"), + Float("mongo.float"), String("mongo.string"), Object("mongo.object"), Delete("mongo.delete"); Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2010-01-03 03:04:48 UTC (rev 105) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2010-01-03 03:08:22 UTC (rev 106) @@ -87,6 +87,7 @@ 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); @@ -283,6 +284,51 @@ } /** + * 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 + */ + @Override + public void installDocument(JTextField field) { + try { + String val = field.getText(); + field.setText(""); + field.setDocument(new FloatDocument()); + field.getDocument().insertString(0, val, null); + field.setEnabled(true); + } catch (BadLocationException ble) { + } + } + + /** + * get the field's values as an Float + * + * @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 + * + * @return the string 'Float' + */ + @Override + public String toString() { + return MongoBundle.getString(MongoBundle.Key.Float); + } + } + + + /** * a value type representing an String object */ static class StringValueType implements ValueType { Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties 2010-01-03 03:04:48 UTC (rev 105) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties 2010-01-03 03:08:22 UTC (rev 106) @@ -35,6 +35,7 @@ mongo.value = Value mongo.integer = Integer mongo.double = Double +mongo.float = Float mongo.string = String mongo.object = Object mongo.delete = Delete This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2011-06-23 03:53:25
|
Revision: 132 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=132&view=rev Author: dbrosius Date: 2011-06-23 03:53:16 +0000 (Thu, 23 Jun 2011) Log Message: ----------- implement index management Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.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/resources/resource.properties Added Paths: ----------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoConstants.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/SwingUtils.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ManageIndicesAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellEditor.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellRenderer.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesDialog.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesModel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeCellRenderer.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/ascending.png trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/descending.png trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/index.png trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/manageindices.png Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2011-06-19 07:14:41 UTC (rev 131) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2011-06-23 03:53:16 UTC (rev 132) @@ -29,14 +29,36 @@ * 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"), + ManageIndices("mongo.manageindices"), + NewObject("mongo.newobject"), + NewKeyValue("mongo.newkeyvalue"), + RemoveIndex("mongo.removeindex"), + AddIndex("mongo.addindex"), + Key("mongo.key"), + Value("mongo.value"), + Integer("mongo.integer"), + Double("mongo.double"), + Float("mongo.float"), + String("mongo.string"), + Object("mongo.object"), + Delete("mongo.delete"), + IndexName("mongo.indexname"), + IndexFields("mongo.indexfields"), + IndexPrefix("mongo.indexprefix"); - String id; + private String id; /** * creates a key given the properties file name Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoConstants.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoConstants.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoConstants.java 2011-06-23 03:53:16 UTC (rev 132) @@ -0,0 +1,32 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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; + +public class MongoConstants { + + public static final String NAME = "name"; + public static final String KEY = "key"; + public static final Integer ASCENDING = Integer.valueOf(1); + public static final Integer DESCENDING = Integer.valueOf(-1); + public static final String ID_INDEX = "_id_"; + public static final String SYSTEM_PREFIX = "system."; + + private MongoConstants() { + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoConstants.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/SwingUtils.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/SwingUtils.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/SwingUtils.java 2011-06-23 03:53:16 UTC (rev 132) @@ -0,0 +1,60 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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; + +import java.awt.Dimension; + +import javax.swing.JComponent; + +public class SwingUtils { + + private SwingUtils() { + } + + public static void sizeUniformly(JComponent... components) { + + for (JComponent c : components) { + c.setPreferredSize(null); + c.setMinimumSize(null); + c.setMaximumSize(null); + } + + int width = 0; + int height = 0; + + for (JComponent c : components) { + Dimension d = c.getPreferredSize(); + if (d.width > width) { + width = d.width; + } + if (d.height > height) { + height = d.height; + } + } + + for (JComponent c : components) { + Dimension d = c.getPreferredSize(); + d.width = width; + d.height = height; + c.setPreferredSize(d); + c.setMinimumSize(d); + c.setMaximumSize(d); + } + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/SwingUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ManageIndicesAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ManageIndicesAction.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ManageIndicesAction.java 2011-06-23 03:53:16 UTC (rev 132) @@ -0,0 +1,106 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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.actions; + +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.swing.AbstractAction; +import javax.swing.JTree; + +import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.MongoConstants; +import com.mebigfatguy.mongobrowser.MongoContext; +import com.mebigfatguy.mongobrowser.dialogs.ManageIndicesDialog; +import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode; +import com.mebigfatguy.mongobrowser.model.IndexDescription; +import com.mebigfatguy.mongobrowser.model.IndexField; +import com.mebigfatguy.mongobrowser.model.IndexFieldList; +import com.mongodb.BasicDBObject; +import com.mongodb.DBCollection; +import com.mongodb.DBObject; + +public class ManageIndicesAction extends AbstractAction { + + private static final long serialVersionUID = 554299884297317739L; + private final MongoContext context; + + public ManageIndicesAction(MongoContext ctxt) { + super(MongoBundle.getString(MongoBundle.Key.ManageIndices)); + context = ctxt; + } + + @Override + public void actionPerformed(ActionEvent e) { + JTree tree = context.getTree(); + + MongoTreeNode[] nodes = context.getSelectedNodes(); + DBCollection collection = (DBCollection) nodes[0].getUserObject(); + List<IndexDescription> indices = buildIndexDescriptions(collection); + + ManageIndicesDialog dialog = new ManageIndicesDialog(indices); + dialog.setLocationRelativeTo(tree); + dialog.setModal(true); + dialog.setVisible(true); + + if (dialog.isOK()) { + indices = dialog.getIndicesNames(); + updateIndices(collection, indices); + } + } + + private List<IndexDescription> buildIndexDescriptions(DBCollection collection) { + List<IndexDescription> indices = new ArrayList<IndexDescription>(); + List<DBObject> dbIndices = collection.getIndexInfo(); + for (DBObject dbIndex : dbIndices) { + String name = (String) dbIndex.get(MongoConstants.NAME); + Map<String, Integer> srcFields = (Map<String, Integer>) dbIndex.get(MongoConstants.KEY); + IndexFieldList fieldSet = new IndexFieldList(); + + for (Map.Entry<String, Integer> entry : srcFields.entrySet()) { + fieldSet.add(entry.getKey(), MongoConstants.ASCENDING.equals(entry.getValue())); + } + + indices.add(new IndexDescription(name, fieldSet)); + } + + return indices; + } + + private void updateIndices(DBCollection collection, List<IndexDescription> indices) { + + collection.dropIndexes(); + + for (IndexDescription index : indices) { + if (!MongoConstants.ID_INDEX.equals(index.getIndexName())) { + + BasicDBObject dbFields = new BasicDBObject(); + IndexFieldList fieldList = index.getIndexFieldList(); + + for (IndexField field : fieldList) { + dbFields.append(field.getFieldName(), Integer.valueOf(field.isAscending() ? 1 : -1)); + } + + collection.ensureIndex(dbFields, index.getIndexName()); + } + } + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/ManageIndicesAction.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2011-06-19 07:14:41 UTC (rev 131) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/NewKeyValueAction.java 2011-06-23 03:53:16 UTC (rev 132) @@ -41,6 +41,12 @@ private static final long serialVersionUID = -500965537578361564L; private final MongoContext context; + /** + * constructs an action to handle creating a new key/value pair + * + * @param ctxt + * the state context + */ public NewKeyValueAction(MongoContext ctxt) { super(MongoBundle.getString(MongoBundle.Key.NewKeyValue)); context = ctxt; Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java 2011-06-19 07:14:41 UTC (rev 131) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ConnectionDialog.java 2011-06-23 03:53:16 UTC (rev 132) @@ -35,6 +35,7 @@ import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.SwingUtils; /** * a dialog for requesting server and port information for a mongo server @@ -119,6 +120,8 @@ p.add(cancelButton); p.add(Box.createHorizontalStrut(10)); + SwingUtils.sizeUniformly(okButton, cancelButton); + return p; } Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellEditor.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellEditor.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellEditor.java 2011-06-23 03:53:16 UTC (rev 132) @@ -0,0 +1,164 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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 java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.AbstractCellEditor; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.table.TableCellEditor; + +import com.mebigfatguy.mongobrowser.model.IndexField; +import com.mebigfatguy.mongobrowser.model.IndexFieldList; + +/** + * a cell editor for a set of fields/directions for an index + */ +public class IndexFieldListCellEditor extends AbstractCellEditor implements TableCellEditor { + + private static final long serialVersionUID = 3996145084996105628L; + + private static final Icon ASCENDING = new ImageIcon( + IndexFieldListCellEditor.class.getResource("/com/mebigfatguy/mongobrowser/resources/ascending.png")); + private static final Icon DESCENDING = new ImageIcon( + IndexFieldListCellEditor.class.getResource("/com/mebigfatguy/mongobrowser/resources/descending.png")); + + private final JPanel panel = new JPanel(); + private final List<FieldControl> controls = new ArrayList<FieldControl>(); + + public IndexFieldListCellEditor() { + panel.setLayout(new FlowLayout(FlowLayout.CENTER, 2, 0)); + panel.setOpaque(true); + } + + @Override + public Object getCellEditorValue() { + IndexFieldList fieldList = new IndexFieldList(); + + for (FieldControl control : controls) { + String fieldName = control.nameField.getText().trim(); + + if (!fieldName.isEmpty()) { + fieldList.add(fieldName, control.directionButton.getIcon().equals(ASCENDING)); + } + } + + return fieldList; + + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + + panel.removeAll(); + panel.setFont(table.getFont()); + + if (isSelected) { + panel.setBackground(table.getSelectionBackground()); + panel.setForeground(table.getSelectionForeground()); + } else { + panel.setBackground(table.getBackground()); + panel.setForeground(table.getForeground()); + } + + if (value instanceof IndexFieldList) { + IndexFieldList fields = (IndexFieldList) value; + + for (FieldControl control : controls) { + control.nameField.setText(""); + } + + for (int i = 0; i < fields.size(); i++) { + if (controls.size() <= i) { + controls.add(new FieldControl()); + } + + IndexField field = fields.get(i); + FieldControl control = controls.get(i); + control.nameField.setFont(table.getFont()); + control.nameField.setText(field.getFieldName()); + control.setAscending(field.isAscending()); + panel.add(control.nameField); + panel.add(control.directionButton); + } + + if (controls.size() <= fields.size()) { + controls.add(new FieldControl()); + } + + FieldControl control = controls.get(fields.size()); + control.nameField.setFont(table.getFont()); + control.nameField.setText(""); + control.setAscending(true); + panel.add(control.nameField); + panel.add(control.directionButton); + } + + return panel; + } + + /** + * holds one set of controls for a index field, a name and direction + * indicator + * + */ + static class FieldControl { + private final JTextField nameField = new JTextField(5); + private final JButton directionButton = new JButton(); + private boolean isAscending = true; + + /** + * constructs the controls for one index field + */ + public FieldControl() { + directionButton.setPreferredSize(new Dimension(ASCENDING.getIconWidth(), ASCENDING.getIconHeight())); + directionButton.setBorderPainted(false); + directionButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + setAscending(!isAscending); + } + + }); + } + + /** + * set the direction of the index on this field + * + * @param ascending + * either ascending or descending + */ + public void setAscending(boolean ascending) { + directionButton.setIcon(ascending ? ASCENDING : DESCENDING); + isAscending = ascending; + } + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellRenderer.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellRenderer.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellRenderer.java 2011-06-23 03:53:16 UTC (rev 132) @@ -0,0 +1,98 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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 java.awt.Component; +import java.awt.FlowLayout; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.table.TableCellRenderer; + +import sun.swing.DefaultLookup; + +import com.mebigfatguy.mongobrowser.model.IndexField; +import com.mebigfatguy.mongobrowser.model.IndexFieldList; + +public class IndexFieldListCellRenderer extends JPanel implements TableCellRenderer { + + private static final long serialVersionUID = 1447611436027408402L; + + private static final Icon ASCENDING = new ImageIcon( + IndexFieldListCellRenderer.class.getResource("/com/mebigfatguy/mongobrowser/resources/ascending.png")); + private static final Icon DESCENDING = new ImageIcon( + IndexFieldListCellRenderer.class.getResource("/com/mebigfatguy/mongobrowser/resources/descending.png")); + + private final List<JLabel> fieldLabels = new ArrayList<JLabel>(); + + public IndexFieldListCellRenderer() { + setLayout(new FlowLayout(FlowLayout.CENTER, 2, 0)); + setOpaque(true); + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, + int row, int column) { + + removeAll(); + setFont(table.getFont()); + + if (isSelected) { + setBackground(table.getSelectionBackground()); + setForeground(table.getSelectionForeground()); + } else { + setBackground(table.getBackground()); + setForeground(table.getForeground()); + } + + if (hasFocus) { + setBorder(isSelected ? DefaultLookup.getBorder(this, ui, "Table.focusSelectedCellHighlightBorder") + : DefaultLookup.getBorder(this, ui, "Table.focusCellHighlightBorder")); + } else { + setBorder(DefaultLookup.getBorder(this, ui, "Table.cellNoFocusBorder")); + } + + if (value instanceof IndexFieldList) { + IndexFieldList fields = (IndexFieldList) value; + + for (int i = 0; i < fields.size(); i++) { + if (fieldLabels.size() <= i) { + JLabel l = new JLabel(); + fieldLabels.add(l); + l.setHorizontalTextPosition(SwingConstants.LEFT); + l.setVerticalTextPosition(SwingConstants.CENTER); + } + + JLabel l = fieldLabels.get(i); + l.setFont(table.getFont()); + IndexField field = fields.get(i); + l.setText(field.getFieldName()); + l.setIcon(field.isAscending() ? ASCENDING : DESCENDING); + add(l); + } + } + return this; + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/IndexFieldListCellRenderer.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2011-06-19 07:14:41 UTC (rev 131) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2011-06-23 03:53:16 UTC (rev 132) @@ -23,6 +23,7 @@ import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.SwingUtils; import com.mongodb.BasicDBObject; /** @@ -117,6 +118,8 @@ p.add(cancelButton); p.add(Box.createHorizontalStrut(10)); + SwingUtils.sizeUniformly(okButton, cancelButton); + return p; } Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesDialog.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesDialog.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesDialog.java 2011-06-23 03:53:16 UTC (rev 132) @@ -0,0 +1,192 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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 java.awt.BorderLayout; +import java.awt.Container; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; + +import com.jgoodies.forms.layout.CellConstraints; +import com.jgoodies.forms.layout.FormLayout; +import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.SwingUtils; +import com.mebigfatguy.mongobrowser.model.IndexDescription; +import com.mebigfatguy.mongobrowser.model.IndexFieldList; + +public class ManageIndicesDialog extends JDialog { + + private static final long serialVersionUID = -4263800895451732866L; + private static int INDEX_SEQ = 1; + + private JTable indicesTable; + private JButton addIndexButton; + private JButton removeIndexButton; + private JButton okButton; + private JButton cancelButton; + private boolean ok = false; + + public ManageIndicesDialog(List<IndexDescription> indices) { + setTitle(MongoBundle.getString(MongoBundle.Key.ManageIndices)); + initComponents(indices); + initListeners(); + pack(); + } + + /** + * did the user click ok + * + * @return if the user clicked ok + */ + public boolean isOK() { + return ok; + } + + public List<IndexDescription> getIndicesNames() { + + ManageIndicesModel model = (ManageIndicesModel) indicesTable.getModel(); + return model.getIndices(); + } + + private void initComponents(List<IndexDescription> indices) { + Container cp = getContentPane(); + cp.setLayout(new BorderLayout(4, 4)); + cp.add(createIndicesListPanel(indices), BorderLayout.CENTER); + cp.add(createCtrlPanel(), BorderLayout.SOUTH); + + SwingUtils.sizeUniformly(okButton, cancelButton, addIndexButton, removeIndexButton); + } + + 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(); + } + }); + + addIndexButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + String indexName = createUniqueIndexName(); + IndexDescription index = new IndexDescription(indexName, new IndexFieldList()); + ManageIndicesModel model = (ManageIndicesModel) indicesTable.getModel(); + model.add(index); + } + }); + + removeIndexButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + ManageIndicesModel model = (ManageIndicesModel) indicesTable.getModel(); + int[] selRows = indicesTable.getSelectedRows(); + for (int i = selRows.length - 1; i >= 0; i--) { + model.removeAt(selRows[i]); + } + } + }); + } + + private JPanel createIndicesListPanel(List<IndexDescription> indices) { + JPanel p = new JPanel(); + p.setLayout(new FormLayout("6dlu, pref:grow, 5dlu, pref, 6dlu", + "6dlu, 12dlu:grow, pref, 3dlu, pref, 12dlu:grow, 6dlu, pref, 6dlu")); + CellConstraints cc = new CellConstraints(); + + ManageIndicesModel model = new ManageIndicesModel(indices); + + indicesTable = new JTable(model); + indicesTable.setDefaultEditor(String.class, new DefaultCellEditor(new JTextField())); + indicesTable.setDefaultEditor(IndexFieldList.class, new IndexFieldListCellEditor()); + indicesTable.setDefaultRenderer(IndexFieldList.class, new IndexFieldListCellRenderer()); + p.add(new JScrollPane(indicesTable), cc.xywh(2, 2, 1, 5)); + + addIndexButton = new JButton(MongoBundle.getString(MongoBundle.Key.AddIndex)); + p.add(addIndexButton, cc.xy(4, 3)); + + removeIndexButton = new JButton(MongoBundle.getString(MongoBundle.Key.RemoveIndex)); + p.add(removeIndexButton, cc.xy(4, 5)); + + return p; + } + + /** + * creates a panel holding the ok and cancel buttons + * + * @return the ok/cancel button panel + */ + private JPanel createCtrlPanel() { + JPanel p = new JPanel(); + p.setBorder(BorderFactory.createEmptyBorder(20, 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; + } + + private String createUniqueIndexName() { + String name = null; + do { + name = MongoBundle.getString(MongoBundle.Key.IndexPrefix) + INDEX_SEQ++; + } while (indexExists(name)); + + return name; + } + + private boolean indexExists(String name) { + ManageIndicesModel model = (ManageIndicesModel) indicesTable.getModel(); + for (int i = 0; i < model.getRowCount(); i++) { + if (name.equals(model.getValueAt(i, 0))) { + return true; + } + } + + return false; + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesDialog.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesModel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesModel.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesModel.java 2011-06-23 03:53:16 UTC (rev 132) @@ -0,0 +1,126 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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 java.util.List; + +import javax.swing.table.AbstractTableModel; + +import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.MongoConstants; +import com.mebigfatguy.mongobrowser.model.IndexDescription; +import com.mebigfatguy.mongobrowser.model.IndexFieldList; + +public class ManageIndicesModel extends AbstractTableModel { + + private static final long serialVersionUID = 2062960191211526719L; + + private final List<IndexDescription> indices; + + public ManageIndicesModel(List<IndexDescription> indexInfo) { + indices = indexInfo; + } + + public List<IndexDescription> getIndices() { + return indices; + } + + public void add(IndexDescription index) { + indices.add(index); + fireTableRowsInserted(indices.size() - 1, indices.size() - 1); + } + + public void removeAt(int index) { + indices.remove(index); + fireTableRowsDeleted(index, index); + } + + @Override + public int getRowCount() { + return indices.size(); + } + + @Override + public int getColumnCount() { + return 2; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + IndexDescription index = indices.get(rowIndex); + switch (columnIndex) { + case 0: + return index.getIndexName(); + case 1: + return index.getIndexFieldList(); + default: + throw new IllegalArgumentException("columnIndex = " + columnIndex); + } + } + + @Override + public void setValueAt(Object value, int rowIndex, int columnIndex) { + IndexDescription index = indices.get(rowIndex); + switch (columnIndex) { + case 0: + index.setIndexName((String) value); + break; + case 1: + index.setIndexFieldList((IndexFieldList) value); + break; + default: + throw new IllegalArgumentException("columnIndex = " + columnIndex); + } + + fireTableCellUpdated(rowIndex, columnIndex); + } + + @Override + public String getColumnName(int columnIndex) { + switch (columnIndex) { + case 0: + return MongoBundle.getString(MongoBundle.Key.IndexName); + case 1: + return MongoBundle.getString(MongoBundle.Key.IndexFields); + default: + throw new IllegalArgumentException("columnIndex = " + columnIndex); + } + } + + @Override + public Class<?> getColumnClass(int columnIndex) { + switch (columnIndex) { + case 0: + return String.class; + case 1: + return IndexFieldList.class; + default: + throw new IllegalArgumentException("columnIndex = " + columnIndex); + } + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + String name = (String) getValueAt(rowIndex, 0); + if (MongoConstants.ID_INDEX.equals(name)) { + return false; + } + return (columnIndex == 0) || (columnIndex == 1); + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/ManageIndicesModel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2011-06-19 07:14:41 UTC (rev 131) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoControlPanel.java 2011-06-23 03:53:16 UTC (rev 132) @@ -43,6 +43,7 @@ import com.mebigfatguy.mongobrowser.MongoBundle; import com.mebigfatguy.mongobrowser.MongoContext; import com.mebigfatguy.mongobrowser.actions.DeleteAction; +import com.mebigfatguy.mongobrowser.actions.ManageIndicesAction; import com.mebigfatguy.mongobrowser.actions.NewCollectionAction; import com.mebigfatguy.mongobrowser.actions.NewKeyValueAction; import com.mebigfatguy.mongobrowser.actions.NewObjectAction; @@ -58,6 +59,7 @@ private final MongoContext context; private JComboBox dbComboBox; private JButton dbNewCollectionButton; + private JButton dbManageIndicesButton; private JButton dbNewObjectButton; private JButton dbNewKeyValueButton; private JButton dbDeleteButton; @@ -120,11 +122,13 @@ public void adjustEnabled(MongoTreeNode... selectedNodes) { if ((selectedNodes == null) || (selectedNodes.length == 0)) { dbNewCollectionButton.setEnabled(true); + dbManageIndicesButton.setEnabled(false); dbNewObjectButton.setEnabled(false); dbNewKeyValueButton.setEnabled(false); dbDeleteButton.setEnabled(false); } else { + boolean canDoManageIndices = selectedNodes.length == 1; boolean canDoNewObject = true; boolean canDoNewKeyValue = true; boolean canDoDelete = true; @@ -137,12 +141,14 @@ break; case Object: + canDoManageIndices = false; canDoNewObject = false; break; case KeyValue: MongoTreeNode.KV kv = (MongoTreeNode.KV) selectedNode.getUserObject(); Object value = kv.getValue(); + canDoManageIndices = false; canDoNewObject = false; canDoNewKeyValue = value instanceof DBObject; canDoDelete = !kv.getKey().startsWith("_"); @@ -150,6 +156,7 @@ } if (selectedNode.isReadOnly()) { + canDoManageIndices = false; canDoNewObject = false; canDoNewKeyValue = false; canDoDelete = false; @@ -157,6 +164,7 @@ } dbNewCollectionButton.setEnabled(true); + dbManageIndicesButton.setEnabled(true); dbNewObjectButton.setEnabled(canDoNewObject); dbNewKeyValueButton.setEnabled(canDoNewKeyValue); dbDeleteButton.setEnabled(canDoDelete); @@ -184,7 +192,8 @@ private void initComponents() { setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(5, 5, 5, 5))); - setLayout(new FormLayout("3dlu, pref, 1dlu, 200px:grow, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref", "pref")); + setLayout(new FormLayout( + "3dlu, pref, 1dlu, 200px:grow, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref", "pref")); CellConstraints cc = new CellConstraints(); JLabel dbLabel = new JLabel(MongoBundle.getString(MongoBundle.Key.Database)); @@ -204,6 +213,16 @@ add(dbNewCollectionButton, cc.xy(6, 1)); dbNewCollectionButton.setEnabled(false); + dbManageIndicesButton = new JButton(new ManageIndicesAction(context)); + icon = new ImageIcon( + MongoControlPanel.class.getResource("/com/mebigfatguy/mongobrowser/resources/manageindices.png")); + dbManageIndicesButton.setIcon(icon); + dbManageIndicesButton.setText(""); + dbManageIndicesButton.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); + dbManageIndicesButton.setToolTipText(MongoBundle.getString(MongoBundle.Key.ManageIndices)); + add(dbManageIndicesButton, cc.xy(8, 1)); + dbManageIndicesButton.setEnabled(false); + dbNewObjectButton = new JButton(new NewObjectAction(context)); icon = new ImageIcon( MongoControlPanel.class.getResource("/com/mebigfatguy/mongobrowser/resources/newobject.png")); @@ -211,7 +230,7 @@ dbNewObjectButton.setText(""); dbNewObjectButton.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); dbNewObjectButton.setToolTipText(MongoBundle.getString(MongoBundle.Key.NewObject)); - add(dbNewObjectButton, cc.xy(8, 1)); + add(dbNewObjectButton, cc.xy(10, 1)); dbNewObjectButton.setEnabled(false); dbNewKeyValueButton = new JButton(new NewKeyValueAction(context)); @@ -221,7 +240,7 @@ dbNewKeyValueButton.setText(""); dbNewKeyValueButton.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); dbNewKeyValueButton.setToolTipText(MongoBundle.getString(MongoBundle.Key.NewKeyValue)); - add(dbNewKeyValueButton, cc.xy(10, 1)); + add(dbNewKeyValueButton, cc.xy(12, 1)); dbNewKeyValueButton.setEnabled(false); dbDeleteButton = new JButton(new DeleteAction(context)); @@ -230,7 +249,7 @@ dbDeleteButton.setText(null); dbDeleteButton.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); dbDeleteButton.setToolTipText(MongoBundle.getString(MongoBundle.Key.Delete)); - add(dbDeleteButton, cc.xy(12, 1)); + add(dbDeleteButton, cc.xy(14, 1)); dbDeleteButton.setEnabled(false); } Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2011-06-19 07:14:41 UTC (rev 131) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2011-06-23 03:53:16 UTC (rev 132) @@ -36,9 +36,11 @@ import javax.swing.tree.ExpandVetoException; import javax.swing.tree.TreePath; +import com.mebigfatguy.mongobrowser.MongoConstants; import com.mebigfatguy.mongobrowser.MongoContext; import com.mebigfatguy.mongobrowser.TreeUtils; import com.mebigfatguy.mongobrowser.actions.DeleteAction; +import com.mebigfatguy.mongobrowser.actions.ManageIndicesAction; import com.mebigfatguy.mongobrowser.actions.NewCollectionAction; import com.mebigfatguy.mongobrowser.actions.NewKeyValueAction; import com.mebigfatguy.mongobrowser.actions.NewObjectAction; @@ -55,6 +57,7 @@ private static final long serialVersionUID = 1579613544693305078L; private final MongoContext context; private JTree tree; + private JMenuItem manageIndicesItem; private JMenuItem newCollectionItem; private JMenuItem newObjectItem; private JMenuItem newKeyValueItem; @@ -85,7 +88,7 @@ Set<String> collectionNames = db.getCollectionNames(); for (String collectionName : collectionNames) { DBCollection collection = db.getCollection(collectionName); - boolean readOnly = collectionName.startsWith("system."); + boolean readOnly = collectionName.startsWith(MongoConstants.SYSTEM_PREFIX); MongoTreeNode col = new MongoTreeNode(collection, readOnly); root.add(col); MongoTreeNode slug = new MongoTreeNode(); @@ -125,6 +128,7 @@ context.setTree(tree); newCollectionItem = new JMenuItem(new NewCollectionAction(context)); + manageIndicesItem = new JMenuItem(new ManageIndicesAction(context)); newObjectItem = new JMenuItem(new NewObjectAction(context)); newKeyValueItem = new JMenuItem(new NewKeyValueAction(context)); deleteItem = new JMenuItem(new DeleteAction(context)); @@ -167,6 +171,7 @@ context.setSelectedNodes(node); if (node.getType() == MongoTreeNode.Type.Collection) { if (!node.isReadOnly()) { + menu.add(manageIndicesItem); menu.add(newObjectItem); menu.show(tree, x, y); } Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeCellRenderer.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeCellRenderer.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeCellRenderer.java 2011-06-23 03:53:16 UTC (rev 132) @@ -0,0 +1,89 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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 java.awt.Component; +import java.util.List; + +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JTree; +import javax.swing.tree.DefaultTreeCellRenderer; + +import com.mebigfatguy.mongobrowser.MongoConstants; +import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode.KV; +import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode.Type; +import com.mongodb.BasicDBObject; +import com.mongodb.DBCollection; +import com.mongodb.DBObject; + +/** + * a table cell renderer for showing the list of fields that an index controls + */ +public class MongoTreeCellRenderer extends DefaultTreeCellRenderer { + + private static final long serialVersionUID = -5461207993315946236L; + private final Icon indexIcon; + + /** + * constructs a renderer for the list of fields of an index + */ + public MongoTreeCellRenderer() { + indexIcon = new ImageIcon(getClass().getResource("/com/mebigfatguy/mongobrowser/resources/index.png")); + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, + boolean leaf, int row, boolean hasFocus) { + + MongoTreeNode treeNode = (MongoTreeNode) value; + + JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + label.setHorizontalTextPosition(JLabel.RIGHT); + label.setVerticalTextPosition(JLabel.CENTER); + + label.setIcon(null); + + if (treeNode.getType() == Type.KeyValue) { + MongoTreeNode parentTreeNode = treeNode; + + do { + parentTreeNode = (MongoTreeNode) parentTreeNode.getParent(); + } while ((parentTreeNode != null) && (parentTreeNode.getType() != Type.Collection)); + + if (parentTreeNode != null) { + + DBCollection collection = (DBCollection) parentTreeNode.getUserObject(); + List<DBObject> indices = collection.getIndexInfo(); + String key = ((KV) treeNode.getUserObject()).getKey(); + + for (DBObject index : indices) { + BasicDBObject kvIndex = (BasicDBObject) index.get(MongoConstants.KEY); + if (kvIndex.get(key) != null) { + label.setIcon(indexIcon); + break; + } + } + } + } + + return label; + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeCellRenderer.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mimetype + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/ascending.png =================================================================== (Binary files differ) Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/ascending.png ___________________________________________________________________ Added: svn:mime-type + image/png Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/descending.png =================================================================== (Binary files differ) Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/descending.png ___________________________________________________________________ Added: svn:mime-type + image/png Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/index.png =================================================================== (Binary files differ) Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/index.png ___________________________________________________________________ Added: svn:mime-type + image/png Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/manageindices.png =================================================================== (Binary files differ) Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/manageindices.png ___________________________________________________________________ Added: svn:mime-type + image/png Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties 2011-06-19 07:14:41 UTC (rev 131) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties 2011-06-23 03:53:16 UTC (rev 132) @@ -29,8 +29,11 @@ mongo.database = Database mongo.newdatabase = New Database... mongo.newcollection = New Collection... -mongo.newobject = New Object... +mongo.manageindices = Manage Indices... +mongo.newobject = New Object mongo.newkeyvalue = New Key/Value... +mongo.removeindex = Remove Index +mongo.addindex = Add Index mongo.key = Key mongo.value = Value mongo.integer = Integer @@ -39,3 +42,6 @@ mongo.string = String mongo.object = Object mongo.delete = Delete +mongo.indexname = Index Name +mongo.indexfields = Index Fields +mongo.indexprefix = index_ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2011-06-24 06:10:20
|
Revision: 133 http://mongobrowser.svn.sourceforge.net/mongobrowser/?rev=133&view=rev Author: dbrosius Date: 2011-06-24 06:10:13 +0000 (Fri, 24 Jun 2011) Log Message: ----------- add support for editing existing property values Modified Paths: -------------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties Added Paths: ----------- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/EditKeyValueAction.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/DateDocument.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexDescription.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexField.java trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexFieldList.java Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2011-06-23 03:53:16 UTC (rev 132) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/MongoBundle.java 2011-06-24 06:10:13 UTC (rev 133) @@ -44,6 +44,7 @@ ManageIndices("mongo.manageindices"), NewObject("mongo.newobject"), NewKeyValue("mongo.newkeyvalue"), + EditKeyValue("mongo.editkeyvalue"), RemoveIndex("mongo.removeindex"), AddIndex("mongo.addindex"), Key("mongo.key"), @@ -52,11 +53,15 @@ Double("mongo.double"), Float("mongo.float"), String("mongo.string"), + Date("mongo.date"), Object("mongo.object"), Delete("mongo.delete"), IndexName("mongo.indexname"), IndexFields("mongo.indexfields"), - IndexPrefix("mongo.indexprefix"); + IndexPrefix("mongo.indexprefix"), + DateRegex("mongo.dateregex"), + MonthValues("mongo.monthvalues"), + DateFormat("mongo.dateformat"); private String id; Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/EditKeyValueAction.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/EditKeyValueAction.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/EditKeyValueAction.java 2011-06-24 06:10:13 UTC (rev 133) @@ -0,0 +1,83 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.JTree; + +import com.mebigfatguy.mongobrowser.MongoBundle; +import com.mebigfatguy.mongobrowser.MongoContext; +import com.mebigfatguy.mongobrowser.TreeUtils; +import com.mebigfatguy.mongobrowser.dialogs.KeyValueDialog; +import com.mebigfatguy.mongobrowser.dialogs.MongoTreeNode; +import com.mongodb.DBCollection; +import com.mongodb.DBObject; + +/** + * an action for editing a mongo object's key value pair + */ +public class EditKeyValueAction extends AbstractAction { + + private final MongoContext context; + + /** + * constructs an action to handle editing a new key/value pair + * + * @param ctxt + * the state context + */ + public EditKeyValueAction(MongoContext ctxt) { + super(MongoBundle.getString(MongoBundle.Key.EditKeyValue)); + context = ctxt; + } + + @Override + public void actionPerformed(ActionEvent e) { + JTree tree = context.getTree(); + MongoTreeNode[] selectedNodes = TreeUtils.getSelectedNodes(tree); + + if (selectedNodes.length == 1) { + + DBObject dbObject = (DBObject) ((MongoTreeNode) selectedNodes[0].getParent()).getUserObject(); + MongoTreeNode.KV keyValue = ((MongoTreeNode.KV) selectedNodes[0].getUserObject()); + + String key = keyValue.getKey(); + Object value = keyValue.getValue(); + + KeyValueDialog dialog = new KeyValueDialog(key, value); + dialog.setLocationRelativeTo(tree); + dialog.setModal(true); + dialog.setVisible(true); + + if (dialog.isOK()) { + key = dialog.getKey(); + value = dialog.getValue(); + + dbObject.put(key, value); + keyValue.setValue(value); + + MongoTreeNode collectionNode = TreeUtils.findCollectionNode(selectedNodes[0]); + DBCollection collection = (DBCollection) collectionNode.getUserObject(); + collection.save(dbObject); + } + } + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/actions/EditKeyValueAction.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/DateDocument.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/DateDocument.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/DateDocument.java 2011-06-24 06:10:13 UTC (rev 133) @@ -0,0 +1,58 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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 java.awt.Toolkit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; + +import com.mebigfatguy.mongobrowser.MongoBundle; + +public class DateDocument extends PlainDocument { + + private static Pattern DATE_PATTERN = Pattern.compile(MongoBundle.getString(MongoBundle.Key.DateRegex)); + + /** + * intercepts string insertions to make sure that the values to be put into + * a text component is only a date 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) + */ + @Override + public void insertString(int pos, String insertStr, AttributeSet atts) throws BadLocationException { + StringBuilder text = new StringBuilder(getText(0, getLength())); + text.insert(pos, insertStr); + + Matcher m = DATE_PATTERN.matcher(text.toString()); + if (m.matches() || m.hitEnd()) { + super.insertString(pos, insertStr, atts); + } else { + Toolkit.getDefaultToolkit().beep(); + } + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/DateDocument.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2011-06-23 03:53:16 UTC (rev 132) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/KeyValueDialog.java 2011-06-24 06:10:13 UTC (rev 133) @@ -1,3 +1,21 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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 java.awt.BorderLayout; @@ -6,6 +24,11 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.BorderFactory; import javax.swing.Box; @@ -44,9 +67,23 @@ * constructs a dialog to collect a key value for a mongo object's property */ public KeyValueDialog() { + this(null, null); + } + + /** + * constructs a dialog to collect a key value for a mongo object's property + */ + public KeyValueDialog(String key, Object value) { setTitle(MongoBundle.getString(MongoBundle.Key.NewKeyValue)); initComponents(); initListeners(); + + if (key != null) { + keyField.setText(key); + keyField.setEnabled(false); + installValue(value); + } + pack(); } @@ -90,6 +127,7 @@ model.addElement(new DoubleValueType()); model.addElement(new FloatValueType()); model.addElement(new StringValueType()); + model.addElement(new DateValueType()); model.addElement(new ObjectValueType()); valueTypeBox.setSelectedIndex(3); p.add(valueTypeBox, cc.xy(6, 4)); @@ -184,6 +222,47 @@ } /** + * updates the key value dialog based on the value, this is kind of crufty, + * would be nicer to handle the popup a better way + * + * @param value + * the value to set + */ + private void installValue(Object value) { + if (value != null) { + DefaultComboBoxModel model = (DefaultComboBoxModel) valueTypeBox.getModel(); + + if (value instanceof Integer) { + valueTypeBox.setSelectedIndex(0); + ValueType vt = (ValueType) model.getElementAt(0); + vt.installDocument(valueField); + valueField.setText(String.valueOf(value)); + } else if (value instanceof Double) { + valueTypeBox.setSelectedIndex(1); + ValueType vt = (ValueType) model.getElementAt(1); + vt.installDocument(valueField); + valueField.setText(String.valueOf(value)); + } else if (value instanceof Float) { + valueTypeBox.setSelectedIndex(2); + ValueType vt = (ValueType) model.getElementAt(2); + vt.installDocument(valueField); + valueField.setText(String.valueOf(value)); + } else if (value instanceof String) { + valueTypeBox.setSelectedIndex(3); + ValueType vt = (ValueType) model.getElementAt(3); + vt.installDocument(valueField); + valueField.setText((String) value); + } else if (value instanceof Date) { + valueTypeBox.setSelectedIndex(4); + ValueType vt = (ValueType) model.getElementAt(4); + vt.installDocument(valueField); + SimpleDateFormat sdf = new SimpleDateFormat(MongoBundle.getString(MongoBundle.Key.DateFormat)); + valueField.setText(sdf.format((Date) value)); + } + } + } + + /** * interface for items that are put into the Value type combobox */ interface ValueType { @@ -390,6 +469,91 @@ } /** + * a value type representing a Date object + */ + static class DateValueType implements ValueType { + + /** + * installs an PlainDocument as the field's model + * + * @param field + * the text edit field to install the model + */ + @Override + public void installDocument(JTextField field) { + try { + String val = field.getText(); + field.setText(""); + field.setDocument(new DateDocument()); + field.getDocument().insertString(0, val, null); + field.setEnabled(true); + } catch (BadLocationException ble) { + } + } + + /** + * get the field's values as an String + * + * @param field + * the component that holds the string value + * @return an Date that is the value of the text field + */ + @Override + public Object getValue(JTextField field) { + Pattern p = Pattern.compile(MongoBundle.getString(MongoBundle.Key.DateRegex)); + + Calendar c = Calendar.getInstance(); + + Matcher m = p.matcher(field.getText()); + if (m.matches() || m.hitEnd()) { + c.clear(); + + int groupCounts = m.groupCount(); + if (groupCounts > 0) { + String[] monthVals = MongoBundle.getString(MongoBundle.Key.MonthValues).split(","); + String month = m.group(1); + for (String mv : monthVals) { + if (month.startsWith(mv)) { + c.set(Calendar.MONTH, Integer.parseInt(mv.split(":")[1])); + } + } + if (groupCounts > 1) { + c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(m.group(2))); + if (groupCounts > 2) { + c.set(Calendar.YEAR, Integer.parseInt(m.group(3))); + if (groupCounts > 3) { + String[] time = m.group(4).split(":"); + + if (time.length > 0) { + c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time[0])); + if (time.length > 1) { + c.set(Calendar.MINUTE, Integer.parseInt(time[1])); + if (time.length > 2) { + c.set(Calendar.SECOND, Integer.parseInt(time[2])); + } + } + } + } + } + } + } + } + + return c.getTime(); + } + + /** + * returns the display value shown in the combo box + * + * @return the string 'String' + */ + @Override + public String toString() { + return MongoBundle.getString(MongoBundle.Key.Date); + } + } + + /** * a value type representing an BasicDBObject object */ static class ObjectValueType implements ValueType { Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2011-06-23 03:53:16 UTC (rev 132) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoDataPanel.java 2011-06-24 06:10:13 UTC (rev 133) @@ -40,6 +40,7 @@ import com.mebigfatguy.mongobrowser.MongoContext; import com.mebigfatguy.mongobrowser.TreeUtils; import com.mebigfatguy.mongobrowser.actions.DeleteAction; +import com.mebigfatguy.mongobrowser.actions.EditKeyValueAction; import com.mebigfatguy.mongobrowser.actions.ManageIndicesAction; import com.mebigfatguy.mongobrowser.actions.NewCollectionAction; import com.mebigfatguy.mongobrowser.actions.NewKeyValueAction; @@ -61,6 +62,7 @@ private JMenuItem newCollectionItem; private JMenuItem newObjectItem; private JMenuItem newKeyValueItem; + private JMenuItem editKeyValueItem; private JMenuItem deleteItem; /** @@ -131,6 +133,7 @@ manageIndicesItem = new JMenuItem(new ManageIndicesAction(context)); newObjectItem = new JMenuItem(new NewObjectAction(context)); newKeyValueItem = new JMenuItem(new NewKeyValueAction(context)); + editKeyValueItem = new JMenuItem(new EditKeyValueAction(context)); deleteItem = new JMenuItem(new DeleteAction(context)); } @@ -190,6 +193,9 @@ if (value instanceof DBObject) { menu.add(newKeyValueItem); needsSeparator = true; + } else { + menu.add(editKeyValueItem); + needsSeparator = true; } if (!kv.getKey().startsWith("_")) { Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2011-06-23 03:53:16 UTC (rev 132) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/dialogs/MongoTreeNode.java 2011-06-24 06:10:13 UTC (rev 133) @@ -41,7 +41,7 @@ * holds the key value of a mongo object property */ public static class KV { - private String key; + private final String key; private Object value; public KV(String k, Object v) { @@ -57,6 +57,10 @@ return value; } + public void setValue(Object o) { + value = o; + } + @Override public String toString() { return key + " : " + value; Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexDescription.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexDescription.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexDescription.java 2011-06-24 06:10:13 UTC (rev 133) @@ -0,0 +1,76 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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.model; + +import java.io.Serializable; + +public class IndexDescription implements Comparable<IndexDescription>, Serializable { + + private static final long serialVersionUID = 1616892606319350318L; + + private String indexName; + private IndexFieldList indexFields; + + public IndexDescription(String name, IndexFieldList fields) { + indexName = name; + indexFields = fields; + } + + public String getIndexName() { + return indexName; + } + + public void setIndexName(String name) { + indexName = name; + } + + public IndexFieldList getIndexFieldList() { + return indexFields; + } + + public void setIndexFieldList(IndexFieldList fieldList) { + indexFields = fieldList; + } + + @Override + public int hashCode() { + return indexName.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof IndexDescription) { + IndexDescription that = (IndexDescription) o; + + return indexName.equals(that.indexName); + } + + return false; + } + + @Override + public int compareTo(IndexDescription o) { + return indexName.compareTo(o.indexName); + } + + @Override + public String toString() { + return indexName + "==> " + indexFields.toString(); + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexDescription.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexField.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexField.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexField.java 2011-06-24 06:10:13 UTC (rev 133) @@ -0,0 +1,59 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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.model; + +public class IndexField { + + private final String fieldName; + private final boolean ascending; + + public IndexField(String name, boolean asc) { + + fieldName = name; + ascending = asc; + } + + public String getFieldName() { + return fieldName; + } + + public boolean isAscending() { + return ascending; + } + + @Override + public int hashCode() { + return fieldName.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof IndexField) { + IndexField that = (IndexField) o; + return fieldName.equals(that.fieldName); + } + + return false; + } + + @Override + public String toString() { + return fieldName + (ascending ? ": ASC" : ": DESC"); + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexField.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexFieldList.java =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexFieldList.java (rev 0) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexFieldList.java 2011-06-24 06:10:13 UTC (rev 133) @@ -0,0 +1,66 @@ +/* + * mongobrowser - a webstart gui application for viewing, + * editing and administering a Mongo Database + * 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. + * 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.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +public class IndexFieldList implements Iterable<IndexField>, Serializable { + + private static final long serialVersionUID = -2452588491740324146L; + private final List<IndexField> indexFields = new ArrayList<IndexField>(); + + public IndexFieldList() { + } + + public IndexFieldList(Collection<IndexField> fields) { + indexFields.addAll(fields); + } + + public void add(String fieldName, boolean ascending) { + IndexField indexField = new IndexField(fieldName, ascending); + int index = indexFields.indexOf(indexField); + if (index < 0) { + indexFields.add(indexField); + } else { + indexFields.set(index, indexField); + } + } + + @Override + public Iterator<IndexField> iterator() { + return indexFields.iterator(); + } + + public int size() { + return indexFields.size(); + } + + public IndexField get(int index) { + return indexFields.get(index); + } + + @Override + public String toString() { + return indexFields.toString(); + } +} Property changes on: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/model/IndexFieldList.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties =================================================================== --- trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties 2011-06-23 03:53:16 UTC (rev 132) +++ trunk/mongobrowser/src/com/mebigfatguy/mongobrowser/resources/resource.properties 2011-06-24 06:10:13 UTC (rev 133) @@ -32,6 +32,7 @@ mongo.manageindices = Manage Indices... mongo.newobject = New Object mongo.newkeyvalue = New Key/Value... +mongo.editkeyvalue = Edit Key/Value... mongo.removeindex = Remove Index mongo.addindex = Add Index mongo.key = Key @@ -40,8 +41,12 @@ mongo.double = Double mongo.float = Float mongo.string = String +mongo.date = Date mongo.object = Object mongo.delete = Delete mongo.indexname = Index Name mongo.indexfields = Index Fields mongo.indexprefix = index_ +mongo.dateregex=(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\\s+([0-9]{1,2})(?:\\,)?\\s+([0-9]{4})\\s+([0-3][0-9](?::[0-6][0-9]){1,2})? +mongo.monthvalues=Jan:1,Feb:2,Mar:3,Apr:4,May:5,Jun:6,Jul:7,Aug:8,Sep:9,Oct:10,Nov:11,Dec:12 +mongo.dateformat=MMM d, yyyy HH:mm:ss \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |