Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 32b1fd9f8246e5d44168bbfbf441ca8e1d58d922 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**********************************************************************
 * Copyright (c) 2004, 2012 QNX Software Systems 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:
 * QNX Software Systems - Initial API and implementation
 * Wind River Systems - Pawel Piech - Added Modules view (bug 211158)
 * IBM - Added the abiliity to update view label, context help and the orientation
 *       action upon input change
***********************************************************************/
package org.eclipse.debug.internal.ui.views.modules;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.internal.ui.DebugPluginImages;
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.internal.ui.actions.variables.ToggleDetailPaneAction;
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
import org.eclipse.debug.internal.ui.views.variables.VariablesView;
import org.eclipse.debug.internal.ui.views.variables.details.AvailableDetailPanesAction;
import org.eclipse.debug.ui.IDebugUIConstants;
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.viewers.ILabelProvider;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;

/**
 * Displays modules and symbols with a detail area.
 */
public class ModulesView extends VariablesView {

	/**
	 * @see org.eclipse.debug.ui.AbstractDebugView#getHelpContextId()
	 */
	@Override
	protected String getHelpContextId() {
		return IDebugHelpContextIds.MODULES_VIEW;
	}

	/**
	 * @see org.eclipse.debug.ui.AbstractDebugView#configureToolBar(org.eclipse.jface.action.IToolBarManager)
	 */
	@Override
	protected void configureToolBar(IToolBarManager tbm) {
        tbm.add(new Separator(this.getClass().getName()));
        tbm.add(new Separator(IDebugUIConstants.RENDER_GROUP));
        tbm.add(getAction("CollapseAll")); //$NON-NLS-1$
        tbm.add( new Separator( IDebugUIConstants.MODULES_GROUP ) );
	}

	   /* (non-Javadoc)
     * @see org.eclipse.debug.ui.AbstractDebugView#fillContextMenu(org.eclipse.jface.action.IMenuManager)
     */
    @Override
	protected void fillContextMenu( IMenuManager menu ) {
        menu.add( new Separator( IDebugUIConstants.EMPTY_MODULES_GROUP ) );
        menu.add( new Separator( IDebugUIConstants.MODULES_GROUP ) );
        menu.add(getAction(FIND_ACTION));
        menu.add(new Separator());
        IAction action = new AvailableDetailPanesAction(this);
        if (isDetailPaneVisible() && action.isEnabled()) {
            menu.add(action);
        }
        menu.add(new Separator(IDebugUIConstants.EMPTY_RENDER_GROUP));
        menu.add(new Separator(IDebugUIConstants.EMPTY_NAVIGATION_GROUP));
        menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) );
    }

	/**
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getDetailPanePreferenceKey()
	 */
	@Override
	protected String getDetailPanePreferenceKey() {
		return IDebugPreferenceConstants.MODULES_DETAIL_PANE_ORIENTATION;
	}

	/**
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getToggleActionLabel()
	 */
	@Override
	protected String getToggleActionLabel() {

		if (getViewer() != null)
		{
			Object viewerInput = getViewer().getInput();
			if (viewerInput != null)
			{
				String name = getViewName(viewerInput);
				if (name != null)
				{
					String label = NLS.bind(ModulesViewMessages.ModulesView_1, name);
					return label;
				}
			}
		}

		return ModulesViewMessages.ModulesView_0;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getPresentationContextId()
	 */
	@Override
	protected String getPresentationContextId() {
		return IDebugUIConstants.ID_MODULE_VIEW;
	}

	@Override
	protected void setViewerInput(Object context) {
		super.setViewerInput(context);

		// update view label when viewer input is changed
		updateViewLabels(context);

		// update orientation action based on input
		updateOrientationAction(context);

		// update context help hook when viewer input is changed
		updateContextHelp(context);
	}

	private void updateContextHelp(Object context) {
		if (context instanceof IAdaptable) {
			IAdaptable adaptable = (IAdaptable) context;
			if (adaptable.getAdapter(IHelpContextIdProvider.class) != null) {
				IHelpContextIdProvider provider = adaptable
						.getAdapter(IHelpContextIdProvider.class);
				String helpId = provider.getHelpContextId(IDebugHelpContextIds.MODULES_VIEW);
				if (helpId != null) {
					PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl().getParent(), helpId);
					return;
				}
			}
		}
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl().getParent(), IDebugHelpContextIds.MODULES_VIEW);
	}

	private void updateViewLabels(Object context)
	{
		String viewName = getViewName(context);

		// only update label if the name has changed
		if (!getPartName().equals(viewName))
			setPartName(viewName);

		// only update image if the image has changed
		Image image = getViewImage(context);
		if (!getTitleImage().equals(image))
			setTitleImage(image);
	}

	/**
	 * @param context
	 */
	private String getViewName(Object context) {
		if (context instanceof IAdaptable) {
			IAdaptable adaptable = (IAdaptable) context;
			if (adaptable.getAdapter(ILabelProvider.class) != null) {
				ILabelProvider provider = adaptable
						.getAdapter(ILabelProvider.class);
				String label = provider.getText(this);
				if (label != null)
					return label;
			}
		}
		return ModulesViewMessages.ModulesView_2;
	}

	private Image getViewImage(Object context)
	{
		if (context instanceof IAdaptable) {
			IAdaptable adaptable = (IAdaptable) context;
			if (adaptable.getAdapter(ILabelProvider.class) != null) {
				ILabelProvider provider = adaptable
						.getAdapter(ILabelProvider.class);
				Image image = provider.getImage(this);
				if (image != null)
					return image;
			}
		}
		return DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_CVIEW_MODULES_VIEW);
	}

	private void updateOrientationAction(Object context)
	{
		ToggleDetailPaneAction action = getToggleDetailPaneAction(IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_HIDDEN);
		if (action != null)
		{
			String label = NLS.bind(ModulesViewMessages.ModulesView_1, getViewName(context));
			action.setText(label);
		}
	}

}

Back to the top