Search in sources :

Example 31 with TreePath

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();
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Image(org.eclipse.swt.graphics.Image) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) INatExample(org.eclipse.nebula.widgets.nattable.examples.INatExample) Display(org.eclipse.swt.widgets.Display)

Example 32 with TreePath

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);
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) MenuManager(org.eclipse.jface.action.MenuManager) ActionContext(org.eclipse.ui.actions.ActionContext) SemanticDiscoveryAction(org.talend.dataprofiler.core.ui.action.actions.predefined.SemanticDiscoveryAction) Test(org.junit.Test)

Example 33 with TreePath

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());
            }
        }
    });
}
Also used : DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) TreePath(org.eclipse.jface.viewers.TreePath) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TreeSelection(org.eclipse.jface.viewers.TreeSelection) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode)

Example 34 with TreePath

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();
    }
}
Also used : DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TreePath(org.eclipse.jface.viewers.TreePath) CreateColumnAnalysisAction(org.talend.dataprofiler.core.ui.action.actions.predefined.CreateColumnAnalysisAction) TreeSelection(org.eclipse.jface.viewers.TreeSelection)

Example 35 with TreePath

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);
                }
            }
        }
    });
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) Tree(org.eclipse.swt.widgets.Tree) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Aggregations

TreePath (org.eclipse.jface.viewers.TreePath)104 TreeSelection (org.eclipse.jface.viewers.TreeSelection)55 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ArrayList (java.util.ArrayList)20 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)18 XSDComponent (org.eclipse.xsd.XSDComponent)14 Test (org.junit.Test)14 Iterator (java.util.Iterator)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)12 HashSet (java.util.HashSet)10 Set (java.util.Set)10 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)10 List (java.util.List)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 IProject (org.eclipse.core.resources.IProject)5 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5