List of usage examples for org.eclipse.jface.viewers TableViewer setContentProvider
@Override public void setContentProvider(IContentProvider provider)
AbstractTableViewer
. From source file:org.eclipse.emf.example.databinding.project.ui.rcp.views.ProjectCommittersPart.java
License:Open Source License
private void init(IViewSite site, CTabFolder folder, DataBindingContext ctx, EditingDomain editingDomain, IObservableValue master) {/*from ww w . j a va 2s. c o m*/ final TableViewer viewer = new TableViewer(folder, SWT.FULL_SELECTION); { IValueProperty prop = EMFEditProperties.value(editingDomain, ProjectPackage.Literals.PROJECT__COMMITTERS); CTabItem item = new CTabItem(folder, SWT.NONE); item.setControl(viewer.getControl()); ctx.bindValue(WidgetProperties.text().observe(item), prop.observeDetail(master), new EMFUpdateValueStrategy(), new EMFUpdateValueStrategy().setConverter(new LengthConverter())); } folder.setSelection(0); viewer.getTable().setHeaderVisible(true); ObservableListContentProvider cp = new ObservableListContentProvider(); { IObservableMap[] attributeMap = new IObservableMap[2]; attributeMap[0] = EMFEditProperties .value(editingDomain, FeaturePath.fromList(ProjectPackage.Literals.COMMITTER_SHIP__PERSON, ProjectPackage.Literals.PERSON__LASTNAME)) .observeDetail(cp.getKnownElements()); attributeMap[1] = EMFEditProperties .value(editingDomain, FeaturePath.fromList(ProjectPackage.Literals.COMMITTER_SHIP__PERSON, ProjectPackage.Literals.PERSON__FIRSTNAME)) .observeDetail(cp.getKnownElements()); TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText("Name"); column.getColumn().setWidth(150); column.setLabelProvider(new GenericMapCellLabelProvider("{0}, {1}", attributeMap)); } { IObservableMap attributeMap = EMFEditProperties .value(editingDomain, ProjectPackage.Literals.COMMITTER_SHIP__START) .observeDetail(cp.getKnownElements()); TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText("Start"); column.getColumn().setWidth(100); column.setLabelProvider(new GenericMapCellLabelProvider("{0,date,short}", attributeMap)); } { IObservableMap attributeMap = EMFEditProperties .value(editingDomain, ProjectPackage.Literals.COMMITTER_SHIP__END) .observeDetail(cp.getKnownElements()); TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText("End"); column.getColumn().setWidth(100); column.setLabelProvider(new GenericMapCellLabelProvider("{0,date,short}", attributeMap)); } IListProperty prop = EMFEditProperties.list(editingDomain, ProjectPackage.Literals.PROJECT__COMMITTERS); viewer.setContentProvider(cp); viewer.setInput(prop.observeDetail(master)); MenuManager mgr = new MenuManager(); mgr.add(new Action("Hide historic committers", IAction.AS_CHECK_BOX) { @Override public void run() { if (isChecked()) { viewer.addFilter(new ViewerFilterImpl()); } else { viewer.setFilters(new ViewerFilter[0]); } } }); viewer.getControl().setMenu(mgr.createContextMenu(viewer.getControl())); site.registerContextMenu(Activator.PLUGIN_ID + ".committers", mgr, viewer); }
From source file:org.eclipse.emf.example.databinding.project.ui.rcp.views.ProjectFormAreaPart.java
License:Open Source License
private void createFormArea(IViewSite site, final Composite parent, FormToolkit toolkit, final IModelResource resource, ObservablesManager manager, final IObservableValue master) { final EditingDomain editingDomain = resource.getEditingDomain(); ctx = new EMFDataBindingContext(); // Fix for bug 278301 Util.masterDetailFixup(ctx, master); addStatusSupport(manager, ctx);/*from w ww . j av a 2s . c o m*/ form = toolkit.createForm(parent); toolkit.decorateFormHeading(form); form.setText(" "); form.setImage(projectImage); Composite body = form.getBody(); body.setLayout(new GridLayout(3, false)); IWidgetValueProperty prop = WidgetProperties.text(SWT.Modify); { final IEMFValueProperty shortProp = EMFEditProperties.value(editingDomain, ProjectPackage.Literals.PROJECT__SHORTNAME); toolkit.createLabel(body, "&Short name"); Text t = toolkit.createText(body, ""); t.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1)); ctx.bindValue(prop.observeDelayed(400, t), shortProp.observeDetail(master)); final IEMFValueProperty longProp = EMFEditProperties.value(editingDomain, ProjectPackage.Literals.PROJECT__LONGNAME); toolkit.createLabel(body, "&Long name"); t = toolkit.createText(body, ""); t.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1)); ctx.bindValue(prop.observeDelayed(400, t), longProp.observeDetail(master)); ComputedValue cVal = new ComputedValue() { private IObservableValue shortname = shortProp.observeDetail(master); private IObservableValue longname = longProp.observeDetail(master); @Override protected Object calculate() { return shortname.getValue() + " - " + longname.getValue(); } }; manager.addObservable(cVal); ctx.bindValue(FormTextProperty.create().observe(form), cVal); } { IEMFValueProperty mProp = EMFEditProperties.value(editingDomain, ProjectPackage.Literals.PROJECT__START); toolkit.createLabel(body, "Start Date"); Text t = toolkit.createText(body, ""); t.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1)); ctx.bindValue(prop.observeDelayed(400, t), mProp.observeDetail(master), UpdateStrategyFactory.stringToDateNotNull( NLSMessages.ProjectAdminViewPart_StartDateNotParseable, "Start date must not be null"), UpdateStrategyFactory.dateToString()); } { IEMFValueProperty mProp = EMFEditProperties.value(editingDomain, ProjectPackage.Literals.PROJECT__END); toolkit.createLabel(body, "End Date"); Text t = toolkit.createText(body, ""); t.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1)); ctx.bindValue(prop.observeDelayed(400, t), mProp.observeDetail(master), UpdateStrategyFactory.stringToDate(NLSMessages.ProjectAdminViewPart_EndDateNotParseable), UpdateStrategyFactory.dateToString()); } { IEMFValueProperty mProp = EMFEditProperties.value(editingDomain, ProjectPackage.Literals.PROJECT__HOMEPAGE); toolkit.createLabel(body, "Homepage"); Text t = toolkit.createText(body, ""); t.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1)); ctx.bindValue(prop.observeDelayed(400, t), mProp.observeDetail(master)); } { IEMFValueProperty mProp = EMFEditProperties.value(editingDomain, ProjectPackage.Literals.PROJECT__DEVMAIL); toolkit.createLabel(body, "Dev-Mail"); Text t = toolkit.createText(body, ""); t.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1)); ctx.bindValue(prop.observeDelayed(400, t), mProp.observeDetail(master)); } { IEMFListProperty mProp = EMFEditProperties.list(editingDomain, ProjectPackage.Literals.PROJECT__PROJECTLEADS); toolkit.createLabel(body, "Project Leads") .setLayoutData(new GridData(SWT.TOP, SWT.DEFAULT, false, false)); Table c = toolkit.createTable(body, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); final TableViewer tv = new TableViewer(c); tv.setLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { Person p = (Person) element; return p.getLastname() + ", " + p.getFirstname(); } }); tv.setContentProvider(new ObservableListContentProvider()); tv.setInput(mProp.observeDetail(master)); GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = 100; c.setLayoutData(gd); Composite buttonContainer = toolkit.createComposite(body); buttonContainer.setLayoutData(new GridData(SWT.DEFAULT, SWT.BOTTOM, false, false)); buttonContainer.setLayout(new GridLayout()); Button b = toolkit.createButton(buttonContainer, "Add ...", SWT.FLAT); gd = new GridData(SWT.DEFAULT, SWT.DEFAULT); gd.horizontalAlignment = SWT.FILL; b.setLayoutData(gd); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { PersonFilterDialog dialog = new PersonFilterDialog(parent.getShell(), resource); if (dialog.open() == IDialogConstants.OK_ID) { Command cmd = AddCommand.create(editingDomain, master.getValue(), ProjectPackage.Literals.PROJECT__PROJECTLEADS, dialog.getFirstResult()); if (cmd.canExecute()) { resource.executeCmd(cmd); } } } }); b = toolkit.createButton(buttonContainer, "Remove", SWT.FLAT); gd = new GridData(SWT.DEFAULT, SWT.DEFAULT); gd.horizontalAlignment = SWT.FILL; b.setLayoutData(gd); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection s = (IStructuredSelection) tv.getSelection(); if (!s.isEmpty()) { Command cmd = RemoveCommand.create(editingDomain, master.getValue(), ProjectPackage.Literals.PROJECT__PROJECTLEADS, s.toList()); if (cmd.canExecute()) { resource.executeCmd(cmd); } } } }); } addTabArea(site, body, toolkit, ctx, editingDomain, manager, master); body.setBackgroundMode(SWT.INHERIT_DEFAULT); }
From source file:org.eclipse.epf.search.ui.MethodSearchResultPage.java
License:Open Source License
/** * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTableViewer(TableViewer) *//* w w w . ja va2 s .co m*/ protected void configureTableViewer(TableViewer viewer) { contentProvider = createContentProvider(viewer); viewer.setContentProvider(contentProvider); viewer.setLabelProvider(labelProvider); viewer.setSorter(new MethodElementViewSorter()); }
From source file:org.eclipse.equinox.examples.app.selector.ApplicationView.java
License:Open Source License
/** * This is a callback that will allow us * to create the viewer and initialize it. *//*from w w w . j ava 2 s. c o m*/ public void createPartControl(Composite parent) { TableViewer newViewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION); newViewer.setContentProvider(new ApplicationContentProvider()); newViewer.setLabelProvider(new ApplicationLabelProvider()); newViewer.setSorter(new NameSorter()); newViewer.getTable().setLinesVisible(true); newViewer.getTable().setHeaderVisible(true); TableColumn column = new TableColumn(newViewer.getTable(), SWT.NONE); column.setWidth(150); column.setText("Application"); column = new TableColumn(newViewer.getTable(), SWT.NONE); column.setWidth(75); column.setText("Enabled"); column = new TableColumn(newViewer.getTable(), SWT.NONE); column.setWidth(75); column.setText("State"); newViewer.setInput(applications.getServices()); viewer = newViewer; makeActions(); hookContextMenu(); contributeToActionBars(); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = viewer.getSelection(); ApplicationInfo appInfo = (ApplicationInfo) ((IStructuredSelection) selection).getFirstElement(); startAction.setEnabled(appInfo.isEnabled()); stopAction.setEnabled(!appInfo.isEnabled()); } }); }
From source file:org.eclipse.etrice.ui.layout.preferences.ETriceBehaviorPreferencePage.java
License:Open Source License
/** * Adds a table to display options and buttons to edit the options. * /*w w w . j av a 2s . co m*/ * @param parent * the parent to which controls are added * @param entries * the list of table entries */ private void addOptionTable(final Composite parent, final List<OptionsTableProvider.DataEntry> entries) { // construct the options table final Table table = new Table(parent, SWT.BORDER); final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText(Messages.getString("kiml.ui.29")); //$NON-NLS-1$ final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText(Messages.getString("kiml.ui.9")); //$NON-NLS-1$ final TableColumn column3 = new TableColumn(table, SWT.NONE); column3.setText(Messages.getString("kiml.ui.19")); //$NON-NLS-1$ final TableColumn column4 = new TableColumn(table, SWT.NONE); column4.setText(Messages.getString("kiml.ui.20")); //$NON-NLS-1$ table.setHeaderVisible(true); final TableViewer tableViewer = new TableViewer(table); OptionsTableProvider optionsTableProvider = new OptionsTableProvider(); tableViewer.setContentProvider(optionsTableProvider); tableViewer.setLabelProvider(optionsTableProvider); tableViewer.setInput(entries); optionTableViewer = tableViewer; column1.pack(); column2.pack(); column3.pack(); column4.pack(); GridData tableLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); table.setLayoutData(tableLayoutData); table.pack(); tableLayoutData.heightHint = ETricePreferenceUtil.OPTIONS_TABLE_HEIGHT; // add button to add new options Composite composite = new Composite(parent, SWT.NONE); final Button newButton = new Button(composite, SWT.PUSH | SWT.CENTER); newButton.setText(Messages.getString("kiml.ui.41")); //$NON-NLS-1$ // add button to edit the options final Button editButton = new Button(composite, SWT.PUSH | SWT.CENTER); editButton.setText(Messages.getString("kiml.ui.21")); //$NON-NLS-1$ editButton.setEnabled(false); editButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { OptionsTableProvider.DataEntry entry = ETricePreferenceUtil.getEntry(entries, table.getSelectionIndex()); if (entry != null) { ETricePreferenceUtil.showEditDialog(parent.getShell(), entry); tableViewer.refresh(); } } }); // add button to remove an option final Button removeButton = new Button(composite, SWT.PUSH | SWT.CENTER); removeButton.setText(Messages.getString("kiml.ui.22")); //$NON-NLS-1$ removeButton.setEnabled(false); removeButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { OptionsTableProvider.DataEntry entry = ETricePreferenceUtil.getEntry(entries, table.getSelectionIndex()); if (entry != null) { entry.setValue(null); tableViewer.refresh(); int count = 0; for (OptionsTableProvider.DataEntry e : entries) { if (e.getValue() != null) { count++; } } if (count == 0) { editButton.setEnabled(false); removeButton.setEnabled(false); } } } }); // react on selection changes of the options table table.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { if (!entries.isEmpty() && event.item != null) { editButton.setEnabled(true); removeButton.setEnabled(true); } else { editButton.setEnabled(false); removeButton.setEnabled(false); } } }); newButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { int newIndex = showNewDialog(parent.getShell(), entries); if (newIndex >= 0) { tableViewer.refresh(); tableViewer.setSelection(new StructuredSelection(entries.get(newIndex))); editButton.setEnabled(true); removeButton.setEnabled(true); column1.pack(); column2.pack(); column3.pack(); column4.pack(); } } }); composite.setLayout(new FillLayout(SWT.VERTICAL)); GridData compositeLayoutData = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1); composite.setLayoutData(compositeLayoutData); }
From source file:org.eclipse.example.CTabFolderSnippet.java
License:Open Source License
/** * @param args/*from w ww.ja va2s.co m*/ */ public static void main(String[] args) { // Create the shell Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Again, everything is centered... except the Tabs"); shell.setLayout(new GridLayout()); // Create a top part Composite topComposite = new Composite(shell, SWT.NONE); topComposite.setLayout(new GridLayout(2, true)); topComposite.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false)); File f = new File(System.getProperty("java.io.tmpdir")); File[] files = f.listFiles(); if (files == null) files = new File[0]; for (int i = 0; i < 2; i++) { TableViewer viewer = new TableViewer(topComposite, SWT.BORDER); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { String name = ((File) element).getName(); if (name.length() > 11) name = name.substring(0, 10); return name; } }); viewer.setInput(files); viewer.getTable().setLayoutData(new GridData(120, 140)); } // Create the tabs new CTabFolderSnippet().createTabs(shell); // Open the shell shell.setSize(600, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.example.OtherTabsWithScrolledPageBookSnippet.java
License:Open Source License
/** * @param args/* w w w . jav a2 s.com*/ */ public static void main(String[] args) { // Create the shell Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Nice too"); GridLayout layout = new GridLayout(); layout.verticalSpacing = 0; shell.setLayout(layout); // Create a top part Composite topComposite = new Composite(shell, SWT.NONE); layout = new GridLayout(2, true); layout.marginBottom = 15; topComposite.setLayout(layout); topComposite.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false)); File f = new File(System.getProperty("java.io.tmpdir")); File[] files = f.listFiles(); if (files == null) files = new File[0]; for (int i = 0; i < 2; i++) { TableViewer viewer = new TableViewer(topComposite, SWT.BORDER); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { String name = ((File) element).getName(); if (name.length() > 11) name = name.substring(0, 10); return name; } }); viewer.setInput(files); viewer.getTable().setLayoutData(new GridData(120, 140)); } // Create the tabs Composite downComposite = new Composite(shell, SWT.NONE); layout = new GridLayout(2, false); layout.horizontalSpacing = 0; downComposite.setLayout(layout); downComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); new OtherTabsWithScrolledPageBookSnippet().createTabs(downComposite); // Open the shell shell.setSize(600, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.example.SimpleScrolledPageBookSnippet.java
License:Open Source License
/** * @param args//from www . ja v a 2s . c om */ public static void main(String[] args) { // Create the shell Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Everything is centered... but it's ugly... for the moment"); shell.setLayout(new GridLayout()); // Create a top part Composite topComposite = new Composite(shell, SWT.NONE); topComposite.setLayout(new GridLayout(2, true)); topComposite.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false)); File f = new File(System.getProperty("java.io.tmpdir")); File[] files = f.listFiles(); if (files == null) files = new File[0]; for (int i = 0; i < 2; i++) { TableViewer viewer = new TableViewer(topComposite, SWT.BORDER); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { String name = ((File) element).getName(); if (name.length() > 11) name = name.substring(0, 10); return name; } }); viewer.setInput(files); viewer.getTable().setLayoutData(new GridData(120, 140)); } // Create the tabs new SimpleScrolledPageBookSnippet().createTabs(shell); // Open the shell shell.setSize(600, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.example.TabFolderSnippet.java
License:Open Source License
/** * @param args//from w ww .ja v a 2s .c o m */ public static void main(String[] args) { // Create the shell Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Everything is centered... except the Tabs"); shell.setLayout(new GridLayout()); // Create a top part Composite topComposite = new Composite(shell, SWT.NONE); topComposite.setLayout(new GridLayout(2, true)); topComposite.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false)); File f = new File(System.getProperty("java.io.tmpdir")); File[] files = f.listFiles(); if (files == null) files = new File[0]; for (int i = 0; i < 2; i++) { TableViewer viewer = new TableViewer(topComposite, SWT.BORDER); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { String name = ((File) element).getName(); if (name.length() > 11) name = name.substring(0, 10); return name; } }); viewer.setInput(files); viewer.getTable().setLayoutData(new GridData(120, 140)); } // Create the tabs new TabFolderSnippet().createTabs(shell); // Open the shell shell.setSize(600, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.example.TabsWithScrolledPageBookSnippet.java
License:Open Source License
/** * @param args/*from w w w.j a va 2 s.co m*/ */ public static void main(String[] args) { // Create the shell Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Not bad!"); GridLayout layout = new GridLayout(); layout.verticalSpacing = 0; shell.setLayout(layout); // Create a top part Composite topComposite = new Composite(shell, SWT.NONE); layout = new GridLayout(2, true); layout.marginBottom = 15; topComposite.setLayout(layout); topComposite.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false)); File f = new File(System.getProperty("java.io.tmpdir")); File[] files = f.listFiles(); if (files == null) files = new File[0]; for (int i = 0; i < 2; i++) { TableViewer viewer = new TableViewer(topComposite, SWT.BORDER); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { String name = ((File) element).getName(); if (name.length() > 11) name = name.substring(0, 10); return name; } }); viewer.setInput(files); viewer.getTable().setLayoutData(new GridData(120, 140)); } // Create the tabs new TabsWithScrolledPageBookSnippet().createTabs(shell); // Open the shell shell.setSize(600, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }