KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > PresentationFactoryUtil


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 package org.eclipse.ui.internal.presentations;
12
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.ui.IMemento;
15 import org.eclipse.ui.presentations.AbstractPresentationFactory;
16 import org.eclipse.ui.presentations.IPresentationSerializer;
17 import org.eclipse.ui.presentations.IStackPresentationSite;
18 import org.eclipse.ui.presentations.StackPresentation;
19
20 /**
21  *
22  */

23 public class PresentationFactoryUtil {
24
25     public static final int ROLE_EDITOR = 0x01;
26
27     public static final int ROLE_VIEW = 0x02;
28
29     public static final int ROLE_STANDALONE = 0x03;
30
31     public static final int ROLE_STANDALONE_NOTITLE = 0x04;
32     
33     public static StackPresentation createPresentation(
34             AbstractPresentationFactory factory, int role, Composite parent,
35             IStackPresentationSite site, IPresentationSerializer serializer,
36             IMemento memento) {
37
38         StackPresentation presentation = null;
39
40         switch (role) {
41         case ROLE_EDITOR:
42             presentation = factory.createEditorPresentation(parent, site);
43             break;
44         case ROLE_STANDALONE:
45             presentation = factory.createStandaloneViewPresentation(parent,
46                     site, true);
47             break;
48         case ROLE_STANDALONE_NOTITLE:
49             presentation = factory.createStandaloneViewPresentation(parent,
50                     site, false);
51             break;
52         default:
53             presentation = factory.createViewPresentation(parent, site);
54         }
55
56         //don't initialize editors at creation time - it will not contain any parts
57
if (role != ROLE_EDITOR && memento != null && serializer != null) {
58             presentation.restoreState(serializer, memento);
59         }
60
61         return presentation;
62     }
63
64     private PresentationFactoryUtil() {
65
66     }
67 }
68
Popular Tags