Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 517b5dc1fd95d9be66be5d70e37f2d4e50e2e577 (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
/*******************************************************************************
 * Copyright (c) 2012, 2014 Tilera 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:
 *     William R. Swanson (Tilera Corporation)
 *     Xavier Raynaud <xavier.raynaud@kalray.eu> - fix #428424
 *******************************************************************************/

package org.eclipse.cdt.visualizer.examples.sourcegraph;

import org.eclipse.cdt.visualizer.examples.VisualizerExamplesPlugin;
import org.eclipse.cdt.visualizer.ui.Visualizer;
import org.eclipse.cdt.visualizer.ui.util.Colors;
import org.eclipse.cdt.visualizer.ui.util.ScrollPanel;
import org.eclipse.cdt.visualizer.ui.util.SelectionManager;
import org.eclipse.cdt.visualizer.ui.util.SelectionUtils;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

//---------------------------------------------------------------------------
// SourceGraphVisualizer
//---------------------------------------------------------------------------

public class SourceGraphVisualizer extends Visualizer
{
	// --- constants ---
	
	/** Eclipse ID for this view */
	public static final String ECLIPSE_ID = "org.eclipse.cdt.visualizer.examples.sourcegraph"; //$NON-NLS-1$

	
	// --- members ---
	
	/** ScrollPanel container for visualizer control. */
	ScrollPanel m_scrollPanel = null;
	
	/** visualizer control (downcast reference) */
	SourceGraphControl m_sourceGraphControl = null;
	
	
	// --- constructors/destructors ---
	
	/** Constructor. */
	public SourceGraphVisualizer()
	{
		super(VisualizerExamplesPlugin.getString("SourceGraphVisualizer.name"),        //$NON-NLS-1$
			  VisualizerExamplesPlugin.getString("SourceGraphVisualizer.displayName"), //$NON-NLS-1$
			  VisualizerExamplesPlugin.getString("SourceGraphVisualizer.description")  //$NON-NLS-1$
			  );
	}

	/** Dispose method. */
	@Override
	public void dispose() {
		super.dispose();
	}

	
	// --- control management ---
	
	/** Creates and returns visualizer control on specified parent. */
	@Override
	public Control createControl(Composite parent)
	{
		if (m_sourceGraphControl == null) {

			m_scrollPanel = new ScrollPanel(parent);
			m_scrollPanel.setBackground(Colors.BLACK);

			m_sourceGraphControl = new SourceGraphControl(m_scrollPanel);
			m_scrollPanel.setContent(m_sourceGraphControl);

			// source graph control sets its own height based on the graph size
			m_scrollPanel.setAutoResizeHeight(false);
			// auto-resize to fit scrollpanel width
			m_scrollPanel.setAutoResizeWidth(true);

			setControl(m_scrollPanel);
		}
		return getControl();
	}
	
	/** Invoked when visualizer control should be disposed. */
	@Override
	public void disposeControl()
	{
		if (m_sourceGraphControl != null) {
			setControl(null);
			m_sourceGraphControl.dispose();
			m_scrollPanel.dispose();
			m_sourceGraphControl = null;
			m_scrollPanel = null;
		}
	}

	// --- visualizer events ---

	@Override
	public void visualizerDeselected() {
	}
	
	@Override
	public void visualizerSelected() {
	}
	

	// --- update methods ---
	
	/**
	 * Refresh the visualizer display based on the existing data.
	 */
	public void refresh() {
		m_sourceGraphControl.refresh();
	}

	// --- selection handling ---
	
	/** Invoked when selection changes, to determine whether this
	 *  visualizer knows how to display the current selection.
	 */
	@Override
	public int handlesSelection(ISelection selection) {
		Object s = SelectionUtils.getSelectedObject(selection);
		if (s instanceof TextSelection) return 1;		
		return 0;
	}

	/** Invoked when workbench selection changes and this visualizer
	 *  is selected to display it.
	 */
	@Override
	public void workbenchSelectionChanged(ISelection selection) {
		Object o = SelectionUtils.getSelectedObject(selection);
		if (o instanceof TextSelection) {
			String text = ((TextSelection) o).getText();
			m_sourceGraphControl.setSourceText(text);
		} else {
			m_sourceGraphControl.setSourceText(""); //$NON-NLS-1$
		}
	}
	
	public SelectionManager getSelectionManager() {
		return m_selectionManager;
	}	

	
	// --- menu/toolbar management ---

	/** Invoked when visualizer is selected, to populate the toolbar. */
	@Override
	public void populateToolBar(IToolBarManager toolBarManager)
	{}

	/** Invoked when visualizer is selected, to populate the toolbar's menu. */
	@Override
	public void populateMenu(IMenuManager menuManager)
	{}

	
	// --- context menu handling ---
	
	/** Invoked when visualizer view's context menu is invoked, to populate it. */
	@Override
	public void populateContextMenu(IMenuManager menuManager)
	{}

}

Back to the top