Skip to main content
summaryrefslogtreecommitdiffstats
blob: d0922db11ba19cc443bac2b33a7f5f0d8ddb0f06 (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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package org.eclipse.debug.internal.ui;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */

import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.actions.SelectionProviderAction;
import org.eclipse.ui.dialogs.PropertyDialogAction;

public class LaunchesView extends AbstractDebugView implements ISelectionChangedListener, IDoubleClickListener {

	protected final static String PREFIX= "launches_view.";

	protected SelectionProviderAction fTerminateAction;
	protected RemoveTerminatedAction fRemoveTerminatedAction;
	protected TerminateAllAction fTerminateAllAction;
	protected SelectionProviderAction fDisconnectAction;
	protected SelectionProviderAction fRelaunchAction;
	protected SelectionProviderAction fTerminateAndRemoveAction;
	
	protected PropertyDialogAction fPropertyDialogAction;
	
	/**
	 * Updates the state of the buttons in the view
	 */
	protected void updateButtons() {
		ISelection s= fViewer.getSelection();
		if (s instanceof IStructuredSelection) {
			IStructuredSelection selection= (IStructuredSelection) s;
			fTerminateAction.selectionChanged(selection);
			fDisconnectAction.selectionChanged(selection);
		}
		fRemoveTerminatedAction.update();
	}

	/**
	 * Initializes the actions of this view.
	 */
	protected void initializeActions(LaunchesViewer viewer) {

		fTerminateAction= new ControlAction(viewer, new TerminateActionDelegate());
		fTerminateAction.setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_TERMINATE));
		fTerminateAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TERMINATE));
		fTerminateAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE));
		fTerminateAction.setEnabled(false);

		fDisconnectAction= new ControlAction(viewer, new DisconnectActionDelegate());
		fDisconnectAction.setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_DISCONNECT));
		fDisconnectAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_DISCONNECT));
		fDisconnectAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_DISCONNECT));
		fDisconnectAction.setEnabled(false);

		fRemoveTerminatedAction= new RemoveTerminatedAction(this instanceof DebugView);
		fRemoveTerminatedAction.setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_REMOVE_TERMINATED));
		fRemoveTerminatedAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_REMOVE_TERMINATED));
		fRemoveTerminatedAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_REMOVE_TERMINATED));
		fRemoveTerminatedAction.setEnabled(false);

		fRelaunchAction= new ControlAction(viewer, new RelaunchActionDelegate());
		fRelaunchAction.setEnabled(false);

		fTerminateAndRemoveAction= new ControlAction(viewer, new TerminateAndRemoveActionDelegate());

		fTerminateAllAction= new TerminateAllAction();
		
		fPropertyDialogAction= new PropertyDialogAction(getSite().getWorkbenchWindow().getShell(), getSite().getSelectionProvider());
	}

	/**
	 * @see IWorkbenchPart
	 */
	public void createPartControl(Composite parent) {
		boolean showDebugTargets = getSite().getId().equals(IDebugUIConstants.ID_DEBUG_VIEW);
		LaunchesViewer lv = new LaunchesViewer(parent, showDebugTargets, this);
		fViewer= lv;
		fViewer.addSelectionChangedListener(this);
		fViewer.addDoubleClickListener(this);
		fViewer.setContentProvider(getContentProvider());
		fViewer.setLabelProvider(new DelegatingModelPresentation());
		fViewer.setUseHashlookup(true);
		// add my viewer as a selection provider, so selective re-launch works
		getSite().setSelectionProvider(fViewer);
		initializeActions(lv);
		// register this viewer as the debug UI selection provider
		DebugUIPlugin.getDefault().addSelectionProvider(fViewer, this);

		// create context menu
		createContextMenu(lv.getTree());
		initializeToolBar();
		lv.expandToLevel(2);
		fViewer.setInput(DebugPlugin.getDefault().getLaunchManager());
		fViewer.getControl().addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				handleKeyPressed(e);
			}
		});
		setTitleToolTip(getTitleToolTipText(getPrefix()));
	}

	/**
	 * Configures the toolBar
	 */
	protected void configureToolBar(IToolBarManager tbm) {
		tbm.add(fTerminateAction);
		tbm.add(fDisconnectAction);
		tbm.add(fRemoveTerminatedAction);
	}

	/**
	 * @see IWorkbenchPart
	 */
	public void setFocus() {
		Control c = fViewer.getControl();
		if (!c.isFocusControl()) {
			c.setFocus();
			//ensure that all downstream listeners
			//know the current selection..switching from another view
			DebugUIPlugin.getDefault().selectionChanged(new SelectionChangedEvent(fViewer, fViewer.getSelection()));
		}
	}
	
	/**
	 * Adds items to the context menu
	 */
	protected void fillContextMenu(IMenuManager mgr) {
		fRemoveTerminatedAction.update();
		fTerminateAllAction.update();

		mgr.add(new Separator(IDebugUIConstants.EMPTY_LAUNCH_GROUP));
		mgr.add(new Separator(IDebugUIConstants.LAUNCH_GROUP));
		
		mgr.add(fTerminateAction);
		mgr.add(fDisconnectAction);
		mgr.add(new Separator());
		mgr.add(fTerminateAndRemoveAction);
		mgr.add(fTerminateAllAction);
		mgr.add(fRemoveTerminatedAction);
		mgr.add(fRelaunchAction);
		mgr.add(new Separator(IDebugUIConstants.PROPERTY_GROUP));
		fPropertyDialogAction.setEnabled(fPropertyDialogAction.isApplicableForSelection());
		mgr.add(fPropertyDialogAction);
		mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
	}

	/**
	 * @see IWorkbenchPart
	 */
	public void dispose() {
		if (fViewer != null) {
			DebugUIPlugin.getDefault().removeSelectionProvider(fViewer, this);
			fViewer.removeDoubleClickListener(this);
			fViewer.removeSelectionChangedListener(this);
		}
		super.dispose();
	}

	/**
	 * Auto-expand and select the given element - must be called in UI thread.
	 * This is used to implement auto-expansion-and-select on a SUSPEND event.
	 */
	public void autoExpand(Object element) {
		Object selectee = element;
		if (element instanceof ILaunch) {
			IProcess[] ps= ((ILaunch)element).getProcesses();
				if (ps != null && ps.length > 0) {
					selectee= ps[0];
				}
		}
		fViewer.setSelection(new StructuredSelection(selectee), true);
	}
	
	/**
	 * Returns the content provider to use for the viewer of this view.
	 */
	protected DebugContentProvider getContentProvider() {
		return new ProcessesContentProvider();
	}
	
	/**
	 * The selection has changed in the viewer. Update
	 * the state of the buttons.
	 */
	public void selectionChanged(SelectionChangedEvent event) {
		updateButtons();
	}
	
	/**
	 * Returns the resource bundle prefix for this action
	 */
	protected String getPrefix(){
		return PREFIX;
	}
	
	/**
	 * Handles key events in viewer.  Specifically interested in
	 * the Delete key.
	 */
	protected void handleKeyPressed(KeyEvent event) {
		if (event.character == SWT.DEL && event.stateMask == 0 
			&& fTerminateAndRemoveAction.isEnabled()) {
				fTerminateAndRemoveAction.run();
		}
	}
	
	/**
	 * @see IDoubleClickListener#doubleClick(DoubleClickEvent)
	 */
	public void doubleClick(DoubleClickEvent event) {
		ISelection selection= event.getSelection();
		if (!(selection instanceof IStructuredSelection)) {
			return;
		}
		IStructuredSelection ss= (IStructuredSelection)selection;
		Object o= ss.getFirstElement();
		if (o instanceof IStackFrame) {
			return;
		} 
		TreeViewer tViewer= (TreeViewer)fViewer;
		boolean expanded= tViewer.getExpandedState(o);
		tViewer.setExpandedState(o, !expanded);
	}
}


Back to the top