/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2011, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/**
 * @license RequireJS domReady 1.0.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
 * Available via the MIT or new BSD license.
 * see: http://github.com/jrburke/requirejs for details
 */
/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/
/*

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2011, 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation
 RequireJS domReady 1.0.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
 Available via the MIT or new BSD license.
 see: http://github.com/jrburke/requirejs for details

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation
*/
(function(d,g){typeof define==="function"&&define.amd?define("orion/Deferred",[],g):typeof exports==="object"?module.exports=g():(d.orion=d.orion||{},d.orion.Deferred=g())})(this,function(){function d(){for(var a;a=f.shift()||l.shift();)a();j=!1}function g(a,b){(b?l:f).push(a);j||(j=!0,b?setTimeout(d,0):d())}function m(a){return function(){a.apply(null,arguments)}}function e(){}function b(){var a=Error("Cancel");a.name="Cancel";return a}function a(){function i(){for(var a;a=c.shift();){var b=a.deferred,
h=k==="resolved"?"resolve":"reject";if(typeof a[h]==="function")try{var i=a[h](f);i&&typeof i.then==="function"?(b.cancel=i.cancel||e,i.then(m(b.resolve),m(b.reject),b.progress)):b.resolve(i)}catch(g){b.reject(g)}else b[h](f)}}var f,k,c=[],h=this;this.reject=function(a){k||(k="rejected",f=a,c.length&&g(i));return h.promise};this.resolve=function(a){k||(k="resolved",f=a,c.length&&g(i));return h.promise};this.progress=function(a){k||c.forEach(function(c){c.progress&&c.progress(a)});return h.promise};
this.cancel=function(){k||h.reject(b())};this.then=function(b,h,f){var b={resolve:b,reject:h,progress:f,deferred:new a},e=b.deferred,l=this.cancel.bind(this),d=function(){g(function(){(e.cancel===d?l:e.cancel)()},!0)};e.cancel=d;h=e.promise;h.cancel=function(){e.cancel()};c.push(b);k&&g(i,!0);return h};this.promise={then:this.then,cancel:this.cancel}}var f=[],l=[],j=!1;a.all=function(b,f){function k(c,a){g||(e[c]=a,--h===0&&d.resolve(e))}function c(c,a){if(!g){if(f)try{k(c,f(a));return}catch(b){a=
b}d.reject(a)}}var h=b.length,e=[],g=!1,d=new a;d.then(null,function(){g=!0;b.forEach(function(c){c.cancel&&c.cancel()})});h===0?d.resolve(e):b.forEach(function(a,b){a.then(k.bind(null,b),c.bind(null,b))});return d.promise};a.when=function(b,e,k,c){var h;if(!(b&&typeof b.then==="function"))h=new a,h.resolve(b),b=h.promise;return b.then(e,k,c)};return a});
define("orion/xhr",["orion/Deferred"],function(d){function g(d,e,b,a){var f=typeof b.response!=="undefined"?b.response:b.responseText,g;try{g=b.status}catch(j){g=0}d={args:e,response:f,responseText:typeof f==="string"?f:null,status:g,url:d,xhr:b};if(typeof a!=="undefined")d.error=a;return d}return function(m,e,b){var b=b||{},a=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,f=new d,l=b.headers||{},j=b.log||!1,i;typeof l["X-Requested-With"]==="undefined"&&(l["X-Requested-With"]="XMLHttpRequest");
if(typeof b.data!=="undefined"&&(m==="POST"||m==="PUT"))i=b.data;if(typeof b.responseType==="string")a.responseType=b.responseType;a.onprogress=function(c){c.xhr=a;f.progress(c)};a.onreadystatechange=function(){if(a.readyState===4){var c=g(e,b,a),k=a.status;200<=k&&k<400?f.resolve(c):(j&&typeof console!=="undefined"&&console.log(Error(a.statusText)),f.reject(c))}};try{a.open(m,e,!0);if(typeof b.timeout==="number")if(typeof a.timeout==="number")a.timeout=b.timeout,a.addEventListener("timeout",function(){f.reject(g(e,
b,a,"Timeout exceeded"))});else{var n=setTimeout(function(){f.reject(g(e,b,a,"Timeout exceeded"))},b.timeout);f.then(clearTimeout.bind(null,n),clearTimeout.bind(null,n))}Object.keys(l).forEach(function(c){a.setRequestHeader(c,l[c])});a.send(i)}catch(k){f.reject(g(e,b,a,k))}return f.promise}});(function(){var d=this;if(!d.define)d.define=function(g){d.orion=d.orion||{};d.orion.PluginProvider=g();d.eclipse=d.orion;delete d.define}})();
define("orion/plugin",[],function(){return function(d){function g(a){n&&(typeof ArrayBuffer==="undefined"&&(a=JSON.stringify(a)),n===self?n.postMessage(a):n.postMessage(a,"*"))}function m(a,c){return c&&c instanceof XMLHttpRequest?{status:c.status,statusText:c.statusText}:c}function e(a){var c=a?JSON.parse(JSON.stringify(a,m)):a;if(a instanceof Error)c.__isError=!0,c.message=c.message||a.message,c.name=c.name||a.name;return c}function b(a){return function(c){j&&g({serviceId:a,method:"dispatchEvent",
params:[c]})}}function a(a){if(a.source===n){var c=typeof a.data!=="string"?a.data:JSON.parse(a.data);if(typeof c.cancel==="string"){var h=i[c.id];h&&(delete i[c.id],h.cancel&&h.cancel(c.cancel))}else{var a=c.serviceId,d=c.method,f=c.params,j=l[a],m=j.implementation,p=m[d];d==="addEventListener"?(d=f[0],j.listeners[d]=j.listeners[d]||b(a),f=[d,j.listeners[d]]):d==="removeEventListener"&&(d=f[0],f=[d,j.listeners[d]],delete j.listeners[d]);var o={id:c.id,result:null,error:null};try{(h=p.apply(m,f))&&
typeof h.then==="function"?(i[c.id]=h,h.then(function(a){delete i[c.id];o.result=a;g(o)},function(a){if(i[c.id])delete i[c.id],o.error=e(a),g(o)},function(){g({requestId:c.id,method:"progress",params:Array.prototype.slice.call(arguments)})})):(o.result=h,g(o))}catch(q){o.error=e(q),g(o)}}}}var f=d,l=[],j=!1,i={},n=null;this.updateHeaders=function(a){if(j)throw Error("Cannot update headers. Plugin Provider is connected");f=a};this.registerServiceProvider=this.registerService=function(a,c,b){if(j)throw Error("Cannot register service. Plugin Provider is connected");
typeof a==="string"?a=[a]:Array.isArray(a)||(a=[]);var d=null,f=[];for(d in c)typeof c[d]==="function"&&f.push(d);l[l.length]={names:a,methods:f,implementation:c,properties:b||{},listeners:{}}};this.connect=function(b,c){if(!j){if(typeof window==="undefined")n=self;else if(window!==window.parent)n=window.parent;else if(window.opener!==null)n=window.opener;else{c&&c("No valid plugin target");return}addEventListener("message",a,!1);for(var d=[],e=0;e<l.length;e++)d.push({serviceId:e,names:l[e].names,
methods:l[e].methods,properties:l[e].properties});g({method:"plugin",params:[{headers:f||{},services:d}]});j=!0}b&&b()};this.disconnect=function(){j&&(removeEventListener("message",a),n=null,j=!1)}}});
define("domReady",[],function(){function d(a){for(var b=0,d;d=a[b];b++)d(f)}function g(){var c=l,b=j;a&&(c.length&&(l=[],d(c)),i.resourcesDone&&b.length&&(j=[],d(b)))}function m(){a||(a=!0,k&&clearInterval(k),g())}function e(c){a?c(f):l.push(c);return e}var b=typeof window!=="undefined"&&window.document,a=!b,f=b?document:null,l=[],j=[],i=requirejs||require||{},n=i.resourcesReady,k;if("resourcesReady"in i)i.resourcesReady=function(a){n&&n(a);a&&g()};b&&(document.addEventListener?(document.addEventListener("DOMContentLoaded",
m,!1),window.addEventListener("load",m,!1)):window.attachEvent&&(window.attachEvent("onload",m),self===self.top&&(k=setInterval(function(){try{document.body&&(document.documentElement.doScroll("left"),m())}catch(a){}},30))),document.readyState==="complete"&&m());e.withResources=function(b){a&&i.resourcesDone?b(f):j.push(b);return e};e.version="1.0.0";e.load=function(a,b,d,f){f.isBuild?d(null):e(d)};return e});
define("plugins/preferencesPlugin",["orion/xhr","orion/plugin","domReady!"],function(d,g){function m(a){this.location=a}m.prototype={get:function(a){return d("GET",this.location+a,{headers:{"Orion-Version":"1"},timeout:15E3,log:!1}).then(function(a){return a.response?JSON.parse(a.response):null})},put:function(a,b){return d("PUT",this.location+a,{data:JSON.stringify(b),headers:{"Orion-Version":"1"},contentType:"application/json;charset=UTF-8",timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):
null})}};var e=document.createElement("a");e.href="../prefs/user";var b=e.href;e.href="../mixloginstatic/LoginWindow.html";e=new g({name:"Orion Preferences",version:"1.0",description:"This plugin provides access to user preferences.",login:e.href});b=new m(b);e.registerService("orion.core.preference.provider",b,{});e.connect()});