[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[pde-dev] TableEditor example
|
Title: TableEditor example
Hi,
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:
org.eclipse.jface_2.1.0/jface.jar
org.eclipse.swt.win32_2.1.0/ws/win32/swt.jar
jdk1.3.1_03/jre/lib/rt.jar
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(ClassLoader.java:1344)
at java.lang.Runtime.loadLibrary0(Runtime.java:744)
at java.lang.System.loadLibrary(System.java:815)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:104)
at org.eclipse.swt.internal.win32.OS.<clinit>(OS.java:42)
at org.eclipse.swt.widgets.Display.internal_new_GC(Display.java:1178)
at org.eclipse.swt.graphics.Device.init(Device.java:541)
at org.eclipse.swt.widgets.Display.init(Display.java:1197)
at org.eclipse.swt.graphics.Device.<init>(Device.java:90)
at org.eclipse.swt.widgets.Display.<init>(Display.java:287)
at org.eclipse.swt.widgets.Display.<init>(Display.java:283)
at com.example.tableeditor.TableEditor.main(TableEditor.java:21)
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.graphics.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.events.*;
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),
"row2col2",
listComb[0])};
create = new Button(shell, SWT.PUSH);
create.setText("Create New");
Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
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));
table.setLayout(tableLayout);
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());
tableViewer.setCellEditors(
new CellEditor[] {
new ColorCellEditor(table),
new TextCellEditor(table),
new ComboBoxCellEditor(table, listComb)});
create.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
tableViewer.getTable().removeAll();
}
});
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);
}
else
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);
}
});
tableViewer.setColumnProperties(
new String[] { "col1", "col2", "col3" });
tableViewer.setInput(datas);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
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;
break;
case 1 :
columnText = "" + dummyElement.col2;
break;
case 2 :
columnText = "" + dummyElement.col3;
break;
}
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)
}
}
}