Grid grid = new Grid("Plain Grid");
grid.setWidth("100%");
// grid component~
/*
* 1. 기본 그리드
* **/
/*
grid.addColumn("Col 1") ;
grid.addColumn("Co1 2") ;
grid.addRow("a1","1");
grid.addRow("a2","2");
*/
/*
* 2. 콘테이너란 걸 써 보자 ...
* 데이터를 객체로 받아서 그냥 쫘르륵 넣어준다.
* */
BeanItemContainer<TrainingMemberVo> trainingMemberContainer = createMember();
grid.setContainerDataSource(trainingMemberContainer);
//grid.setEditorEnabled(true);
/*3. 헤더의 캡션을 바꿔 볼 까*/
grid.setColumnOrder("memberId", "memberName" , "memberWeight", "memberTrainingTime" , "memberCheck" , "joinDate" ,"memberSex");
grid.getColumn("memberId").setHeaderCaption("ID");
grid.getColumn("memberName").setHeaderCaption("Name");
grid.getColumn("memberWeight").setHeaderCaption("Weight");
/**
* 4. 보기 싫은건 지워버리면 그만이겠지
* */
// grid.removeColumn("memberCheck");
/*5. 컬럼 고정...와우*/
// grid.getColumn("memberWeight").setLastFrozenColumn();
/*0일 경우, 움직이지 않는 컬럼이 없어진다는 이야기 임
* 숫자가 있으면 딱 거기까지만 보여줌*/
// grid.setFrozenColumnCount(5);
/**6. 데이터를 보여주는 다양한 방법
* 숫자 형태나 여러가지 html 을 넣는 방법도 있음
* 레퍼런스 참고 할 것
* */
// grid.getColumn("memberWeight").setRenderer(new ProgressBarRenderer() ) ;
/*7. 헤더를 묶어보자*/
HeaderRow extraHeader = grid.prependHeaderRow() ;
// 기본 두개
//extraHeader.join("memberId", "memberName").setText("Info");
// 여러개 할 때.. 중간에 memberName을 빼면 이상한 모양이 됨
extraHeader.join("memberId", "memberName","memberWeight").setText("Info");
/*8. footer**/
FooterRow footer = grid.appendFooterRow() ;
footer.getCell("joinDate").setText("5");
footer.getCell("memberCheck").setHtml("<span style='color:#3F48CC'>"+"oh, 난 너무 이뻐~"+"</span>");
footer.getCell("memberTrainingTime").setComponent(new ProgressBar());
/*8. 수정하는 방법 이네*/
grid.setEditorEnabled(true);
grid.getColumn("memberId") .setEditable(false) ;
grid.getColumn("memberTrainingTime") .setEditable(false) ;
grid.getColumn("memberSex").getEditorField().setCaption("");
Field<?> customerField = grid.getColumn("state").getEditorField() ;
customerField.setRequired(true);
customerField.setRequiredError("oh, my god");
//Get an event when the users saves in the editor
// 수정이 발생하면 알럿 창 띄워주기
grid.getEditorFieldGroup().addCommitHandler(new CommitHandler() {
@Override
public void preCommit(CommitEvent commitEvent) throws CommitException {
// TODO Auto-generated method stub
Notification.show("change!!!!!!!!");
}
@Override
public void postCommit(CommitEvent commitEvent) throws CommitException {
// TODO Auto-generated method stub
Notification.show("change");
}
});
//// New feature going into Vaadin 7.5 : Column reordering
grid.setColumnReorderingAllowed(true);
// New feature going into Vaadin 7.5 : Row details
grid.setDetailsGenerator(new DetailsGenerator() {
@Override
public Component getDetails(RowReference rowReference) {
// Find the bean to generate details for
final TrainingMemberVo bean = (TrainingMemberVo) rowReference.getItemId();
// A basic label with bean data
Label label = new Label("Extra data for " + bean.getMemberName());
// A button just for the sake of the example
Button button = new Button("Click me", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Notification.show("Button clicked for " + bean.getMemberName());
}
});
// Wrap up all the parts into a vertical layout
VerticalLayout layout = new VerticalLayout(label, button);
layout.setSpacing(true);
layout.setMargin(true);
return layout;
}
});
grid.addItemClickListener(new ItemClickListener() {
@Override
public void itemClick(ItemClickEvent event) {
Object itemId = event.getItemId();
grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId));
}
});
//grid.setEditorEnabled(false);
// multi item select
grid.setSelectionMode(SelectionMode.MULTI);
/*
grid.addSelectionListener(new SelectionListener() {
@Override
public void select(SelectionEvent event) {
// TODO Auto-generated method stub
Notification.show("mung");
// however, 웹의 특성상 보통 선택하자 마자 이벤트를 보여주지는 않는다.
// 보여주는 경우도 있어서 이런 리스너도 있다고 ...
}
});
*/
Button btn = new Button("multi select");
Label l = new Label();
btn.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
// TODO Auto-generated method stub
Collection<Object> selected = grid.getSelectedRows();
String str = "selected Member : " ;
for (Object component : selected) {
TrainingMemberVo value = (TrainingMemberVo)component ;
str = str + value.getMemberName() ;
}
l.setValue(str);
}
});
layout.addComponent(btn);
layout.addComponent(l);
//
layout.addComponent(grid);
댓글 없음:
댓글 쓰기