List of usage examples for org.eclipse.jface.viewers TreeViewer setSelection
@Override public void setSelection(ISelection selection, boolean reveal)
From source file:org.xtuml.bp.core.test.I810_SlowDeletionTestGenerics.java
License:Open Source License
@Test public void testSlowDeletion() { IWorkbenchPage page = TestUtil.showBridgePointPerspective(); ExplorerView explorer = null;/* w w w. ja v a2 s .co m*/ Display display = Display.getCurrent(); while (display.readAndDispatch()) ; Package_c[] domains = Package_c.PackageInstances(modelRoot); try { explorer = (ExplorerView) page.showView("org.xtuml.bp.ui.explorer.ExplorerView", null, //$NON-NLS-1$ IWorkbenchPage.VIEW_CREATE); } catch (PartInitException e) { fail(e.toString()); } TreeViewer viewer = explorer.getTreeViewer(); viewer.expandToLevel(2); UIUtil.refreshViewer(viewer); while (display.readAndDispatch()) ; // select the only domain node that should be present viewer.setSelection(new StructuredSelection(new Object[] { domains[0] }), false); while (display.readAndDispatch()) { } long startTime = System.currentTimeMillis(); TransactionManager.getSingleton().disableDialog = true; explorer.doDelete(); TransactionManager.getSingleton().disableDialog = false; while (display.readAndDispatch()) { } long endTime = System.currentTimeMillis(); System.out.println("Deletion Took : " + (float) (endTime - startTime) / 1000 + " sec");//$NON-NLS-1$//$NON-NLS-2$ }
From source file:org.xtuml.bp.io.mdl.test.DataUpgradeCreatesNoDeltasTestGenerics.java
License:Open Source License
@Test public void testUpgradeCreatesNoDeltas() throws Exception { loadProject("CommunicationTestModel"); for (int i = 0; i < unaffectedDomNames.length; i++) { loadProject(unaffectedDomNames[i]); }// ww w . ja v a 2 s . c om Display display = Display.getCurrent(); while (display.readAndDispatch()) ; m_sys = getSystemModel("CommunicationTestModel"); Package_c dom = Package_c.getOneEP_PKGOnR1405(m_sys, new ClassQueryInterface_c() { public boolean evaluate(Object candidate) { return ((Package_c) candidate).getName().equals("CommunicationTestModel"); } }); assertNotNull("No test Domain found", dom); Package_c[] unaffectedDoms = new Package_c[unaffectedDomNames.length]; for (int i = 0; i < unaffectedDomNames.length; i++) { final String name = unaffectedDomNames[i]; m_sys = getSystemModel(name); unaffectedDoms[i] = Package_c.getOneEP_PKGOnR1405(m_sys, new ClassQueryInterface_c() { public boolean evaluate(Object candidate) { return ((Package_c) candidate).getName().equals(name); } }); assertNotNull("No reference Domain found", unaffectedDoms[i]); } Package_c ss = Package_c.getOneEP_PKGOnR8001(PackageableElement_c.getManyPE_PEsOnR8000(dom), new ClassQueryInterface_c() { public boolean evaluate(Object candidate) { return ((Package_c) candidate).getName().equals("Subsystem"); } }); assertNotNull("No Subsystem found", ss); IWorkbenchPage page = TestUtil.showBridgePointPerspective(); ExplorerView explorer = null; try { explorer = (ExplorerView) page.showView("org.xtuml.bp.ui.explorer.ExplorerView", null, //$NON-NLS-1$ IWorkbenchPage.VIEW_CREATE); } catch (PartInitException e) { fail(e.toString()); } TreeViewer viewer = explorer.getTreeViewer(); viewer.expandToLevel(2); UIUtil.refreshViewer(viewer); while (display.readAndDispatch()) ; // select the only domain node that should be present viewer.setSelection(new StructuredSelection(new Object[] { ss }), false); while (display.readAndDispatch()) { } TransactionManager manager = getSystemModel().getTransactionManager(); DeltaCheckingTransactionListener dctl = new DeltaCheckingTransactionListener(unaffectedDomNames, unaffectedDoms); manager.addTransactionListener(dctl); explorer.doDelete(); while (manager.getActiveTransaction() != null || display.readAndDispatch()) ; assertTrue("Unexpected deltas found on domains, " + dctl.getAffected(), dctl.getAffected().isEmpty()); }
From source file:org.xtuml.bp.test.common.ExplorerUtil.java
License:Apache 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 BaseTest.dispatchEvents();//from w ww. j ava2s . c om TestCase.assertTrue("Tree Item still exist after deletion ", tree.getSelectionCount() == 0); }
From source file:org.xtuml.bp.test.common.ExplorerUtil.java
License:Apache 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 BaseTest.dispatchEvents();/*ww w. j av a 2s . com*/ TestCase.assertTrue("Tree Item with text '" + name + "' dz not exist", tree.getSelection()[0].getText().equals(name)); }
From source file:org.xtuml.bp.test.common.ExplorerUtil.java
License:Apache License
/** * Select the NonRootModelElement from Model Explorer * @return /*from w w w .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 BaseTest.dispatchEvents(); TestCase.assertTrue("Tree Item not selected ", tree.getSelectionCount() > 0); return tree.getSelection()[0]; }
From source file:org.xtuml.bp.test.common.ExplorerUtil.java
License:Apache License
/** * Selects the given item in the model explorer tree. *//* w w w .j a v a2 s.c o m*/ 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 BaseTest.dispatchEvents(); }
From source file:phasereditor.canvas.ui.editors.behaviors.SelectionBehavior.java
License:Open Source License
@Override public void setSelection(ISelection selection) { TreeViewer outline = _canvas.getOutline(); _canvas.getPGrid().getViewer().getTree().setRedraw(false); outline.setSelection(selection, true); setSelection_private(selection); _canvas.getPGrid().getViewer().getTree().setRedraw(true); }
From source file:pow.views.EntityView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { tv = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); tv.setContentProvider(new EntityContentProvider()); tv.setLabelProvider(new EntityLabelProvider()); tv.setInput(getViewSite());//from w w w . j av a 2s.co m tv.setSorter(new ViewerSorter()); getSite().setSelectionProvider(tv); tv.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { IStructuredSelection thisSelection = (IStructuredSelection) event.getSelection(); Object selectedNode = thisSelection.getFirstElement(); if (selectedNode instanceof Parameter) { ArrayList<Object> path = new ArrayList<Object>(); BPMNObject current = ((Parameter) selectedNode).getActivity(); TreeViewer viewer = Activator.getDefault().bpmnView.getViewer(); while (current != null) { path.add(current); current = current.getParent(); } path.add(Activator.getDefault().getPOWModel()); Collections.reverse(path); TreePath tp = new TreePath(path.toArray()); TreeSelection sel = new TreeSelection(tp); viewer.setExpandedTreePaths(new TreePath[] { tp }); viewer.setExpandedState(((Parameter) selectedNode).getActivity(), true); viewer.setSelection(sel, true); IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); try { handlerService.executeCommand("pow.commands.openactivityeditor", null); } catch (Exception ex) { POWConsole.printError(ex.getMessage()); ex.printStackTrace(); } } } }); makeActions(); contributeToActionBars(); }
From source file:v9t9.gui.client.swt.shells.modules.ModuleSelector.java
License:Open Source License
/** * @param moduleManager/*from w w w. j a v a 2 s . co m*/ */ protected TreeViewer createTable() { final TreeViewer viewer = new TreeViewer(this, SWT.READ_ONLY | SWT.BORDER | SWT.FULL_SELECTION); moduleImageResizer = new ILazyImageAdjuster() { @Override public Image adjustImage(Object element, URI imageURI, Image image) { //final boolean moduleLoadable = module == null || isModuleLoadable(module); //final String imageKey = imageURI.toString() + (moduleLoadable ? "" : "?grey"); Rectangle bounds = image.getBounds(); int sz = Math.max(bounds.width, bounds.height); if (sz > MAX) { sz = MAX; Image scaled = ImageUtils.scaleImage(getDisplay(), image, new Point(MAX, MAX), true, true); image.dispose(); // if (!moduleLoadable) { // Image grey = ImageUtils.convertToGreyscale(display, scaled); // scaled.dispose(); // scaled = grey; // } image = scaled; } return image; } }; try { builtinImagesURI = machine.getRomPathFileLocator() .resolveInsideURI(machine.getModel().getDataURL().toURI(), "images/"); logger.info("builtinImagesURI = " + builtinImagesURI); } catch (URISyntaxException e3) { logger.error("Failed to load stock module image", e3); } stockModuleImage = loadStockImage("stock_module_missing.png"); lazyImageLoader = new LazyImageLoader(viewer, executor, stockModuleImage); modulesListImage = EmulatorGuiData.loadImage(getDisplay(), "icons/module_list.png"); noModuleImage = ImageUtils.scaleImage(getDisplay(), EmulatorGuiData.loadImage(getDisplay(), "icons/stock_no_module.png"), new Point(MAX, MAX)); viewer.setUseHashlookup(true); viewer.setComparer(new IElementComparer() { @Override public int hashCode(Object element) { return element.hashCode(); } @Override public boolean equals(Object a, Object b) { return a == b || a.equals(b); } }); Tree tree = viewer.getTree(); tree.setHeaderVisible(true); tree.setLinesVisible(true); GridDataFactory.fillDefaults().grab(true, true).applyTo(tree); FontDescriptor desc = FontUtils .getFontDescriptor(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); tableFont = desc.createFont(getDisplay()); tree.setFont(tableFont); nameColumn = new TreeColumn(tree, SWT.LEFT); nameColumn.setText("Name"); final ModuleContentProvider contentProvider = new ModuleContentProvider(); viewer.setContentProvider(contentProvider); CellLabelProvider cellLabelProvider = new CellLabelProvider() { @Override public void update(ViewerCell cell) { if (cell.getElement() instanceof URI) { URI uri = (URI) cell.getElement(); String text = machine.getRomPathFileLocator().splitFileName(uri).second; cell.setText(text); cell.setImage(getModuleListImage()); } else if (cell.getElement() instanceof IModule) { IModule module = (IModule) cell.getElement(); cell.setText(module.getName()); ModuleInfo info = module.getInfo(); cell.setForeground(isModuleLoadable(module) ? null : viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND)); cell.setImage(getOrLoadModuleImage(module, module, info != null ? info.getImagePath() : null)); } else { cell.setText(String.valueOf(cell.getElement())); cell.setImage(getNoModuleImage()); } } }; viewer.setLabelProvider(cellLabelProvider); viewer.setColumnProperties(NAME_PROPERTY_ARRAY); viewer.setComparator(new ViewerComparator() { /* (non-Javadoc) * @see org.eclipse.jface.viewers.ViewerComparator#isSorterProperty(java.lang.Object, java.lang.String) */ @Override public boolean isSorterProperty(Object element, String property) { return "name".equals(property); } @Override public int compare(Viewer viewer, Object e1, Object e2) { if (!sortModules) return 0; if (e1 instanceof IModule && e2 instanceof IModule) { IModule mod1 = (IModule) e1; IModule mod2 = (IModule) e2; boolean l1 = isModuleLoadable(mod1); boolean l2 = isModuleLoadable(mod2); if (l1 == l2) return sortDirection * mod1.getName().toLowerCase().compareTo(mod2.getName().toLowerCase()); else if (l1) return -1; else return 1; } else if (e1 instanceof IModule) { return 1; } /* else if (e2 instanceof IModule) */ { return -1; } } }); selectedModule = null; addIterativeSearch(viewer, tree); sortModules = dialogSettings.getBoolean(SORT_ENABLED); sortDirection = dialogSettings.getInt(SORT_DIRECTION); moduleMap = new LinkedHashMap<URI, Collection<IModule>>(); revertModules(); viewer.setInput(new ModuleInput("No module", moduleMap)); viewer.expandToLevel(3); viewer.setSelection(new StructuredSelection(moduleManager.getLoadedModules()), true); tree.addKeyListener(new KeyAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent) */ @Override public void keyPressed(KeyEvent e) { if (e.keyCode == '\r' || e.keyCode == '\n') { switchModule(false); e.doit = false; } else if (e.keyCode == SWT.ARROW_LEFT) { if (selectedModule != null) { viewer.setSelection(new StructuredSelection(contentProvider.getParent(selectedModule))); } } } }); TreeViewerColumn nameViewerColumn = new TreeViewerColumn(viewer, nameColumn); nameViewerColumn.setLabelProvider(cellLabelProvider); editingSupport = new ModuleNameEditingSupport(viewer, dirtyModuleLists); nameViewerColumn.setEditingSupport(editingSupport); addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { for (Image image : stockImages.values()) image.dispose(); stockImages.clear(); if (modulesListImage != null) modulesListImage.dispose(); if (noModuleImage != null) noModuleImage.dispose(); if (tableFont != null) tableFont.dispose(); /*for (Image image : loadedImages.values()) { image.dispose(); }*/ } }); lazyImageLoader.addListener(new ILazyImageLoadedListener() { @Override public void imageLoaded(Object element, URI imageURI, Image image) { if (element != null) viewerUpdater.post(element); } }); return viewer; }
From source file:v9t9.gui.client.swt.shells.modules.ModuleSelector.java
License:Open Source License
/** * @param viewer//from w ww. j ava2 s . c o m * @param tree * @param realModules */ protected void addIterativeSearch(final TreeViewer viewer, Tree tree) { tree.addKeyListener(new KeyAdapter() { StringBuilder search = new StringBuilder(); int index = 0; IModule[] modules; @Override public void keyPressed(KeyEvent e) { if (modules == null) { modules = moduleManager.getModules(); } if (e.keyCode == '\b') { search.setLength(0); index = 0; e.doit = e.keyCode != '\b'; modules = moduleManager.getModules(); } else if (e.keyCode == SWT.ARROW_DOWN) { index++; e.doit = false; } else if (e.keyCode == SWT.ARROW_UP) { index--; e.doit = false; } else if (e.character >= 32 && e.character < 127) { search.append(e.character); e.doit = false; } else { return; } if (search.length() > 0) { int end = (index + modules.length - 1) % modules.length; for (int i = index; i != end; i = (i + 1) % modules.length) { IModule m = modules[i]; String lowSearch = search.toString().toLowerCase(); if (m.getName().toLowerCase().contains(lowSearch) || m.getKeywords().contains(lowSearch)) { viewer.setSelection(new StructuredSelection(m), true); index = i; break; } } } } }); }