Create the following label and content provider for your JFace viewers.
package de.vogella.dnd.jface.viewers;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import de.vogella.dnd.jface.model.Todo;
public class TableContentProvider implements IStructuredContentProvider {
@Override
public Object[] getElements(Object inputElement) {
Listlist = (List ) inputElement;
return list.toArray();
}
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
package de.vogella.dnd.jface.viewers;
import java.util.List;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
public class TreeContentProvider implements ITreeContentProvider {
@Override
public Object[] getChildren(Object parentElement) {
return null;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object[] getElements(Object inputElement) {
Listlist = (List ) inputElement;
return list.toArray();
}
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
package de.vogella.dnd.jface.viewers;
import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
import de.vogella.dnd.jface.model.Todo;
public class TableLabelProvider extends BaseLabelProvider implements
ITableLabelProvider {
@Override
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
@Override
public String getColumnText(Object element, int columnIndex) {
Todo todo = (Todo) element;
switch (columnIndex) {
case 0:
return todo.getShortDescription();
case 1:
return todo.getLongDescription();
}
return "Not supported";
}
}
package de.vogella.dnd.jface.viewers;
import org.eclipse.jface.viewers.LabelProvider;
public class TreeLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
String s = (String) element;
return s;
}
}
0 comments:
Post a Comment