001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.web.client.grid; 017 018import com.smartgwt.client.types.Alignment; 019import com.smartgwt.client.types.VerticalAlignment; 020import com.smartgwt.client.widgets.Label; 021import com.smartgwt.client.widgets.events.ClickEvent; 022import com.smartgwt.client.widgets.events.ClickHandler; 023import com.smartgwt.client.widgets.layout.HLayout; 024import com.smartgwt.client.widgets.layout.VLayout; 025 026/** 027 * Pattern for grid view. 028 * 029 * @author kulikov 030 */ 031public class TabsetGrid extends VLayout { 032 private final TabGrid<?,?>[] tabs; 033 private Label[] labels; 034 public TabsetGrid(String[] caption, TabGrid<?,?>[] tbs) { 035 super(); 036 this.tabs = tbs; 037 038 init(caption); 039 } 040 041 private void init(String... caption) { 042 this.setStyleName("grid-bg"); 043 this.setLayoutMargin(1); 044 045 VLayout background = new VLayout(); 046 background.setWidth100(); 047 background.setHeight100(); 048 background.setStyleName("grid-panel"); 049 addMember(background); 050 051 052 HLayout topPanel = new HLayout(); 053 topPanel.setHeight(30); 054 topPanel.setAlign(VerticalAlignment.CENTER); 055 topPanel.setAlign(Alignment.LEFT); 056 057 topPanel.setLayoutMargin(3); 058 topPanel.setBackgroundColor("#e6f1f6"); 059 060 labels = new Label[tabs.length]; 061 for (int i = 0; i < tabs.length; i++) { 062 Label label = new Label(caption[i]); 063// label.setWidth100(); 064 label.setDataPath(Integer.toString(i)); 065 label.setStyleName("caption"); 066 label.setWidth(100); 067 068 label.addClickHandler(new ClickHandler() { 069 @Override 070 public void onClick(ClickEvent event) { 071 Label l = (Label) event.getSource(); 072 int i = Integer.parseInt(l.getDataPath()); 073 showTab(i); 074 } 075 }); 076 labels[i] = label; 077 topPanel.addMember(label); 078 } 079 080 background.addMember(topPanel); 081 for (int i = 0; i < tabs.length; i++) { 082 background.addMember(tabs[i]); 083 } 084 085 setAutoHeight(); 086 087 HLayout bottomPanel = new HLayout(); 088 bottomPanel.setHeight(30); 089 bottomPanel.setBackgroundColor("#e6f1f6"); 090 091// viewPort.setAutoHeight(); 092// background.addMember(viewPort); 093 background.addMember(bottomPanel); 094 095 showTab(0); 096 } 097 098 public void showTab(int k) { 099 for (int i = 0; i < tabs.length; i++) { 100 tabs[i].setVisible(i == k); 101 } 102 for (int i = 0; i < labels.length; i++) { 103 if (i == k) { 104 labels[i].setStyleName("caption-selected"); 105 } else { 106 labels[i].setStyleName("caption"); 107 } 108 } 109 } 110 111 protected class Strut extends HLayout { 112 public Strut(int size) { 113 super(); 114 setWidth(size); 115 } 116 } 117 118}