Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 52efea39d7a6365f4ae0a0bace07bba0f1085507 (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
/*******************************************************************************
 * Copyright (c) 2006, 2009 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
 *******************************************************************************/
package org.eclipse.debug.internal.ui.views.variables.details;


import java.util.Set;

import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.PlatformUI;

/**
 * Drop down action that displays the available detail panes for a selection.
 *
 * @since 3.3
 * @see IDetailPaneContainer
 */
public class AvailableDetailPanesAction extends Action implements IMenuCreator {

	private Menu fMenu;
	private Set<String> fAvailableIDs;
	private IDetailPaneContainer fDetailPaneContainer;

	/**
	 * Each entry in the menu will be of this type.  It represents one possible detail pane
	 * that the user can select.  If the user selects it, the display is changed to use that
	 * detail pane and the preferred detail pane map in the pane manager is updated.
	 *
	 * @see DetailPaneManager
	 * @since 3.3
	 */
	private class SetDetailPaneAction extends Action {

		private String fPaneID;
		private Set<String> fPossiblePaneIDs;

		public SetDetailPaneAction(String name, String paneID, Set<String> possiblePaneIDs) {
			super(name,AS_RADIO_BUTTON);
			fPaneID = paneID;
			fPossiblePaneIDs = possiblePaneIDs;
		}

		@Override
		public void run() {
			// Don't change panes unless the user is selecting a different pane than the one currently displayed
			if (isChecked() && !fDetailPaneContainer.getCurrentPaneID().equals(fPaneID)){
				DetailPaneManager.getDefault().setPreferredDetailPane(fPossiblePaneIDs, fPaneID);
				fDetailPaneContainer.refreshDetailPaneContents();
			}
		}

	}

	public AvailableDetailPanesAction(IDetailPaneContainer detailPaneContainer) {
		fDetailPaneContainer = detailPaneContainer;
		setText(DetailMessages.AvailableDetailPanesAction_0);
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.VARIABLES_SELECT_DETAIL_PANE);

		setEnabled(false);
		setMenuCreator(this);
		init();
	}

	@Override
	public void run() {
	}

	@Override
	public void dispose() {
		if (fMenu != null) {
			fMenu.dispose();
		}
		fAvailableIDs.clear();
	}

	@Override
	public Menu getMenu(Control parent) {
		return null;
	}

	protected void addActionToMenu(Menu parent, IAction action) {
		ActionContributionItem item= new ActionContributionItem(action);
		item.fill(parent, -1);
	}

	@Override
	public Menu getMenu(Menu parent) {
		if (fMenu != null) {
			fMenu.dispose();
		}
		fMenu= new Menu(parent);
		int i = 0;
		for (String currentID : fAvailableIDs) {
			StringBuilder name = new StringBuilder();
			//add the numerical accelerator
            i++;
			if (i < 9) {
                name.append('&');
                name.append(i);
                name.append(' ');
            }

			String typeName = DetailPaneManager.getDefault().getNameFromID(currentID);
			if (typeName != null && typeName.length() > 0){
				name.append(typeName);
			} else {
				name.append(currentID);
			}

			IAction action = new SetDetailPaneAction(name.toString(),currentID,fAvailableIDs);

			if (currentID.equals(fDetailPaneContainer.getCurrentPaneID())){
				action.setChecked(true);
			}

			addActionToMenu(fMenu, action);
		}

		return fMenu;
	}

	public void init() {
		fAvailableIDs = DetailPaneManager.getDefault().getAvailablePaneIDs(fDetailPaneContainer.getCurrentSelection());
		if (fAvailableIDs.size() > 1){
			setEnabled(true);
		}
	}
}

Back to the top