private void initTabs() { // Create a tab panel final DecoratedTabPanel tabPanel = new DecoratedTabPanel(); tabPanel.setAnimationEnabled(true); for (final ContactModel contactModel : contactList) { final FlexTable o_layout = new FlexTable(); o_layout.setCellSpacing(6); FlexCellFormatter o_cellFormatter = o_layout.getFlexCellFormatter(); o_cellFormatter.setColSpan(0, 0, 2); tabPanel.add(o_layout, contactModel.getNikeName()); final ListBox dropBox = new ListBox(false); for (AlbumModel album : contactModel.getAlbumList()) { dropBox.addItem(album.getName()); } o_layout.setWidget(0, 0, dropBox); dropBox.addChangeHandler( new ChangeHandler() { @Override public void onChange(ChangeEvent event) { initPhotoLayout(contactModel, dropBox.getSelectedIndex(), o_layout); } }); tabPanel.addSelectionHandler( new SelectionHandler<Integer>() { @Override public void onSelection(SelectionEvent<Integer> event) { FlexTable currentPhotoTable = (FlexTable) tabPanel.getWidget(event.getSelectedItem()); ListBox currentDropBox = (ListBox) currentPhotoTable.getWidget(0, 0); currentDropBox.setSelectedIndex(0); } }); initPhotoLayout(contactModel, 0, o_layout); } tabPanel.selectTab(0); RootPanel.get("kirin_tabs").add(tabPanel); }
private void initPhotoLayout( ContactModel contactModel, int selectedIdx, final FlexTable o_layout) { for (int i = 1; i < o_layout.getRowCount(); i++) { o_layout.removeRow(i); } final FlexTable m_layout = new FlexTable(); o_layout.setCellSpacing(6); FlexCellFormatter o_cellFormatter = o_layout.getFlexCellFormatter(); o_cellFormatter.setColSpan(0, 0, 6); AlbumModel currentAlbum = contactModel.getAlbumList().get(selectedIdx); if (currentAlbum.getPhotos() == null || currentAlbum.getPhotos().size() == 0) { kirinService.loadPhoto( contactModel.getNikeName(), currentAlbum.getAlbumid(), new AsyncCallback<List<PhotoModel>>() { @Override public void onSuccess(List<PhotoModel> result) { int i = 0, j = 0; // share popup windows final PopupPanel imagePopup = new PopupPanel(true); imagePopup.setAnimationEnabled(true); for (int k = 0; k < result.size(); k++) { PhotoModel photoModel = result.get(k); FlexTable i_layout = new FlexTable(); i_layout.setCellSpacing(6); FlexCellFormatter i_cellFormatter = i_layout.getFlexCellFormatter(); i_layout.setHTML(0, 0, photoModel.getTitle()); // add small image to flexTable Image thumbImage = new Image(photoModel.getThumbURL()); i_cellFormatter.setColSpan(0, 0, 1); i_cellFormatter.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); i_layout.setWidget(1, 0, thumbImage); DecoratorPanel decPanel = new DecoratorPanel(); decPanel.setWidget(i_layout); if (j >= 5) { j = 0; i++; } m_layout.setWidget(i, j++, decPanel); // add full image popup windows for small image imagePopup.setHeight(photoModel.getHeight() + "px"); imagePopup.setWidth(photoModel.getWidth() + "px"); final String fullImageURL = photoModel.getURL(); final Image fullImage = new Image(); thumbImage.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { imagePopup.clear(); fullImage.setUrl(fullImageURL); imagePopup.setWidget(fullImage); // show full image imagePopup.center(); } }); // add event handling // fullImage.addClickHandler(new ClickHandler() { // public void onClick(ClickEvent event) { // // hide full image // imagePopup.hide(true); // } // }); ImageMouseDownHandler mouseDownHandler = new ImageMouseDownHandler(); mouseDownHandler.setPhotoModelList(result); mouseDownHandler.setImagePopup(imagePopup); mouseDownHandler.setCurrIdx(k); mouseDownHandler.setFullImage(fullImage); fullImage.addMouseDownHandler(mouseDownHandler); ImageMouseMoveHandler mouseMoveHandler = new ImageMouseMoveHandler(); mouseMoveHandler.setFullImage(fullImage); fullImage.addMouseMoveHandler(mouseMoveHandler); } o_layout.setWidget(1, 0, m_layout); } @Override public void onFailure(Throwable caught) { // TODO render error div } }); } }