Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[pde-dev] TableEditor example

Title: TableEditor example


I am trying to test some example code that I found on the website. The source is shown at the bottom of this email. My problem is that I get the following message in the console when I try to run. Can anyone tell me what I am missing in my project space or classpath?

Note: I have included the following jars in my buildpath and classpath:

I have also set the TableEditory to run as a "Java Application".

Thanks, Bob

java.lang.UnsatisfiedLinkError: no swt-win32-2116 in java.library.path
        at java.lang.ClassLoader.loadLibrary(
        at java.lang.Runtime.loadLibrary0(
        at java.lang.System.loadLibrary(
        at org.eclipse.swt.internal.Library.loadLibrary(
        at org.eclipse.swt.internal.win32.OS.<clinit>(
        at org.eclipse.swt.widgets.Display.internal_new_GC(
        at org.eclipse.swt.widgets.Display.init(
        at org.eclipse.swt.widgets.Display.<init>(
        at org.eclipse.swt.widgets.Display.<init>(
        at com.example.tableeditor.TableEditor.main(
Exception in thread "main"


package com.example.tableeditor;

import java.util.Arrays;

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.custom.*;

public class TableEditor {

 static Button create;
 static String[] listComb = new String[] { "vert", "bleu", "rouge" };

 public static void main(String[] args) {
  Display display = new Display();
  Shell shell = new Shell(display);
  shell.setSize(400, 400);
  shell.setLayout(new FillLayout());

  DummyElement[] datas =
   new DummyElement[] {
    new DummyElement(new RGB(255, 12, 40), "row1col2", listComb[0]),
    new DummyElement(
     new RGB(70, 255, 40),

  create = new Button(shell, SWT.PUSH);
  create.setText("Create New");

  Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
  TableLayout tableLayout = new TableLayout();
  tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
  tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
  tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
  new TableColumn(table, SWT.LEFT).setText("col1");
  new TableColumn(table, SWT.NONE).setText("col2");
  new TableColumn(table, SWT.RIGHT).setText("col3");
  final TableViewer tableViewer = new TableViewer(table);
  tableViewer.setContentProvider(new DummyContentProvider());
  tableViewer.setLabelProvider(new DummyLabelProvider());
   new CellEditor[] {
    new ColorCellEditor(table),
    new TextCellEditor(table),
    new ComboBoxCellEditor(table, listComb)});
  create.addSelectionListener(new SelectionAdapter() {
   public void widgetSelected(SelectionEvent e) {

  tableViewer.setCellModifier(new ICellModifier() {
   public boolean canModify(Object element, String property) {
    return true;

   public Object getValue(Object element, String property) {
    DummyElement e = (DummyElement) element;
    if (property == "col1")
     return e.col1;
    else if (property == "col2")
     return e.col2;
    else if (property == "col3") {
     int i = Arrays.asList(listComb).indexOf(e.col3);
     return i == -1 ? null : new Integer(i);
     return null;

   public void modify(Object element, String property, Object value) {
    // workaround for bug 1938 where element is Item rather than model element
    if (element instanceof Item)
     element = ((Item) element).getData();

    DummyElement e = (DummyElement) element;

    if (property == "col1")
     e.col1 = (RGB) value;
    else if (property == "col2")
     e.col2 = (String) value;
    else if (property == "col3")
     if (value instanceof Integer) {
      int i = ((Integer) value).intValue();
      e.col3 = listComb[i];

    // This is a hack. Changing the model above should cause it to notify
    // the content provider, which should update the viewer.
    // It should not be done directly here.
    tableViewer.update(e, null);

   new String[] { "col1", "col2", "col3" });


  while (!shell.isDisposed()) {
   if (!display.readAndDispatch())




 public static class DummyElement {
  public RGB col1;
  public String col2;
  public String col3;
  public DummyElement(RGB col1, String col2, String col3) {
   this.col1 = col1;
   this.col2 = col2;
   this.col3 = col3;

 public static class DummyLabelProvider
  extends LabelProvider
  implements ITableLabelProvider {

  public Image getColumnImage(Object element, int columnIndex) {
   return null;

  public String getColumnText(Object element, int columnIndex) {
   String columnText = null;
   DummyElement dummyElement = (DummyElement) element;
   switch (columnIndex) {
    case 0 :
     columnText = "" + dummyElement.col1;
    case 1 :
     columnText = "" + dummyElement.col2;
    case 2 :
     columnText = "" + dummyElement.col3;
   return columnText;



 public static class DummyContentProvider
  implements IStructuredContentProvider {

  public Object[] getElements(Object input) {
   return (DummyElement[]) input;

  public void dispose() {

  public void inputChanged(
   Viewer viewer,
   Object oldInput,
   Object newInput) {

   // should hook a listener on the model here (newInput)



Back to the top