Orion/Documentation/Developer Guide/Core client services

From Eclipsepedia

Jump to: navigation, search

Contents

Overview of core client services

Orion provides a number of basic infrastructure services that can be used by client scripts for performing various tasks. These services have no user interface component and can be used within any page of a client application. This section of the guide outlines what services are available, along with simple examples of how to use them.

orion.core.favorite

The orion.core.favorite service is used to access and store the user's bookmarks or favorites. While a user may opt to use their own browser's bookmark mechanism instead, there are some specific advantages to using Orion's favorite service instead:

  • Favorites are persisted on the server, so the user can switch to another client computer or browser and access their familiar bookmarks
  • Favorites are associated with a specific Orion application and user, so favorites from different users or applications are not all mixed into a single place.

Here is an example usage of the favorites service:

serviceRegistry.getService("orion.core.favorite").then(function(service) {
  service.makeFavorites(item);
});

See orion.favorites.FavoritesService in the Orion client API reference for a complete list of functions available on the favorite service.

orion.core.file

The orion.core.file service is used to provide file system contents for the Orion workspace. For example a plug-in can use this service to include content from one server into a workspace on another server. Each file service is displayed as a root element in the Orion Navigator page.

The code snippet below demonstrates a use of this service:

 provider.registerServiceProvider("orion.core.file", service, {Name: 'Sample File System'});

The above code will contribute a top level node to the Navigator named "Sample File System". The parameter "service" in the API above must provide the functions specified by the Orion file client API. Refer to orion.fileClient.FileClient in the client API reference for further details. For more information on client-server interaction, see Orion File Server API. For an complete file system example, see the sample file plugin in the Orion Git repository.

orion.core.linkScanner

Link scanners are declarative services that specify patterns of text to replace with link anchors. Scanners contribute a regular expression pattern to match in the source text. They then provide a link to be inserted for each match. These scanners are used by the text link service to convert text into a DOM node with appropriate anchor and text nodes as children.

Service methods

None.

Service attributes

Implementations of orion.core.linkScanner must define the following attributes:

pattern
A regular expression string to locate links in the source text
words
A Number identifying the number of white-space delimited words in each match
anchor
A template of the URL for each match. The template may contain variables of the form %1, %2, etc, which are substituted by each of the words in the match.

Examples

The following scanner will replace text of the form "bug 123456" with links of the form "https://bugs.eclipse.org/123456

var provider = new eclipse.PluginProvider();
var serviceImpl = {};
var serviceProperties = { 
  pattern: "bug\\s\\d{4,7}",
  words: 2,
  anchor: "https://bugs.eclipse.org/%2"
};
provider.registerServiceProvider("orion.core.linkScanner", serviceImpl, serviceProperties);
provider.connect();

This scanner will replace email addresses with mailto: URLs:

var provider = new eclipse.PluginProvider();
var serviceImpl = {};
var serviceProperties = { 
  pattern: "\\b[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b",
  words: 1,
  anchor: "mailto:%1"
};
provider.registerServiceProvider("orion.core.linkScanner", serviceImpl, serviceProperties);
provider.connect();

orion.core.marker

The marker service is used to store problems found by a builder or syntax validator. A client can register with this service for notification when markers are changed. Here is an example of a component that is registering for notification of marker changes:

 serviceRegistry.getService("orion.core.marker").then(function(markers) {
   markers.addEventListener("problemsChanged", function(problems) {
     //do something with the new problems
   });
 });

Each marker is a simple JSON object with the following properties:

reason
A string stating the description of the problem or marker
line
The line number of the marker
character
The column position of the marker

orion.core.preference

The preferences service manages a hierarchical set of preference nodes. Nodes are identified by a path string, where segments are delimited by the slash character ('/'). Each node is a JSON object with string keys and values that are String, Boolean, or Number.

Here is an example of retrieving a preference storing the list of recently used projects:

 prefService.getPreferences("/window/recent").then(function(prefs) {
   var projects =  prefs.get("projects");
   if (typeof projects === "string") {
     projects = JSON.parse(projects);
   }
   if (projects && projects.length && projects.length > 0) {
     //do something with the projects
   }
 });

And here is an example of adding a new project to the list, and storing the result back in the preference service:

 prefService.getPreferences("/window/recent").then(function(prefs) {
   var projects = prefs.get("projects");
   if (typeof projects === "string") {
     projects = JSON.parse(projects);
   }
   projects.push({name: "My Proj", location: "http://example.com/myproj"});
   prefs.put("projects", projects);
 });

orion.core.textlink

The text link service scans text for segments that could be interpreted as hyperlinks, and inserts appropriate anchor elements representing each link. For example the service could scan for email addresses in a piece of text and convert them to mailto: links.

Here is an example of using the text link service:

var divWithLinks = linkService.addLinks(someText);
dojo.place(divWithLinks, body, "first");

The text link service makes use of link scanners contributed by plugins to perform the analysis and replacement of text with links. If no link scanners are available, the text link service simply returns a DOM element containing the entire input text.


orion.file.contenttype

The content type service tells Orion about a new kind of file. The content types provided by this service don't have any direct effect on the Orion UI, but they can be referred to by other services that need to associate themselves with a particular kind of file. For an example, see orion.navigate.openWith.

Service attributes

contentTypes
An Array containing one or more content types to register. Each element of the array has this shape:
id
String The unique identifier of the content type. This is a simple hierarchical name and usually starts with a category like "text" or "image".
name
String The user-readable name of the content type.
extension
String[] Optional. Array of file extensions to be associated with this content type.
extension
String[] Optional. Array of filenames to be associated with this content type. Use this when a type does not have a characteristic file extension, but rather a filename. (For example, "Makefile", "README").
extends
String Optional. If this content type is a subtype of another, this gives the parent content type's ID.

Service methods

None. This service is purely declarative.

Example

This example code contributes contributes a new content type for Perl files. A Perl file extends from "text.plain" and has the extension .pl.

 provider.registerServiceProvider("orion.file.contenttype", {}, {
   contentTypes: [{  id: "text.perl",
                     name: "Perl",
                     extension: ["pl"],
                     "extends": "text.plain"
                  }]);
 provider.connect();

The example code below contributes a new content type for Ant build files. An Ant build file is a special kind of XML file that always has the name "build.xml".

 provider.registerServiceProvider("orion.file.contenttype", {}, {
   contentTypes: [{  id: "text.ant",
                     name: "Ant build file",
                     filename: ["build.xml"],
                     "extends": "text.xml"
                  }]);
 provider.connect();