Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Manage Mongo Database.

  • Loading branch information...
commit 84177abf07eb81af78e2f53003e6cab0f17f92c0 1 parent 14944f5
@angelozerr angelozerr authored
Showing with 577 additions and 155 deletions.
  1. +7 −2 com.mongodb.tools/src/com/mongodb/tools/driver/MongoDriverHelper.java
  2. +1 −1  ....ide.launching/src/fr/opensagres/mongodb/ide/launching/internal/launchConfigurations/mongod/PingThread.java
  3. +2 −2 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/extensions/AbstractServerFactory.java
  4. +1 −1  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/extensions/IServerFactory.java
  5. +22 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/internal/Messages.java
  6. +8 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/internal/Messages.properties
  7. +8 −3 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/internal/settings/ServersContentHandler.java
  8. +24 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/AbstractCollection.java
  9. +52 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/AbstractCollectionsCategory.java
  10. +23 −1 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/AbstractServer.java
  11. +1 −0  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/Error.java
  12. +5 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ICollection.java
  13. +5 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ICollectionsCategory.java
  14. +0 −2  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/IDatabase.java
  15. +2 −0  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/IServer.java
  16. +2 −0  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ITreeContainerNode.java
  17. +2 −0  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ITreeSimpleNode.java
  18. +4 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/TreeSimpleNode.java
  19. +17 −2 ...osql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/extensions/ConnectServerRunner.java
  20. +1 −1  ...nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/extensions/MongoServerFactory.java
  21. +16 −0 ...ql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/shell/DBAuthenticateShellCommand.java
  22. +15 −0 ...l.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/shell/ShowCollectionsShellCommand.java
  23. +14 −0 ...nsagres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/shell/UseShellCommand.java
  24. +19 −0 fr.opensagres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/Collection.java
  25. +24 −0 fr.opensagres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/CollectionsCategory.java
  26. +45 −1 fr.opensagres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/Database.java
  27. +6 −4 fr.opensagres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/MongoServer.java
  28. +33 −0 ...nsagres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/shell/MongoShellCommandManager.java
  29. +9 −8 fr.opensagres.nosql.ide.orientdb.core/src/fr/opensagres/nosql/ide/orientdb/core/model/OrientServer.java
  30. +4 −2 ...s.nosql.ide.orientdb.core/src/fr/opensagres/nosql/ide/orientdb/core/model/internal/OrientServerFactory.java
  31. +7 −6 ...agres.nosql.ide.orientdb.ui/src/fr/opensagres/nosql/ide/orientdb/ui/wizards/server/NewServerWizardPage.java
  32. BIN  fr.opensagres.nosql.ide.ui/icons/obj16/command.gif
  33. +5 −2 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/ImageResources.java
  34. +10 −2 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/viewers/ServerLabelProvider.java
  35. +20 −0 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/viewers/ShellCommandContentProvider.java
  36. +32 −0 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/viewers/ShellCommandLabelProvider.java
  37. +80 −115 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/views/ShellCommandsView.java
  38. +51 −0 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/views/ShellServerItem.java
View
9 com.mongodb.tools/src/com/mongodb/tools/driver/MongoDriverHelper.java
@@ -61,8 +61,13 @@ public static void stopMongoServer(Mongo mongo, String username,
shutdownResult.throwOnError();
}
- public static void tryConnection(Mongo mongo) throws MongoException {
- mongo.getDatabaseNames();
+ public static void tryConnection(Mongo mongo, String dbname)
+ throws MongoException {
+ if (dbname == null || dbname.length() < 1) {
+ mongo.getDatabaseNames();
+ } else {
+ mongo.getDB(dbname).getCollectionNames();
+ }
}
/**
View
2  .../fr/opensagres/mongodb/ide/launching/internal/launchConfigurations/mongod/PingThread.java
@@ -72,7 +72,7 @@ protected void ping() {
count++;
Trace.trace(Trace.STRING_FINEST, "Ping: pinging " + count);
- MongoDriverHelper.tryConnection(server.getMongo());
+ MongoDriverHelper.tryConnection(server.getMongo(), server.getDatabaseName());
// ping worked - server is up
if (!stop) {
View
4 ...res.nosql.ide.core/src/fr/opensagres/nosql/ide/core/extensions/AbstractServerFactory.java
@@ -9,7 +9,7 @@
public abstract class AbstractServerFactory implements IServerFactory {
- public IServer create(Attributes attributes) {
+ public IServer create(Attributes attributes) throws Exception {
String id = attributes.getValue(ServersConstants.ID_ATTR);
String name = attributes.getValue(ServersConstants.NAME_ATTR);
String url = attributes.getValue(ServersConstants.URL_ATTR);
@@ -36,5 +36,5 @@ public IServer create(Attributes attributes) {
}
protected abstract IServer doCreate(String id, String name, String url,
- Attributes attributes);
+ Attributes attributes) throws Exception ;
}
View
2  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/extensions/IServerFactory.java
@@ -6,6 +6,6 @@
public interface IServerFactory {
- IServer create(Attributes attributes);
+ IServer create(Attributes attributes) throws Exception;
}
View
22 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/internal/Messages.java
@@ -0,0 +1,22 @@
+package fr.opensagres.nosql.ide.core.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "fr.opensagres.nosql.ide.core.internal.Messages";//$NON-NLS-1$
+
+ public static String errorStopAlreadyStopped;
+
+ public static String Collections_label;
+ public static String GridFS_label;
+ public static String StoredJavascript_label;
+ public static String Users_label;
+ public static String Indexes_label;
+
+ static {
+ // load message values from bundle file
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+}
View
8 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/internal/Messages.properties
@@ -0,0 +1,8 @@
+errorStopAlreadyStopped=The server cannot be stopped because it is already stopped or stopping.
+
+# Static name of the nodes of tree of server explorer
+Collections_label=Collections
+GridFS_label=GridFS
+StoredJavascript_label=Stored Javascript
+Users_label=Users
+Indexes_label=Indexes
View
11 ...ql.ide.core/src/fr/opensagres/nosql/ide/core/internal/settings/ServersContentHandler.java
@@ -8,6 +8,7 @@
import fr.opensagres.nosql.ide.core.Platform;
import fr.opensagres.nosql.ide.core.extensions.IServerFactory;
import fr.opensagres.nosql.ide.core.extensions.IServerType;
+import fr.opensagres.nosql.ide.core.internal.Trace;
import fr.opensagres.nosql.ide.core.model.IServer;
import fr.opensagres.nosql.ide.core.settings.ServersConstants;
import fr.opensagres.nosql.ide.core.utils.StringUtils;
@@ -31,9 +32,13 @@ public void startElement(String uri, String localName, String qName,
IServerFactory factory = Platform
.getServerFactoryRegistry().getFactory(serverType);
if (factory != null) {
- IServer server = factory.create(attributes);
- if (server != null) {
- super.list.add(server);
+ try {
+ IServer server = factory.create(attributes);
+ if (server != null) {
+ super.list.add(server);
+ }
+ } catch (Exception e) {
+ Trace.trace(Trace.STRING_SEVERE, e.getMessage());
}
}
}
View
24 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/AbstractCollection.java
@@ -0,0 +1,24 @@
+package fr.opensagres.nosql.ide.core.model;
+
+public abstract class AbstractCollection extends
+ TreeContainerNode<ICollectionsCategory> implements ICollection {
+
+ private String name;
+
+ public AbstractCollection(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getLabel() {
+ return getName();
+ }
+
+ public final int getType() {
+ return NodeTypeConstants.Collection;
+ }
+
+}
View
52 ...es.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/AbstractCollectionsCategory.java
@@ -0,0 +1,52 @@
+package fr.opensagres.nosql.ide.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import fr.opensagres.nosql.ide.core.internal.Messages;
+
+public abstract class AbstractCollectionsCategory extends
+ TreeContainerNode<IDatabase> implements ICollectionsCategory {
+
+ protected final List<ICollection> collections;
+
+ public AbstractCollectionsCategory() {
+ this.collections = new ArrayList<ICollection>();
+ }
+
+ public String getName() {
+ return Messages.Collections_label;
+ }
+
+ public String getLabel() {
+ return getName();
+ }
+
+ public final IServer getServer() {
+ return getParent().getServer();
+ }
+
+ public final int getType() {
+ return NodeTypeConstants.CollectionsCategory;
+ }
+
+ public List<ICollection> getCollections() {
+ // Compute if needed list of collection.
+ getChildren();
+ return collections;
+ }
+
+ @Override
+ public void clearNodes() {
+ super.clearNodes();
+ this.collections.clear();
+ }
+
+ @Override
+ protected void doGetChildren() throws Exception {
+ this.collections.clear();
+ loadCollections();
+ }
+
+ protected abstract void loadCollections() throws Exception;
+}
View
24 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/AbstractServer.java
@@ -23,6 +23,8 @@
private IServerRuntime runtime;
private IServerType serverType;
+ private IDatabase currentDatabase;
+
public AbstractServer(String serverTypeId, String name) {
this(serverTypeId, String.valueOf(System.currentTimeMillis()), name);
}
@@ -224,6 +226,11 @@ public IServerType getServerType() {
return serverType;
}
+ @Override
+ public IServer getServer() {
+ return this;
+ }
+
public final void save(Writer writer) throws IOException {
writer.append("<");
writer.append(ServersConstants.SERVER_ELT);
@@ -264,7 +271,22 @@ protected void doSave(Writer writer) throws IOException {
}
- protected abstract String getDatabaseName();
+ /**
+ * Select the given database and returns true if current database is not the
+ * same than the given database.
+ *
+ * @param database
+ * @return
+ */
+ public boolean selectDatabase(IDatabase database) {
+ if (currentDatabase == null) {
+ currentDatabase = database;
+ return true;
+ }
+ boolean result = currentDatabase.getId().equals(database.getId());
+ currentDatabase = database;
+ return !result;
+ }
protected abstract void loadDatabases() throws Exception;
View
1  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/Error.java
@@ -23,5 +23,6 @@ public String getId() {
public String getName() {
return null;
}
+
}
View
5 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ICollection.java
@@ -0,0 +1,5 @@
+package fr.opensagres.nosql.ide.core.model;
+
+public interface ICollection extends ITreeContainerNode<ICollectionsCategory> {
+
+}
View
5 ...pensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ICollectionsCategory.java
@@ -0,0 +1,5 @@
+package fr.opensagres.nosql.ide.core.model;
+
+public interface ICollectionsCategory extends ITreeContainerNode<IDatabase> {
+
+}
View
2  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/IDatabase.java
@@ -2,6 +2,4 @@
public interface IDatabase extends ITreeContainerNode<IServer> {
- IServer getServer();
-
}
View
2  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/IServer.java
@@ -29,4 +29,6 @@
void setServerState(ServerState serverState);
String getURL();
+
+ String getDatabaseName();
}
View
2  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ITreeContainerNode.java
@@ -7,4 +7,6 @@
List<ITreeSimpleNode> getChildren();
+ NodeStatus getStatus();
+
}
View
2  fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ITreeSimpleNode.java
@@ -3,6 +3,8 @@
public interface ITreeSimpleNode<Parent extends ITreeContainerNode> extends
IModelIdentity {
+ IServer getServer();
+
Parent getParent();
void setParent(Parent parent);
View
4 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/TreeSimpleNode.java
@@ -25,4 +25,8 @@ protected String computeId() {
public String getId() {
return computeId();
}
+
+ public IServer getServer() {
+ return getParent().getServer();
+ }
}
View
19 ...ore/src/fr/opensagres/nosql/ide/mongodb/core/internal/extensions/ConnectServerRunner.java
@@ -2,6 +2,7 @@
import fr.opensagres.nosql.ide.core.extensions.AbstractServerRunner;
import fr.opensagres.nosql.ide.core.model.IServer;
+import fr.opensagres.nosql.ide.core.model.NodeStatus;
import fr.opensagres.nosql.ide.core.model.ServerState;
public class ConnectServerRunner extends AbstractServerRunner {
@@ -13,10 +14,24 @@ protected boolean doCanSupport(IServer server) {
public void start(IServer server) throws Exception {
server.setServerState(ServerState.Connecting);
- // Try to connect
+ //server.getChildren();
+ //if (server.getStatus() == NodeStatus.StartedWithError) {
+ // server.setServerState(ServerState.Disconnected);
+ //}
+ //else {
+ server.setServerState(ServerState.Connected);
+ //}
+// // Try to connect
+// try {
+// MongoDriverHelper.tryConnection(((MongoServer) server).getMongo(),
+// server.getDatabaseName());
+// server.setServerState(ServerState.Connected);
+// } catch (Throwable e) {
+// server.getChildren().add(new Error(e));
+// server.setServerState(ServerState.Disconnected);
+// }
// MongoDriverHelper.tryConnection(getMongo());
// Connection is OK, update the server state as connected.
- server.setServerState(ServerState.Connected);
}
View
2  ...core/src/fr/opensagres/nosql/ide/mongodb/core/internal/extensions/MongoServerFactory.java
@@ -12,7 +12,7 @@
@Override
protected IServer doCreate(String id, String name, String url,
- Attributes attributes) {
+ Attributes attributes) throws Exception {
MongoURI mongoURI = new MongoURI(url);
return new MongoServer(id, name, mongoURI);
}
View
16 ...e/src/fr/opensagres/nosql/ide/mongodb/core/internal/shell/DBAuthenticateShellCommand.java
@@ -0,0 +1,16 @@
+package fr.opensagres.nosql.ide.mongodb.core.internal.shell;
+
+import com.mongodb.tools.shell.ShellScriptBuilder;
+
+import fr.opensagres.nosql.ide.core.model.IServer;
+import fr.opensagres.nosql.ide.core.shell.AbstractShellCommand;
+
+public class DBAuthenticateShellCommand extends AbstractShellCommand {
+
+ public DBAuthenticateShellCommand(IServer server, String username,
+ char[] passwd) {
+ super(server, SHELL_DB_AUTHENTICATE, ShellScriptBuilder.dbAuthenticate(
+ username, passwd));
+ }
+
+}
View
15 .../src/fr/opensagres/nosql/ide/mongodb/core/internal/shell/ShowCollectionsShellCommand.java
@@ -0,0 +1,15 @@
+package fr.opensagres.nosql.ide.mongodb.core.internal.shell;
+
+import com.mongodb.tools.shell.ShellScriptBuilder;
+
+import fr.opensagres.nosql.ide.core.model.IServer;
+import fr.opensagres.nosql.ide.core.shell.AbstractShellCommand;
+
+public class ShowCollectionsShellCommand extends AbstractShellCommand {
+
+ public ShowCollectionsShellCommand(IServer server) {
+ super(server, SHELL_SHOW_COLLECTIONS, ShellScriptBuilder
+ .showCollections());
+ }
+
+}
View
14 ...mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/shell/UseShellCommand.java
@@ -0,0 +1,14 @@
+package fr.opensagres.nosql.ide.mongodb.core.internal.shell;
+
+import com.mongodb.tools.shell.ShellScriptBuilder;
+
+import fr.opensagres.nosql.ide.core.model.IServer;
+import fr.opensagres.nosql.ide.core.shell.AbstractShellCommand;
+
+public class UseShellCommand extends AbstractShellCommand {
+
+ public UseShellCommand(IServer server, String dbname) {
+ super(server, SHELL_USE, ShellScriptBuilder.use(dbname));
+ }
+
+}
View
19 ...res.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/Collection.java
@@ -0,0 +1,19 @@
+package fr.opensagres.nosql.ide.mongodb.core.model;
+
+import fr.opensagres.nosql.ide.core.model.AbstractCollection;
+
+public class Collection extends AbstractCollection {
+
+ public Collection(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void doGetChildren() throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+}
View
24 ....ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/CollectionsCategory.java
@@ -0,0 +1,24 @@
+package fr.opensagres.nosql.ide.mongodb.core.model;
+
+import java.util.Set;
+
+import com.mongodb.DB;
+
+import fr.opensagres.nosql.ide.core.model.AbstractCollectionsCategory;
+import fr.opensagres.nosql.ide.mongodb.core.shell.MongoShellCommandManager;
+
+public class CollectionsCategory extends AbstractCollectionsCategory {
+
+ @Override
+ protected void loadCollections() throws Exception {
+ DB db = ((Database) getParent()).getDB();
+ Set<String> names = MongoShellCommandManager.getInstance()
+ .showCollections(getServer(), db);
+ for (String name : names) {
+ Collection collection = new Collection(name);
+ collections.add(collection);
+ super.addNode(collection);
+ }
+ }
+
+}
View
46 ...agres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/Database.java
@@ -1,17 +1,61 @@
package fr.opensagres.nosql.ide.mongodb.core.model;
+import java.net.UnknownHostException;
+
+import com.mongodb.DB;
+import com.mongodb.MongoException;
+
import fr.opensagres.nosql.ide.core.model.AbstractDatabase;
+import fr.opensagres.nosql.ide.core.utils.StringUtils;
+import fr.opensagres.nosql.ide.mongodb.core.shell.MongoShellCommandManager;
public class Database extends AbstractDatabase {
+ private DB db;
+ private boolean alreadyAuthenticated;
+ private CollectionsCategory collectionsCategory;
+
public Database(String name) {
super(name);
+ this.alreadyAuthenticated = false;
+ this.collectionsCategory = new CollectionsCategory();
+ // force compute of static children nodes.
+ getChildren();
}
@Override
protected void doGetChildren() throws Exception {
- // TODO Auto-generated method stub
+ super.addNode(collectionsCategory);
+ // Collections folder
+// super.addNode(new StoredJavascriptCategory());
+// // GridFS folder
+// super.addNode(new GridFSCategory());
+// // Users
+// super.addNode(new Users());
+ }
+
+ public DB getDB() throws UnknownHostException, MongoException {
+ boolean databaseChanged = ((MongoServer) getParent())
+ .selectDatabase(this);
+ if (db == null || databaseChanged) {
+ db = getInternalDB();
+ }
+ return db;
+ }
+ private DB getInternalDB() throws UnknownHostException, MongoException {
+ MongoServer server = (MongoServer) getParent();
+ // 1) use databseName
+ DB db = MongoShellCommandManager.getInstance().use(server,
+ server.getMongo(), getName());
+ String username = server.getUsername();
+ // 2) authenticate if needed
+ if (StringUtils.isNotEmpty(username) && !alreadyAuthenticated) {
+ MongoShellCommandManager.getInstance().authenticate(server, db,
+ username, server.getPassword());
+ alreadyAuthenticated = true;
+ }
+ return db;
}
}
View
10 ...es.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/MongoServer.java
@@ -45,7 +45,6 @@ public Integer getPort() {
return port;
}
- @Override
public String getDatabaseName() {
return mongoURI.getDatabase();
}
@@ -110,8 +109,8 @@ protected void loadDatabases() throws Exception {
// Display list of DB (works only if there is admin privilege
// for this DB).
Mongo mongo = getMongo();
- List<String> names = MongoShellCommandManager.getInstance().showDbs(this,
- mongo);
+ List<String> names = MongoShellCommandManager.getInstance().showDbs(
+ this, mongo);
for (String name : names) {
Database database = new Database(name);
super.addNode(database);
@@ -122,12 +121,15 @@ protected void loadDatabases() throws Exception {
protected void loadDatabase(String databaseName) throws Exception {
// Display just the database.
Database database = new Database(databaseName);
+ database.setParent(this);
+ database.getDB().getCollectionNames();
super.addNode(database);
}
public Mongo getMongo() throws UnknownHostException, MongoException {
if (mongo == null) {
- mongo = MongoShellCommandManager.getInstance().connect(this, mongoURI);
+ mongo = MongoShellCommandManager.getInstance().connect(this,
+ mongoURI);
}
return mongo;
}
View
33 ...mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/shell/MongoShellCommandManager.java
@@ -2,7 +2,9 @@
import java.net.UnknownHostException;
import java.util.List;
+import java.util.Set;
+import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
import com.mongodb.MongoURI;
@@ -11,8 +13,11 @@
import fr.opensagres.nosql.ide.core.model.IServer;
import fr.opensagres.nosql.ide.core.shell.AbstractShellCommandManager;
import fr.opensagres.nosql.ide.mongodb.core.internal.shell.ConnectShellCommand;
+import fr.opensagres.nosql.ide.mongodb.core.internal.shell.DBAuthenticateShellCommand;
import fr.opensagres.nosql.ide.mongodb.core.internal.shell.DisconnectShellCommand;
+import fr.opensagres.nosql.ide.mongodb.core.internal.shell.ShowCollectionsShellCommand;
import fr.opensagres.nosql.ide.mongodb.core.internal.shell.ShowDbsShellCommand;
+import fr.opensagres.nosql.ide.mongodb.core.internal.shell.UseShellCommand;
public class MongoShellCommandManager extends AbstractShellCommandManager {
@@ -53,4 +58,32 @@ public void disconnect(IServer server, Mongo mongo) {
return names;
}
+ public DB use(IServer server, Mongo mongo, String dbname) {
+ DB db = mongo.getDB(dbname);
+ if (hasListeners()) {
+ getShellNotificationManager().broadcastChange(
+ new UseShellCommand(server, dbname));
+ }
+ return db;
+ }
+
+ public boolean authenticate(IServer server, DB db, String username,
+ char[] passwd) {
+ boolean result = db.authenticate(username, passwd);
+ if (hasListeners()) {
+ getShellNotificationManager().broadcastChange(
+ new DBAuthenticateShellCommand(server, username, passwd));
+ }
+ return result;
+ }
+
+ public Set<String> showCollections(IServer server, DB db) {
+ Set<String> names = db.getCollectionNames();
+ if (hasListeners()) {
+ getShellNotificationManager().broadcastChange(
+ new ShowCollectionsShellCommand(server));
+ }
+ return names;
+ }
+
}
View
17 ...nosql.ide.orientdb.core/src/fr/opensagres/nosql/ide/orientdb/core/model/OrientServer.java
@@ -1,24 +1,26 @@
package fr.opensagres.nosql.ide.orientdb.core.model;
+import java.net.URL;
+
import fr.opensagres.nosql.ide.core.model.AbstractServer;
public class OrientServer extends AbstractServer {
public static final String TYPE_ID = "fr.opensagres.nosql.ide.orientdb.core";
- private String url;
+ private URL url;
- public OrientServer(String name, String url) {
+ public OrientServer(String name, URL url) {
super(TYPE_ID, name);
this.url = url;
}
- public OrientServer(String id, String name, String url) {
+ public OrientServer(String id, String name, URL url) {
super(TYPE_ID, id, name);
this.url = url;
}
public String getURL() {
- return url;
+ return url.toString();
}
public void dispose() {
@@ -26,12 +28,11 @@ public void dispose() {
}
public String getLabel() {
- return getName() + " [" + url + "] - " + getServerState();
+ return getName() + " [" + getURL() + "] - " + getServerState();
}
- @Override
- protected String getDatabaseName() {
- return null;
+ public String getDatabaseName() {
+ return url.getPath();
}
@Override
View
6 ...db.core/src/fr/opensagres/nosql/ide/orientdb/core/model/internal/OrientServerFactory.java
@@ -1,5 +1,7 @@
package fr.opensagres.nosql.ide.orientdb.core.model.internal;
+import java.net.URL;
+
import org.xml.sax.Attributes;
import fr.opensagres.nosql.ide.core.extensions.AbstractServerFactory;
@@ -10,7 +12,7 @@
@Override
protected IServer doCreate(String id, String name, String url,
- Attributes attributes) {
- return new OrientServer(id, name, url);
+ Attributes attributes) throws Exception {
+ return new OrientServer(id, name, new URL(url));
}
}
View
13 ...ientdb.ui/src/fr/opensagres/nosql/ide/orientdb/ui/wizards/server/NewServerWizardPage.java
@@ -1,5 +1,6 @@
package fr.opensagres.nosql.ide.orientdb.ui.wizards.server;
+import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.jface.viewers.ComboViewer;
@@ -222,12 +223,12 @@ public String getName() {
return nameText.getText();
}
- public String getURL() {
- // return MongoDriverHelper.createMongoURI(hostCombo.getText(),
- // getPort(),
- // userNameText.getText(), passwordText.getText(),
- // databaseNameText.getText());
- return urlText.getText();
+ public URL getURL() {
+ try {
+ return new URL(urlText.getText());
+ } catch (MalformedURLException e) {
+ return null;
+ }
}
public IServerRuntime getRuntime() {
View
BIN  fr.opensagres.nosql.ide.ui/icons/obj16/command.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
7 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/ImageResources.java
@@ -40,6 +40,7 @@
public static final String IMG_USERS_16 = "users_16";
public static final String IMG_INDEX_16 = "index_16";
public static final String IMG_STATS_16 = "stats_16";
+ public static final String IMG_COMMAND_16 = "command_16";
public static final String IMG_TH_HORIZONTAL_16 = "th_horizontal_16";
public static final String IMG_TH_VERTICAL_16 = "th_vertical_16";
@@ -65,7 +66,7 @@
public static final String IMG_WIZBAN_NEW_SERVER = "newServerWiz";
public static final String IMG_WIZBAN_NEW_DATABASE = "newDatabaseWiz";
-
+
public static final String IMG_COLLECTION_NEW_16 = null;
public static void initialize(ImageRegistry imageRegistry) {
@@ -83,7 +84,7 @@ public static void initialize(ImageRegistry imageRegistry) {
registerImage(imageRegistry, IMG_DATABASE_16, PATH_OBJ_16
+ "database.png");
registerImage(imageRegistry, IMG_DATABASE_NEW_16, PATH_OBJ_16
- + "database-new.png");
+ + "database-new.png");
registerImage(imageRegistry, IMG_GRIDFS_16, PATH_OBJ_16 + "gridfs.png");
registerImage(imageRegistry, IMG_COLLECTION_16, PATH_OBJ_16
+ "collection.png");
@@ -95,6 +96,8 @@ public static void initialize(ImageRegistry imageRegistry) {
registerImage(imageRegistry, IMG_USERS_16, PATH_OBJ_16 + "users.png");
registerImage(imageRegistry, IMG_INDEX_16, PATH_OBJ_16 + "index.png");
registerImage(imageRegistry, IMG_STATS_16, PATH_OBJ_16 + "stats.png");
+ registerImage(imageRegistry, IMG_COMMAND_16, PATH_OBJ_16
+ + "command.gif");
registerImage(imageRegistry, IMG_TH_HORIZONTAL_16, PATH_OBJ_16
+ "th_horizontal.gif");
View
12 ...res.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/viewers/ServerLabelProvider.java
@@ -51,16 +51,24 @@ public Image getImage(Object element) {
return ImageResources
.getImage(ImageResources.IMG_SERVER_STOPPED_16);
default:
- return ImageResources.getImage(ImageResources.IMG_SERVER_16);
+ return ImageResources
+ .getImage(ImageResources.IMG_SERVER_16);
}
case NodeTypeConstants.Database:
return ImageResources.getImage(ImageResources.IMG_DATABASE_16);
case NodeTypeConstants.Collection:
- return ImageResources.getImage(ImageResources.IMG_COLLECTION_16);
+ return ImageResources
+ .getImage(ImageResources.IMG_COLLECTION_16);
case NodeTypeConstants.Document:
return ImageResources.getImage(ImageResources.IMG_DOCUMENT_16);
case NodeTypeConstants.Error:
return ImageResources.getImage(ImageResources.IMG_ERROR_16);
+ case NodeTypeConstants.CollectionsCategory:
+ case NodeTypeConstants.GridFSCategory:
+ case NodeTypeConstants.StoredJavascriptCategory:
+ case NodeTypeConstants.IndexesCategory:
+ return ImageResources.getImage(ImageResources.IMG_CATEGORY_16);
+
}
}
return super.getImage(element);
View
20 ...l.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/viewers/ShellCommandContentProvider.java
@@ -0,0 +1,20 @@
+package fr.opensagres.nosql.ide.ui.internal.viewers;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
+
+public class ShellCommandContentProvider extends ArrayContentProvider {
+
+ // private static final Object[] EMPTY_ARRAY = new Object[0];
+
+ private static ShellCommandContentProvider instance;
+
+ public static ShellCommandContentProvider getInstance() {
+ synchronized (ShellCommandContentProvider.class) {
+ if (instance == null) {
+ instance = new ShellCommandContentProvider();
+ }
+ return instance;
+ }
+ }
+
+}
View
32 ...sql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/viewers/ShellCommandLabelProvider.java
@@ -0,0 +1,32 @@
+package fr.opensagres.nosql.ide.ui.internal.viewers;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+import fr.opensagres.nosql.ide.core.shell.IShellCommand;
+import fr.opensagres.nosql.ide.ui.internal.ImageResources;
+
+public class ShellCommandLabelProvider extends LabelProvider {
+
+ private static ShellCommandLabelProvider instance;
+
+ public static ShellCommandLabelProvider getInstance() {
+ synchronized (ShellCommandLabelProvider.class) {
+ if (instance == null) {
+ instance = new ShellCommandLabelProvider();
+ }
+ return instance;
+ }
+ }
+
+ @Override
+ public String getText(Object element) {
+ return ((IShellCommand) element).getCommand();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ return ImageResources.getImage(ImageResources.IMG_COMMAND_16);
+ }
+
+}
View
195 ...nsagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/views/ShellCommandsView.java
@@ -1,33 +1,22 @@
package fr.opensagres.nosql.ide.ui.internal.views;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import fr.opensagres.nosql.ide.core.Platform;
+import fr.opensagres.nosql.ide.core.model.IServer;
import fr.opensagres.nosql.ide.core.shell.IShellCommand;
import fr.opensagres.nosql.ide.core.shell.IShellCommandListener;
@@ -39,11 +28,17 @@
*/
public static final String ID = "fr.opensagres.nosql.ide.ui.views.ShellCommandsView";
- private TableViewer viewer;
private Action action1;
private Action action2;
private Action doubleClickAction;
+ private final Map<IServer, ShellServerItem> serverTabItems;
+ private CTabFolder tabFolder;
+
+ public ShellCommandsView() {
+ serverTabItems = new HashMap<IServer, ShellServerItem>();
+ }
+
/*
* The content provider class is responsible for providing objects to the
* view. It can wrap existing objects in adapters or simply return objects
@@ -52,60 +47,19 @@
* example).
*/
- class ViewContentProvider implements IStructuredContentProvider {
- public void inputChanged(Viewer v, Object oldInput, Object newInput) {
- }
-
- public void dispose() {
- }
-
- public Object[] getElements(Object parent) {
- return new Object[0];
- }
- }
-
- class ViewLabelProvider extends LabelProvider implements
- ITableLabelProvider {
- public String getColumnText(Object obj, int index) {
- return ((IShellCommand) obj).getCommand();
- // return getText(obj);
- }
-
- public Image getColumnImage(Object obj, int index) {
- return getImage(obj);
- }
-
- public Image getImage(Object obj) {
- return PlatformUI.getWorkbench().getSharedImages()
- .getImage(ISharedImages.IMG_OBJ_ELEMENT);
- }
- }
-
- class NameSorter extends ViewerSorter {
- }
-
- /**
- * The constructor.
- */
- public ShellCommandsView() {
- }
-
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
public void createPartControl(Composite parent) {
- viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
- | SWT.V_SCROLL);
- viewer.setContentProvider(new ViewContentProvider());
- viewer.setLabelProvider(new ViewLabelProvider());
- // viewer.setSorter(new NameSorter());
- viewer.setInput(getViewSite());
-
- // Create the help context id for the viewer's control
- // PlatformUI.getWorkbench().getHelpSystem()
- // .setHelp(viewer.getControl(), "_ShellCommandView.viewer");
- //
+
+ // Create the tabs
+ tabFolder = new CTabFolder(parent, SWT.TOP);
+ tabFolder.setBorderVisible(false);
+ tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
+ tabFolder.setSimple(false);
+ tabFolder.setUnselectedImageVisible(false);
+ tabFolder.setUnselectedCloseVisible(false);
Platform.getShellCommandManagerRegistry().addShellListener(this);
@@ -116,22 +70,22 @@ public void createPartControl(Composite parent) {
}
private void hookContextMenu() {
- MenuManager menuMgr = new MenuManager("#PopupMenu");
- menuMgr.setRemoveAllWhenShown(true);
- menuMgr.addMenuListener(new IMenuListener() {
- public void menuAboutToShow(IMenuManager manager) {
- ShellCommandsView.this.fillContextMenu(manager);
- }
- });
- Menu menu = menuMgr.createContextMenu(viewer.getControl());
- viewer.getControl().setMenu(menu);
- getSite().registerContextMenu(menuMgr, viewer);
+ // MenuManager menuMgr = new MenuManager("#PopupMenu");
+ // menuMgr.setRemoveAllWhenShown(true);
+ // menuMgr.addMenuListener(new IMenuListener() {
+ // public void menuAboutToShow(IMenuManager manager) {
+ // ShellCommandsView.this.fillContextMenu(manager);
+ // }
+ // });
+ // Menu menu = menuMgr.createContextMenu(viewer.getControl());
+ // viewer.getControl().setMenu(menu);
+ // getSite().registerContextMenu(menuMgr, viewer);
}
private void contributeToActionBars() {
- IActionBars bars = getViewSite().getActionBars();
- fillLocalPullDown(bars.getMenuManager());
- fillLocalToolBar(bars.getToolBarManager());
+ // IActionBars bars = getViewSite().getActionBars();
+ // fillLocalPullDown(bars.getMenuManager());
+ // fillLocalToolBar(bars.getToolBarManager());
}
private void fillLocalPullDown(IMenuManager manager) {
@@ -153,57 +107,68 @@ private void fillLocalToolBar(IToolBarManager manager) {
}
private void makeActions() {
- action1 = new Action() {
- public void run() {
- showMessage("Action 1 executed");
- }
- };
- action1.setText("Action 1");
- action1.setToolTipText("Action 1 tooltip");
- action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
- .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
-
- action2 = new Action() {
- public void run() {
- showMessage("Action 2 executed");
- }
- };
- action2.setText("Action 2");
- action2.setToolTipText("Action 2 tooltip");
- action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
- .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
- doubleClickAction = new Action() {
- public void run() {
- ISelection selection = viewer.getSelection();
- Object obj = ((IStructuredSelection) selection)
- .getFirstElement();
- showMessage("Double-click detected on " + obj.toString());
- }
- };
+ // action1 = new Action() {
+ // public void run() {
+ // showMessage("Action 1 executed");
+ // }
+ // };
+ // action1.setText("Action 1");
+ // action1.setToolTipText("Action 1 tooltip");
+ // action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
+ // .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
+ //
+ // action2 = new Action() {
+ // public void run() {
+ // showMessage("Action 2 executed");
+ // }
+ // };
+ // action2.setText("Action 2");
+ // action2.setToolTipText("Action 2 tooltip");
+ // action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
+ // .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
+ // doubleClickAction = new Action() {
+ // public void run() {
+ // ISelection selection = viewer.getSelection();
+ // Object obj = ((IStructuredSelection) selection)
+ // .getFirstElement();
+ // showMessage("Double-click detected on " + obj.toString());
+ // }
+ // };
}
private void hookDoubleClickAction() {
- viewer.addDoubleClickListener(new IDoubleClickListener() {
- public void doubleClick(DoubleClickEvent event) {
- doubleClickAction.run();
- }
- });
+ // viewer.addDoubleClickListener(new IDoubleClickListener() {
+ // public void doubleClick(DoubleClickEvent event) {
+ // doubleClickAction.run();
+ // }
+ // });
}
private void showMessage(String message) {
- MessageDialog.openInformation(viewer.getControl().getShell(),
- "ShellCommandView", message);
+ // MessageDialog.openInformation(viewer.getControl().getShell(),
+ // "ShellCommandView", message);
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
- viewer.getControl().setFocus();
+ tabFolder.setFocus();
}
public void commandAdded(IShellCommand command) {
+ IServer server = command.getServer();
+ // 1) Get or create new tab if needed for the server
+ ShellServerItem item = serverTabItems.get(server);
+ if (item == null || item.getTabItem().isDisposed()) {
+ item = new ShellServerItem(server, tabFolder);
+ serverTabItems.put(server, item);
+ }
+ // 2) Add the command to the viewer
+ TableViewer viewer = item.getViewer();
viewer.add(command);
+ // 3) select the tab item linked to the command server
+ tabFolder.setSelection(item.getTabItem());
}
@Override
View
51 ...pensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/views/ShellServerItem.java
@@ -0,0 +1,51 @@
+package fr.opensagres.nosql.ide.ui.internal.views;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+import fr.opensagres.nosql.ide.core.model.IServer;
+import fr.opensagres.nosql.ide.ui.internal.ImageResources;
+import fr.opensagres.nosql.ide.ui.internal.viewers.ShellCommandLabelProvider;
+import fr.opensagres.nosql.ide.ui.internal.viewers.ShellCommandContentProvider;
+
+public class ShellServerItem {
+
+ private final IServer server;
+ private final CTabItem tabItem;
+ private final TableViewer viewer;
+
+ public ShellServerItem(IServer server, CTabFolder tabFolder) {
+ this.server = server;
+ this.tabItem = new CTabItem(tabFolder, SWT.NONE);
+ Composite c1 = new Composite(tabFolder, SWT.NONE);
+ c1.setLayout(new GridLayout());
+ this.viewer = new TableViewer(c1, SWT.MULTI | SWT.H_SCROLL
+ | SWT.V_SCROLL);
+ viewer.setLabelProvider(ShellCommandLabelProvider.getInstance());
+ viewer.setContentProvider(ShellCommandContentProvider.getInstance());
+ viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
+ tabItem.setControl(c1);
+ tabItem.setText(server.getName());
+ tabItem.setImage(ImageResources.getImage(ImageResources.IMG_SERVER_16));
+ tabItem.setShowClose(true);
+ }
+
+ public IServer getServer() {
+ return server;
+ }
+
+ public TableViewer getViewer() {
+ return viewer;
+ }
+
+ public CTabItem getTabItem() {
+ return tabItem;
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.