I am new in Java and in SWT.
I created TableViewer
to show data of tables.
class myTable : TableViewer
I want when I press on button to open dialog of myTable
( like pop up ) and to choose any item from the TableViewer
.
The dialog should have two buttons "OK" and cancel.
Do you know how to do it in java? I mean to open dialog with TableViewer
Does there is standard widget for this?
which component do I need to use?
Do you have any example?
The simplest dialog would be one using org.eclipse.jface.dialog.Dialog
- something like this:
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
public class TestDialog extends Dialog
{
public TestDialog(final Shell parentShell)
{
super(parentShell);
}
@Override
protected Control createDialogArea(final Composite parent)
{
final Composite body = (Composite)super.createDialogArea(parent);
final TableViewer viewer = new TableViewer(body, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// TODO: Set TableViewer content and label providers
// TODO: Set TableViewer input
return body;
}
}
In your code you do:
TestDialog dialog = new TestDialog(shell);
dialog.open(); // Displays the dialog in a popup window