Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4c4f52be84aa708d4d37e13cf66f255b8932eb8d (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
225
226
227
228
229
230
231
232
233
234
235
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.debug.testplugin.detailpane;

import java.util.Iterator;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IVariable;
import org.eclipse.debug.internal.ui.VariablesViewModelPresentation;
import org.eclipse.debug.ui.IDebugModelPresentation;
import org.eclipse.debug.ui.IDetailPane;
import org.eclipse.debug.ui.IValueDetailListener;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.progress.WorkbenchJob;

/**
 * An example detail pane that creates a composite containing several controls, all of which
 * will be displayed in the detail pane.
 * 
 * @since 3.3
 * @see TestDetailPaneFactory
 * @see IDetailPane
 */
public class TableDetailPane implements IDetailPane, IValueDetailListener {

	public static final String ID = "org.eclipse.jdt.debug.testplugin.detailpane.TableDetailPane";
	public static final String NAME = "Example Pane: Table Detail Pane";
	public static final String DESCRIPTION = "Example detail pane that displays details as a composite containing several controls";
	
	IWorkbenchPartSite fWorkbenchPartSite;
	private Table fTable;
	private TextViewer fText;
	private Composite fComposite;
	private Button fWordWrapButton;
	private IDebugModelPresentation fModelPresentation;
	
	/**
	 * Job to calculate detail string
	 */
	class DetailJob implements Runnable{
		
		private IValue fValue;
		private IValueDetailListener fListener;
		
		public DetailJob(IValue value, IValueDetailListener listener){
			fValue = value;
			fListener = listener;
		}

		public void run() {
			fModelPresentation.computeDetail(fValue, fListener);		
		}
			
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.IDetailPane#init(org.eclipse.ui.IWorkbenchPartSite)
	 */
	public void init(IWorkbenchPartSite workbenchPartSite) {
		fWorkbenchPartSite = workbenchPartSite;
		
		fModelPresentation = new VariablesViewModelPresentation();
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.IDetailPane#createControl(org.eclipse.swt.widgets.Composite)
	 */
	public Control createControl(Composite parent) {
		fComposite = new Composite(parent, SWT.NONE);
		fComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
		fComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
		fTable = new Table(fComposite,SWT.FULL_SELECTION);
		fTable.addSelectionListener(new SelectionListener(){

			public void widgetDefaultSelected(SelectionEvent e) {
				widgetSelected(e);
			}

			public void widgetSelected(SelectionEvent e) {
				int index = fTable.getSelectionIndex();
				if (index >= 0){
					TableItem item = fTable.getItem(index);
					if (item != null){
						Thread detailJob = new Thread(new DetailJob((IValue)item.getData(),getValueDetailListener()));
						detailJob.start();						
					}
					else{
						fText.setDocument(null);
					}
				}
			}
			
			
		});
		
		Composite composite = new Composite(fComposite,SWT.NONE);
		composite.setLayout(new FillLayout(SWT.VERTICAL));
		fText = new TextViewer(composite,SWT.READ_ONLY);
		
		fWordWrapButton = new Button(composite,SWT.CHECK);
		fWordWrapButton.setText("Word Wrap");
		fWordWrapButton.setSelection(false);
		fWordWrapButton.addSelectionListener(new SelectionListener(){
			public void widgetDefaultSelected(SelectionEvent e) {
				widgetSelected(e);
			}
			public void widgetSelected(SelectionEvent e) {
				fText.getTextWidget().setWordWrap(fWordWrapButton.getSelection());
			}
		});

		return fComposite;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.IDetailPane#display(org.eclipse.jface.viewers.IStructuredSelection)
	 */
	public void display(IStructuredSelection element) {
		
		if (element != null){
			
			fTable.removeAll();
			fText.setDocument(null);
			
			Iterator iterator = element.iterator();
			while (iterator.hasNext()){
				
				Object selection = iterator.next();
				if (selection != null && selection instanceof IVariable){
				
					IValue val = null;
					try {
						
						val = ((IVariable)selection).getValue();
						TableItem newItem = new TableItem(fTable,SWT.NONE);
						newItem.setText(val.getValueString());
						newItem.setData(val);
					
					} catch (DebugException e) {
						
					}
				}
			}
		}
		else{
			fTable.removeAll();
		}

	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.IDetailPane#setFocus()
	 */
	public boolean setFocus(){
		if (fText != null){
			fText.getTextWidget().setFocus();
			return true;
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.IDetailPane#dispose()
	 */
	public void dispose() {
		if (fComposite != null) fComposite.dispose();
		if (fModelPresentation != null) fModelPresentation.dispose();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.IDetailPane#getDescription()
	 */
	public String getDescription() {
		return DESCRIPTION;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.IDetailPane#getID()
	 */
	public String getID() {
		return ID;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.IDetailPane#getName()
	 */
	public String getName() {
		return NAME;
	}

	protected IValueDetailListener getValueDetailListener(){
		return this;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.IValueDetailListener#detailComputed(org.eclipse.debug.core.model.IValue, java.lang.String)
	 */
	public void detailComputed(IValue value, final String result){
		WorkbenchJob append = new WorkbenchJob("append details") { //$NON-NLS-1$
			public IStatus runInUIThread(IProgressMonitor monitor) {
				fText.setDocument(new Document(result));
				return Status.OK_STATUS;
				
			}
		};
		append.setSystem(true);
		append.schedule();
	}

}

Back to the top