use of org.eclipse.linuxtools.valgrind.ui.CollapseAction in project linuxtools by eclipse.
the class CachegrindViewPart method createPartControl.
@Override
public void createPartControl(Composite parent) {
Composite top = new Composite(parent, SWT.NONE);
GridLayout topLayout = new GridLayout();
topLayout.marginHeight = topLayout.marginWidth = 0;
top.setLayout(topLayout);
top.setLayoutData(new GridData(GridData.FILL_BOTH));
viewer = new TreeViewer(top, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
labelProvider = new CachegrindLabelProvider();
ColumnViewerToolTipSupport.enableFor(viewer);
Tree tree = viewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);
// $NON-NLS-1$
column.getColumn().setText(Messages.getString("CachegrindViewPart.Location"));
column.getColumn().setWidth(COLUMN_SIZE * 4);
column.getColumn().setResizable(true);
column.getColumn().addSelectionListener(getHeaderListener());
column.setLabelProvider(labelProvider);
contentProvider = new CachegrindTreeContentProvider();
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(labelProvider);
viewer.setAutoExpandLevel(2);
doubleClickListener = event -> {
Object selection = ((StructuredSelection) event.getSelection()).getFirstElement();
String path = null;
int line = 0;
if (selection instanceof CachegrindFile) {
path = ((CachegrindFile) selection).getPath();
} else if (selection instanceof CachegrindLine) {
CachegrindLine element = (CachegrindLine) selection;
CachegrindFile file = (CachegrindFile) element.getParent().getParent();
path = file.getPath();
line = element.getLine();
} else if (selection instanceof CachegrindFunction) {
CachegrindFunction function = (CachegrindFunction) selection;
path = ((CachegrindFile) function.getParent()).getPath();
if (function.getModel() instanceof ISourceReference) {
ISourceReference model = (ISourceReference) function.getModel();
try {
ISourceRange sr = model.getSourceRange();
if (sr != null) {
line = sr.getStartLine();
}
} catch (CModelException e1) {
e1.printStackTrace();
}
}
}
if (path != null) {
try {
ProfileUIUtils.openEditorAndSelect(path, line, ValgrindUIPlugin.getDefault().getProfiledProject());
} catch (BadLocationException | CoreException e2) {
e2.printStackTrace();
}
}
};
viewer.addDoubleClickListener(doubleClickListener);
expandAction = new ExpandAction(viewer);
collapseAction = new CollapseAction(viewer);
MenuManager manager = new MenuManager();
manager.addMenuListener(manager1 -> {
ITreeSelection selection = (ITreeSelection) viewer.getSelection();
ICachegrindElement element = (ICachegrindElement) selection.getFirstElement();
if (contentProvider.hasChildren(element)) {
manager1.add(expandAction);
manager1.add(collapseAction);
}
});
manager.setRemoveAllWhenShown(true);
Menu contextMenu = manager.createContextMenu(viewer.getTree());
viewer.getControl().setMenu(contextMenu);
}
Aggregations