use of org.mongodb.meclipse.preferences.MongoInstance in project meclipse by flaper87.
the class Connection method getMongo.
// public TreeObject [] getChildren() {
// loadDatabases();
// return super.getChildren();
// }
/**
* In the style of lazy-loading, this is where we actually initiate the
* connection to a MongoDB instance - and this is where a user would 1st
* request to see data obtained via the connection.
*
* @return
*/
public Mongo getMongo() {
MongoInstance mongoInstance = MeclipsePlugin.getDefault().getMongoInstance(this.getName());
Exception ex;
if (mongoInstance.getMongo() == null) {
Mongo mongo;
try {
mongo = new Mongo(mongoInstance.getHost(), mongoInstance.getPort());
mongo.getDatabaseNames();
// add the active Mongo instance
mongoInstance.setMongo(mongo);
// to the plug-in's state
isDown = false;
return mongo;
/* catch some possible exceptions */
} catch (MongoException e) {
ex = e;
} catch (UnknownHostException e) {
ex = e;
}
if (!isDown) {
this.showMessage(String.format(getCaption("connection.connectionError"), this.getName(), mongoInstance.getHost(), ex));
isDown = true;
}
return null;
} else {
return mongoInstance.getMongo();
}
}
use of org.mongodb.meclipse.preferences.MongoInstance in project meclipse by flaper87.
the class MeclipsePlugin method loadSavedServers.
private MongoInstance[] loadSavedServers() {
CsvReader reader = null;
try {
IPath libPath = MeclipsePlugin.getDefault().getStateLocation();
libPath = libPath.append("servers.cfg");
File file = libPath.toFile();
if (!file.exists())
return new MongoInstance[0];
reader = new CsvReader(new BufferedReader(new FileReader(file)));
java.util.List<MongoInstance> savedServersList = new ArrayList<MongoInstance>();
while (reader.readRecord()) {
MongoInstance server = new MongoInstance(reader.get(0));
server.setHost(reader.get(1));
try {
server.setPort(Integer.valueOf(reader.get(2)));
} catch (NumberFormatException e) {
System.out.println(e);
}
savedServersList.add(server);
}
return savedServersList.toArray(new MongoInstance[savedServersList.size()]);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (reader != null) {
reader.close();
}
}
return new MongoInstance[0];
}
use of org.mongodb.meclipse.preferences.MongoInstance in project meclipse by flaper87.
the class MeclipsePlugin method start.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
* )
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
MongoInstance[] savedServers = loadSavedServers();
for (MongoInstance savedServer : savedServers) {
mongoInstances.put(savedServer.getName(), savedServer);
}
}
use of org.mongodb.meclipse.preferences.MongoInstance in project meclipse by flaper87.
the class MeclipsePlugin method saveServers.
private void saveServers() {
// save server preferences here
CsvWriter writer = null;
try {
IPath libPath = getStateLocation();
libPath = libPath.append("servers.cfg");
File file = libPath.toFile();
if (!file.exists()) {
file.createNewFile();
}
writer = new CsvWriter(new FileWriter(file, false), ',');
for (MongoInstance server : mongoInstances.values()) {
writer.write(server.getName());
writer.write(server.getHost());
writer.write(String.valueOf(server.getPort()));
writer.endRecord();
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (writer != null) {
writer.close();
}
}
}
use of org.mongodb.meclipse.preferences.MongoInstance in project meclipse by flaper87.
the class ConnectionWizard method performFinish.
/**
* This method is called when 'Finish' button is pressed in the wizard. We
* will create an operation and run it using wizard as execution context.
*/
public boolean performFinish() {
// 1st, add the connection to our overall state:
MongoInstance mongoInstance = new MongoInstance(page.getConnName());
mongoInstance.setHost(page.getHost());
mongoInstance.setPort(page.getPort());
MeclipsePlugin.getDefault().addMongo(page.getConnName(), mongoInstance);
return true;
}
Aggregations