KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > model > loader > SharedConfigExtensionsManager


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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
12 package org.eclipse.ui.internal.intro.impl.model.loader;
13
14 import java.util.Hashtable JavaDoc;
15
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.core.runtime.IExtensionRegistry;
18 import org.eclipse.ui.internal.intro.impl.model.IntroStandbyContentPart;
19 import org.eclipse.ui.internal.intro.impl.model.IntroURLAction;
20 import org.eclipse.ui.internal.intro.impl.util.Log;
21 import org.eclipse.ui.internal.intro.impl.util.Util;
22
23 /**
24  * Class for handling all shared Intro Config Extensions. These are StandbyPart
25  * and Command contributions. Once defined these contributions are visible by
26  * all intro configs.
27  */

28
29 public class SharedConfigExtensionsManager {
30
31     private IExtensionRegistry registry;
32
33     // Holds all standbyPart extensions. Key is id, value is
34
// IntroStandbyContentPart.
35
private Hashtable JavaDoc standbyParts = new Hashtable JavaDoc();
36
37     // Holds all command extensions. Key is name, value is IntroURLAction.
38
private Hashtable JavaDoc commands = new Hashtable JavaDoc();
39
40     /*
41      * Prevent creation.
42      */

43     protected SharedConfigExtensionsManager(IExtensionRegistry registry) {
44         this.registry = registry;
45     }
46
47     /**
48      * Loads all shared config extennsions (ie: standby parts and commands.
49      */

50     protected void loadSharedConfigExtensions() {
51         // simply create model classes for all standbyPart elements under a
52
// configExtension.
53

54         long start = 0;
55         // if we need to log performance, capture time.
56
if (Log.logPerformance)
57             start = System.currentTimeMillis();
58
59         IConfigurationElement[] configExtensionElements = registry
60             .getConfigurationElementsFor(BaseExtensionPointManager.CONFIG_EXTENSION);
61
62         if (Log.logPerformance)
63             Util.logPerformanceTime(
64                 "quering registry for configExtensions took: ", start); //$NON-NLS-1$
65

66         for (int i = 0; i < configExtensionElements.length; i++) {
67             IConfigurationElement element = configExtensionElements[i];
68             if (!ModelLoaderUtil.isValidElementName(element,
69                 IntroStandbyContentPart.TAG_STANDBY_CONTENT_PART)
70                     && !ModelLoaderUtil.isValidElementName(element,
71                         IntroURLAction.TAG_ACTION))
72                 // if extension is not a standbypart or command, ignore.
73
continue;
74             createModelClass(element);
75         }
76     }
77
78
79     /**
80      * Create an intro standby part or an intro command model class.
81      *
82      * @param element
83      */

84     private void createModelClass(IConfigurationElement element) {
85         if (element.getName().equals(
86             IntroStandbyContentPart.TAG_STANDBY_CONTENT_PART)) {
87             IntroStandbyContentPart standbyPartContent = new IntroStandbyContentPart(
88                 element);
89             if (standbyPartContent.getId() == null)
90                 // no id, ignore.
91
return;
92             standbyParts.put(standbyPartContent.getId(), standbyPartContent);
93         } else {
94             IntroURLAction introURLCommand = new IntroURLAction(element);
95             if (introURLCommand.getName() == null
96                     || introURLCommand.getReplaceValue() == null)
97                 // no name or resolvedValue, ignore.
98
return;
99             commands.put(introURLCommand.getName(), introURLCommand);
100         }
101     }
102
103
104
105     /**
106      * @return Returns a standbyPart basd on its registred id.
107      */

108     public IntroStandbyContentPart getStandbyPart(String JavaDoc partId) {
109         if (partId == null)
110             return null;
111         return (IntroStandbyContentPart) standbyParts.get(partId);
112     }
113
114     /**
115      * @return Returns the command from its name.
116      */

117     public IntroURLAction getCommand(String JavaDoc commandName) {
118         if (commandName == null)
119             return null;
120         return (IntroURLAction) commands.get(commandName);
121     }
122
123 }
124
Popular Tags