Ch8List.Java
package Ch8;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
public class Ch8List extends Composite {
public Ch8List(Composite parent){
super(parent,SWT.NULL);
populateControl();
}
protected void populateControl(){
FillLayout compositeLayout = new FillLayout();
setLayout(compositeLayout);
int [] Style = {SWT.SINGLE, SWT.MULTI};
for(int style =0; style<Style.length;style++){
createListViewer(Style[style]);
}
}
private void createListViewer(int style){
ListViewer viewer = new ListViewer(this,style);
viewer.setLabelProvider(new LabelProvider(){
public String getText(Object element){
return ((ListItem)element).name;
}
});
viewer.addFilter(new ViewerFilter(){
public boolean select(Viewer viewer, Object parent, Object element) {
// TODO Auto-generated method stub
return((ListItem)element).value % 2 == 0;
}
});
viewer.setSorter(new ViewerSorter(){
public int compare(Viewer viewer, Object obj1, Object obj2){
return ((ListItem)obj2).value - ((ListItem)obj1).value;
}
});
viewer.setContentProvider(new IStructuredContentProvider(){
public Object[] getElements(Object inputElement){
return ((List)inputElement).toArray();
}
public void dispose(){}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput){}
});
List input = new ArrayList();
for(int i=0;i<20;i++){
input.add(new ListItem("item " + i,i));
}
viewer.setInput(input);
}
}
class ListItem
{
public String name;
public int value;
public ListItem(String n, int v){
name=n;
value = v;
}
}
Viewer.java
package Ch8;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
public class Viewer extends ApplicationWindow {
public Viewer()
{
super(null);
}
protected Control createContents(Composite parent){
TabItem chap8List = new TabItem(tf,SWT.NONE);
chap8List.setText("Chapter 8 List");
chap8List.setControl(new Ch8List(tf));
return parent;
}
public static void main(String args[]){
Viewer vi = new Viewer();
vi.setBlockOnOpen(true);
vi.open();
Display.getCurrent().dispose();
}
}
'RCP > SWT & JFACE' 카테고리의 다른 글
현재 화면의 활성화된 shell 얻는 방법 (0) | 2016.12.23 |
---|---|
Tableviwer와 편집모드, 컨텍스트 메뉴 생성 (0) | 2016.12.23 |
JFACE TreeViewer 예제 (0) | 2016.12.23 |
SashForm 소개와 예제 (3) | 2016.12.22 |
SWT의 Text와 StyledText (0) | 2016.12.22 |