KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > platform > internal > CheatSheetStandbyContent


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.platform.internal;
12
13 import org.eclipse.swt.layout.*;
14 import org.eclipse.swt.widgets.*;
15 import org.eclipse.ui.*;
16 import org.eclipse.ui.cheatsheets.*;
17 import org.eclipse.ui.forms.widgets.*;
18 import org.eclipse.ui.intro.*;
19 import org.eclipse.ui.intro.config.*;
20
21 public final class CheatSheetStandbyContent implements IStandbyContentPart {
22
23     private static String JavaDoc MEMENTO_CHEATSHEET_ID_ATT = "cheatsheetId"; //$NON-NLS-1$
24

25     //private IIntroPart introPart;
26
private ICheatSheetViewer viewer;
27     private Composite container;
28     private String JavaDoc input;
29
30     /*
31      * (non-Javadoc)
32      *
33      * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#init(org.eclipse.ui.intro.IIntroPart)
34      */

35     public void init(IIntroPart introPart, IMemento memento) {
36         //this.introPart = introPart;
37
// try to restore last state.
38
input = getCachedInput(memento);
39     }
40
41     /*
42      * (non-Javadoc)
43      *
44      * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#createControl(org.eclipse.swt.widgets.Composite,
45      * org.eclipse.ui.forms.widgets.FormToolkit)
46      */

47     public void createPartControl(Composite parent, FormToolkit toolkit) {
48         container = toolkit.createComposite(parent);
49         FillLayout layout = new FillLayout();
50         layout.marginWidth = layout.marginHeight = 0;
51         container.setLayout(layout);
52
53         viewer = CheatSheetViewerFactory.createCheatSheetView();
54         viewer.createPartControl(container);
55     }
56
57     /*
58      * (non-Javadoc)
59      *
60      * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#getControl()
61      */

62     public Control getControl() {
63         return container;
64     }
65
66
67     /*
68      * (non-Javadoc)
69      *
70      * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#setInput(java.lang.Object)
71      */

72     public void setInput(Object JavaDoc input) {
73         // if the new input is null, use cacched input from momento.
74
if (input != null)
75             this.input = (String JavaDoc) input;
76         viewer.setInput(this.input);
77     }
78
79     /*
80      * (non-Javadoc)
81      *
82      * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#setFocus()
83      */

84     public void setFocus() {
85         viewer.setFocus();
86     }
87
88     /*
89      * (non-Javadoc)
90      *
91      * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#dispose()
92      */

93     public void dispose() {
94
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see org.eclipse.ui.intro.config.IStandbyContentPart#saveState(org.eclipse.ui.IMemento)
101      */

102     public void saveState(IMemento memento) {
103         String JavaDoc currentCheatSheetId = viewer.getCheatSheetID();
104         if (currentCheatSheetId != null)
105             memento.putString(MEMENTO_CHEATSHEET_ID_ATT, currentCheatSheetId);
106     }
107
108     /**
109      * Tries to create the last content part viewed, based on content part id..
110      *
111      * @param memento
112      * @return
113      */

114     private String JavaDoc getCachedInput(IMemento memento) {
115         if (memento == null)
116             return null;
117         return memento.getString(MEMENTO_CHEATSHEET_ID_ATT);
118
119     }
120
121 }
122
Popular Tags