KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > views > CheatSheetHelpPart


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ui.internal.cheatsheets.views;
12
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.help.ui.internal.views.IHelpPart;
15 import org.eclipse.help.ui.internal.views.ReusableHelpPart;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.action.IMenuManager;
18 import org.eclipse.jface.action.IToolBarManager;
19 import org.eclipse.jface.action.Separator;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.ui.IMemento;
24 import org.eclipse.ui.forms.AbstractFormPart;
25 import org.eclipse.ui.forms.widgets.FormToolkit;
26 import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
27 import org.eclipse.ui.internal.cheatsheets.Messages;
28 import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
29 import org.eclipse.ui.internal.cheatsheets.state.ICheatSheetStateManager;
30
31 /**
32  * A help part wrapper that contains a cheat sheet. This is used to display
33  * cheat sheets inside the ReusableHelpPart.
34  */

35 public class CheatSheetHelpPart extends AbstractFormPart implements IHelpPart {
36     
37     public static final String JavaDoc ID = "cheatsheet-page"; //$NON-NLS-1$
38

39     private CheatSheetViewer viewer;
40     private String JavaDoc id;
41     
42     /**
43      * Constructs a new part.
44      *
45      * @param parent the parent Composite that will contain the widgets
46      * @param toolkit the form toolkit to use for creating the widgets
47      * @param tbm the toolbar we will contribute to
48      * @param id the unique id of the cheatsheet to display in the part
49      */

50     public CheatSheetHelpPart(Composite parent, FormToolkit toolkit, IToolBarManager tbm, CheatSheetElement content, ICheatSheetStateManager trayManager) {
51         id = content.getID();
52         viewer = new CheatSheetViewer(true);
53         viewer.createPartControl(parent);
54         viewer.setContent(content, trayManager);
55         contributeToToolBar(tbm);
56     }
57
58     /**
59      * Contributes any actions we have to the toolbar.
60      *
61      * @param tbm the toolbar to contribute to
62      */

63     private void contributeToToolBar(IToolBarManager tbm) {
64         IPath path = CheatSheetPlugin.ICONS_PATH.append(CheatSheetPlugin.T_ELCL).append("collapseall.gif");//$NON-NLS-1$
65
ImageDescriptor collapseImage = CheatSheetPlugin.createImageDescriptor(CheatSheetPlugin.getPlugin().getBundle(), path);
66         CheatSheetExpandRestoreAction expandRestoreAction = new CheatSheetExpandRestoreAction(Messages.COLLAPSE_ALL_BUT_CURRENT_TOOLTIP, false, viewer);
67         expandRestoreAction.setToolTipText(Messages.COLLAPSE_ALL_BUT_CURRENT_TOOLTIP);
68         expandRestoreAction.setImageDescriptor(collapseImage);
69         tbm.insertBefore("back", expandRestoreAction); //$NON-NLS-1$
70
tbm.insertBefore("back", new Separator()); //$NON-NLS-1$
71
viewer.setExpandRestoreAction(expandRestoreAction);
72     }
73     
74     /**
75      * This part doesn't require a context menu.
76      */

77     public boolean fillContextMenu(IMenuManager manager) {
78         return false;
79     }
80     
81     /**
82      * Returns the part's top Control.
83      */

84     public Control getControl() {
85         return viewer.getControl();
86     }
87     
88     /**
89      * This part doesn't use any global actions.
90      */

91     public IAction getGlobalAction(String JavaDoc id) {
92         return null;
93     }
94     
95     /**
96      * Returns the part's unique identifier.
97      *
98      * @param the unique id for the part
99      */

100     public String JavaDoc getId() {
101         return id;
102     }
103     
104     /**
105      * Returns whether or not this part contains the given Control, which
106      * is in focus.
107      *
108      * @param control the Control in focus
109      */

110     public boolean hasFocusControl(Control control) {
111         return viewer.hasFocusControl(control);
112     }
113     
114     /**
115      * Initializes the part.
116      */

117     public void init(ReusableHelpPart parent, String JavaDoc id, IMemento memento) {
118         this.id = id;
119     }
120
121     /**
122      * No filtering required.
123      */

124     public void refilter() {
125     }
126     
127     /**
128      * The cheat sheet automatically saves its state; no action required.
129      */

130     public void saveState(IMemento memento) {
131     }
132     
133     /**
134      * Sets the visibility of the part.
135      *
136      * @param whether or not the part should be visible
137      */

138     public void setVisible(boolean visible) {
139         viewer.getControl().setVisible(visible);
140     }
141     
142     /**
143      * No action needed for this part here.
144      */

145     public void stop() {
146     }
147     
148     /**
149      * No action needed for this part here.
150      */

151     public void toggleRoleFilter() {
152     }
153 }
154
Popular Tags