|
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 |
} |