KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > registry > EditorRegistryReader


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.registry;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IExtensionRegistry;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.ui.PlatformUI;
21
22 /**
23  * This class is used to read resource editor registry descriptors from
24  * the platform registry.
25  */

26 public class EditorRegistryReader extends RegistryReader {
27
28     private EditorRegistry editorRegistry;
29
30     /**
31      * Get the editors that are defined in the registry
32      * and add them to the ResourceEditorRegistry
33      *
34      * Warning:
35      * The registry must be passed in because this method is called during the
36      * process of setting up the registry and at this time it has not been
37      * safely setup with the plugin.
38      */

39     protected void addEditors(EditorRegistry registry) {
40         IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
41         this.editorRegistry = registry;
42         readRegistry(extensionRegistry, PlatformUI.PLUGIN_ID,
43                 IWorkbenchRegistryConstants.PL_EDITOR);
44     }
45
46     /**
47      * Implementation of the abstract method that
48      * processes one configuration element.
49      */

50     protected boolean readElement(IConfigurationElement element) {
51         if (!element.getName().equals(IWorkbenchRegistryConstants.TAG_EDITOR)) {
52             return false;
53         }
54
55         String JavaDoc id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
56         if (id == null) {
57             logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_ID);
58             return true;
59         }
60         
61         EditorDescriptor editor = new EditorDescriptor(id, element);
62         
63         List JavaDoc extensionsVector = new ArrayList JavaDoc();
64         List JavaDoc filenamesVector = new ArrayList JavaDoc();
65         List JavaDoc contentTypeVector = new ArrayList JavaDoc();
66         boolean defaultEditor = false;
67
68         // Get editor name (required field).
69
if (element.getAttribute(IWorkbenchRegistryConstants.ATT_NAME) == null) {
70             logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_NAME);
71             return true;
72         }
73
74         // Get editor icon (required field for internal editors)
75
if (element.getAttribute(IWorkbenchRegistryConstants.ATT_ICON) == null) {
76             if (getClassValue(element, IWorkbenchRegistryConstants.ATT_CLASS) != null) {
77                 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_ICON);
78                 return true;
79             }
80         }
81         
82         // Get target extensions (optional field)
83
String JavaDoc extensionsString = element.getAttribute(IWorkbenchRegistryConstants.ATT_EXTENSIONS);
84         if (extensionsString != null) {
85             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(extensionsString,
86                     ",");//$NON-NLS-1$
87
while (tokenizer.hasMoreTokens()) {
88                 extensionsVector.add(tokenizer.nextToken().trim());
89             }
90         }
91         String JavaDoc filenamesString = element.getAttribute(IWorkbenchRegistryConstants.ATT_FILENAMES);
92         if (filenamesString != null) {
93             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(filenamesString,
94                     ",");//$NON-NLS-1$
95
while (tokenizer.hasMoreTokens()) {
96                 filenamesVector.add(tokenizer.nextToken().trim());
97             }
98         }
99         
100         IConfigurationElement [] bindings = element.getChildren(IWorkbenchRegistryConstants.TAG_CONTENT_TYPE_BINDING);
101         for (int i = 0; i < bindings.length; i++) {
102             String JavaDoc contentTypeId = bindings[i].getAttribute(IWorkbenchRegistryConstants.ATT_CONTENT_TYPE_ID);
103             if (contentTypeId == null) {
104                 continue;
105             }
106             contentTypeVector.add(contentTypeId);
107         }
108         
109         // Is this the default editor?
110
String JavaDoc def = element.getAttribute(IWorkbenchRegistryConstants.ATT_DEFAULT);
111         if (def != null) {
112             defaultEditor = Boolean.valueOf(def).booleanValue();
113         }
114
115         // Add the editor to the manager.
116
editorRegistry.addEditorFromPlugin(editor, extensionsVector,
117                 filenamesVector, contentTypeVector, defaultEditor);
118         return true;
119     }
120
121
122     /**
123      * @param editorRegistry
124      * @param element
125      */

126     public void readElement(EditorRegistry editorRegistry,
127             IConfigurationElement element) {
128         this.editorRegistry = editorRegistry;
129         readElement(element);
130     }
131 }
132
Popular Tags