List of usage examples for org.eclipse.jface.viewers TreeViewer getTree
public Tree getTree()
From source file:com.mentor.nucleus.bp.internal.tools.process.CodeChangesScraper.java
License:Open Source License
public void run(IAction action) { // locate the tree viewer within the synchronize-view ISynchronizePage page = (ISynchronizePage) ((PageBookView) view).getCurrentPage(); TreeViewer viewer = (TreeViewer) page.getViewer(); // expand all nodes of the tree, as only the ones currently displayed // are available to be scraped viewer.expandAll();//ww w. j a va2 s . com StringBuffer changes = new StringBuffer(""); // for each root node in the tree viewer Tree tree = viewer.getTree(); TreeItem[] roots = tree.getItems(); for (int i = 0; i < roots.length; i++) { // append the entries for the tree rooted at this node appendSubtreeText(roots[i], changes); changes.append("\n"); } // output all entries to the system clipboard, to be pasted by the user // into an .int file StringSelection data = new StringSelection(changes.toString()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(data, data); }
From source file:com.mentor.nucleus.bp.test.common.ExplorerUtil.java
License:Open Source License
static public void checkTreeItemDeletion(NonRootModelElement modelElement) { // the tree must be focused for the selection to be // be reported to the model explorer TreeViewer viewer = explorer.getTreeViewer(); final Tree tree = viewer.getTree(); boolean focused = tree.setFocus(); TestCase.assertTrue("Could not focus model explorer tree", focused); // select the node in the tree; note that we must specify // the model element, not its tree-item viewer.setSelection(new StructuredSelection(new Object[] { modelElement }), false); // since this test is running on the event-dispatch thread, we // have to fire the event pump manually to get the // selection event reported, before proceeding Display display = Display.getCurrent(); while (display.readAndDispatch()) ;//from ww w.j av a 2 s . c o m TestCase.assertTrue("Tree Item still exist after deletion ", tree.getSelectionCount() == 0); }
From source file:com.mentor.nucleus.bp.test.common.ExplorerUtil.java
License:Open Source License
static public void checkTreeItemExistance(NonRootModelElement modelElement, String name) { // the tree must be focused for the selection to be // be reported to the model explorer TreeViewer viewer = explorer.getTreeViewer(); final Tree tree = viewer.getTree(); boolean focused = tree.setFocus(); TestCase.assertTrue("Could not focus model explorer tree", focused); // select the node in the tree; note that we must specify // the model element, not its tree-item viewer.setSelection(new StructuredSelection(new Object[] { modelElement }), false); // since this test is running on the event-dispatch thread, we // have to fire the event pump manually to get the // selection event reported, before proceeding Display display = Display.getCurrent(); while (display.readAndDispatch()) ;/*from w ww .j av a 2 s . c o m*/ TestCase.assertTrue("Tree Item with text '" + name + "' dz not exist", tree.getSelection()[0].getText().equals(name)); }
From source file:com.mentor.nucleus.bp.test.common.ExplorerUtil.java
License:Open Source License
/** * Select the NonRootModelElement from Model Explorer * @return /*from www .j a v a 2 s . c o m*/ */ public static TreeItem selectItem(Object item) { // the tree must be focused for the selection to be // be reported to the model explorer TreeViewer viewer = explorer.getTreeViewer(); final Tree tree = viewer.getTree(); boolean focused = tree.setFocus(); TestCase.assertTrue("Could not focus model explorer tree", focused); // select the node in the tree; note that we must specify // the model element, not its tree-item viewer.setSelection(new StructuredSelection(new Object[] { item }), false); // since this test is running on the event-dispatch thread, we // have to fire the event pump manually to get the // selection event reported, before proceeding Display display = Display.getCurrent(); while (display.readAndDispatch()) ; TestCase.assertTrue("Tree Item not selected ", tree.getSelectionCount() > 0); return tree.getSelection()[0]; }
From source file:com.mentor.nucleus.bp.test.common.ExplorerUtil.java
License:Open Source License
/** * Selects the given item in the model explorer tree. *//*w w w .j a v a2s. c om*/ public static void selectItem(TreeItem item) { // the tree must be focused for the selection to be // be reported to the model explorer TreeViewer viewer = explorer.getTreeViewer(); final Tree tree = viewer.getTree(); boolean focused = tree.setFocus(); TestCase.assertTrue("Could not focus model explorer tree", focused); // select the node in the tree; note that we must specify // the model element, not its tree-item viewer.setSelection(new StructuredSelection(new Object[] { item.getData() }), false); // since this test is running on the event-dispatch thread, we // have to fire the event pump manually to get the // selection event reported, before proceeding Display display = Display.getCurrent(); while (display.readAndDispatch()) ; }
From source file:com.mentor.nucleus.bp.test.common.ExplorerUtil.java
License:Open Source License
/** * Returns the item amongst those given which has the given * text as its text./*from w w w .j a v a2 s. c o m*/ */ public static TreeItem findItem(String text) { TreeViewer viewer = explorer.getTreeViewer(); final Tree tree = viewer.getTree(); TreeItem[] items = tree.getItems(); // for each of the items given for (int i = 0; i < items.length; i++) { // if this item's text matches that given if (items[i].getText().equals(text)) { // return this item return items[i]; } } return null; }
From source file:com.mentor.nucleus.bp.test.common.ExplorerUtil.java
License:Open Source License
public static TreeItem findItem(TreeItem item, String text) { if (item == null) { TreeViewer viewer = explorer.getTreeViewer(); final Tree tree = viewer.getTree(); TreeItem[] items = tree.getItems(); // for each of the items given for (int i = 0; i < items.length; i++) { // if this item's text matches that given if (items[i].getText().equals(text)) { // return this item return items[i]; } else { TreeItem findItem = findItem(items[i], text); if (findItem != null) { return findItem; }/* w w w . j a va2 s.c o m*/ } } } else { TreeItem[] items = item.getItems(); // for each of the items given for (int i = 0; i < items.length; i++) { // if this item's text matches that given if (items[i].getText().equals(text)) { // return this item return items[i]; } else { TreeItem findItem = findItem(items[i], text); if (findItem != null) { return findItem; } } } } return null; }
From source file:com.mentor.nucleus.bp.test.common.GitUtil.java
License:Open Source License
public static void startMergeTool(String projectName) { // process any pending events BaseTest.dispatchEvents(0);// w w w . j av a 2 s .co m TreeViewer treeViewer = ExplorerUtil.getTreeViewer(); TreeItem item = UITestingUtilities.findItemInTree(treeViewer.getTree(), projectName); treeViewer.setSelection(new StructuredSelection(item.getData())); TestUtil.okToDialog(400); UITestingUtilities.activateMenuItem(treeViewer.getTree().getMenu(), "Team::Merge Tool"); }
From source file:com.mentor.nucleus.bp.ui.canvas.ModelContentOutlinePage.java
License:Open Source License
protected void createMenus() { // Configure the context menu. MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ MenuManager createMenuManager = new MenuManager("New", "com.mentor.nucleus.bp.ui.newroot"); //$NON-NLS-2$ MenuManager openMenuManager = new MenuManager("Open With", "com.mentor.nucleus.bp.ui.openroot"); //$NON-NLS-2$ final MenuManager classesMenu = new MenuManager("Classes", "com.mentor.nucleus.bp.ui.classroot"); //$NON-NLS-2$ final MenuManager componentsMenu = new MenuManager("Components", "com.mentor.nucleus.bp.ui.componentroot"); //$NON-NLS-2$ final MenuManager externalMenu = new MenuManager("External", "com.mentor.nucleus.bp.ui.externalroot"); //$NON-NLS-2$ final MenuManager interactionMenu = new MenuManager("Interaction", "com.mentor.nucleus.bp.ui.interactionroot"); //$NON-NLS-1$ final MenuManager activityMenu = new MenuManager("Activity", "com.mentor.nucleus.bp.ui.activityroot"); //$NON-NLS-2$ final MenuManager typesMenu = new MenuManager("Types", "com.mentor.nucleus.bp.ui.typeroot"); //$NON-NLS-2$ final MenuManager useCaseMenu = new MenuManager("Usecase", "com.mentor.nucleus.bp.ui.usecaseroot"); //$NON-NLS-2$ menuMgr.add(createMenuManager);/*www. j ava2s .co m*/ createMenuManager.removeAll(); createMenuManager.add(new GroupMarker("com.mentor.nucleus.bp.ui.newmenu")); //$NON-NLS-1$ createMenuManager.add(activityMenu); activityMenu.removeAll(); activityMenu.add(new GroupMarker("com.mentor.nucleus.bp.ui.newactivitymenu")); createMenuManager.add(classesMenu); classesMenu.removeAll(); classesMenu.add(new GroupMarker("com.mentor.nucleus.bp.ui.newclassmenu")); createMenuManager.add(componentsMenu); componentsMenu.removeAll(); componentsMenu.add(new GroupMarker("com.mentor.nucleus.bp.ui.newcomponentmenu")); createMenuManager.add(externalMenu); externalMenu.removeAll(); externalMenu.add(new GroupMarker("com.mentor.nucleus.bp.ui.newexternalmenu")); createMenuManager.add(interactionMenu); interactionMenu.removeAll(); interactionMenu.add(new GroupMarker("com.mentor.nucleus.bp.ui.newinteractionmenu")); createMenuManager.add(typesMenu); typesMenu.removeAll(); typesMenu.add(new GroupMarker("com.mentor.nucleus.bp.ui.newtypemenu")); createMenuManager.add(useCaseMenu); useCaseMenu.removeAll(); useCaseMenu.add(new GroupMarker("com.mentor.nucleus.bp.ui.newusecasemenu")); menuMgr.add(open); menuMgr.add(openMenuManager); openMenuManager.removeAll(); openMenuManager.add(new GroupMarker("com.mentor.nucleus.bp.ui.openmenu")); //$NON-NLS-1$ menuMgr.add(new Separator("com.mentor.nucleus.bp.ui.context-internal")); //$NON-NLS-1$ menuMgr.add(new Separator("com.mentor.nucleus.bp.ui.context-internal-end")); //$NON-NLS-1$ // add the undo/redo actions TransactionManager manager = ((NonRootModelElement) instance).getTransactionManager(); undo = manager.getUndoAction(); redo = manager.getRedoAction(); menuMgr.add(new Separator()); menuMgr.add(undo); menuMgr.add(redo); menuMgr.add(new Separator()); menuMgr.add(cut); menuMgr.add(copy); menuMgr.add(paste); menuMgr.add(delete); menuMgr.add(rename); TreeViewer viewer = getTreeViewer(); Menu menu = menuMgr.createContextMenu(viewer.getTree()); viewer.getTree().setMenu(menu); // Be sure to register it so that other plug-ins can add actions. getSite().registerContextMenu("com.mentor.nucleus.bp.ui.canvas.outline", menuMgr, viewer); //$NON-NLS-1$ }
From source file:com.mentor.nucleus.bp.ui.canvas.test.CanvasTestUtilities.java
License:Open Source License
public static void updateTreeItem(Object t1, String newValue) throws Exception { StructuredSelection sel = new StructuredSelection(t1); Selection.getInstance().setSelection(sel); IWorkbenchPage m_wp = PlatformUI.getWorkbench().showPerspective("com.mentor.nucleus.bp.core.perspective", PlatformUI.getWorkbench().getActiveWorkbenchWindow()); ExplorerView m_bp_view = (ExplorerView) m_wp.findView(BridgePointPerspective.ID_MGC_BP_EXPLORER); TreeViewer m_bp_tree = m_bp_view.getTreeViewer(); m_bp_tree.refresh();/* w ww . j av a 2 s . c o m*/ m_bp_tree.expandAll(); m_bp_tree.getTree().selectAll(); TreeItem x[] = m_bp_tree.getTree().getSelection(); TestCase.assertNotNull("Tree is empty", x); for (int i = 0; i < x.length; ++i) { if (x[i].getData() == t1) { TreeItem[] x_set = { x[i] }; m_bp_tree.getTree().setSelection(x_set); RenameAction t2 = (RenameAction) CorePlugin.getRenameAction(m_bp_tree); t2.run(); t2.getTextEditor().setText(newValue); Event e = new Event(); e.type = SWT.Traverse; e.detail = SWT.TRAVERSE_RETURN; e.widget = t2.getTextEditor(); t2.getTextEditor().notifyListeners(e.type, e); Display d = Display.getCurrent(); while (d.readAndDispatch()) ; return; } } TestCase.fail("Tree item not found"); }