Skip to main content
summaryrefslogtreecommitdiffstats
blob: df70e98c06281923e08f50ca7011eeb53d14f4b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.jem.util">
<annotation>
      <appInfo>
         <meta.schema plugin="org.eclipse.jem.util" id="uiContextSensitiveClass" name="UI Context Sensitive Class"/>
      </appInfo>
      <documentation>
         Components are often designed in such a way that the &quot;Headless&quot; or non-graphical portions are separate from the Graphical User Interface (GUI) portions. Sometimes this is done to follow good design principles, other times there is a specific use case for doing so. When plugins follow this practice because they must vary their behavior based on whether they are running in a headless environment or a graphical environment, they often need to choose the correct implementation of a particular type. The org.eclipse.jem.util.uiContextSensitiveClass extension point provided by the JEM component solves exactly this problem.
&lt;p&gt;    
To use the extension point, you must provide two extensions that are linked by a key. The key is a unique String-based value that you will later use to instanitate your class.
&lt;p&gt;
The first usage of the extension specifies your key, and the Headless context, and the class that should be instantiated for this (key, context) pair. This means in the headless environment this class will be instantiated when requested.
&lt;p&gt;
The second extension specifies the UI context and the same key, but a different implementation designed for graphical environments. This means in the UI environment this other class will be instantiated when requested.
&lt;p&gt;
The actual request is done in your code via:
&lt;pre&gt;
IMyInterface instance = (IMyInterface) UIContextDetermination.createInstance(&quot;myKey&quot;);
&lt;/pre&gt;
where &lt;code&gt;&quot;myKey&quot;&lt;/code&gt; is the key used on both extensions. It will then choose either the UI or the Headless extension depending upon the context.
      </documentation>
   </annotation>

   <element name="extension">
      <complexType>
         <sequence>
            <element ref="uiContextSensitiveClass" minOccurs="1" maxOccurs="unbounded"/>
         </sequence>
         <attribute name="point" type="string" use="required">
            <annotation>
               <documentation>
                  
               </documentation>
            </annotation>
         </attribute>
         <attribute name="id" type="string">
            <annotation>
               <documentation>
                  
               </documentation>
            </annotation>
         </attribute>
         <attribute name="name" type="string">
            <annotation>
               <documentation>
                  
               </documentation>
            </annotation>
         </attribute>
      </complexType>
   </element>

   <element name="uiContextSensitiveClass">
      <annotation>
         <documentation>
            An extension point that defines an instance of a class and its appropriate context (UI or Headless)
         </documentation>
      </annotation>
      <complexType>
         <attribute name="key" type="string" use="required">
            <annotation>
               <documentation>
                  The key that should be used to create an instance of the Context Sensitive super class/interface.
               </documentation>
            </annotation>
         </attribute>
         <attribute name="className" type="string" use="required">
            <annotation>
               <documentation>
                  A concrete implementation for either a UI or Headless context.
               </documentation>
            </annotation>
         </attribute>
         <attribute name="context" use="required">
            <annotation>
               <documentation>
                  One of &quot;UI&quot; or &quot;Headless&quot; This is case-sensitive. It must match exactly as shown here.
               </documentation>
            </annotation>
            <simpleType>
               <restriction base="string">
                  <enumeration value="UI">
                  </enumeration>
                  <enumeration value="Headless">
                  </enumeration>
               </restriction>
            </simpleType>
         </attribute>
      </complexType>
   </element>

   <annotation>
      <appInfo>
         <meta.section type="since"/>
      </appInfo>
      <documentation>
         6.0
      </documentation>
   </annotation>

   <annotation>
      <appInfo>
         <meta.section type="examples"/>
      </appInfo>
      <documentation>
         Usage for the UI context:
&lt;pre&gt;
   &lt;extension
       id=&quot;context.Sensitive.Class.workingCopyManager&quot;
       name=&quot;Working Copy Manager - UI Context Class&quot;
       point=&quot;org.eclipse.jem.util.ContextSensitiveClass&quot;&gt;
     &lt;uiContextSensitiveClass
       context=&quot;UI&quot;
       key=&quot;workingCopyManager&quot;
       className=&quot;com.ibm.wtp.common.ui.WTPUIWorkingCopyManager&quot;/&gt;
   &lt;/extension&gt;
&lt;/pre&gt;
&lt;br&gt;
Usage for the Headless context:
&lt;pre&gt;
   &lt;extension
       id=&quot;context.Sensitive.Class.workingCopyManager&quot;
       name=&quot;Working Copy Manager - Headless Context Class&quot;
       point=&quot;org.eclipse.jem.util.ContextSensitiveClass&quot;&gt;
     &lt;uiContextSensitiveClass
         context=&quot;Headless&quot;
         key=&quot;workingCopyManager&quot;
         className=&quot;com.ibm.wtp.common.ui.WTPHeadlessWorkingCopyManager&quot;/&gt;
   &lt;/extension&gt;
&lt;/pre&gt;
&lt;br&gt;
And finally the retrieval of the class for the current context:

&lt;pre&gt;
IWorkingCopyManager manager = (IWorkingCopyManager) UIContextDetermination.createInstance(&quot;workingCopyManager&quot;);
&lt;/pre&gt;

      </documentation>
   </annotation>

   <annotation>
      <appInfo>
         <meta.section type="apiInfo"/>
      </appInfo>
      <documentation>
         See &lt;code&gt;org.eclipse.jem.util.UIContextDetermination&lt;/code&gt;
      </documentation>
   </annotation>

   <annotation>
      <appInfo>
         <meta.section type="implementation"/>
      </appInfo>
      <documentation>
         
      </documentation>
   </annotation>

   <annotation>
      <appInfo>
         <meta.section type="copyright"/>
      </appInfo>
      <documentation>
         Copyright (c) IBM 2003.
      </documentation>
   </annotation>

</schema>

Back to the top