List of usage examples for org.eclipse.jface.viewers TableViewer setSelection
@Override public void setSelection(ISelection selection, boolean reveal)
Sets a new selection for this viewer and optionally makes it visible.
From source file:org.kalypso.contribs.eclipse.jface.wizard.ProjectTemplatePage.java
License:Open Source License
@Override public void createControl(final Composite parent) { final Composite composite = new Composite(parent, SWT.NONE); setControl(composite);//from w ww.j a v a2 s .c o m composite.setLayout(new GridLayout()); final TableViewer tableViewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER); tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); tableViewer.setContentProvider(new ArrayContentProvider()); tableViewer.setLabelProvider(new LabelProvider() { @Override public String getText(final Object element) { return ((ProjectTemplate) element).getLabel(); } @Override public Image getImage(final Object element) { final String icon = ((ProjectTemplate) element).getIcon(); if (icon == null || icon.length() == 0) { return null; } // TODO: create icon and dispose after use return super.getImage(element); } }); tableViewer.setInput(m_projectTemplates); // Info Group final Group group = new Group(composite, SWT.NONE); group.setLayout(new GridLayout()); group.setText(Messages.getString("org.kalypso.contribs.eclipse.jface.wizard.ProjectTemplatePage.2")); //$NON-NLS-1$ final GridData groupData = new GridData(SWT.FILL, SWT.CENTER, true, false); groupData.heightHint = 100; group.setLayoutData(groupData); final Label descriptionLabel = new Label(group, SWT.H_SCROLL | SWT.V_SCROLL); descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); descriptionLabel .setText(Messages.getString("org.kalypso.contribs.eclipse.jface.wizard.ProjectTemplatePage.3")); //$NON-NLS-1$ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(final SelectionChangedEvent event) { final IStructuredSelection selection = (IStructuredSelection) event.getSelection(); final ProjectTemplate selectedProject = (ProjectTemplate) selection.getFirstElement(); setSelectedProject(selectedProject); if (selectedProject == null) { descriptionLabel.setText(""); //$NON-NLS-1$ } else { descriptionLabel.setText(selectedProject.getDescription()); } } }); if (m_selectedProject != null) { tableViewer.setSelection(new StructuredSelection(m_selectedProject), true); } }
From source file:org.springframework.ide.eclipse.boot.wizard.guides.ChooseOneSectionTable.java
License:Open Source License
@Override public void createContents(Composite page) { Composite field = new Composite(page, SWT.NONE); int cols = label == null ? 1 : 2; GridLayout layout = GridLayoutFactory.fillDefaults().numColumns(cols).create(); field.setLayout(layout);/* w w w . j a v a 2 s . c o m*/ searchBox = new Text(field, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL); GridDataFactory.fillDefaults().grab(true, false).applyTo(searchBox); Label fieldNameLabel = null; if (label != null) { fieldNameLabel = new Label(field, SWT.NONE); fieldNameLabel.setText(label); } final TableViewer tv = new TableViewer(field, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL); tv.addFilter(filter = new ChoicesFilter()); tv.setLabelProvider(labelProvider); tv.setContentProvider(ArrayContentProvider.getInstance()); tv.setInput(options); if (fieldNameLabel != null) { GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).applyTo(fieldNameLabel); } GridDataFactory grab = GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 150); grab.applyTo(field); grab.applyTo(tv.getTable()); whenVisible(tv.getControl(), new Runnable() { public void run() { T preSelect = selection.selection.getValue(); if (preSelect != null) { tv.setSelection(new StructuredSelection(preSelect), true); } else { tv.setSelection(StructuredSelection.EMPTY, true); } } }); tv.addSelectionChangedListener(new ISelectionChangedListener() { @SuppressWarnings("unchecked") public void selectionChanged(SelectionChangedEvent event) { ISelection sel = tv.getSelection(); if (sel.isEmpty()) { selection.selection.setValue(null); } else if (sel instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) sel; selection.selection.setValue((T) ss.getFirstElement()); } } }); searchBox.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { filter.setSearchTerm(searchBox.getText()); tv.refresh(); } }); }
From source file:org.yakindu.sct.examples.wizard.pages.SelectExamplePage.java
License:Open Source License
protected void filterAndSelectExampleToInstall(TableViewer viewer, List<ExampleData> input) { final ExampleData exampleToInstall = Iterables.find(input, new Predicate<ExampleData>() { @Override//from w w w . ja v a 2 s . c o m public boolean apply(ExampleData input) { if (exampleIdToInstall != null) { return exampleIdToInstall.equals(input.getId()); } return true; } }); if (exampleToInstall != null) { viewer.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { if (exampleIdToInstall == null) { return true; } if (element instanceof ExampleData) { return exampleIdToInstall.equals(((ExampleData) element).getId()); } if (element instanceof ExampleContentProvider.Category) { return ((ExampleContentProvider.Category) element).getChildren().contains(exampleToInstall); } return true; } }); viewer.setSelection(new StructuredSelection(exampleToInstall), true); } }