KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > statushandlers > StatusHandlerDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2007 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.statushandlers;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IConfigurationElement;
19 import org.eclipse.ui.IPluginContribution;
20 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
21 import org.eclipse.ui.statushandlers.AbstractStatusHandler;
22
23 /**
24  * The status handler descriptor.
25  *
26  * @since 3.3
27  */

28 public class StatusHandlerDescriptor implements IPluginContribution {
29
30     private AbstractStatusHandler cachedInstance;
31
32     private final static String JavaDoc PREFIX = "prefix"; //$NON-NLS-1$
33

34     private IConfigurationElement configElement;
35
36     private String JavaDoc id;
37
38     private String JavaDoc pluginId;
39
40     private String JavaDoc prefix;
41
42     /**
43      * @param configElement
44      */

45     public StatusHandlerDescriptor(IConfigurationElement configElement) {
46         super();
47         this.configElement = configElement;
48         id = configElement.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
49         pluginId = configElement.getContributor().getName();
50     }
51
52     /**
53      * Gets an instance of the status handler defined in the descriptor.
54      *
55      * @return the status handler
56      * @throws CoreException
57      * thrown if there is a problem creating the handler
58      */

59     public synchronized AbstractStatusHandler getStatusHandler()
60             throws CoreException {
61         if (cachedInstance == null) {
62             AbstractStatusHandler statusHandler = (AbstractStatusHandler) configElement
63                     .createExecutableExtension(IWorkbenchRegistryConstants.ATT_CLASS);
64             statusHandler.setId(configElement
65                     .getAttribute(IWorkbenchRegistryConstants.ATT_ID));
66
67             IConfigurationElement parameters[] = configElement
68                     .getChildren(IWorkbenchRegistryConstants.TAG_PARAMETER);
69
70             Map JavaDoc params = new HashMap JavaDoc();
71
72             for (int i = 0; i < parameters.length; i++) {
73                 params
74                         .put(
75                                 parameters[i]
76                                         .getAttribute(IWorkbenchRegistryConstants.ATT_NAME),
77                                 parameters[i]
78                                         .getAttribute(IWorkbenchRegistryConstants.ATT_VALUE));
79             }
80
81             statusHandler.setParams(params);
82             cachedInstance = statusHandler;
83         }
84         return cachedInstance;
85     }
86
87     /**
88      * Gets prefix parameter for the status handler defined in the descriptor.
89      *
90      * @return prefix parameter
91      */

92     public String JavaDoc getPrefix() {
93         IConfigurationElement parameters[] = configElement
94                 .getChildren(IWorkbenchRegistryConstants.TAG_PARAMETER);
95
96         for (int i = 0; i < parameters.length; i++) {
97             if (parameters[i]
98                     .getAttribute(IWorkbenchRegistryConstants.ATT_NAME).equals(
99                             PREFIX)) {
100                 prefix = parameters[i]
101                         .getAttribute(IWorkbenchRegistryConstants.ATT_VALUE);
102             }
103         }
104         return prefix;
105     }
106
107     /**
108      * Returns the id of the status handler.
109      *
110      * @return the id
111      */

112     public String JavaDoc getId() {
113         return id;
114     }
115
116     /*
117      * (non-Javadoc)
118      *
119      * @see org.eclipse.ui.IPluginContribution#getLocalId()
120      */

121     public String JavaDoc getLocalId() {
122         return id;
123     }
124
125     /*
126      * (non-Javadoc)
127      *
128      * @see org.eclipse.ui.IPluginContribution#getPluginId()
129      */

130     public String JavaDoc getPluginId() {
131         return pluginId;
132     }
133 }
134
Popular Tags