Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7d6f22a8875d37be0975bef33fb41b08af5c1b65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*******************************************************************************
 * Copyright (c) 2005, 2017 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Asma Smaoui - CEA LIST - https://bugs.eclipse.org/bugs/show_bug.cgi?id=517379
 *******************************************************************************/
package org.eclipse.ui.internal.cheatsheets.views;

import org.eclipse.core.runtime.IPath;
import org.eclipse.help.ui.internal.views.IHelpPart;
import org.eclipse.help.ui.internal.views.ReusableHelpPart;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.forms.AbstractFormPart;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
import org.eclipse.ui.internal.cheatsheets.Messages;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
import org.eclipse.ui.internal.cheatsheets.state.ICheatSheetStateManager;

/**
 * A help part wrapper that contains a cheat sheet. This is used to display
 * cheat sheets inside the ReusableHelpPart.
 */
public class CheatSheetHelpPart extends AbstractFormPart implements IHelpPart {

	public static final String ID = "cheatsheet-page"; //$NON-NLS-1$

	public CheatSheetViewer viewer;
	private String id;

	/**
	 * Constructs a new part.
	 *
	 * @param parent the parent Composite that will contain the widgets
	 * @param toolkit the form toolkit to use for creating the widgets
	 * @param tbm the toolbar we will contribute to
	 * @param id the unique id of the cheatsheet to display in the part
	 */
	public CheatSheetHelpPart(Composite parent, FormToolkit toolkit, IToolBarManager tbm, CheatSheetElement content, ICheatSheetStateManager trayManager) {
		id = content.getID();
		viewer = new CheatSheetViewer(true);
		viewer.createPartControl(parent);
		viewer.setContent(content, trayManager);
		contributeToToolBar(tbm);
	}

	/**
	 * Contributes any actions we have to the toolbar.
	 *
	 * @param tbm the toolbar to contribute to
	 */
	private void contributeToToolBar(IToolBarManager tbm) {
		IPath path = CheatSheetPlugin.ICONS_PATH.append(CheatSheetPlugin.T_ELCL).append("collapseall.gif");//$NON-NLS-1$
		ImageDescriptor collapseImage = CheatSheetPlugin.createImageDescriptor(CheatSheetPlugin.getPlugin().getBundle(), path);
		CheatSheetExpandRestoreAction expandRestoreAction = new CheatSheetExpandRestoreAction(Messages.COLLAPSE_ALL_BUT_CURRENT_TOOLTIP, false, viewer);
		expandRestoreAction.setToolTipText(Messages.COLLAPSE_ALL_BUT_CURRENT_TOOLTIP);
		expandRestoreAction.setImageDescriptor(collapseImage);
		tbm.insertBefore("back", expandRestoreAction); //$NON-NLS-1$
		tbm.insertBefore("back", new Separator()); //$NON-NLS-1$
		viewer.setExpandRestoreAction(expandRestoreAction);
	}

	/**
	 * This part doesn't require a context menu.
	 */
	@Override
	public boolean fillContextMenu(IMenuManager manager) {
		return false;
	}

	/**
	 * Returns the part's top Control.
	 */
	@Override
	public Control getControl() {
		return viewer.getControl();
	}

	/**
	 * This part doesn't use any global actions.
	 */
	@Override
	public IAction getGlobalAction(String id) {
		return null;
	}

	/**
	 * Returns the part's unique identifier.
	 *
	 * @param the unique id for the part
	 */
	@Override
	public String getId() {
		return id;
	}

	/**
	 * Returns whether or not this part contains the given Control, which
	 * is in focus.
	 *
	 * @param control the Control in focus
	 */
	@Override
	public boolean hasFocusControl(Control control) {
		return viewer.hasFocusControl(control);
	}

	/**
	 * Initializes the part.
	 */
	@Override
	public void init(ReusableHelpPart parent, String id, IMemento memento) {
		this.id = id;
	}

	/**
	 * No filtering required.
	 */
	@Override
	public void refilter() {
	}

	/**
	 * The cheat sheet automatically saves its state; no action required.
	 */
	@Override
	public void saveState(IMemento memento) {
	}

	/**
	 * Sets the visibility of the part.
	 *
	 * @param whether or not the part should be visible
	 */
	@Override
	public void setVisible(boolean visible) {
		viewer.getControl().setVisible(visible);
	}

	/**
	 * No action needed for this part here.
	 */
	@Override
	public void stop() {
	}

	/**
	 * No action needed for this part here.
	 */
	@Override
	public void toggleRoleFilter() {
	}
}

Back to the top