Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- issue70: save to file dialog does not select files properly on osx

- issue49: cannot easily scroll the job bar and goes to beginning when closing job
- issue62: ability to update a specific field directly by right clicking
- issue67: unlock icon turns back to lock after clicking on db's collection
- issue73: by default no automatic tree updating, cause it can be slow in some situation
- issue57: gridfs download file throws exception that file is directory
- issue52: add "reset to default" button for all forms
- issue71: Allow copy field value from results
  • Loading branch information...
commit 4fadcb634f5a1691825a816b4970054a064d1da5 1 parent 9bcd771
@agirbal authored
Showing with 525 additions and 339 deletions.
  1. BIN  lib/SwingFast.jar
  2. BIN  lib/mongo.jar
  3. +14 −0 nbproject/build-impl.xml
  4. +3 −3 nbproject/genfiles.properties
  5. +3 −2 nbproject/project.properties
  6. +10 −1 nbproject/project.xml
  7. +1 −1  package/common-files/logging.properties
  8. +1 −0  package/osx/package.sh
  9. +1 −1  package/version
  10. BIN  resource/img/mongo-shield.png
  11. +35 −16 resource/xml/JMongoBrowser.xml
  12. +0 −15 resource/xml/docView.xml
  13. +0 −42 src/com/edgytech/jmongobrowser/DBObjectWrapper.java
  14. +2 −1  src/com/edgytech/jmongobrowser/DbNode.java
  15. +1 −1  src/com/edgytech/jmongobrowser/DocField.java
  16. +1 −39 src/com/edgytech/jmongobrowser/DocFieldText.java
  17. +31 −192 src/com/edgytech/jmongobrowser/DocView.java
  18. +160 −0 src/com/edgytech/jmongobrowser/DocumentFieldMenu.java
  19. +151 −0 src/com/edgytech/jmongobrowser/DocumentMenu.java
  20. +49 −1 src/com/edgytech/jmongobrowser/GlobalStore.java
  21. +6 −21 src/com/edgytech/jmongobrowser/MongoUtils.java
  22. +10 −3 src/com/edgytech/jmongobrowser/{TreeNodeDBObject.java → TreeNodeDocument.java}
  23. +46 −0 src/com/edgytech/jmongobrowser/TreeNodeDocumentField.java
View
BIN  lib/SwingFast.jar
Binary file not shown
View
BIN  lib/mongo.jar
Binary file not shown
View
14 nbproject/build-impl.xml
@@ -573,6 +573,13 @@ is divided into following sections:
<propertyfile file="${built-jar.properties}">
<entry key="${basedir}" value=""/>
</propertyfile>
+ <antcall target="-maybe-call-dep">
+ <param name="call.built.properties" value="${built-jar.properties}"/>
+ <param location="${project.SwingFast}" name="call.subproject"/>
+ <param location="${project.SwingFast}/build.xml" name="call.script"/>
+ <param name="call.target" value="jar"/>
+ <param name="transfer.built-jar.properties" value="${built-jar.properties}"/>
+ </antcall>
</target>
<target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
<target depends="init" name="-check-automatic-build">
@@ -1022,6 +1029,13 @@ is divided into following sections:
<propertyfile file="${built-clean.properties}">
<entry key="${basedir}" value=""/>
</propertyfile>
+ <antcall target="-maybe-call-dep">
+ <param name="call.built.properties" value="${built-clean.properties}"/>
+ <param location="${project.SwingFast}" name="call.subproject"/>
+ <param location="${project.SwingFast}/build.xml" name="call.script"/>
+ <param name="call.target" value="clean"/>
+ <param name="transfer.built-clean.properties" value="${built-clean.properties}"/>
+ </antcall>
</target>
<target depends="init" name="-do-clean">
<delete dir="${build.dir}"/>
View
6 nbproject/genfiles.properties
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=64f26677
+build.xml.data.CRC32=0d6a653a
build.xml.script.CRC32=9d7f4f72
build.xml.stylesheet.CRC32=28e38971@1.50.1.46
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=64f26677
-nbproject/build-impl.xml.script.CRC32=3b6ca0b4
+nbproject/build-impl.xml.data.CRC32=0d6a653a
+nbproject/build-impl.xml.script.CRC32=09b2de18
nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.1.46
View
5 nbproject/project.properties
@@ -28,14 +28,13 @@ dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.mongo.jar=lib/mongo.jar
-file.reference.SwingFast.jar=lib/SwingFast.jar
file.reference.trunk-resource=resource
file.reference.trunk-src=src
includes=**
jar.compress=false
javac.classpath=\
${file.reference.mongo.jar}:\
- ${file.reference.SwingFast.jar}
+ ${reference.SwingFast.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
@@ -66,6 +65,8 @@ manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
+project.SwingFast=../SwingFast/trunk
+reference.SwingFast.jar=${project.SwingFast}/dist/SwingFast.jar
resource.dir=${file.reference.trunk-resource}
run.classpath=\
${javac.classpath}:\
View
11 nbproject/project.xml
@@ -10,6 +10,15 @@
</source-roots>
<test-roots/>
</data>
- <references xmlns="http://www.netbeans.org/ns/ant-project-references/2"/>
+ <references xmlns="http://www.netbeans.org/ns/ant-project-references/2">
+ <reference>
+ <foreign-project>SwingFast</foreign-project>
+ <artifact-type>jar</artifact-type>
+ <script>${project.SwingFast}/build.xml</script>
+ <target>jar</target>
+ <clean-target>clean</clean-target>
+ <id>jar</id>
+ </reference>
+ </references>
</configuration>
</project>
View
2  package/common-files/logging.properties
@@ -1,2 +1,2 @@
handlers=java.util.logging.ConsoleHandler
-.level=INFO
+.level=FINE
View
1  package/osx/package.sh
@@ -23,6 +23,7 @@ function package_build {
cp ../dist/JMongoBrowser.jar $app/Contents/Resources/Java/
cp ../lib/*.jar $app/Contents/Resources/Java/
+ cp ./common-files/* $app/Contents/Resources/Java/
zip -r ${appdir}.zip $appdir
}
View
2  package/version
@@ -1 +1 @@
-1.1.2
+1.2.0
View
BIN  resource/img/mongo-shield.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
51 resource/xml/JMongoBrowser.xml
@@ -12,6 +12,25 @@
<IconGroup id="icons" folder="img" resource="true"/>
<IconGroup id="etIcons" folder="com/edgytech/swingfast/img" resource="true"/>
<com.edgytech.jmongobrowser.GlobalStore id="globalStore">
+ <com.edgytech.jmongobrowser.DocumentMenu id="documentMenu">
+ <MenuItem id="update" call="update" showDialog="false">
+ <FormDialog>
+ <com.edgytech.jmongobrowser.DocBuilderField id="upUpdate" label="Update" toolTipText="Update to apply to document, in JSON format"/>
+ </FormDialog>
+ </MenuItem>
+ <MenuItem id="remove" call="remove">
+ <ConfirmDialog text="Are you sure you want to remove this document?"/>
+ </MenuItem>
+ <MenuSeparator/>
+ <MenuItem id="copyValue" call="copyValue"/>
+ </com.edgytech.jmongobrowser.DocumentMenu>
+ <com.edgytech.jmongobrowser.DocumentFieldMenu id="documentFieldMenu">
+ <MenuItem id="set" call="set"/>
+ <MenuItem id="unset" call="unset"/>
+ <MenuSeparator/>
+ <MenuItem id="copyField" call="copyField"/>
+ <MenuItem id="copyValue" call="copyValue"/>
+ </com.edgytech.jmongobrowser.DocumentFieldMenu>
<com.edgytech.jmongobrowser.OptionDialog id="optionDialog">
<TabbedDiv>
<Div id="queryOption">
@@ -48,17 +67,17 @@
<IntSpinner id="autoCount" label="Count" minValue="0" value="100" toolTipText="Number of times to update, 0 means forever"/>
</com.edgytech.jmongobrowser.AutoUpdateDialog>
<com.edgytech.jmongobrowser.ExportDialog id="exportDialog">
- <FileChooserField id="outputFile">
- <FileChooserDialog type="SAVE" mode="FILES_ONLY"/>
- </FileChooserField>
+ <FileSelectorField id="outputFile">
+ <FileSelectorDialog type="SAVE" mode="FILES_ONLY"/>
+ </FileSelectorField>
<ComboBox id="format" items="JSON;JSON Array;CSV;BSON" toolTipText="Format to use for the export"/>
<TextField id="fields" toolTipText="Comma-separated list of fields to export, mandatory for CSV format"/>
<CheckBox id="continueOnError" toolTipText="Continue after an error occurs"/>
</com.edgytech.jmongobrowser.ExportDialog>
<com.edgytech.jmongobrowser.ImportDialog id="importDialog">
- <FileChooserField id="inputFile">
- <FileChooserDialog type="OPEN" mode="FILES_ONLY"/>
- </FileChooserField>
+ <FileSelectorField id="inputFile">
+ <FileSelectorDialog type="OPEN" mode="FILES_ONLY"/>
+ </FileSelectorField>
<ComboBox id="format" items="JSON;JSON Array;CSV;BSON" toolTipText="Format to use for the export"/>
<CheckBox id="continueOnError" toolTipText="Continue after an error occurs"/>
<CheckBox id="dropCollection" toolTipText="Drop collection before import"/>
@@ -210,9 +229,9 @@
<Menu id="GridFS" label="GridFS">
<MenuItem id="uploadFile" call="uploadFile">
<FormDialog id="uploadFileDialog">
- <FileChooserField id="uploadFilePath" label="Local File">
- <FileChooserDialog type="OPEN" selectionMode="FILES_ONLY"/>
- </FileChooserField>
+ <FileSelectorField id="uploadFilePath" label="Local File">
+ <FileSelectorDialog type="OPEN" selectionMode="FILES_ONLY"/>
+ </FileSelectorField>
<TextField id="uploadFileName" label="File Name" toolTipText="Optional, Name of the file as stored on the server"/>
<TextField id="uploadContentType" toolTipText="Optional, Content type to associate with file"/>
<com.edgytech.jmongobrowser.DocBuilderField id="uploadMetadata" label="Metadata" toolTipText="Optional, JSON object representing the file's metadata"/>
@@ -223,9 +242,9 @@
<Text value="Specify a query object or a file name"/>
<com.edgytech.jmongobrowser.DocBuilderField id="downloadQuery" label="Query" toolTipText="Find the file using this query"/>
<TextField id="downloadFileName" label="File Name" toolTipText="Name of the file as stored on the server"/>
- <FileChooserField id="downloadFilePath" label="Save As">
- <FileChooserDialog type="SAVE" selectionMode="FILES_ONLY"/>
- </FileChooserField>
+ <FileSelectorField id="downloadFilePath" label="Save As">
+ <FileSelectorDialog type="SAVE" selectionMode="FILES_ONLY"/>
+ </FileSelectorField>
</FormDialog>
</MenuItem>
<MenuItem id="deleteFile" call="deleteFile">
@@ -312,7 +331,7 @@
</FormDialog>
</MenuItem>
<MenuItem id="mapReduce" call="mapReduce">
- <FormDialog buttons="OK_CANCEL_RESET">
+ <FormDialog>
<TextArea id="mrMap" label="Map JS Function" toolTipText="map javascript function with signature 'void function map()' which should contain one or more calls to emit(key, obj)" nonEmpty="true" value="function(){ emit(this._id, {count: 1}); }"/>
<TextArea id="mrReduce" label="Reduce JS Function" toolTipText="reduce javascript function with signature 'result reduce(key, values)' where key is the emit key and values is the list of values to reduce.'" nonEmpty="true" value="function(key, values) { total = 0; for (var i = 0; i &lt; values.length; ++i) { total += values[i].count; }; return {count: total}; }"/>
<TextArea id="mrFinalize" label="Finalize JS Function" toolTipText="optional finalize javascript function with signature 'result finalize(key, out)' where out is the result for that key"/>
@@ -737,12 +756,12 @@
<MenuItem id="importFile" alt="i" call="importFile"/>
<MenuSeparator/>
<MenuItem id="preferences" alt="p" key="comma" keyMod="cmd">
- <com.edgytech.jmongobrowser.AppPreferences id="prefDialog" start="start" buttons="OK_CANCEL_RESET">
+ <com.edgytech.jmongobrowser.AppPreferences id="prefDialog" start="start">
<TabbedDiv id="optionTabs">
<Div id="general" gap="true">
<Div id="view" gap="true" titled="true">
- <IntSpinner id="treeUpdateRate" minValue="0" step="1000" value="10000" toolTipText="Rate in ms at which to update the Tree information (server down, master, etc). 0 means no automatic updating."/>
- <IntSpinner id="inlineDocumentLength" minValue="1" value="100" toolTipText="Number of characters to display for the document inline preview"/>
+ <IntSpinner id="treeUpdateRate" minValue="0" step="1000" value="0" toolTipText="Rate in ms at which to update the Tree information (server down, master, etc). 0 means no automatic updating."/>
+ <IntSpinner id="inlineDocumentLength" minValue="1" value="200" toolTipText="Number of characters to display for the document inline preview"/>
</Div>
<Div id="querying" gap="true" titled="true">
<IntSpinner id="getMoreSize" minValue="1" value="50" toolTipText="Number of documents to fetch when getting more results from a cursor"/>
View
15 resource/xml/docView.xml
@@ -15,10 +15,6 @@
<Text label=" "/>
<Button id="tabClose" icon="dialog-close_16.png" iconGroup="icons" call="close" fixedSize="20;20"/>
</Div>
- <PopUpMenu id="popUp">
- <MenuItem id="popUpdate" label="Update" call="update"/>
- <MenuItem id="popRemove" label="Remove" call="remove"/>
- </PopUpMenu>
</XmlUnit>
<MenuBar zone="NORTH" id="menuBar">
<Text id="icon" icon="page_table.png" iconGroup="icons" toolTipText="Index"/>
@@ -33,17 +29,6 @@
<MenuItem id="expandAll" call="expandAll"/>
<MenuItem id="collapseAll" call="collapseAll"/>
</Menu>
- <Menu id="document" enabled="false">
- <MenuItem id="update" call="update" showDialog="false">
- <FormDialog>
- <com.edgytech.jmongobrowser.DocBuilderField id="upUpdate" label="Update" toolTipText="Update to apply to document, in JSON format"/>
- <CheckBox id="upMulti" label="Multi" toolTipText="Update all matched documents"/>
- </FormDialog>
- </MenuItem>
- <MenuItem id="remove" call="remove">
- <ConfirmDialog text="Remove document?"/>
- </MenuItem>
- </Menu>
<Menu id="tools">
<MenuItem id="startAutoUpdate" call="startAutoUpdate" enabled="false"/>
<MenuItem id="stopAutoUpdate" call="stopAutoUpdate" enabled="false"/>
View
42 src/com/edgytech/jmongobrowser/DBObjectWrapper.java
@@ -1,42 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package com.edgytech.jmongobrowser;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBObject;
-
-/**
- *
- * @author antoine
- */
-public class DBObjectWrapper {
- Object key;
- DBObject obj;
-
- public DBObjectWrapper(Object key, DBObject obj) {
- this.key = key;
- this.obj = obj;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- if (key != null)
- sb.append(key).append(": ");
- sb.append(MongoUtils.dbObjectToString(obj));
- return sb.toString();
- }
-
- public Object getKey() {
- return key;
- }
-
- public DBObject getDBObject() {
- return obj;
- }
-
-
-}
View
3  src/com/edgytech/jmongobrowser/DbNode.java
@@ -5,6 +5,7 @@
package com.edgytech.jmongobrowser;
import com.edgytech.swingfast.SwingFast;
+import com.mongodb.BasicDBObject;
import com.mongodb.CommandResult;
import com.mongodb.DB;
import com.mongodb.DBCollection;
@@ -56,7 +57,7 @@ protected void updateNode(List<ImageIcon> overlays) {
label = db.getName();
// db.getStats is too slow.. just do a quick command
// CommandResult res = db.getStats();
- CommandResult res = db.command("getLastError");
+ CommandResult res = db.command(new BasicDBObject("profile", -1));
res.throwOnError();
// label += " (" + res.getInt("objects") + "/" + res.getInt("dataSize") + ")";
View
2  src/com/edgytech/jmongobrowser/DocField.java
@@ -58,7 +58,7 @@ public void setDoc(DBObject doc) {
return;
}
- value = MongoUtils.dbObjectToString(doc);
+ value = MongoUtils.getObjectString(doc);
}
public DBObject getDoc() {
View
40 src/com/edgytech/jmongobrowser/DocFieldText.java
@@ -73,46 +73,8 @@ public DocFieldText(String id, String key, Object value, DocFieldObject object)
}
public void edit() {
- Class ceditor = null;
- if (value == null) {
- ceditor = null;
- } else if (value instanceof String) {
- ceditor = EditStringDialog.class;
- } else if (value instanceof Binary) {
- ceditor = EditBinaryDialog.class;
- } else if (value instanceof ObjectId || value instanceof DBRefBase) {
- ceditor = EditObjectIdDialog.class;
- } else if (value instanceof Boolean) {
- ceditor = EditBooleanDialog.class;
- } else if (value instanceof Code || value instanceof CodeWScope) {
- ceditor = EditCodeDialog.class;
- } else if (value instanceof Date) {
- ceditor = EditDateDialog.class;
- } else if (value instanceof Double || value instanceof Float) {
- ceditor = EditDoubleDialog.class;
- } else if (value instanceof Long || value instanceof Integer) {
- ceditor = EditLongDialog.class;
- } else if (value instanceof Pattern) {
- ceditor = EditPatternDialog.class;
- } else if (value instanceof BSONTimestamp) {
- ceditor = EditTimestampDialog.class;
- } else if (value instanceof UUID) {
- ceditor = EditUuidDialog.class;
- }
-
- if (ceditor == null)
- return;
- EditFieldDialog editor = (EditFieldDialog) JMongoBrowser.instance.getGlobalStore().getFirstChildOfClass(ceditor, null);
- editor.setKey(key);
- editor.setValue(value);
-
- if (!editor.show()) {
- return;
- }
- value = editor.getValue();
+ value = JMongoBrowser.instance.getGlobalStore().editValue(key, value);
setStringFieldValue(Item.value, JSON.serialize(value));
- System.out.println(value.toString());
- System.out.println(JSON.serialize(value));
updateComponent();
_object.commitComponent();
}
View
223 src/com/edgytech/jmongobrowser/DocView.java
@@ -45,17 +45,6 @@
cursor,
getMore,
getAll,
- document,
- remove,
- duplicate,
- dupCount,
- update,
- upUpdate,
- upMulti,
- popUp,
- popUpdate,
- popDuplicate,
- popRemove,
tools,
startAutoUpdate,
stopAutoUpdate,
@@ -107,7 +96,6 @@ public DocView(String id, String label, Iterator<DBObject> iterator, Object root
this.dbcursor = (DBCursor) iterator;
this.iterator = dbcursor;
((MenuItem) getBoundUnit(Item.refresh)).enabled = true;
- ((Menu) getBoundUnit(Item.document)).enabled = true;
((MenuItem) getBoundUnit(Item.startAutoUpdate)).enabled = true;
} else {
this.iterator = iterator;
@@ -144,20 +132,21 @@ Tree getTree() {
return (Tree) getBoundUnit(Item.docTree);
}
+ public DBCursor getDBCursor() {
+ return dbcursor;
+ }
+
public void close() {
if (dbcursor != null) {
dbcursor.close();
dbcursor = null;
}
- tabbedDiv.removeChild(this);
- tabbedDiv.structureComponent();
+ tabbedDiv.removeTab(this);
}
void addToTabbedDiv() {
tabbedDiv = JMongoBrowser.instance.getTabbedResult();
- tabbedDiv.addChild(this);
- tabbedDiv.structureComponent();
- tabbedDiv.selectLastTab();
+ tabbedDiv.addTab(this, true);
getTree().expandNode(getTree().getTreeNode());
}
@@ -180,10 +169,10 @@ public void export() throws IOException {
DBObject doc = null;
if (obj instanceof DBObject) {
doc = (DBObject) obj;
- } else if (obj instanceof DBObjectWrapper) {
- doc = ((DBObjectWrapper) obj).getDBObject();
- } else if (obj instanceof TreeNodeDBObject) {
- doc = ((TreeNodeDBObject) obj).getDBObject();
+ } else if (obj instanceof TreeNodeDocumentField) {
+ doc = (DBObject) ((TreeNodeDocumentField) obj).getValue();
+ } else if (obj instanceof TreeNodeDocument) {
+ doc = ((TreeNodeDocument) obj).getDBObject();
}
if (doc != null) {
os.writeObject(doc);
@@ -382,7 +371,7 @@ public DefaultMutableTreeNode getSelectedNode() {
if (path == null || path.getPathCount() < 2) {
return null;
}
- return (DefaultMutableTreeNode) path.getPathComponent(1);
+ return (DefaultMutableTreeNode) path.getLastPathComponent();
}
public DBObject getSelectedDocument() {
@@ -390,122 +379,32 @@ public DBObject getSelectedDocument() {
if (path == null || path.getPathCount() < 2) {
return null;
}
- DefaultMutableTreeNode node = getSelectedNode();
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getPathComponent(1);
Object obj = node.getUserObject();
- if (obj instanceof DBObjectWrapper) {
- return ((DBObjectWrapper) obj).getDBObject();
+ if (obj instanceof TreeNodeDocumentField) {
+ return (DBObject) ((TreeNodeDocumentField) obj).getValue();
} else if (obj instanceof DBObject) {
return (DBObject) obj;
- } else if (obj instanceof TreeNodeDBObject) {
- return ((TreeNodeDBObject) obj).getDBObject();
+ } else if (obj instanceof TreeNodeDocument) {
+ return ((TreeNodeDocument) obj).getDBObject();
}
return null;
}
-
- public void remove() {
- DBObject doc = getSelectedDocument();
- if (doc == null) {
- return;
- }
-
- if (!((MenuItem) getBoundUnit(Item.remove)).getDialog().show()) {
- return;
- }
-
- if (dbcursor == null) {
- getTree().removeChild((TreeNodeDBObject) getSelectedNode().getUserObject());
- getTree().structureComponent();
- getTree().expandNode(getTree().getTreeNode());
- return;
+
+ String getSelectedDocumentPath() {
+ TreePath path = getTree().getSelectionPath();
+ String pathStr = "";
+ if (path.getPathCount() < 2)
+ return null;
+ for (int i = 2; i < path.getPathCount(); ++i) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getPathComponent(i);
+ String key = ((TreeNodeDocumentField) node.getUserObject()).getKey();
+ pathStr += "." + key;
}
-
- // go by _id if possible
- final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc;
- new DbJob() {
-
- @Override
- public Object doRun() throws IOException {
- return dbcursor.getCollection().remove(query);
- }
-
- @Override
- public String getNS() {
- return dbcursor.getCollection().getFullName();
- }
-
- @Override
- public String getShortName() {
- return "Remove";
- }
-
- @Override
- public void wrapUp(Object res) {
- super.wrapUp(res);
- updateCursor();
- }
-
- @Override
- public Object getRoot(Object result) {
- return query;
- }
- }.addJob();
+ return pathStr.substring(1);
}
-// public void duplicate() {
-// final DBObject doc = getSelectedDocument();
-// if (doc == null) {
-// return;
-// }
-// final int num = getIntFieldValue(Item.dupCount);
-//
-// if (dbcursor == null) {
-// for (int i = 0; i < num; ++i) {
-// DBObject newdoc = new BasicDBObject(doc.toMap());
-// newdoc.removeField("_id");
-// addDocument(newdoc);
-// }
-// getTree().structureComponent();
-// getTree().expandNode(getTree().getTreeNode());
-// return;
-// }
-//
-// new DbJob() {
-//
-// @Override
-// public Object doRun() throws IOException {
-// List list = new ArrayList(num);
-// for (int i = 0; i < num; ++i) {
-// DBObject newdoc = new BasicDBObject(doc.toMap());
-// newdoc.removeField("_id");
-// list.add(newdoc);
-// }
-// return dbcursor.getCollection().insert(list);
-// }
-//
-// @Override
-// public String getNS() {
-// return dbcursor.getCollection().getFullName();
-// }
-//
-// @Override
-// public String getShortName() {
-// return "Duplicate";
-// }
-//
-// @Override
-// public void wrapUp(Object res) {
-// super.wrapUp(res);
-// updateCursor();
-// }
-//
-// @Override
-// public Object getRoot(Object result) {
-// return doc;
-// }
-// }.addJob();
-// }
-
- private void updateCursor() {
+ public void updateCursor() {
if (dbcursor == null) {
return;
}
@@ -559,72 +458,12 @@ private void updateButtons() {
getComponentBoundUnit(Item.getAll).updateComponent();
}
- public void update() {
- final DBObject doc = getSelectedDocument();
- if (doc == null) {
- return;
- }
-
- ((DocBuilderField) getBoundUnit(Item.upUpdate)).setDBObject((BasicDBObject) doc);
- if (!((MenuItem) getBoundUnit(Item.update)).getDialog().show()) {
- return;
- }
-
- final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc;
- final DBObject update = ((DocBuilderField) getBoundUnit(Item.upUpdate)).getDBObject();
- final boolean multi = getBooleanFieldValue(Item.upMulti);
-
- if (dbcursor == null) {
- getTree().removeChild((TreeNodeDBObject) getSelectedNode().getUserObject());
- addDocument(update, null);
- getTree().structureComponent();
- getTree().expandNode(getTree().getTreeNode());
- return;
- }
-
- final DBCollection col = dbcursor.getCollection();
- new DbJob() {
-
- @Override
- public Object doRun() {
- return col.update(query, update, false, multi);
- }
-
- @Override
- public String getNS() {
- return col.getFullName();
- }
-
- @Override
- public String getShortName() {
- return "Update";
- }
-
- @Override
- public Object getRoot(Object result) {
- StringBuilder sb = new StringBuilder();
- sb.append("query=").append(query);
- sb.append(", update=").append(update);
- sb.append(", multi=").append(multi);
- return sb.toString();
- }
-
- @Override
- public void wrapUp(Object res) {
- super.wrapUp(res);
- updateCursor();
- }
- }.addJob();
- }
-
- private void addDocument(DBObject doc, DbJob job) {
+ public void addDocument(DBObject doc, DbJob job) {
addDocument(doc, job, false);
}
- private void addDocument(DBObject doc, DbJob job, boolean expand) {
- TreeNodeLabel node = new TreeNodeDBObject(doc, job);
- final PopUpMenu popUp = (PopUpMenu) getBoundUnit(Item.popUp);
- node.setPopUpMenu(popUp);
+ public void addDocument(DBObject doc, DbJob job, boolean expand) {
+ TreeNodeLabel node = new TreeNodeDocument(doc, job);
getTree().addChild(node);
if (expand)
getTree().expandNode(node);
View
160 src/com/edgytech/jmongobrowser/DocumentFieldMenu.java
@@ -0,0 +1,160 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.edgytech.jmongobrowser;
+
+import com.edgytech.jmongobrowser.DocumentFieldMenu.Item;
+import com.edgytech.swingfast.EnumListener;
+import com.edgytech.swingfast.InfoDialog;
+import com.edgytech.swingfast.PopUpMenu;
+import com.edgytech.swingfast.XmlComponentUnit;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
+
+/**
+ *
+ * @author antoine
+ */
+public class DocumentFieldMenu extends PopUpMenu implements EnumListener<Item> {
+
+ enum Item {
+ set,
+ unset,
+ copyField,
+ copyValue
+ }
+
+ public DocumentFieldMenu() {
+ setEnumBinding(Item.values(), this);
+ }
+
+ @Override
+ public void actionPerformed(Item enm, XmlComponentUnit unit, Object src) {
+ }
+
+ public void set() {
+ final DocView dv = (DocView) (JMongoBrowser.instance.getTabbedResult().getSelectedUnit());
+ TreeNodeDocumentField field = (TreeNodeDocumentField) dv.getSelectedNode().getUserObject();
+ DBObject doc = dv.getSelectedDocument();
+ String path = dv.getSelectedDocumentPath();
+ Object newValue = JMongoBrowser.instance.getGlobalStore().editValue(field.getKey(), field.getValue());
+
+ if (newValue == null) {
+ new InfoDialog(null, null, null, "Cannot edit this type of data.").show();
+ return;
+ }
+ if (dv.getDBCursor() == null) {
+ // local data
+ new InfoDialog(null, null, null, "Cannot do in-place update on local data.").show();
+ return;
+ }
+
+ final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc;
+ DBObject setValue = new BasicDBObject(path, newValue);
+ final DBObject update = new BasicDBObject("$set", setValue);
+
+ final DBCollection col = dv.getDBCursor().getCollection();
+ new DbJob() {
+
+ @Override
+ public Object doRun() {
+ return col.update(query, update, false, false);
+ }
+
+ @Override
+ public String getNS() {
+ return col.getFullName();
+ }
+
+ @Override
+ public String getShortName() {
+ return "Update";
+ }
+
+ @Override
+ public Object getRoot(Object result) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("query=").append(query);
+ sb.append(", update=").append(update);
+ return sb.toString();
+ }
+
+ @Override
+ public void wrapUp(Object res) {
+ super.wrapUp(res);
+ dv.updateCursor();
+ }
+ }.addJob();
+ }
+
+ public void unset() {
+ final DocView dv = (DocView) (JMongoBrowser.instance.getTabbedResult().getSelectedUnit());
+ DBObject doc = dv.getSelectedDocument();
+ String path = dv.getSelectedDocumentPath();
+
+ if (dv.getDBCursor() == null) {
+ // local data
+ new InfoDialog(null, null, null, "Cannot do in-place update on local data.").show();
+ return;
+ }
+
+ final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc;
+ DBObject setValue = new BasicDBObject(path, 1);
+ final DBObject update = new BasicDBObject("$unset", setValue);
+
+ final DBCollection col = dv.getDBCursor().getCollection();
+ new DbJob() {
+
+ @Override
+ public Object doRun() {
+ return col.update(query, update, false, false);
+ }
+
+ @Override
+ public String getNS() {
+ return col.getFullName();
+ }
+
+ @Override
+ public String getShortName() {
+ return "Update";
+ }
+
+ @Override
+ public Object getRoot(Object result) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("query=").append(query);
+ sb.append(", update=").append(update);
+ return sb.toString();
+ }
+
+ @Override
+ public void wrapUp(Object res) {
+ super.wrapUp(res);
+ dv.updateCursor();
+ }
+ }.addJob();
+ }
+
+ public void copyField() {
+ final DocView dv = (DocView) (JMongoBrowser.instance.getTabbedResult().getSelectedUnit());
+ TreeNodeDocumentField node = (TreeNodeDocumentField) dv.getSelectedNode().getUserObject();
+ StringSelection data = new StringSelection(node.getKey().toString());
+ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ clipboard.setContents(data, data);
+ }
+
+ public void copyValue() {
+ final DocView dv = (DocView) (JMongoBrowser.instance.getTabbedResult().getSelectedUnit());
+ TreeNodeDocumentField node = (TreeNodeDocumentField) dv.getSelectedNode().getUserObject();
+ StringSelection data = new StringSelection(node.getValue().toString());
+ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ clipboard.setContents(data, data);
+ }
+
+}
View
151 src/com/edgytech/jmongobrowser/DocumentMenu.java
@@ -0,0 +1,151 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.edgytech.jmongobrowser;
+
+import com.edgytech.jmongobrowser.DocumentMenu.Item;
+import com.edgytech.swingfast.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
+
+/**
+ *
+ * @author antoine
+ */
+public class DocumentMenu extends PopUpMenu implements EnumListener<Item> {
+
+ enum Item {
+ update,
+ upUpdate,
+ remove,
+ copyValue
+ }
+
+ public DocumentMenu() {
+ setEnumBinding(Item.values(), this);
+ }
+
+ @Override
+ public void actionPerformed(Item enm, XmlComponentUnit unit, Object src) {
+ }
+
+ public void update() {
+ final DocView dv = (DocView) (JMongoBrowser.instance.getTabbedResult().getSelectedUnit());
+ TreeNodeDocument node = (TreeNodeDocument) dv.getSelectedNode().getUserObject();
+ final DBObject doc = node.getDBObject();
+
+ ((DocBuilderField) getBoundUnit(Item.upUpdate)).setDBObject((BasicDBObject) doc);
+ if (!((MenuItem) getBoundUnit(Item.update)).getDialog().show()) {
+ return;
+ }
+
+ final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc;
+ final DBObject update = ((DocBuilderField) getBoundUnit(Item.upUpdate)).getDBObject();
+
+ if (dv.getDBCursor() == null) {
+ // local data
+ Tree tree = dv.getTree();
+ tree.removeChild(node);
+ dv.addDocument(update, null);
+ tree.structureComponent();
+ tree.expandNode(tree.getTreeNode());
+ return;
+ }
+
+ final DBCollection col = dv.getDBCursor().getCollection();
+ new DbJob() {
+
+ @Override
+ public Object doRun() {
+ return col.update(query, update, false, false);
+ }
+
+ @Override
+ public String getNS() {
+ return col.getFullName();
+ }
+
+ @Override
+ public String getShortName() {
+ return "Update";
+ }
+
+ @Override
+ public Object getRoot(Object result) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("query=").append(query);
+ sb.append(", update=").append(update);
+ return sb.toString();
+ }
+
+ @Override
+ public void wrapUp(Object res) {
+ super.wrapUp(res);
+ dv.updateCursor();
+ }
+ }.addJob();
+ }
+
+ public void remove() {
+ final DocView dv = (DocView) (JMongoBrowser.instance.getTabbedResult().getSelectedUnit());
+ TreeNodeDocument node = (TreeNodeDocument) dv.getSelectedNode().getUserObject();
+ final DBObject doc = node.getDBObject();
+
+ if (dv.getDBCursor() == null) {
+ // local data
+ Tree tree = dv.getTree();
+ tree.removeChild(node);
+ tree.structureComponent();
+ tree.expandNode(tree.getTreeNode());
+ return;
+ }
+
+ // go by _id if possible
+ final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc;
+ final DBCollection col = dv.getDBCursor().getCollection();
+ new DbJob() {
+
+ @Override
+ public Object doRun() {
+ return col.remove(query);
+ }
+
+ @Override
+ public String getNS() {
+ return col.getFullName();
+ }
+
+ @Override
+ public String getShortName() {
+ return "Remove";
+ }
+
+ @Override
+ public void wrapUp(Object res) {
+ super.wrapUp(res);
+ dv.updateCursor();
+ }
+
+ @Override
+ public Object getRoot(Object result) {
+ return query;
+ }
+ }.addJob();
+ }
+
+ public void copyValue() {
+ final DocView dv = (DocView) (JMongoBrowser.instance.getTabbedResult().getSelectedUnit());
+ TreeNodeDocument node = (TreeNodeDocument) dv.getSelectedNode().getUserObject();
+ final DBObject doc = node.getDBObject();
+ String selection = doc.toString();
+ StringSelection data = new StringSelection(selection);
+ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ clipboard.setContents(data, data);
+ }
+
+}
View
50 src/com/edgytech/jmongobrowser/GlobalStore.java
@@ -7,6 +7,11 @@
import com.edgytech.swingfast.ConfirmDialog;
import com.edgytech.swingfast.XmlUnit;
+import com.mongodb.DBRefBase;
+import java.util.Date;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.bson.types.*;
/**
*
@@ -28,7 +33,9 @@
importDialog,
autoUpdateDialog,
docBuilderDialog,
- lockingOperationDialog
+ lockingOperationDialog,
+ documentMenu,
+ documentFieldMenu
}
public GlobalStore() {
@@ -96,4 +103,45 @@ boolean confirmLockingOperation() {
return false;
return true;
}
+
+ public Object editValue(String key, Object value) {
+ Class ceditor = null;
+ if (value == null) {
+ ceditor = null;
+ } else if (value instanceof String) {
+ ceditor = EditStringDialog.class;
+ } else if (value instanceof Binary) {
+ ceditor = EditBinaryDialog.class;
+ } else if (value instanceof ObjectId || value instanceof DBRefBase) {
+ ceditor = EditObjectIdDialog.class;
+ } else if (value instanceof Boolean) {
+ ceditor = EditBooleanDialog.class;
+ } else if (value instanceof Code || value instanceof CodeWScope) {
+ ceditor = EditCodeDialog.class;
+ } else if (value instanceof Date) {
+ ceditor = EditDateDialog.class;
+ } else if (value instanceof Double || value instanceof Float) {
+ ceditor = EditDoubleDialog.class;
+ } else if (value instanceof Long || value instanceof Integer) {
+ ceditor = EditLongDialog.class;
+ } else if (value instanceof Pattern) {
+ ceditor = EditPatternDialog.class;
+ } else if (value instanceof BSONTimestamp) {
+ ceditor = EditTimestampDialog.class;
+ } else if (value instanceof UUID) {
+ ceditor = EditUuidDialog.class;
+ }
+
+ if (ceditor == null)
+ return null;
+ EditFieldDialog editor = (EditFieldDialog) getFirstChildOfClass(ceditor, null);
+ editor.setKey(key);
+ editor.setValue(value);
+
+ if (!editor.show()) {
+ return value;
+ }
+
+ return editor.getValue();
+ }
}
View
27 src/com/edgytech/jmongobrowser/MongoUtils.java
@@ -48,16 +48,6 @@ public static String queryOptionsToString(int options) {
return opt;
}
- public static DefaultMutableTreeNode dbObjectToTreeNode(DBObject obj) {
- return dbObjectToTreeNode(null, obj);
- }
-
- public static DefaultMutableTreeNode dbObjectToTreeNode(Object objkey, DBObject obj) {
- DefaultMutableTreeNode node = new DefaultMutableTreeNode(new DBObjectWrapper(objkey, obj));
- addChildrenToTreeNode(node, obj);
- return node;
- }
-
public static void addChildrenToTreeNode(DefaultMutableTreeNode node, DBObject obj) {
for (String key : obj.keySet()) {
Object val = obj.get(key);
@@ -65,15 +55,10 @@ public static void addChildrenToTreeNode(DefaultMutableTreeNode node, DBObject o
continue;
}
- DefaultMutableTreeNode child = null;
+ DefaultMutableTreeNode child = new DefaultMutableTreeNode(new TreeNodeDocumentField(key, val));
if (val instanceof DBObject) {
- child = dbObjectToTreeNode(key, (DBObject) val);
- } else {
- String str = key + " : " + JSON.serialize(val);
- child = new DefaultMutableTreeNode(limitString(str, 0));
- }
-
- if (val instanceof ObjectId) {
+ addChildrenToTreeNode(child, (DBObject) val);
+ } else if (val instanceof ObjectId) {
// break it down
ObjectId id = (ObjectId) val;
child.add(new DefaultMutableTreeNode("Time: " + id.getTime() + " = " + new Date(id.getTime()).toString()));
@@ -84,11 +69,11 @@ public static void addChildrenToTreeNode(DefaultMutableTreeNode node, DBObject o
}
}
- public static String dbObjectToString(DBObject obj) {
- return dbObjectToString(obj, 0);
+ public static String getObjectString(Object obj) {
+ return getObjectString(obj, 0);
}
- public static String dbObjectToString(DBObject obj, int limit) {
+ public static String getObjectString(Object obj, int limit) {
return limitString(obj.toString(), limit);
}
View
13 src/com/edgytech/jmongobrowser/TreeNodeDBObject.java → src/com/edgytech/jmongobrowser/TreeNodeDocument.java
@@ -5,6 +5,7 @@
package com.edgytech.jmongobrowser;
+import com.edgytech.swingfast.PopUpMenu;
import com.edgytech.swingfast.TreeNodeLabel;
import com.mongodb.DBObject;
@@ -12,11 +13,11 @@
*
* @author antoine
*/
-public class TreeNodeDBObject extends TreeNodeLabel {
+public class TreeNodeDocument extends TreeNodeLabel {
DBObject dbobject;
DbJob job;
- public TreeNodeDBObject(DBObject dbobject, DbJob job) {
+ public TreeNodeDocument(DBObject dbobject, DbJob job) {
this.dbobject = dbobject;
this.job = job;
MongoUtils.addChildrenToTreeNode(getTreeNode(), dbobject);
@@ -29,9 +30,15 @@ public DBObject getDBObject() {
@Override
public String toString() {
- String str = MongoUtils.dbObjectToString(dbobject);
+ String str = MongoUtils.getObjectString(dbobject);
if (job != null)
str += " in " + job.getRunTime() + "ms";
return str;
}
+
+ @Override
+ public PopUpMenu getPopUpMenu() {
+ return (PopUpMenu) JMongoBrowser.instance.getGlobalStore().getBoundUnit(GlobalStore.Item.documentMenu);
+ }
+
}
View
46 src/com/edgytech/jmongobrowser/TreeNodeDocumentField.java
@@ -0,0 +1,46 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.edgytech.jmongobrowser;
+
+import com.edgytech.swingfast.PopUpMenu;
+import com.edgytech.swingfast.TreeNodeLabel;
+
+/**
+ *
+ * @author antoine
+ */
+public class TreeNodeDocumentField extends TreeNodeLabel {
+ String key;
+ Object value;
+
+ public TreeNodeDocumentField(String key, Object value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ if (key != null)
+ sb.append(key).append(": ");
+ sb.append(MongoUtils.getObjectString(value));
+ return sb.toString();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ @Override
+ public PopUpMenu getPopUpMenu() {
+ return (PopUpMenu) JMongoBrowser.instance.getGlobalStore().getBoundUnit(GlobalStore.Item.documentFieldMenu);
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.