Java Code Examples for org.eclipse.jface.viewers.TreeViewer#setSelection()
The following examples show how to use
org.eclipse.jface.viewers.TreeViewer#setSelection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LibraryExplorerTreeViewPage.java From birt with Eclipse Public License 1.0 | 6 votes |
public void refreshRoot( ) { TreeViewer treeViewer = getTreeViewer( ); if ( treeViewer != null && !treeViewer.getTree( ).isDisposed( ) ) { ISelection selection = getSelection( ); treeViewer.setSelection( null ); treeViewer.setInput( getRootEntries( ) ); handleTreeViewerRefresh( ); if ( selection != null ) { setSelection( selection ); } } }
Example 2
Source File: M2DocFileSelectionDialog.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
@Override protected Control createCustomArea(Composite parent) { final Composite container = new Composite(parent, parent.getStyle()); container.setLayout(new GridLayout(1, false)); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); fileText = createFilePathComposite(container, defaultFileName); final TreeViewer containerTreeViewer = new TreeViewer(container, SWT.BORDER); Tree tree = containerTreeViewer.getTree(); final GridData gdTable = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); gdTable.minimumWidth = TABLE_MINIMUM_WIDTH; gdTable.minimumHeight = TABLE_MINIMUM_HEIGHT; tree.setLayoutData(gdTable); containerTreeViewer.setContentProvider(new WorkbenchContentProvider() { @Override public Object[] getChildren(Object element) { final List<Object> res = new ArrayList<>(); for (Object obj : super.getChildren(element)) { if (obj instanceof IContainer || (obj instanceof IFile && fileExtension.equals(((IFile) obj).getFileExtension()))) { res.add(obj); } } return res.toArray(); } }); containerTreeViewer.setLabelProvider(new WorkbenchLabelProvider()); containerTreeViewer.addSelectionChangedListener(new ContainerSelectionChangedListener()); containerTreeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); if (defaultFileName != null && !defaultFileName.isEmpty()) { final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(defaultFileName)); containerTreeViewer.setSelection(new StructuredSelection(file)); } return container; }
Example 3
Source File: M2DocTypeSelectionDialog.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
@Override protected Control createCustomArea(Composite parent) { final Composite container = new Composite(parent, parent.getStyle()); container.setLayout(new GridLayout(1, false)); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); final FilteredTree filteredTree = new FilteredTree(container, SWT.BORDER, new PatternFilter(), true); final TreeViewer treeViewer = filteredTree.getViewer(); final Tree tree = treeViewer.getTree(); final GridData gdTable = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); gdTable.minimumWidth = TABLE_MINIMUM_WIDTH; gdTable.minimumHeight = TABLE_MINIMUM_HEIGHT; tree.setLayoutData(gdTable); treeViewer.setContentProvider(new CollectionContentProvider()); treeViewer.setLabelProvider(new LabelProvider()); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { final Object selected = ((IStructuredSelection) event.getSelection()).getFirstElement(); selectedType = (String) selected; } }); treeViewer.setInput(getAvailableTypes(nsURIs)); if (defaultType != null) { treeViewer.setSelection(new StructuredSelection(defaultType)); } return container; }
Example 4
Source File: FolderSelectionDialog.java From typescript.java with MIT License | 5 votes |
protected void newFolderButtonPressed() { NewFolderDialog dialog = new NewFolderDialog(getShell(), fSelectedContainer); if (dialog.open() == Window.OK) { TreeViewer treeViewer = getTreeViewer(); treeViewer.refresh(fSelectedContainer); Object createdFolder = dialog.getResult()[0]; treeViewer.reveal(createdFolder); treeViewer.setSelection(new StructuredSelection(createdFolder)); } }
Example 5
Source File: JSIndexViewActionProvider.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * @param view * @param typeNames * @return */ protected IAction createAction(final IndexView view, final List<String> typeNames) { IAction action = new Action() { @Override public void run() { TreeViewer treeViewer = view.getTreeViewer(); if (treeViewer != null) { Object input = treeViewer.getInput(); if (input instanceof IProject) { IProject project = (IProject) input; JSIndexQueryHelper queryHelper = new JSIndexQueryHelper(project); Collection<TypeElement> types = queryHelper.getTypes(typeNames.get(0), true); List<ClassElement> classes = JSTypeUtil.typesToClasses(types); if (!CollectionsUtil.isEmpty(classes)) { ClassElement c = classes.get(0); treeViewer.setSelection(new StructuredSelection(c), true); } } } } }; action.setText(Messages.JSIndexViewActionProvider_JumpToType); return action; }
Example 6
Source File: ReorgMoveWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void doNewButtonPressed() { Object newElement= fCreateTargetQuery.getCreatedTarget(fDestination); if (newElement != null) { TreeViewer viewer= getTreeViewer(); ITreeContentProvider contentProvider= (ITreeContentProvider) viewer.getContentProvider(); viewer.refresh(contentProvider.getParent(newElement)); viewer.setSelection(new StructuredSelection(newElement), true); viewer.getTree().setFocus(); } }
Example 7
Source File: FolderSelectionDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void newFolderButtonPressed() { NewFolderDialog dialog= new NewFolderDialog(getShell(), fSelectedContainer); if (dialog.open() == Window.OK) { TreeViewer treeViewer= getTreeViewer(); treeViewer.refresh(fSelectedContainer); Object createdFolder= dialog.getResult()[0]; treeViewer.reveal(createdFolder); treeViewer.setSelection(new StructuredSelection(createdFolder)); } }
Example 8
Source File: JavaWorkingSetPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected void configureTree(TreeViewer tree) { tree.setContentProvider(new JavaWorkingSetPageContentProvider()); AppearanceAwareLabelProvider javaElementLabelProvider= new AppearanceAwareLabelProvider( AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.P_COMPRESSED, AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | JavaElementImageProvider.SMALL_ICONS ); tree.setLabelProvider(new DecoratingJavaLabelProvider(javaElementLabelProvider)); tree.setComparator(new JavaElementComparator()); tree.addFilter(new EmptyInnerPackageFilter()); tree.setInput(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())); if (getSelection() == null) return; Object[] selection= getInitialTreeSelection(); if (selection.length > 0) { try { tree.getTree().setRedraw(false); for (int i= 0; i < selection.length; i++) { tree.expandToLevel(selection[i], 0); } tree.setSelection(new StructuredSelection(selection)); } finally { tree.getTree().setRedraw(true); } } }
Example 9
Source File: MasterSelectionDialog.java From neoscada with Eclipse Public License 1.0 | 4 votes |
@Override protected Control createDialogArea ( final Composite parent ) { setTitle ( "Select master server" ); setMessage ( "Choose a master server from the world model" ); final Composite composite = (Composite)super.createDialogArea ( parent ); final Composite wrapper = new Composite ( composite, SWT.NONE ); wrapper.setLayout ( new GridLayout ( 1, true ) ); wrapper.setLayoutData ( new GridData ( SWT.FILL, SWT.FILL, true, true ) ); final ObservablesManager mgr = new ObservablesManager (); final TreeViewer viewer = new TreeViewer ( wrapper ); viewer.setAutoExpandLevel ( 2 ); viewer.getControl ().setLayoutData ( new GridData ( SWT.FILL, SWT.FILL, true, true, 1, 1 ) ); viewer.addDoubleClickListener ( new IDoubleClickListener () { @Override public void doubleClick ( final DoubleClickEvent event ) { handleDoubleClick (); } } ); final Button add = new Button ( wrapper, SWT.RADIO ); add.setText ( "Add master server" ); add.setToolTipText ( "Assign the component to the selected master server in addition" ); this.replace = new Button ( wrapper, SWT.RADIO ); this.replace.setText ( "Replace all master servers" ); this.replace.setToolTipText ( "Assign the component soley to the selected master server" ); this.replace.setSelection ( true ); this.delete = new Button ( wrapper, SWT.RADIO ); this.delete.setText ( "Remove master server" ); this.delete.setToolTipText ( "Un-assign the component from the selected master server" ); mgr.runAndCollect ( new Runnable () { @Override public void run () { createDataModel ( viewer ); } } ); if ( this.lastSelection != null ) { viewer.setSelection ( new StructuredSelection ( this.lastSelection ) ); viewer.reveal ( this.lastSelection ); } return composite; }
Example 10
Source File: MoveRemoteResourceWizardMainPage.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * Creates the UI part of the page. * * @param parent the parent of the created widgets */ public void createControl(Composite parent) { Composite composite = createComposite(parent, 1); // set F1 help PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.MOVE_RENAME_REMOTE_RESOURCE_PAGE); Listener listener = new Listener() { public void handleEvent(Event event) { resourceName = resourceNameText.getText(); validateFields(); } }; // the text field for the parent folder createLabel(composite, Policy.bind("MoveRemoteResourceWizardMainPage.selectParentUrl")); //$NON-NLS-1$ urlParentText = createTextField(composite); urlParentText.addListener(SWT.Selection, listener); urlParentText.addListener(SWT.Modify, listener); urlParentText.setEditable(false); // Create drill down. DrillDownComposite drillDown = new DrillDownComposite(composite, SWT.BORDER); GridData spec = new GridData(GridData.FILL_BOTH); spec.widthHint = LIST_WIDTH; spec.heightHint = LIST_HEIGHT; drillDown.setLayoutData(spec); // Create tree viewer inside drill down. viewer = new TreeViewer(drillDown, SWT.H_SCROLL | SWT.V_SCROLL); drillDown.setChildTree(viewer); viewer.setLabelProvider(new WorkbenchLabelProvider()); viewer.setContentProvider(new RemoteContentProvider()); viewer.setInput(new AllRootsElement()); viewer.addFilter(RepositoryFilters.FOLDERS_ONLY); viewer.addSelectionChangedListener(treeSelectionChangedListener); // the text field for the resource name createLabel(composite, Policy.bind("MoveRemoteResourceWizardMainPage.resourceName")); //$NON-NLS-1$ resourceNameText = createTextField(composite); resourceNameText.addListener(SWT.Selection, listener); resourceNameText.addListener(SWT.Modify, listener); resourceNameText.setText(resourceName); validateFields(); resourceNameText.setFocus(); setControl(composite); // set the initial selection in the tree if (parentFolder != null) { Object toSelect = null; if (parentFolder.getParent() == null) { // the root folder : select the repository toSelect = parentFolder.getRepository(); } else toSelect = parentFolder; viewer.expandToLevel(toSelect,0); viewer.setSelection(new StructuredSelection(toSelect),true); } }
Example 11
Source File: ConfigurationWizardRepositorySourceProviderPage.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
public void createControl(Composite parent) { Composite outerContainer = new Composite(parent,SWT.NONE); outerContainer.setLayout(new GridLayout()); outerContainer.setLayoutData( new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); Composite treeGroup = new Composite(outerContainer, SWT.NONE); GridLayout treeLayout = new GridLayout(); treeLayout.numColumns = 1; treeGroup.setLayout(treeLayout); treeGroup.setLayoutData( new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); treeViewer = new TreeViewer(treeGroup, SWT.BORDER | SWT.SINGLE); treeViewer.setLabelProvider(new RepositorySourceLabelProvider()); treeViewer.setContentProvider(new RepositorySourceContentProvider()); treeViewer.setUseHashlookup(true); GridData layoutData = new GridData(); layoutData.grabExcessHorizontalSpace = true; layoutData.grabExcessVerticalSpace = true; layoutData.horizontalAlignment = GridData.FILL; layoutData.verticalAlignment = GridData.FILL; layoutData.minimumHeight = 300; layoutData.minimumWidth = 300; treeViewer.getControl().setLayoutData(layoutData); treeViewer.setInput(this); treeViewer.setSelection(new StructuredSelection("URL")); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { Object selectedObject = ((IStructuredSelection)treeViewer.getSelection()).getFirstElement(); if (selectedObject instanceof ISVNRepositorySourceProvider) { selectedRepositorySourceProvider = (ISVNRepositorySourceProvider)selectedObject; } else { selectedRepositorySourceProvider = null; } setPageComplete(!treeViewer.getSelection().isEmpty()); } }); Hyperlink repositoryProviderLink = new Hyperlink(treeGroup, SWT.NONE); repositoryProviderLink.setUnderlined(true); repositoryProviderLink.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE)); repositoryProviderLink.setText("Click here to see the list of available providers."); repositoryProviderLink.setToolTipText(REPOSITORY_PROVIDERS_WIKI_URL); repositoryProviderLink.addHyperlinkListener(new HyperlinkAdapter() { public void linkActivated(HyperlinkEvent evt) { showAvailableProviders(); } }); Composite cloudForgeComposite = new CloudForgeComposite(outerContainer, SWT.NONE); GridData data = new GridData(GridData.VERTICAL_ALIGN_END | GridData.GRAB_VERTICAL | GridData.FILL_VERTICAL); cloudForgeComposite.setLayoutData(data); setControl(outerContainer); }
Example 12
Source File: NewRemoteFolderWizardMainPage.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * Creates the UI part of the page. * * @param parent the parent of the created widgets */ public void createControl(Composite parent) { Composite composite = createComposite(parent, 1); // set F1 help PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.CREATE_REMOTE_FOLDER_PAGE); Listener listener = new Listener() { public void handleEvent(Event event) { validateFields(); } }; // the text field for the parent folder createLabel(composite, Policy.bind("NewRemoteFolderWizardMainPage.selectParentUrl")); //$NON-NLS-1$ urlParentText = createTextField(composite); urlParentText.addListener(SWT.Selection, listener); urlParentText.addListener(SWT.Modify, listener); urlParentText.setEditable(false); // Create drill down. DrillDownComposite drillDown = new DrillDownComposite(composite, SWT.BORDER); GridData spec = new GridData(GridData.FILL_BOTH); spec.widthHint = LIST_WIDTH; spec.heightHint = LIST_HEIGHT; drillDown.setLayoutData(spec); // Create tree viewer inside drill down. viewer = new TreeViewer(drillDown, SWT.H_SCROLL | SWT.V_SCROLL); drillDown.setChildTree(viewer); viewer.setLabelProvider(new WorkbenchLabelProvider()); RemoteContentProvider remoteContentProvider = new RemoteContentProvider(); remoteContentProvider.setUseDeferredContentManager(false); viewer.setContentProvider(remoteContentProvider); viewer.setInput(new AllRootsElement()); viewer.addFilter(RepositoryFilters.FOLDERS_ONLY); viewer.addSelectionChangedListener(treeSelectionChangedListener); // the text field for the folder name createLabel(composite, Policy.bind("NewRemoteFolderWizardMainPage.folderName")); //$NON-NLS-1$ folderNameText = createTextField(composite); folderNameText.addListener(SWT.Selection, listener); folderNameText.addListener(SWT.Modify, listener); validateFields(); folderNameText.setFocus(); setControl(composite); // set the initial selection in the tree if (parentFolder != null) { List itemsToExpand = new ArrayList(); ISVNRemoteFolder remoteParent = parentFolder.getParent(); while (remoteParent != null) { if (remoteParent.getParent() == null) itemsToExpand.add(0, remoteParent.getRepository()); else itemsToExpand.add(0, remoteParent); remoteParent = remoteParent.getParent(); } viewer.setExpandedElements(itemsToExpand.toArray()); if (parentFolder.getParent() == null) viewer.setSelection(new StructuredSelection(parentFolder.getRepository()), true); else viewer.setSelection(new StructuredSelection(parentFolder), true); } }
Example 13
Source File: WorkspaceDialog.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
protected Control createDialogArea(Composite parent){ Composite composite = (Composite) super.createDialogArea(parent); GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); composite.setLayout(layout); final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); composite.setLayoutData(data); getShell().setText(windowTitle); treeViewer = new TreeViewer(composite, SWT.BORDER); final GridData gd= new GridData(SWT.FILL, SWT.FILL, true, true); gd.widthHint= 550; gd.heightHint= 250; treeViewer.getTree().setLayoutData(gd); treeViewer.setContentProvider(new LocationPageContentProvider()); treeViewer.setLabelProvider(new WorkbenchLabelProvider()); treeViewer.setInput(ResourcesPlugin.getWorkspace()); //Open to whatever is selected in the workspace field IPath existingWorkspacePath = new Path(pathText.getText()); if (existingWorkspacePath != null){ //Ensure that this workspace path is valid IResource selectedResource = ResourcesPlugin.getWorkspace().getRoot().findMember(existingWorkspacePath); if (selectedResource != null) { treeViewer.expandToLevel(selectedResource, 0); treeViewer.setSelection(new StructuredSelection(selectedResource)); } } final Composite group = new Composite(composite, SWT.NONE); layout = new GridLayout(2, false); layout.marginWidth = 0; group.setLayout(layout); group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); final Label label = new Label(group, SWT.NONE); label.setLayoutData(new GridData()); label.setText(Policy.bind("WorkspaceDialog.fileName")); //$NON-NLS-1$ fileNameText = new Text(group,SWT.BORDER); fileNameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); setupListeners(); return parent; }
Example 14
Source File: XPathOperatorEditor.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public Composite createOpeartorEditor(Composite parent,final Operator operator,final Expression sourceExpression) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(GridDataFactory.fillDefaults().grab(true,true).create()) ; composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 5).create()); final XMLData data = (XMLData) sourceExpression.getReferencedElements().get(0) ; String namespace = data.getNamespace() ; String element = data.getType(); XSDRepositoryStore xsdStore = (XSDRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(XSDRepositoryStore.class) ; XSDElementDeclaration root = xsdStore.findElementDeclaration(namespace, element); final XSDContentProvider provider = new XSDContentProvider(true) ; provider.setElement(root); xsdViewer = new TreeViewer(composite); xsdViewer.setContentProvider(provider); XSDLabelProvider labelProvider = new XSDLabelProvider(); xsdViewer.setLabelProvider(new DecoratingLabelProvider(labelProvider, labelProvider)); xsdViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).create()); xsdViewer.setInput(new Object()); String content = operator.getExpression() ; if(content == null){ content = "" ; } xsdViewer.setSelection(new StructuredSelection(createTreePath(content, provider))); xpathText = new Text(composite, SWT.WRAP | SWT.BORDER); xpathText.setLayoutData(GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 40).grab(true, false).create()); xpathText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { operator.setExpression(xpathText.getText()) ; } }); xsdViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ITreeSelection selection = (ITreeSelection) xsdViewer.getSelection(); String xpath = computeXPath(selection, false); if(xpath == null || xpath.isEmpty()){ xpathText.setText(data.getName()); }else{ xpathText.setText(xpath); } xpathText.redraw(); fireSelectionChange(event) ; } }); return composite ; }