use of org.eclipse.jface.viewers.ITreeSelection in project linuxtools by eclipse.
the class NewProjectCreationPage method getSelectedWorkingSet.
/**
* Try our best to set the working sets field to something sensible based on the
* current selection.
*/
private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) {
if (!(selection instanceof ITreeSelection)) {
return EMPTY_WORKING_SET_ARRAY;
}
ITreeSelection treeSelection = (ITreeSelection) selection;
if (treeSelection.isEmpty()) {
return EMPTY_WORKING_SET_ARRAY;
}
List<?> elements = treeSelection.toList();
if (elements.size() == 1) {
Object element = elements.get(0);
TreePath[] paths = treeSelection.getPathsFor(element);
if (paths.length != 1 || paths[0].getSegmentCount() == 0) {
return EMPTY_WORKING_SET_ARRAY;
}
Object candidate = paths[0].getSegment(0);
if (!(candidate instanceof IWorkingSet)) {
return EMPTY_WORKING_SET_ARRAY;
}
IWorkingSet workingSetCandidate = (IWorkingSet) candidate;
if (!workingSetCandidate.isAggregateWorkingSet()) {
return new IWorkingSet[] { workingSetCandidate };
}
return EMPTY_WORKING_SET_ARRAY;
}
ArrayList<IWorkingSet> result = new ArrayList<>();
for (Object element : elements) {
if (element instanceof IWorkingSet && !((IWorkingSet) element).isAggregateWorkingSet()) {
result.add((IWorkingSet) element);
}
}
if (!result.isEmpty()) {
return result.toArray(new IWorkingSet[result.size()]);
} else {
return EMPTY_WORKING_SET_ARRAY;
}
}
use of org.eclipse.jface.viewers.ITreeSelection 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);
}
use of org.eclipse.jface.viewers.ITreeSelection in project linuxtools by eclipse.
the class ConnectionSettingsPropertySection method setInput.
@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
super.setInput(part, selection);
Assert.isTrue(selection instanceof ITreeSelection);
Object input = ((ITreeSelection) selection).getFirstElement();
Assert.isTrue(input instanceof IDockerConnection);
IDockerConnection connection = (IDockerConnection) input;
if (getTreeViewer() != null) {
getTreeViewer().setInput(connection);
getTreeViewer().expandAll();
}
}
use of org.eclipse.jface.viewers.ITreeSelection in project linuxtools by eclipse.
the class DockerExplorerView method refresh.
private void refresh(final IDockerConnection connection) {
Display.getDefault().asyncExec(() -> {
if (getCommonViewer().getTree() != null && !getCommonViewer().getTree().isDisposed()) {
ITreeSelection old = (ITreeSelection) getCommonViewer().getSelection();
getCommonViewer().refresh(connection, true);
// Bug 499919 - Deselected connection after deleted tag
// if we had an old selection and now we don't, assume that
// operation in another view removed the item we had selected
// so reset the connection so the Images and Containers views
// don't reset to no connection.
ITreeSelection current = (ITreeSelection) getCommonViewer().getSelection();
if (!old.isEmpty() && current.isEmpty()) {
getCommonViewer().setSelection(new StructuredSelection(connection));
}
}
});
}
use of org.eclipse.jface.viewers.ITreeSelection in project linuxtools by eclipse.
the class DockerConnectionWatcher method selectionChanged.
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
final ITreeSelection treeSelection = (ITreeSelection) selection;
if (treeSelection.isEmpty()) {
setConnection(null);
return;
}
final Object firstSegment = treeSelection.getPaths()[0].getFirstSegment();
if (firstSegment instanceof IDockerConnection) {
setConnection((IDockerConnection) firstSegment);
}
}
Aggregations