Merge branch 'master' of ssh://dev.eclipse.org/gitroot/e4/org.eclipse.orion.client
diff --git a/bundles/org.eclipse.orion.client.core/static/edit-site.html b/bundles/org.eclipse.orion.client.core/static/edit-site.html
index 6be095c..c895ba2 100644
--- a/bundles/org.eclipse.orion.client.core/static/edit-site.html
+++ b/bundles/org.eclipse.orion.client.core/static/edit-site.html
@@ -53,15 +53,22 @@
 	

 	<script src="js/auth.js"></script>

 	

-	<script src="js/util.js"></script>

-	<script src="js/fileClient.js"></script>

+	<!-- EAS -->

 	<script src="js/commands.js"></script>

-	<script src="js/log.js"></script>

 	<script src="js/dialogs.js"></script>

+	<script src="js/log.js"></script>

+	<script src="js/preferences.js"></script>

 	<script src="js/status.js"></script>

 	<script src="js/users.js"></script>

-	<script src="js/treetable.js"></script>

+	

+	<script src="js/fileClient.js"></script>

+	<script src="js/searchClient.js"></script>

+	

+	<script src="js/util.js"></script>

 	<script src="js/globalCommands.js"></script>

+	<script src="js/treetable.js"></script>

+	

+	<!-- Sites -->

 	<script src="js/sites/siteService.js"></script>

 	<script src="js/sites/siteTree.js"></script>

 	<script src="js/sites/siteUtils.js"></script>

@@ -70,12 +77,7 @@
 	<script src="js/sites/edit-site.js"></script>

 	

 	<div dojoType="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%;">

-		<div dojoType="dijit.layout.ContentPane" region="top" class="toolbar">

-			<div style="float: left;">

-				<img class="toolbarLabel" src="/images/orion.png" alt="Orion Logo" align="top">

-				<span class="statuspane" id="statusPane">Loading...</span>

-			</div>

-			<div id="eclipseWebToolbar" style="float: right;" class="innerToolbar"></div>

+		<div class="toolbar" id="toolbar" dojoType="dijit.layout.ContentPane" region="top">

 		</div>

 		

 		<div dojoType="dijit.layout.ContentPane" region="center">

diff --git a/bundles/org.eclipse.orion.client.core/static/js/sites/edit-site.js b/bundles/org.eclipse.orion.client.core/static/js/sites/edit-site.js
index d92c832..84849ca 100644
--- a/bundles/org.eclipse.orion.client.core/static/js/sites/edit-site.js
+++ b/bundles/org.eclipse.orion.client.core/static/js/sites/edit-site.js
@@ -22,8 +22,9 @@
 	var statusService = new eclipse.StatusReportingService(serviceRegistry, "statusPane");

 	var commandService = new eclipse.CommandService({serviceRegistry: serviceRegistry});

 	var fileClient = new eclipse.FileClient(serviceRegistry, pluginRegistry);

-	var siteService = new eclipse.sites.SiteService();

-	serviceRegistry.registerService(eclipse.sites.SITE_SERVICE_NAME, siteService);

+	var siteService = new eclipse.sites.SiteService(serviceRegistry);

+	var preferenceService = new eclipse.Preferences(serviceRegistry, "/prefs/user");

+	var searcher = new eclipse.Searcher({serviceRegistry: serviceRegistry});

 	

 	// File operations

 	var filePlugin = pluginRegistry.getPlugin("/plugins/fileClientPlugin.html");

@@ -31,6 +32,8 @@
 		pluginRegistry.installPlugin("/plugins/fileClientPlugin.html");

 	}

 	

+	eclipse.globalCommandUtils.generateBanner("toolbar", commandService, preferenceService, searcher);

+	

 	/**

 	 * TODO move into SiteEditor

 	 * Does something after the site has been loaded into the editor, for example adds a new mapping entry.

@@ -60,7 +63,10 @@
 	

 	// Initialize the widget

 	(function() {

-		var widget = new widgets.SiteEditor({serviceRegistry: serviceRegistry, id: "site-editor"});

+		var widget = new widgets.SiteEditor({

+			fileClient: fileClient,

+			siteService: siteService,

+			id: "site-editor"});

 		dojo.place(widget.domNode, dojo.byId("site"), "only");

 		widget.startup();

 		

diff --git a/bundles/org.eclipse.orion.client.core/static/js/sites/siteService.js b/bundles/org.eclipse.orion.client.core/static/js/sites/siteService.js
index bc5a3aa..cfa12b7 100644
--- a/bundles/org.eclipse.orion.client.core/static/js/sites/siteService.js
+++ b/bundles/org.eclipse.orion.client.core/static/js/sites/siteService.js
@@ -25,16 +25,13 @@
 	 * Constructs a new SiteService.

 	 * 

 	 * @name eclipse.sites.SiteService

-	 * @class Implements a service that provides access to the server API for managing site configurations.

-	 * To do this it may be registered with a {eclipse.ServiceRegistry}, for example:

-	 * <code>

-	 * var serviceRegistry = ...

-	 * var siteService = new eclipse.sites.SiteService();

-	 * var registration = serviceRegistry.registerService(eclipse.sites.SITE_SERVICE_NAME, siteService);

-	 * </code>

+	 * @class Defines and implements a service that provides access to the server API for managing site 

+	 * configurations.

+	 * @param serviceRegistry {eclipse.ServiceRegistry} The service registry to register ourself with.

 	 */

-	function SiteService() {

+	function SiteService(serviceRegistry) {

 		this._siteUrl = "/site";

+		this._serviceRegistration = serviceRegistry.registerService(eclipse.sites.SITE_SERVICE_NAME, this);

 	}

 	SiteService.prototype = /** @lends eclipse.sites.SiteService.prototype */ {

 		/**

diff --git a/bundles/org.eclipse.orion.client.core/static/js/sites/siteUtils.js b/bundles/org.eclipse.orion.client.core/static/js/sites/siteUtils.js
index 6f36640..d08f328 100644
--- a/bundles/org.eclipse.orion.client.core/static/js/sites/siteUtils.js
+++ b/bundles/org.eclipse.orion.client.core/static/js/sites/siteUtils.js
@@ -10,8 +10,8 @@
 /*global dojo eclipse:true */

 /*jslint devel:true*/

 

-dojo.getObject("eclipse.sites.util", true);

 // require utils.js

+dojo.getObject("eclipse.sites.util", true);

 

 /**

  * Utility methods

@@ -19,8 +19,9 @@
  */

 eclipse.sites.util = {

 	/**

+	 * @static

 	 * @param {SiteConfiguration} siteConfig

-	 * @return Href for a link to the editing page of the given siteConfiguration.

+	 * @return The href for a link to the editing page of the given siteConfiguration.

 	 */

 	generateEditSiteHref: function(siteConfig) {

 		return "edit-site.html#site=" + eclipse.util.makeRelative(siteConfig.Location);

@@ -28,6 +29,7 @@
 	

 	/**

 	 * Parses the state of the edit-site page from a hash value.

+	 * @static

 	 * @param {String} hash

 	 * @return {site: String, [action: String], [actionDetails:String]}

 	 */

@@ -37,6 +39,7 @@
 	

 	/**

 	 * Turns the state of the edit-site page into a hash value.

+	 * @static

 	 * @param {String} siteLocation

 	 * @param {String} action

 	 * @param {String} actionDetails

@@ -54,5 +57,66 @@
 			obj.actionDetails = actionDetails;

 		}

 		return dojo.objectToQuery(obj);

+	},

+	

+	/**

+	 * Creates & adds commands that act on an individual site configuration.

+	 * @static

+	 * @param errorCallback {Function} Called when a server request fails.

+	 */

+	createSiteConfigurationCommands: function(commandService, siteService, statusService, dialogService,

+			startCallback, stopCallback, deleteCallback, errorCallback) {

+		var editCommand = new eclipse.Command({

+			name: "Edit",

+			image: "images/editing_16.gif",

+			id: "eclipse.sites.edit",

+			visibleWhen: function(item) {

+				return item.HostingStatus && item.HostingStatus.Status === "stopped";

+			},

+			hrefCallback: eclipse.sites.util.generateEditSiteHref});

+		commandService.addCommand(editCommand, "object");

+		

+		var startCommand = new eclipse.Command({

+			name: "Start",

+			image: "images/lrun_obj.gif",

+			id: "eclipse.sites.start",

+			visibleWhen: function(item) {

+				return item.HostingStatus && item.HostingStatus.Status === "stopped";

+			},

+			callback: function(item) {

+				statusService.setMessage("Starting...");

+				siteService.startStopSiteConfiguration(item.Id, "start").then(startCallback, errorCallback);

+			}});

+		commandService.addCommand(startCommand, "object");

+		

+		var stopCommand = new eclipse.Command({

+			name: "Stop",

+			image: "images/stop.gif",

+			id: "eclipse.sites.stop",

+			visibleWhen: function(item) {

+				return item.HostingStatus && item.HostingStatus.Status === "started";

+			},

+			callback: function(item) {

+				statusService.setMessage("Stopping " + item.Name + "...");

+				siteService.startStopSiteConfiguration(item.Id, "stop").then(stopCallback, errorCallback);

+			}});

+		commandService.addCommand(stopCommand, "object");

+		

+		var deleteCommand = new eclipse.Command({

+			name: "Delete",

+			image: "images/remove.gif",

+			id: "eclipse.sites.delete",

+			visibleWhen: function(item) {

+				return item.HostingStatus && item.HostingStatus.Status === "stopped";

+			},

+			callback: function(item) {

+				var msg = "Are you sure you want to delete the site configuration '" + item.Name + "'?";

+				dialogService.confirm(msg, function(confirmed) {

+						if (confirmed) {

+							siteService.deleteSiteConfiguration(item.Id).then(deleteCallback, errorCallback);

+						}

+					});

+			}});

+		commandService.addCommand(deleteCommand, "object");

 	}

 };
\ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.core/static/js/sites/sites.js b/bundles/org.eclipse.orion.client.core/static/js/sites/sites.js
index 26025d8..8bee86f 100644
--- a/bundles/org.eclipse.orion.client.core/static/js/sites/sites.js
+++ b/bundles/org.eclipse.orion.client.core/static/js/sites/sites.js
@@ -22,8 +22,9 @@
 	var statusService = new eclipse.StatusReportingService(serviceRegistry, "statusPane");

 	var commandService = new eclipse.CommandService({serviceRegistry: serviceRegistry});

 	var fileClient = new eclipse.FileClient(serviceRegistry, pluginRegistry);

-	var siteService = new eclipse.sites.SiteService();

-	serviceRegistry.registerService(eclipse.sites.SITE_SERVICE_NAME, siteService);

+	var siteService = new eclipse.sites.SiteService(serviceRegistry);

+	var preferenceService = new eclipse.Preferences(serviceRegistry, "/prefs/user");

+	var searcher = new eclipse.Searcher({serviceRegistry: serviceRegistry});

 	

 	// File operations

 	var filePlugin = pluginRegistry.getPlugin("/plugins/fileClientPlugin.html");

@@ -31,6 +32,8 @@
 		pluginRegistry.installPlugin("/plugins/fileClientPlugin.html");

 	}

 	

+	eclipse.globalCommandUtils.generateBanner("toolbar", commandService, preferenceService, searcher);

+	

 	// Create the visuals

 	var model;

 	var treeWidget;

@@ -49,16 +52,18 @@
 		});

 	}());

 	

-	var refreshFunction = function() {

-		statusService.setMessage("Loading...");

-		siteService.getSiteConfigurations().then(function(siteConfigs) {

-			treeWidget.refreshAndExpand("site-table-tree", siteConfigs);

-			statusService.setMessage("");

-		});

-	};

-	

 	(function() {

-		// Page-level commands

+		// Reloads the table view after doing a command

+		var refresher = function() {

+			siteService.getSiteConfigurations().then(function(siteConfigs) {

+				statusService.setMessage("");

+				treeWidget.refreshAndExpand("site-table-tree", siteConfigs);

+			});

+		};

+		var errorHandler = function(error) {

+			statusService.setErrorMessage(error);

+		};

+		

 		var createCommand = new eclipse.Command({

 			name : "Create Site Configuration",

 			image : "/images/add_obj.gif",

@@ -69,83 +74,20 @@
 					title: "Create Site Configuration",

 					serviceRegistry: serviceRegistry,

 					func: function(name, workspace) {

-						siteService.createSiteConfiguration(name, workspace).then(refreshFunction);

+						siteService.createSiteConfiguration(name, workspace).then(refresher);

 					}});

 				dialog.startup();

 				dialog.show();

 			}});

 		commandService.addCommand(createCommand, "dom");

 		

-		// Commands for the Actions toolbar

-		var editCommand = new eclipse.Command({

-			name: "Edit",

-			image: "images/editing_16.gif",

-			id: "eclipse.sites.edit",

-			visibleWhen: function(item) {

-				return item.HostingStatus && item.HostingStatus.Status === "stopped";

-			},

-			hrefCallback: eclipse.sites.util.generateEditSiteHref});

-		commandService.addCommand(editCommand, "object");

-		

-		var startCommand = new eclipse.Command({

-			name: "Start",

-			image: "images/lrun_obj.gif",

-			id: "eclipse.sites.start",

-			visibleWhen: function(item) {

-				return item.HostingStatus && item.HostingStatus.Status === "stopped";

-			},

-			callback: function(item) {

-				statusService.setMessage("Starting " + item.Name + "...");

-				siteService.startStopSiteConfiguration(item.Id, "start").then(function() {

-					siteService.getSiteConfigurations().then(function(siteConfigs) {

-						treeWidget.refreshAndExpand("site-table-tree", siteConfigs);

-					});

-				});

-			}});

-		commandService.addCommand(startCommand, "object");

-		

-		var stopCommand = new eclipse.Command({

-			name: "Stop",

-			image: "images/stop.gif",

-			id: "eclipse.sites.stop",

-			visibleWhen: function(item) {

-				return item.HostingStatus && item.HostingStatus.Status === "started";

-			},

-			callback: function(item) {

-				statusService.setMessage("Stopping " + item.Name + "...");

-				siteService.startStopSiteConfiguration(item.Id, "stop").then(function() {

-					siteService.getSiteConfigurations().then(function(siteConfigs) {

-						treeWidget.refreshAndExpand("site-table-tree", siteConfigs);

-					});

-				});

-			}});

-		commandService.addCommand(stopCommand, "object");

-		

-		var deleteCommand = new eclipse.Command({

-			name: "Delete",

-			image: "images/remove.gif",

-			id: "eclipse.sites.delete",

-			visibleWhen: function(item) {

-				return item.HostingStatus && item.HostingStatus.Status === "stopped";

-			},

-			callback: function(item) {

-				var msg = "Are you sure you want to delete the site configuration '" + item.Name + "'?";

-				dialogService.confirm(msg, function(confirmed) {

-						if (confirmed) {

-							siteService.deleteSiteConfiguration(item.Id).then(function() {

-								siteService.getSiteConfigurations().then(function(siteConfigs) {

-									treeWidget.refreshAndExpand("site-table-tree", siteConfigs);

-								});

-							});

-						}

-					});

-			}});

-		commandService.addCommand(deleteCommand, "object");

+		// Add commands that deal with individual site configuration (edit, start, stop..)

+		eclipse.sites.util.createSiteConfigurationCommands(commandService, siteService, statusService,

+				dialogService, /*start*/ refresher, /*stop*/ refresher, /*delete*/ refresher, errorHandler);

 		

 		// Register command contributions

 		commandService.addCommandGroup("eclipse.sitesGroup", 100);

 		commandService.registerCommandContribution("eclipse.sites.create", 1, "site-toolbar", "eclipse.sitesGroup");

-		

 		commandService.registerCommandContribution("eclipse.sites.edit", 1);

 		commandService.registerCommandContribution("eclipse.sites.start", 2);

 		commandService.registerCommandContribution("eclipse.sites.stop", 3);

diff --git a/bundles/org.eclipse.orion.client.core/static/js/widgets/SiteEditor.js b/bundles/org.eclipse.orion.client.core/static/js/widgets/SiteEditor.js
index a138ddc..c0bf264 100644
--- a/bundles/org.eclipse.orion.client.core/static/js/widgets/SiteEditor.js
+++ b/bundles/org.eclipse.orion.client.core/static/js/widgets/SiteEditor.js
@@ -23,9 +23,9 @@
 

 /**

  * Editor for an individual SiteConfiguration model object.

- * @param {Object} options Dijit options bag for creating the widget.

- * @param {eclipse.ServiceRegistry} options.serviceRegistry The service registry to use.

- * Must have FileClient, SiteService.

+ * @param {Object} options Options bag for creating the widget.

+ * @param {eclipse.FileClient} options.fileClient

+ * @param {eclipse.SiteService} options.siteService

  * @param {String} [options.location] Optional URL of a site configuration to load & edit 

  * immediately after widget is created.

  */

@@ -45,13 +45,17 @@
 	constructor: function() {

 		this.inherited(arguments);

 		this.options = arguments[0] || {};

-		if (!this.options.serviceRegistry) { throw new Error("options.serviceRegistry is required"); }

-		if (this.options.location) {

-			this.load(this.options.location);

-		}

+		if (!this.options.fileClient) { throw new Error("options.fileClient is required"); }

+		if (!this.options.siteService) { throw new Error("options.siteService is required"); }

+		this._fileClient = this.options.fileClient;

+		this._siteService = this.options.siteService;

 		

 		// Start loading workspaces right away

 		this._loadWorkspaces();

+		

+		if (this.options.location) {

+			this.load(this.options.location);

+		}

 	},

 	

 	postMixInProperties: function() {

@@ -94,13 +98,12 @@
 		this._busy("Loading...");

 		var deferred = new dojo.Deferred();

 		// TODO errback for the deferred(s)

-		this._getSiteService().then(dojo.hitch(this, function(siteService) {

-			siteService.loadSiteConfiguration(location).then(dojo.hitch(this, function(siteConfig) {

+		this._siteService.loadSiteConfiguration(location).then(dojo.hitch(this, 

+			function(siteConfig) {

 				this._setSiteConfiguration(siteConfig);

-				this._done("Done.");

+				this._done("");

 				deferred.callback(siteConfig);

 			}));

-		}));

 		return deferred;

 	},

 	

@@ -161,26 +164,16 @@
 	},

 	

 	/**

-	 * @return {dojo.Deferred} A deferred, resolved with the service

-	 */

-	_getSiteService: function() {

-		return this.options.serviceRegistry.getService(eclipse.sites.SITE_SERVICE_NAME);

-	},

-	

-	/**

 	 * Starts loading workspaces and resolves this._workspaces when they're ready.

 	 */

 	_loadWorkspaces: function() {

 		var widget = this;

 		widget._workspaces = new dojo.Deferred();

-		this.options.serviceRegistry.getService("IFileService").then(

-			function(fileService) {

-				fileService.loadWorkspaces().then(function(workspaces) {

-					widget._workspaces.callback(workspaces);

-				},

-				function(error) {

-					widget._workspaces.errback(error);

-				});

+		this._fileClient.loadWorkspaces().then(function(workspaces) {

+				widget._workspaces.callback(workspaces);

+			},

+			function(error) {

+				widget._workspaces.errback(error);

 			});

 	},

 	

@@ -201,14 +194,12 @@
 		if (form.isValid()) {

 			this._busy("Saving...");

 			var widget = this;

-			this._getSiteService().then(

-					function(siteService) {

-						var siteConfig = widget._siteConfiguration;

-						siteService.updateSiteConfiguration(siteConfig.Id, siteConfig).then(

-								function(updatedSiteConfig) {

-									widget._setSiteConfiguration(updatedSiteConfig);

-									widget._done("Saved.");

-								});

+			

+			var siteConfig = widget._siteConfiguration;

+			this._siteService.updateSiteConfiguration(siteConfig.Id, siteConfig).then(

+					function(updatedSiteConfig) {

+						widget._setSiteConfiguration(updatedSiteConfig);

+						widget._done("Saved.");

 					});

 			return true;

 		} else {

diff --git a/bundles/org.eclipse.orion.client.core/static/sites.html b/bundles/org.eclipse.orion.client.core/static/sites.html
index c1cb2b8..3bf8255 100644
--- a/bundles/org.eclipse.orion.client.core/static/sites.html
+++ b/bundles/org.eclipse.orion.client.core/static/sites.html
@@ -74,15 +74,22 @@
 	<script src="js/pluginregistry.js"></script>

 	

 	<script src="js/auth.js"></script>

-	<script src="js/util.js"></script>

-	<script src="js/fileClient.js"></script>

+	

+	<!-- EAS -->

 	<script src="js/commands.js"></script>

-	<script src="js/log.js"></script>

 	<script src="js/dialogs.js"></script>

+	<script src="js/log.js"></script>

+	<script src="js/preferences.js"></script>

 	<script src="js/status.js"></script>

 	<script src="js/users.js"></script>

-	<script src="js/treetable.js"></script>

+	<script src="js/fileClient.js"></script>

+	<script src="js/searchClient.js"></script>

+

+	<script src="js/util.js"></script>

 	<script src="js/globalCommands.js"></script>

+	<script src="js/treetable.js"></script>

+	

+	<!-- Sites -->

 	<script src="js/sites/siteService.js"></script>

 	<script src="js/sites/siteTree.js"></script>

 	<script src="js/sites/siteUtils.js"></script>

@@ -91,12 +98,7 @@
 	<script src="js/sites/sites.js"></script>

 	

 	<div dojoType="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%;">

-		<div dojoType="dijit.layout.ContentPane" region="top" class="toolbar">

-			<div style="float: left;">

-				<img class="toolbarLabel" src="/images/orion.png" alt="Orion Logo" align="top">

-				<span class="statuspane" id="statusPane"></span>

-			</div>

-			<div id="eclipseWebToolbar" style="float: right;" class="innerToolbar"></div>

+		<div class="toolbar" id="toolbar" dojoType="dijit.layout.ContentPane" region="top">

 		</div>

 		

 		<div dojoType="dijit.layout.ContentPane" region="center">