/*******************************************************************************
 * @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 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) 2011 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
 ******************************************************************************/
/*

 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
 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

 Copyright (c) 2011 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(){var i=this;if(!i.define)i.define=function(c){i.orion=i.orion||{};i.orion.Deferred=c();delete i.define}})();
define("orion/Deferred",[],function(){function i(c){if(j)e?(h.next={notify:c,next:null},h=h.next):h=e={notify:c,next:null};else{j=!0;do{for(;c;){c();if(a)e?h.next=a:e=a,h=d;e?(a=e.next,d=h,c=e.notify,e=h=null):c=null}j=!1}while(j)}}function c(){function a(){for(;k;){var g=k;k=k.next;var c=g.deferred;if(g[b])try{var e=g[b](d);e&&typeof e.then==="function"?e.then(c.resolve,c.reject,c.update):c.resolve(e)}catch(h){c.reject(h)}else c[b](d)}k=f=null}var d,b,k,f;this.resolve=function(g){if(b)throw Error("'"+
b+"' already called");b="resolve";d=g;i(a)};this.reject=function(g){if(b)throw Error("'"+b+"' already called");b="reject";d=g;i(a)};this.update=this.progress=this.notify=function(g){for(var b=k;b;){if(b.update)try{b.update(g)}catch(a){}b=b.next}};this.then=function(g,d,e){g={resolve:g,reject:d,update:e,deferred:new c};k?f.next=g:k=g;f=g;b&&i(a);return g.deferred.promise};this.promise={then:this.then};this.state=function(){return b||"wait"};this.all=function(g,a){function d(a,g){b||(e[a]=g,--c===0&&
h.resolve(e))}function f(g,c){if(!b){if(a)try{d(g,a(c));return}catch(e){c=e}h.reject(c)}}var c=g.length,e=[],h=this;c===0?this.resolve(e):g.forEach(function(b,g){b.then(d.bind(null,g),f.bind(null,g))});return this.promise}}var e,h,a,d,j=!1;c.when=function(a,d,b,e){var f;if(!(a&&typeof a.then==="function"))f=new c,f.resolve(a),a=f.promise;return a.then(d,b,e)};return c});
define("orion/xhr",["orion/Deferred"],function(i){function c(c){return encodeURIComponent(c).replace(/[!'()*]/g,function(c){return"%"+c.charCodeAt(0).toString(16).toUpperCase()})}return function(e,h,a){var a=a||{},d=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,j=new i,l=a.headers||{},m=a.log||!1,b,k;typeof l["X-Requested-With"]==="undefined"&&(l["X-Requested-With"]="XMLHttpRequest");if(a.query&&typeof a.query==="object"){var f=a.query,g=Object.keys(f),n=[];for(k=0;k<g.length;k++){var o=
g[k],r=f[o];n.push(c(o)+"="+c(r))}n.length&&(f=h.split("#"),f[0]+=(f[0].indexOf("?")===-1?"?":"&")+n.join("&"),h=f.join("#"))}if(typeof a.data!=="undefined"&&(e==="POST"||e==="PUT"))b=a.data;if(typeof a.responseType==="string")d.responseType=a.responseType;d.onreadystatechange=function(){if(d.readyState===4){var g=d.status,b=typeof d.response!=="undefined"?d.response:d.responseText,b={args:a,response:b,responseText:typeof b==="string"?b:null,status:g,url:h,xhr:d};200<=g&&g<400?j.resolve(b):(m&&console&&
console.log(Error(d.statusText)),j.reject(b))}};try{d.open(e,h,!0);if(typeof a.timeout==="number")d.timeout=a.timeout,d.addEventListener("timeout",function(b){j.reject("Timeout exceeded: "+b)});var q=Object.keys(l);for(k=0;k<q.length;k++){var p=q[k];d.setRequestHeader(p,l[p])}d.send(b)}catch(s){j.reject(s)}return j}});
define("domReady",[],function(){function i(b){for(var a=0,c;c=b[a];a++)c(j)}function c(){var a=l,c=m;d&&(a.length&&(l=[],i(a)),b.resourcesDone&&c.length&&(m=[],i(c)))}function e(){d||(d=!0,f&&clearInterval(f),c())}function h(b){d?b(j):l.push(b);return h}var a=typeof window!=="undefined"&&window.document,d=!a,j=a?document:null,l=[],m=[],b=requirejs||require||{},k=b.resourcesReady,f;if("resourcesReady"in b)b.resourcesReady=function(b){k&&k(b);b&&c()};a&&(document.addEventListener?(document.addEventListener("DOMContentLoaded",
e,!1),window.addEventListener("load",e,!1)):window.attachEvent&&(window.attachEvent("onload",e),self===self.top&&(f=setInterval(function(){try{document.body&&(document.documentElement.doScroll("left"),e())}catch(b){}},30))),document.readyState==="complete"&&e());h.withResources=function(a){d&&b.resourcesDone?a(j):m.push(a);return h};h.version="1.0.0";h.load=function(b,a,c,d){d.isBuild?c(null):h(c)};return h});var eclipse=eclipse||{};
eclipse.ServiceProvider=function(i,c){this.dispatchEvent=function(e){c.dispatchEvent.apply(c,[i,e].concat(Array.prototype.slice.call(arguments,1)))};this.unregister=function(){c.unregisterServiceProvider(i)}};
eclipse.PluginProvider=function(i){function c(a){j&&(typeof ArrayBuffer==="undefined"&&(a=JSON.stringify(a)),j===self?j.postMessage(a):j.postMessage(a,"*"))}function e(a,b){return b&&b instanceof XMLHttpRequest?{status:b.status,statusText:b.statusText}:b}function h(d){if(d.source===j){var b=typeof d.data!=="string"?d.data:JSON.parse(d.data),d=a[b.serviceId].implementation,h=d[b.method],f={id:b.id,result:null,error:null};try{var g=h.apply(d,b.params);g&&typeof g.then==="function"?g.then(function(b){f.result=
b;c(f)},function(b){f.error=b?JSON.parse(JSON.stringify(b,e)):b;c(f)},function(){c({requestId:b.id,method:"progress",params:Array.prototype.slice.call(arguments)})}):(f.result=g,c(f))}catch(i){f.error=i?JSON.parse(JSON.stringify(i,e)):i,c(f)}}}var a=[],d=!1,j=null,l={dispatchEvent:function(a,b){if(!d)throw Error("Cannot dispatchEvent. Plugin Provider not connected");var e={serviceId:a,method:"dispatchEvent",params:[b].concat(Array.prototype.slice.call(arguments,2))};c(e)},unregisterServiceProvider:function(c){if(d)throw Error("Cannot unregister. Plugin Provider is connected");
a[c]=null}};this.registerServiceProvider=function(c,b,e){if(d)throw Error("Cannot register. Plugin Provider is connected");var f=null,g=[];for(f in b)typeof b[f]==="function"&&g.push(f);f=a.length;a[f]={type:c,methods:g,implementation:b,properties:e||{}};return new eclipse.ServiceProvider(f,l)};this.connect=function(e,b){if(!d){if(typeof window==="undefined")j=self;else if(window!==window.parent)j=window.parent;else if(window.opener!==null)j=window.opener;else{b&&b("No valid plugin target");return}addEventListener("message",
h,!1);for(var k=[],f=0;f<a.length;f++)a[f]&&k.push({serviceId:f,type:a[f].type,methods:a[f].methods,properties:a[f].properties});c({method:"plugin",params:[{services:k,metadata:i||{}}]});d=!0}e&&e()};this.disconnect=function(){d&&(removeEventListener("message",h),j=null,d=!1)}};define("orion/plugin",function(){});
define("plugins/preferencesPlugin",["orion/xhr","domReady!","orion/plugin"],function(i){function c(a){this.location=a}c.prototype={get:function(a){return i("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,c){return i("PUT",this.location+a,{data:JSON.stringify(c),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 e=new c(e.href),h=new eclipse.PluginProvider;h.registerServiceProvider("orion.core.preference.provider",e,{});h.connect()});