Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 284700
Collapse All | Expand All

(-)Eclipse UI/org/eclipse/rap/ui/interactiondesign/layout/LayoutRegistry.java (-71 / +48 lines)
Lines 51-56 Link Here
51
  
51
  
52
  private static Map layoutMap;
52
  private static Map layoutMap;
53
  private static Map layoutSetToPluginId; 
53
  private static Map layoutSetToPluginId; 
54
  private static List overridenLayoutSets;
54
  
55
  
55
  static {
56
  static {
56
    init();
57
    init();
Lines 89-95 Link Here
89
  
90
  
90
  /**
91
  /**
91
   * Sets the active <code>Layout</code> to the one, which belongs to the 
92
   * Sets the active <code>Layout</code> to the one, which belongs to the 
92
   * id in the paramter and save the new id if necessary.
93
   * id in the parameter and save the new id if necessary.
93
   * 
94
   * 
94
   * @param id the new <code>Layout</code> id.
95
   * @param id the new <code>Layout</code> id.
95
   * @param save if <code>true</code> then the new <code>Layout</code> will be
96
   * @param save if <code>true</code> then the new <code>Layout</code> will be
Lines 121-154 Link Here
121
  }
122
  }
122
  
123
  
123
  /**
124
  /**
124
   * Returns the active <code>Layout</code>. If the active <code>Layout</code>
125
   * Returns the active <code>Layout</code>. 
125
   * is not the default <code>Layout</code> then a hybrid <code>Layout</code>
126
   * is created. This contains the default <code>Layout</code> and the active
127
   * <code>Layout</code>. 
128
   * <p>
129
   * This is necessary because a active layout can override
130
   * single <code>LayoutSet</code>s of a <code>Layout</code> but their can also
131
   * be <code>LayoutSet</code>s, which the active <code>Layout</code> doesn't 
132
   * override.
133
   * </p>
134
   *  
126
   *  
135
   * @return the active layout containing default <code>LayoutSet</code>s if the
127
   * @return the active layout 
136
   * active <code>Layout</code> doesn't override all default <code>LayoutSet
137
   * </code>s.
138
   * 
139
   * @see LayoutSet
140
   * @see Layout
128
   * @see Layout
141
   */
129
   */
142
  public Layout getActiveLayout() {
130
  public Layout getActiveLayout() {
143
    Layout result = activeLayout;
131
    Layout result = activeLayout;
144
    if( activeLayoutId.equals( DEFAULT_LAYOUT_ID ) ) {
132
    if( result == null ) {
145
      if( result == null ) {
133
      result =  ( Layout ) layoutMap.get( activeLayoutId );
146
        result =  ( Layout ) layoutMap.get( activeLayoutId );
134
      activeLayout = result;
147
        activeLayout = result;
135
    }         
148
      }      
149
    } else {
150
      result = createHybridLayout();
151
    }    
152
    return result;
136
    return result;
153
  }
137
  }
154
138
Lines 208-222 Link Here
208
192
209
  /**
193
  /**
210
   * Initialize the <code>{@link LayoutSet}</code> contributed to the
194
   * Initialize the <code>{@link LayoutSet}</code> contributed to the
211
   * <code>org.eclipse.rap.ui.layouts</code> extension point. 
195
   * <code>org.eclipse.rap.ui.layouts</code> extension point.
212
   * Additional it sets the active <code>Layout</code> to 
213
   * <code>{#DEFAULT_LAYOUT_ID}</code>.
214
   */
196
   */
215
  private static void init() {
197
  private static void init() {
216
    layoutSetToPluginId = new HashMap();
198
    layoutSetToPluginId = new HashMap();
217
    layoutMap = new HashMap();
199
    layoutMap = new HashMap();
200
    overridenLayoutSets = new ArrayList();
218
    IConfigurationElement[] elements = getLayoutExtensions();
201
    IConfigurationElement[] elements = getLayoutExtensions();
219
    for( int i = elements.length - 1; i >= 0; i-- ) {
202
    for( int i = 0; i < elements.length; i++ ) {
220
      String id = elements[ i ].getAttribute( "id" );
203
      String id = elements[ i ].getAttribute( "id" );
221
      
204
      
222
      Layout layout = ( Layout ) layoutMap.get( id );
205
      Layout layout = ( Layout ) layoutMap.get( id );
Lines 240-247 Link Here
240
    return result;
223
    return result;
241
  }
224
  }
242
225
243
  private static void createLayoutSets( final IConfigurationElement[] layoutSets, 
226
  private static void createLayoutSets( 
244
                                        final Layout layout ) 
227
    final IConfigurationElement[] layoutSets, 
228
    final Layout layout ) 
245
  {
229
  {
246
    if( layoutSets != null && layoutSets.length > 0 ) {
230
    if( layoutSets != null && layoutSets.length > 0 ) {
247
      for( int i = 0; i < layoutSets.length; i++ ) {
231
      for( int i = 0; i < layoutSets.length; i++ ) {
Lines 249-303 Link Here
249
233
250
        String pluginId = layoutSetElement.getContributor().getName();
234
        String pluginId = layoutSetElement.getContributor().getName();
251
        String layoutSetId = layoutSetElement.getAttribute( "id" );
235
        String layoutSetId = layoutSetElement.getAttribute( "id" );
252
236
        String overrides = layoutSetElement.getAttribute( "overrides" );
253
        layout.clearLayoutSet( layoutSetId );
237
        if( overrides != null ) {
254
        LayoutSet layoutSet = layout.getLayoutSet( layoutSetId );
238
          // clear the old layoutset if it exists and create it with the new 
255
        layoutSetToPluginId.put( layoutSetId, pluginId );
239
          // contents. Addition create a new layoutset with the new id if 
256
240
          // someone want to override it again.
257
        try {
241
          layout.clearLayoutSet( overrides );
258
          Object initializer 
242
          LayoutSet layoutSet = layout.getLayoutSet( overrides );
259
            = layoutSetElement.createExecutableExtension( "class" );
243
          layoutSetToPluginId.remove( overrides );
260
          if( initializer instanceof ILayoutSetInitializer ) {
244
          layoutSetToPluginId.put( overrides, pluginId );
261
            ILayoutSetInitializer layoutInitializer 
245
          initializeLayoutSet( layoutSetElement, layoutSet );
262
              = ( ILayoutSetInitializer ) initializer;
246
          LayoutSet overridingLayoutSet = layout.getLayoutSet( layoutSetId );
263
            layoutInitializer.initializeLayoutSet( layoutSet );
247
          layoutSetToPluginId.put( layoutSetId, pluginId );
248
          initializeLayoutSet( layoutSetElement, overridingLayoutSet );
249
          overridenLayoutSets.add( overrides );
250
        } else {          
251
          if( !overridenLayoutSets.contains( layoutSetId ) ) {
252
            // a new layoutset will only created if it's not already overridden.
253
            layout.clearLayoutSet( layoutSetId );
254
            LayoutSet layoutSet = layout.getLayoutSet( layoutSetId );
255
            layoutSetToPluginId.put( layoutSetId, pluginId );  
256
            initializeLayoutSet( layoutSetElement, layoutSet );
264
          }
257
          }
265
        } catch( CoreException e ) {
266
          e.printStackTrace();
267
        }
258
        }
268
      }      
259
      }      
269
    }
260
    }
270
  }
261
  }
271
262
272
  private void combineLayoutSets( final Layout layout,
263
  private static void initializeLayoutSet( 
273
                                  final Layout defaultLayout,
264
    final IConfigurationElement layoutSetElement,
274
                                  final Layout activeLayout )
265
    final LayoutSet layoutSet )
275
  {
266
  {
276
    if( defaultLayout != null ) {
267
    try {
277
      Map defaultLayoutSets = defaultLayout.getLayoutSets();
268
      Object initializer 
278
      createLayoutSetFromLayout( layout, defaultLayoutSets );
269
        = layoutSetElement.createExecutableExtension( "class" );
270
      if( initializer instanceof ILayoutSetInitializer ) {
271
        ILayoutSetInitializer layoutInitializer 
272
          = ( ILayoutSetInitializer ) initializer;
273
        layoutInitializer.initializeLayoutSet( layoutSet );
274
      }
275
    } catch( CoreException e ) {
276
      e.printStackTrace();
279
    }
277
    }
280
    Map activeLayoutSets = activeLayout.getLayoutSets();
281
    createLayoutSetFromLayout( layout, activeLayoutSets );
282
  }
278
  }
283
279
284
  private Layout createHybridLayout() {
285
    // TODO [hs] think about cache for hybrid Layouts
286
    Layout result = new Layout( activeLayoutId );    
287
    Layout defaultLayout = ( Layout )layoutMap.get( DEFAULT_LAYOUT_ID );
288
    combineLayoutSets( result, defaultLayout, activeLayout );    
289
    return result;
290
  }
291
  
292
  private void createLayoutSetFromLayout( final Layout layout,
293
                                          final Map layoutSets )
294
  {
295
    Object[] keys = layoutSets.keySet().toArray();
296
    for( int i = 0; i < keys.length; i++ ) {
297
      String key = ( String )keys[ i ];
298
      LayoutSet set = ( LayoutSet )layoutSets.get( key );
299
      layout.clearLayoutSet( key );
300
      layout.addLayoutSet( set );
301
    }
302
  }
303
}
280
}
(-)Eclipse UI/org/eclipse/rap/ui/interactiondesign/layout/model/Layout.java (+1 lines)
Lines 58-63 Link Here
58
    LayoutSet set = ( LayoutSet ) layoutSets.get( layoutSetId );
58
    LayoutSet set = ( LayoutSet ) layoutSets.get( layoutSetId );
59
    if( set != null ) {
59
    if( set != null ) {
60
      layoutSets.remove( layoutSetId );
60
      layoutSets.remove( layoutSetId );
61
      set = null;
61
    }
62
    }
62
  }
63
  }
63
  
64
  
(-)schema/rap/layouts.exsd (-18 / +28 lines)
Lines 2-10 Link Here
2
<!-- Schema file written by PDE -->
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.rap.ui" xmlns="http://www.w3.org/2001/XMLSchema">
3
<schema targetNamespace="org.eclipse.rap.ui" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
4
<annotation>
5
      <appinfo>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.rap.ui" id="layouts" name="Layouts"/>
6
         <meta.schema plugin="org.eclipse.rap.ui" id="layouts" name="Layouts"/>
7
      </appinfo>
7
      </appInfo>
8
      <documentation>
8
      <documentation>
9
         This extension point is used to register a custom Layout. This means a grafical Layout not a Layout from the programmers point of view.&lt;br&gt;
9
         This extension point is used to register a custom Layout. This means a grafical Layout not a Layout from the programmers point of view.&lt;br&gt;
10
Every Layout can hold attributes called LayoutSets. A LayoutSet is a simple container for images, fonts, colors and position data. These sets are usually coupled to a &lt;code&gt;ElementBuilder&lt;/code&gt;.&lt;br&gt;
10
Every Layout can hold attributes called LayoutSets. A LayoutSet is a simple container for images, fonts, colors and position data. These sets are usually coupled to a &lt;code&gt;ElementBuilder&lt;/code&gt;.&lt;br&gt;
Lines 15-23 Link Here
15
15
16
   <element name="extension">
16
   <element name="extension">
17
      <annotation>
17
      <annotation>
18
         <appinfo>
18
         <appInfo>
19
            <meta.element />
19
            <meta.element />
20
         </appinfo>
20
         </appInfo>
21
      </annotation>
21
      </annotation>
22
      <complexType>
22
      <complexType>
23
         <sequence>
23
         <sequence>
Lines 42-50 Link Here
42
               <documentation>
42
               <documentation>
43
                  
43
                  
44
               </documentation>
44
               </documentation>
45
               <appinfo>
45
               <appInfo>
46
                  <meta.attribute translatable="true"/>
46
                  <meta.attribute translatable="true"/>
47
               </appinfo>
47
               </appInfo>
48
            </annotation>
48
            </annotation>
49
         </attribute>
49
         </attribute>
50
      </complexType>
50
      </complexType>
Lines 71-79 Link Here
71
               <documentation>
71
               <documentation>
72
                  The definition of a LayoutSet. This is a class that has to implement the ILayoutSetInitializer interface.
72
                  The definition of a LayoutSet. This is a class that has to implement the ILayoutSetInitializer interface.
73
               </documentation>
73
               </documentation>
74
               <appinfo>
74
               <appInfo>
75
                  <meta.attribute kind="java" basedOn=":org.eclipse.rap.ui.interactiondesign.layout.model.ILayoutSetInitializer"/>
75
                  <meta.attribute kind="java" basedOn=":org.eclipse.rap.ui.interactiondesign.layout.model.ILayoutSetInitializer"/>
76
               </appinfo>
76
               </appInfo>
77
            </annotation>
78
         </attribute>
79
         <attribute name="overrides" type="string">
80
            <annotation>
81
               <documentation>
82
                  To replace a layoutSet you can define a a new one and set the overrides attribute to make clear that the new layoutSet will replace the one defined in this attribute.
83
               </documentation>
84
               <appInfo>
85
                  <meta.attribute kind="identifier" basedOn="org.eclipse.rap.ui.layouts/layout/layoutSet/@id"/>
86
               </appInfo>
77
            </annotation>
87
            </annotation>
78
         </attribute>
88
         </attribute>
79
      </complexType>
89
      </complexType>
Lines 102-119 Link Here
102
   </element>
112
   </element>
103
113
104
   <annotation>
114
   <annotation>
105
      <appinfo>
115
      <appInfo>
106
         <meta.section type="since"/>
116
         <meta.section type="since"/>
107
      </appinfo>
117
      </appInfo>
108
      <documentation>
118
      <documentation>
109
         RAP 1.2
119
         RAP 1.2
110
      </documentation>
120
      </documentation>
111
   </annotation>
121
   </annotation>
112
122
113
   <annotation>
123
   <annotation>
114
      <appinfo>
124
      <appInfo>
115
         <meta.section type="examples"/>
125
         <meta.section type="examples"/>
116
      </appinfo>
126
      </appInfo>
117
      <documentation>
127
      <documentation>
118
         The following is an example of a Layout with three LayoutSets: 
128
         The following is an example of a Layout with three LayoutSets: 
119
&lt;p&gt;
129
&lt;p&gt;
Lines 149-157 Link Here
149
   </annotation>
159
   </annotation>
150
160
151
   <annotation>
161
   <annotation>
152
      <appinfo>
162
      <appInfo>
153
         <meta.section type="apiinfo"/>
163
         <meta.section type="apiinfo"/>
154
      </appinfo>
164
      </appInfo>
155
      <documentation>
165
      <documentation>
156
         Each LayoutSet in a Layout has to implement the &lt;code&gt;ILayoutSetInitializer&lt;/code&gt; interface. The method within is called during the plugin activation to initialize components like images or fonts for this LayoutSet. This implementation can look like this:
166
         Each LayoutSet in a Layout has to implement the &lt;code&gt;ILayoutSetInitializer&lt;/code&gt; interface. The method within is called during the plugin activation to initialize components like images or fonts for this LayoutSet. This implementation can look like this:
157
167
Lines 170-187 Link Here
170
   </annotation>
180
   </annotation>
171
181
172
   <annotation>
182
   <annotation>
173
      <appinfo>
183
      <appInfo>
174
         <meta.section type="implementation"/>
184
         <meta.section type="implementation"/>
175
      </appinfo>
185
      </appInfo>
176
      <documentation>
186
      <documentation>
177
         A detailed implementation example can be found in the &lt;code&gt;org.eclipse.rap.presentation.example&lt;/code&gt; project. This project defines two Layouts and a bunch of LayoutSets. They look not pretty but they do their job.
187
         A detailed implementation example can be found in the &lt;code&gt;org.eclipse.rap.presentation.example&lt;/code&gt; project. This project defines two Layouts and a bunch of LayoutSets. They look not pretty but they do their job.
178
      </documentation>
188
      </documentation>
179
   </annotation>
189
   </annotation>
180
190
181
   <annotation>
191
   <annotation>
182
      <appinfo>
192
      <appInfo>
183
         <meta.section type="copyright"/>
193
         <meta.section type="copyright"/>
184
      </appinfo>
194
      </appInfo>
185
      <documentation>
195
      <documentation>
186
         Copyright (c) 2008 EclipseSource and others. All rights reserved. This
196
         Copyright (c) 2008 EclipseSource and others. All rights reserved. This
187
program and the accompanying materials are made available under the terms of
197
program and the accompanying materials are made available under the terms of
(-)plugin.xml (-3 / +4 lines)
Lines 66-76 Link Here
66
         point="org.eclipse.rap.ui.layouts">
66
         point="org.eclipse.rap.ui.layouts">
67
      <layout
67
      <layout
68
            id="org.eclipse.rap.design.example.business.layout"
68
            id="org.eclipse.rap.design.example.business.layout"
69
            name="Business Layout Blue">
69
            name="Business Layout Blue Extended">
70
         <layoutSet
70
         <layoutSet
71
               class="org.eclipse.rap.examples.internal.design.LogoInitializer"
71
               class="org.eclipse.rap.examples.internal.design.LogoInitializer"
72
               id="org.eclipse.rap.design.example.business.layoutset.logo"
72
               id="org.eclipse.rap.design.example.business.layoutset.logo.extended"
73
               name="Logo">
73
               name="Logo"
74
               overrides="org.eclipse.rap.design.example.business.layoutset.logo">
74
         </layoutSet>
75
         </layoutSet>
75
      </layout>
76
      </layout>
76
   </extension>
77
   </extension>

Return to bug 284700