From 362a277c5876e5eafedf426749863becb92ae9dc Mon Sep 17 00:00:00 2001 From: David Huynh Date: Fri, 17 Sep 2010 06:52:10 +0000 Subject: [PATCH] Added main menu command to open system file explorer at the workspace directory. Made project manager more careful at disposing projects, in case any of them is null. git-svn-id: http://google-refine.googlecode.com/svn/trunk@1272 7d457c2a-affb-35e4-300a-418c747d4874 --- .../com/google/gridworks/ProjectManager.java | 4 +- .../commands/OpenWorkspaceDirCommand.java | 37 +++++++++++++++++++ .../webapp/modules/core/MOD-INF/controller.js | 1 + .../modules/core/scripts/project/menu-bar.js | 19 ++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 main/src/com/google/gridworks/commands/OpenWorkspaceDirCommand.java diff --git a/main/src/com/google/gridworks/ProjectManager.java b/main/src/com/google/gridworks/ProjectManager.java index cf8dcb708..48842f0c2 100644 --- a/main/src/com/google/gridworks/ProjectManager.java +++ b/main/src/com/google/gridworks/ProjectManager.java @@ -66,7 +66,9 @@ public abstract class ProjectManager { save(true); // complete save for (Project project : _projects.values()) { - project.dispose(); + if (project != null) { + project.dispose(); + } } _projects.clear(); diff --git a/main/src/com/google/gridworks/commands/OpenWorkspaceDirCommand.java b/main/src/com/google/gridworks/commands/OpenWorkspaceDirCommand.java new file mode 100644 index 000000000..2352e910e --- /dev/null +++ b/main/src/com/google/gridworks/commands/OpenWorkspaceDirCommand.java @@ -0,0 +1,37 @@ +package com.google.gridworks.commands; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.google.gridworks.ProjectManager; +import com.google.gridworks.io.FileProjectManager; + +public class OpenWorkspaceDirCommand extends Command { + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String serverName = request.getServerName(); + + if (!"127.0.0.1".equals(serverName) && !"localhost".equals(serverName)) { + respond(response, "{ \"code\" : \"error\", \"message\" : \"Workspace directory can only be opened on the local machine where Gridworks is run.\" }"); + } else if (ProjectManager.singleton instanceof FileProjectManager) { + File dir = ((FileProjectManager) ProjectManager.singleton).getWorkspaceDir(); + + Runtime.getRuntime().exec( + "open .", + new String[] {}, + dir + ); + + respond(response, "{ \"code\" : \"ok\" }"); + } else { + respond(response, "{ \"code\" : \"error\", \"message\" : \"Workspace is not stored on the file system.\" }"); + } + } + +} diff --git a/main/webapp/modules/core/MOD-INF/controller.js b/main/webapp/modules/core/MOD-INF/controller.js index 31489681e..97ff6909b 100644 --- a/main/webapp/modules/core/MOD-INF/controller.js +++ b/main/webapp/modules/core/MOD-INF/controller.js @@ -99,6 +99,7 @@ function registerCommands() { GS.registerCommand(module, "get-preference", new Packages.com.google.gridworks.commands.GetPreferenceCommand()); GS.registerCommand(module, "get-all-preferences", new Packages.com.google.gridworks.commands.GetAllPreferencesCommand()); GS.registerCommand(module, "set-preference", new Packages.com.google.gridworks.commands.SetPreferenceCommand()); + GS.registerCommand(module, "open-workspace-dir", new Packages.com.google.gridworks.commands.OpenWorkspaceDirCommand()); } function registerOperations() { diff --git a/main/webapp/modules/core/scripts/project/menu-bar.js b/main/webapp/modules/core/scripts/project/menu-bar.js index d86ef87c6..cbc097dbf 100644 --- a/main/webapp/modules/core/scripts/project/menu-bar.js +++ b/main/webapp/modules/core/scripts/project/menu-bar.js @@ -73,6 +73,12 @@ MenuBar.MenuItems = [ "id" : "core/export-project", "label": "Export Project", "click": function() { MenuBar.handlers.exportProject(); } + }, + {}, + { + "id" : "core/open-workspace-dir", + "label": "Open Workspace Directory", + "click": function() { MenuBar.handlers.openWorkspaceDir(); } } ] }, @@ -318,6 +324,19 @@ MenuBar.handlers.renameProject = function() { }); }; +MenuBar.handlers.openWorkspaceDir = function() { + $.ajax({ + type: "POST", + url: "/command/core/open-workspace-dir", + dataType: "json", + success: function (data) { + if (data.code != "ok" && "message" in data) { + alert(data.message); + } + } + }); +}; + MenuBar.handlers.autoSchemaAlignment = function() { //SchemaAlignment.autoAlign(); };