List of usage examples for org.eclipse.jface.viewers TreeViewer getSelection
@Override
public ISelection getSelection()
AbstractTreeViewer
implementation of this method returns the result as an ITreeSelection
. From source file:org.eclipse.jubula.client.ui.rcp.handlers.StartObjectMappingModeHandler.java
License:Open Source License
/** * @param autId The ID of the AUT for which to start the * Object Mapping Mode.// w ww .j av a 2s . c o m * @param editor the actual om-editor * @param unmappedTechNames the top-level category for unmapped * Technical Names */ private void startMappingMode(AutIdentifier autId, ObjectMappingMultiPageEditor editor, IObjectMappingCategoryPO unmappedTechNames) { IObjectMappingCategoryPO category = null; TreeViewer treeViewer = editor.getTreeViewer(); if (treeViewer != null && ((treeViewer.getSelection() instanceof IStructuredSelection) || (treeViewer.getContentProvider() instanceof ITreeContentProvider))) { IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); Object node; if (selection.size() == 1) { node = selection.getFirstElement(); if (node instanceof IObjectMappingCategoryPO && OMEditorDndSupport .getSection((IObjectMappingCategoryPO) node).equals(unmappedTechNames)) { category = (IObjectMappingCategoryPO) node; } else if (node instanceof IObjectMappingAssoziationPO && OMEditorDndSupport .getSection((IObjectMappingAssoziationPO) node).equals(unmappedTechNames)) { category = ((IObjectMappingAssoziationPO) node).getCategory(); } if (category != null) { editor.getOmEditorBP().setCategoryToCreateIn(category); } else { ObjectMappingEventDispatcher.setCategoryToCreateIn(null); } } } if (!AutAgentRegistration.getInstance().getRegisteredAuts().contains(autId)) { String message = Messages.OMStartMappingModeActionError1; ErrorHandlingUtil.createMessageDialog(new JBException(message, MessageIDs.E_UNEXPECTED_EXCEPTION), null, new String[] { message }); } else { IPreferenceStore preferenceStore = Plugin.getDefault().getPreferenceStore(); int mappingMod = preferenceStore.getInt(Constants.MAPPING_MOD_KEY); int mappingKey = preferenceStore.getInt(Constants.MAPPING_TRIGGER_KEY); int mappingType = preferenceStore.getInt(Constants.MAPPING_TRIGGER_TYPE_KEY); int mappingWPMod = preferenceStore.getInt(Constants.MAPPING_WITH_PARENTS_MOD_KEY); int mappingWPKey = preferenceStore.getInt(Constants.MAPPING_WITH_PARENTS_TRIGGER_KEY); int mappingWPType = preferenceStore.getInt(Constants.MAPPING_WITH_PARENTS_TRIGGER_TYPE_KEY); final String toolkit = editor.getAut().getToolkit(); Job startObjectMappingModeJob = new StartObjectMappingModeJob(editor, autId, mappingMod, mappingKey, category, mappingType, mappingWPMod, mappingWPKey, mappingWPType); startObjectMappingModeJob.setSystem(true); JobUtils.executeJob(startObjectMappingModeJob, null); } }
From source file:org.eclipse.jubula.client.ui.rcp.views.TestCaseBrowser.java
License:Open Source License
/** * @param po The persistent object for which the structure has changed *///w w w.j a v a 2 s .co m private void handleDataStructureModified(final IPersistentObject po) { if (po instanceof INodePO) { final TreeViewer tv = getTreeViewer(); try { tv.getTree().getParent().setRedraw(false); // retrieve tree state Object[] expandedElements = tv.getExpandedElements(); ISelection selection = tv.getSelection(); // update elements if (po instanceof IProjectPO) { rebuildTree(); } // refresh tree viewer tv.refresh(); // restore tree state tv.setExpandedElements(expandedElements); tv.setSelection(selection); } finally { tv.getTree().getParent().setRedraw(true); } } }
From source file:org.eclipse.linuxtools.internal.oprofile.ui.view.OprofileViewDoubleClickListener.java
License:Open Source License
@Override public void doubleClick(DoubleClickEvent event) { TreeViewer tv = (TreeViewer) event.getSource(); TreeSelection tsl = (TreeSelection) tv.getSelection(); IUiModelElement element = (IUiModelElement) tsl.getFirstElement(); try {//from w w w . java2 s . co m if (element instanceof UiModelEvent) { // UiModelEvent event = (UiModelEvent)element; } else if (element instanceof UiModelSession) { /* moved into an action menu */ } else if (element instanceof UiModelImage) { // UiModelImage image = (UiModelImage)element; } else if (element instanceof UiModelSymbol) { final UiModelSymbol symbol = (UiModelSymbol) element; final String fileName = symbol.getFileName(); int line = symbol.getLineNumber(); ProfileUIUtils.openEditorAndSelect(fileName, line); } else if (element instanceof UiModelSample) { // jump to line number in the appropriate file UiModelSample sample = (UiModelSample) element; int line = sample.getLine(); // get file name from the parent sample final String fileName = sample.getFile(); ProfileUIUtils.openEditorAndSelect(fileName, line, getProject()); } } catch (BadLocationException e1) { e1.printStackTrace(); } catch (PartInitException e2) { e2.printStackTrace(); } catch (CoreException e) { e.printStackTrace(); } }
From source file:org.eclipse.linuxtools.oprofile.ui.view.OprofileViewDoubleClickListener.java
License:Open Source License
public void doubleClick(DoubleClickEvent event) { TreeViewer tv = (TreeViewer) event.getSource(); TreeSelection tsl = (TreeSelection) tv.getSelection(); IUiModelElement element = (IUiModelElement) tsl.getFirstElement(); ICProject project;//from w ww . j ava 2 s. co m try { if (element instanceof UiModelEvent) { // UiModelEvent event = (UiModelEvent)element; } else if (element instanceof UiModelSession) { /* moved into an action menu */ } else if (element instanceof UiModelImage) { // UiModelImage image = (UiModelImage)element; } else if (element instanceof UiModelSymbol) { final UiModelSymbol symbol = (UiModelSymbol) element; final String imageLabel = symbol.getParent().getLabelText(); final String fileName = symbol.getFileName(); String functionName = symbol.getFunctionName(); int numOfArgs = -1; HashMap<String, int[]> map; // hard coded to match "XY.PQ% in /some/arbitrary/path/to/binary" String absPath = imageLabel.substring(imageLabel.indexOf(" in ") + 4); project = ProfileUIUtils.findCProjectWithAbsolutePath(absPath); if (project == null) { return; } // detect function with arguments and narrow search accordingly if (functionName.matches(".*\\(.*\\)")) { int start = functionName.indexOf('('); if (functionName.contains(",")) { int end = functionName.indexOf(')'); numOfArgs = functionName.substring(start, end).split(",").length; } else { numOfArgs = 1; } functionName = functionName.substring(0, start); } else { numOfArgs = 0; } if (fileName.length() > 0 && functionName.length() > 0) { // this should almost ALWAYS be the case // try and go to the function in the file map = ProfileUIUtils.findFunctionsInProject(project, functionName, numOfArgs, fileName, true); // if function still can't be found, go to first line in the file if (map.isEmpty()) { ProfileUIUtils.openEditorAndSelect(fileName, 1); } else { for (String loc : map.keySet()) { ProfileUIUtils.openEditorAndSelect(loc, map.get(loc)[0], map.get(loc)[1]); } } } else if (functionName.length() > 0) { // can this ever happen ? // try to find the file name that has this function map = ProfileUIUtils.findFunctionsInProject(project, functionName, numOfArgs, null, true); for (String loc : map.keySet()) { ProfileUIUtils.openEditorAndSelect(loc, map.get(loc)[0], map.get(loc)[1]); } } else if (fileName.length() > 0) { // can this ever happen ? // jump to 1st line in the file ProfileUIUtils.openEditorAndSelect(fileName, 1); } } else if (element instanceof UiModelSample) { // jump to line number in the appropriate file UiModelSample sample = (UiModelSample) element; int line = sample.getLine(); // get file name from the parent sample final UiModelSymbol symbol = ((UiModelSymbol) sample.getParent()); final String fileName = symbol.getFileName(); ProfileUIUtils.openEditorAndSelect(fileName, line); } } catch (BadLocationException e1) { e1.printStackTrace(); } catch (PartInitException e2) { e2.printStackTrace(); } catch (CoreException e3) { e3.printStackTrace(); } }
From source file:org.eclipse.linuxtools.systemtap.ui.dashboard.actions.hidden.GetSelectedModule.java
License:Open Source License
/** * This class examins the provied view and retreives the selected item from * it. It then converts the selected item into a DashboardModule and returns it. * @param view The DashboardModuleBrowserView that is currently open * @return The selected DashboardModule from the view *///from w ww. j a v a2s. c o m private static DashboardModule getModule2(DashboardModuleBrowserView view) { TreeViewer viewer = view.getViewer(); ISelection selected = viewer.getSelection(); if (null != selected && selected instanceof IStructuredSelection) { Object element = ((IStructuredSelection) selected).getFirstElement(); if (element instanceof ModuleTreeNode) { ModuleTreeNode mod = (ModuleTreeNode) element; return (DashboardModule) mod.getData(); } } return null; }
From source file:org.eclipse.linuxtools.systemtap.ui.dashboard.actions.hidden.GetSelectedModule.java
License:Open Source License
public static TreeNode getNode(IViewPart view) { TreeViewer viewer = null; if (null == view) view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .findView(DashboardModuleBrowserView.ID); if (view instanceof DashboardModuleBrowserView) viewer = ((DashboardModuleBrowserView) view).getViewer(); else/* w w w .ja v a 2s. c om*/ viewer = ((ActiveModuleBrowserView) view).getViewer(); ISelection selected = viewer.getSelection(); if (null != selected && selected instanceof IStructuredSelection) { Object element = ((IStructuredSelection) selected).getFirstElement(); if (element instanceof TreeNode) { TreeNode node = (TreeNode) element; return node; } } return null; }
From source file:org.eclipse.linuxtools.systemtap.ui.dashboard.actions.hidden.GetSelectedModule.java
License:Open Source License
/** * This class examins the provied view and retreives the selected item from * it. It then gets the DashboardModule contained within the selected item * and returns it./* w w w. j a va 2s.c om*/ * @param view The ActiveModuleBrowserView that is currently open * @return The selected DashboardModule from the view */ private static DashboardModule getModule2(ActiveModuleBrowserView view) { TreeViewer viewer = view.getViewer(); ISelection selected = viewer.getSelection(); if (null != selected && selected instanceof IStructuredSelection) { Object element = ((IStructuredSelection) selected).getFirstElement(); if (element instanceof TreeNode) { TreeNode mod = (TreeNode) element; return ((ActiveModuleData) mod.getData()).module; } } return null; }
From source file:org.eclipse.mylyn.internal.bugzilla.ui.wizard.BugzillaProductPage.java
License:Open Source License
@SuppressWarnings("deprecation") public void createControl(Composite parent) { // create the composite to hold the widgets Composite composite = new Composite(parent, SWT.NULL); // create the desired layout for this wizard page composite.setLayout(new GridLayout()); // create the list of bug reports // TODO e3.5 move to new FilteredTree API productList = new FilteredTree(composite, SWT.SINGLE | SWT.BORDER, new ComponentFilter()); productList.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true) .hint(SWT.DEFAULT, 200).create()); final TreeViewer productViewer = productList.getViewer(); productViewer.setLabelProvider(new LabelProvider()); productViewer.setContentProvider(new ITreeContentProvider() { public Object[] getChildren(Object parentElement) { if (parentElement instanceof Collection<?>) { return ((Collection<?>) parentElement).toArray(); }/*from ww w .j a va 2 s . co m*/ return null; } public Object getParent(Object element) { return null; } public boolean hasChildren(Object element) { return false; } public Object[] getElements(Object inputElement) { return getChildren(inputElement); } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); productViewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { if (getWizard().canFinish()) { if (getWizard().performFinish()) { ((WizardDialog) getContainer()).close(); } } } }); initProducts(); productViewer.setInput(products); productViewer.addPostSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { // Initialize a variable with the no error status Status status = new Status(IStatus.OK, BugzillaUiPlugin.ID_PLUGIN, 0, "", null); //$NON-NLS-1$ if (productViewer.getSelection().isEmpty()) { status = new Status(IStatus.ERROR, BugzillaUiPlugin.ID_PLUGIN, 0, Messages.BugzillaProductPage_YOU_MUST_SELECT_PRODUCT, null); } // Show the most serious error applyToStatusLine(status); isPageComplete(); getWizard().getContainer().updateButtons(); } }); // HACK: waiting on delayed refresh of filtered tree final String[] selectedProducts = getSelectedProducts(); if (selectedProducts.length > 0) { new UIJob("") { //$NON-NLS-1$ @Override public IStatus runInUIThread(IProgressMonitor monitor) { if (BugzillaProductPage.this.getControl() != null && BugzillaProductPage.this.getControl().isDisposed()) { return Status.OK_STATUS; } productViewer.setSelection(new StructuredSelection(selectedProducts), true); productViewer.getControl().setFocus(); return Status.OK_STATUS; } }.schedule(300L); } else { productList.setFocus(); } Button updateButton = new Button(composite, SWT.LEFT | SWT.PUSH); updateButton.setText(LABEL_UPDATE); updateButton.setLayoutData(new GridData()); updateButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { updateProdcts(); productViewer.setInput(products); } }); Dialog.applyDialogFont(composite); // set the composite as the control for this page setControl(composite); isPageComplete(); getWizard().getContainer().updateButtons(); }
From source file:org.eclipse.mylyn.internal.context.ui.BrowseFilteredListener.java
License:Open Source License
public void keyReleased(KeyEvent event) { InterestFilter filter = getInterestFilter(viewer); if (event.keyCode == SWT.ARROW_RIGHT) { if (filter == null || !(viewer instanceof TreeViewer)) { return; }//from w ww . java 2s . c o m final TreeViewer treeViewer = (TreeViewer) viewer; ISelection selection = treeViewer.getSelection(); if (selection instanceof IStructuredSelection) { Object targetObject = ((IStructuredSelection) selection).getFirstElement(); unfilter(filter, treeViewer, targetObject); } } }
From source file:org.eclipse.mylyn.internal.gerrit.ui.egit.GerritRepositorySearchPage.java
License:Open Source License
private void refreshConfigIfTaskRepositoryIsSelected(final TreeViewer tv) { ITreeSelection selection = (ITreeSelection) tv.getSelection(); Object element = selection.getFirstElement(); if (element instanceof TaskRepository) { refreshConfig(tv, (TaskRepository) element); } else if (element instanceof Project) { TreePath path = selection.getPaths()[0]; refreshConfig(tv, (TaskRepository) path.getSegment(0)); }/*from w ww . j a va 2 s. co m*/ }