Search in sources :

Example 31 with TreeNode

use of org.eclipse.linuxtools.systemtap.structures.TreeNode in project linuxtools by eclipse.

the class KernelSourceAction method run.

/**
 * The main code body for this action. Causes one of the following to occur:
 * <ul>
 *     <li>If the selected node is clickable, as specified in <code>TreeNode.isClickable</code>
 *         the browser creates an instance of <code>CEditor</code> on the file specified in the selection
 *         (<code>KernelBrowserView</code>'s tree only marks clickable on files, not folders) and
 *         opens it on the current window</li>
 *     <li>If the selected node is not clickable, the code runs the action specified in
 *         <code>TreeExpandCollapseAction</code></li>
 * @see org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.c.CEditor
 * @see TreeNode#isClickable()
 * @see TreeExpandCollapseAction
 */
@Override
public void run() {
    IWorkbench wb = PlatformUI.getWorkbench();
    Object o = getSelectedElement();
    if (o instanceof TreeNode) {
        TreeNode t = (TreeNode) o;
        if (t.isClickable()) {
            IFileStore fs = (IFileStore) t.getData();
            if (fs != null) {
                IEditorInput input = new FileStoreEditorInput(fs);
                try {
                    wb.getActiveWorkbenchWindow().getActivePage().openEditor(input, CDT_EDITOR_ID);
                } catch (PartInitException e) {
                    // $NON-NLS-1$
                    ExceptionErrorDialog.openError(Localization.getString("KernelSourceAction.CantOpenEditor"), e);
                }
            }
        } else {
            runExpandAction();
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) IFileStore(org.eclipse.core.filesystem.IFileStore) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 32 with TreeNode

use of org.eclipse.linuxtools.systemtap.structures.TreeNode in project linuxtools by eclipse.

the class TreeNodeTest method testAdd.

@Test
public void testAdd() {
    t.add(new TreeNode("One", "tne", false));
    assertEquals("Add child", 3, t.getChildCount());
    t.add(new TreeNode("two", false));
    assertEquals("Add child2", 4, t.getChildCount());
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) Test(org.junit.Test)

Example 33 with TreeNode

use of org.eclipse.linuxtools.systemtap.structures.TreeNode in project linuxtools by eclipse.

the class TreeNodeTest method testGetChildAt.

@Test
public void testGetChildAt() {
    TreeNode child1 = new TreeNode("1", false);
    t.add(child1);
    TreeNode child2 = new TreeNode("2", false);
    t.add(child2);
    TreeNode c = t.getChildAt(0);
    assertEquals("Retreive first child from tree", child, c);
    c = t.getChildAt(2);
    assertEquals("Retreive middle child from tree", child1, c);
    c = t.getChildAt(3);
    assertEquals("Retreive last child from tree", child2, c);
    assertNull("No child here", t.getChildAt(10));
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) Test(org.junit.Test)

Example 34 with TreeNode

use of org.eclipse.linuxtools.systemtap.structures.TreeNode in project linuxtools by eclipse.

the class TreeNodeTest method testRemove.

@Test
public void testRemove() {
    TreeNode child1 = new TreeNode("1", false);
    t.add(child1);
    TreeNode child2 = new TreeNode("2", false);
    t.add(child2);
    TreeNode child3 = new TreeNode("3", false);
    t.add(child3);
    assertEquals("Full tree before remove", 5, t.getChildCount());
    assertTrue(t.remove(1));
    assertEquals("Remove middle child from tree", 4, t.getChildCount());
    assertTrue(t.remove(0));
    assertEquals("Remove first child from tree", 3, t.getChildCount());
    assertTrue(t.remove(1));
    assertEquals("Remove last child from tree", 2, t.getChildCount());
    assertFalse(t.remove(10));
    assertEquals("Remove IndexOutOfBounds", 2, t.getChildCount());
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) Test(org.junit.Test)

Aggregations

TreeNode (org.eclipse.linuxtools.systemtap.structures.TreeNode)34 Test (org.junit.Test)15 TreeDefinitionNode (org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode)4 Scanner (java.util.Scanner)3 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 ProbevarNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbevarNodeData)3 ArrayList (java.util.ArrayList)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 FuncparamNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FuncparamNodeData)2 FunctionNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData)2 ProbeNodeData (org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbeNodeData)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Matcher (java.util.regex.Matcher)1 IStatus (org.eclipse.core.runtime.IStatus)1