use of org.eclipse.jface.viewers.TreePath in project nebula.widgets.nattable by eclipse.
the class TabbedNatExampleRunner method run.
public static void run(int shellWidth, int shellHeight, final String... examplePaths) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
// Setup
final Display display = Display.getDefault();
final Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.setLayout(new GridLayout(2, false));
shell.setSize(shellWidth, shellHeight);
shell.setText("NatTable Examples Application");
Image nebula16 = new Image(display, TabbedNatExampleRunner.class.getResourceAsStream("nebula_logo_16.png"));
Image nebula32 = new Image(display, TabbedNatExampleRunner.class.getResourceAsStream("nebula_logo_32.png"));
Image nebula64 = new Image(display, TabbedNatExampleRunner.class.getResourceAsStream("nebula_logo_64.png"));
shell.setImages(new Image[] { nebula16, nebula32, nebula64 });
// Nav tree
final TreeViewer navTreeViewer = new TreeViewer(shell);
GridData gridData = new GridData(GridData.FILL_VERTICAL);
gridData.widthHint = 300;
navTreeViewer.getControl().setLayoutData(gridData);
final NavContentProvider contentProvider = new NavContentProvider();
navTreeViewer.setContentProvider(contentProvider);
navTreeViewer.setLabelProvider(new NavLabelProvider(contentProvider));
navTreeViewer.setInput(examplePaths);
navTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
TreeSelection selection = (TreeSelection) event.getSelection();
for (TreePath path : selection.getPaths()) {
// check for item - if node expand/collapse, if child open
if (contentProvider.hasChildren(path.getLastSegment().toString())) {
boolean expanded = navTreeViewer.getExpandedState(path);
navTreeViewer.setExpandedState(path, !expanded);
} else {
openExampleInTab(path.getLastSegment().toString());
}
}
}
});
tabFolder = new CTabFolder(shell, SWT.BORDER);
tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
for (INatExample example : exampleControlMap.keySet()) {
// Stop
example.onStop();
Control exampleControl = exampleControlMap.get(example);
exampleControl.dispose();
}
tabFolder.dispose();
shell.dispose();
display.dispose();
}
use of org.eclipse.jface.viewers.TreePath in project tdq-studio-se by Talend.
the class SemanticDiscoveryActionProviderTest method testFillContextMenuIMenuManager.
/**
* Test method for {@link org.talend.dataprofiler.core.ui.action.provider.SemanticDiscoveryActionProvider#fillContextMenu(org.eclipse.jface.action.IMenuManager)}.
*/
@Test
public void testFillContextMenuIMenuManager() {
SemanticDiscoveryActionProvider semanticDiscoveryActionProvider = new SemanticDiscoveryActionProvider();
IRepositoryNode createNewColumnRepNode = createNewColumnRepNode();
TreePath treePath = new TreePath(new IRepositoryNode[] { createNewColumnRepNode });
TreeSelection treeSelection = new TreeSelection(new TreePath[] { treePath });
semanticDiscoveryActionProvider.setContext(new ActionContext(treeSelection));
MenuManager menuManager = new MenuManager();
semanticDiscoveryActionProvider.fillContextMenu(menuManager);
Assert.assertEquals(1, menuManager.getSize());
// $NON-NLS-1$
Assert.assertTrue(// $NON-NLS-1$
"Current action must be SemanticDiscoveryAction", ((ActionContributionItem) menuManager.getItems()[0]).getAction() instanceof SemanticDiscoveryAction);
}
use of org.eclipse.jface.viewers.TreePath in project tdq-studio-se by Talend.
the class TablesSelectionDialog method addCheckedListener.
@Override
protected void addCheckedListener() {
// When user checks a checkbox in the tree, check all its children
getTreeViewer().addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
TreePath treePath = new TreePath(new Object[] { event.getElement() });
getTreeViewer().setSelection(new TreeSelection(treePath));
if (event.getChecked()) {
Object element = event.getElement();
getTreeViewer().setSubtreeChecked(element, true);
if (element instanceof IRepositoryNode) {
setOutput(element);
handleTablesChecked((IRepositoryNode) element, true);
}
} else {
Object element = event.getElement();
getTreeViewer().setSubtreeChecked(element, false);
if (element instanceof IRepositoryNode) {
setOutput(element);
handleTablesChecked((IRepositoryNode) element, false);
}
}
updateOKStatus();
}
});
getTableViewer().addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
Object element = event.getElement();
if (element instanceof DBTableRepNode || element instanceof DBViewRepNode) {
handleTableChecked((IRepositoryNode) element, event.getChecked());
}
}
});
}
use of org.eclipse.jface.viewers.TreePath in project tdq-studio-se by Talend.
the class CreateAnalysisOnHDFSAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
DBTableRepNode newTableNode = openCreateHiveTable();
if (newTableNode != null) {
List<IRepositoryNode> allColumns = newTableNode.getAllColumns();
TreePath[] paths = new TreePath[allColumns.size()];
int i = 0;
for (IRepositoryNode column : allColumns) {
paths[i++] = new TreePath(new Object[] { column });
}
CreateColumnAnalysisAction analysisAction = new CreateColumnAnalysisAction();
analysisAction.setSelection(new TreeSelection(paths));
analysisAction.run();
}
}
use of org.eclipse.jface.viewers.TreePath in project tdq-studio-se by Talend.
the class GridTreeViewer method remove.
/**
* Removes the element at the specified index of the parent. The selection is updated if required.
*
* @param parentOrTreePath the parent element, the input element, or a tree path to the parent element
* @param index child index
* @since 3.3
*/
public void remove(final Object parentOrTreePath, final int index) {
if (checkBusy())
return;
final List oldSelection = new LinkedList(Arrays.asList(((TreeSelection) getSelection()).getPaths()));
preservingSelection(new Runnable() {
public void run() {
TreePath removedPath = null;
if (internalIsInputOrEmptyPath(parentOrTreePath)) {
Tree tree = (Tree) getControl();
if (index < tree.getItemCount()) {
TreeItem item = tree.getItem(index);
if (item.getData() != null) {
removedPath = getTreePathFromItem(item);
disassociate(item);
}
item.dispose();
}
} else {
Widget[] parentItems = internalFindItems(parentOrTreePath);
for (int i = 0; i < parentItems.length; i++) {
TreeItem parentItem = (TreeItem) parentItems[i];
if (parentItem.isDisposed())
continue;
if (index < parentItem.getItemCount()) {
TreeItem item = parentItem.getItem(index);
if (item.getData() != null) {
removedPath = getTreePathFromItem(item);
disassociate(item);
}
item.dispose();
}
}
}
if (removedPath != null) {
boolean removed = false;
for (Iterator it = oldSelection.iterator(); it.hasNext(); ) {
TreePath path = (TreePath) it.next();
if (path.startsWith(removedPath, getComparer())) {
it.remove();
removed = true;
}
}
if (removed) {
setSelection(new TreeSelection((TreePath[]) oldSelection.toArray(new TreePath[oldSelection.size()]), getComparer()), false);
}
}
}
});
}
Aggregations