Search in sources :

Example 1 with RequiredInputValidator

use of org.mongodb.meclipse.util.RequiredInputValidator in project meclipse by flaper87.

the class Collection method makeActions.

private void makeActions() {
    insert = new Action(getCaption("collection.insertDoc")) {

        @Override
        public void run() {
            FileDialog dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
            dialog.setFilterExtensions(new String[] { "*.json" });
            String result = dialog.open();
            if (result != null) {
                try {
                    String jsonText = IOUtils.readFile(new File(result));
                    JSONObject jsonObj = new JSONObject(jsonText);
                    col.insert(JSONUtils.toDBObject(jsonObj));
                } catch (Exception ex) {
                    UIUtils.openErrorDialog(view.getSite().getShell(), ex.toString());
                }
            }
        }
    };
    rename = new Action(getCaption("collection.renameColl")) {

        @Override
        public void run() {
            InputDialog dialog = new InputDialog(view.getSite().getShell(), getCaption("collection.renameColl"), getCaption("collection.msg.newCollName"), col.getName(), new RequiredInputValidator(getCaption("collection.msg.inputCollName")));
            if (dialog.open() == InputDialog.OK) {
                try {
                    col.rename(dialog.getValue());
                } catch (MongoException ex) {
                    UIUtils.openErrorDialog(view.getSite().getShell(), ex.toString());
                }
                view.getViewer().refresh(getParent());
            }
        }
    };
    delete = new Action(getCaption("collection.deleteColl")) {

        @Override
        public void run() {
            if (MessageDialog.openConfirm(view.getSite().getShell(), getCaption("confirm"), String.format(getCaption("collection.msg.reallyDeleteColl"), col.getName()))) {
                col.drop();
                view.getViewer().refresh(getParent());
            }
        }
    };
}
Also used : RequiredInputValidator(org.mongodb.meclipse.util.RequiredInputValidator) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) InputDialog(org.eclipse.jface.dialogs.InputDialog) MongoException(com.mongodb.MongoException) JSONObject(org.json.JSONObject) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) MongoException(com.mongodb.MongoException)

Aggregations

MongoException (com.mongodb.MongoException)1 File (java.io.File)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 JSONObject (org.json.JSONObject)1 RequiredInputValidator (org.mongodb.meclipse.util.RequiredInputValidator)1