001/* 002 * #%L 003 * GwtMaterial 004 * %% 005 * Copyright (C) 2015 - 2017 GwtMaterialDesign 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package gwt.material.design.client.ui.table; 021 022import com.google.gwt.user.client.DOM; 023import com.google.gwt.user.client.ui.HasWidgets; 024import com.google.gwt.user.client.ui.Panel; 025import gwt.material.design.client.base.MaterialWidget; 026import gwt.material.design.client.js.JsTableElement; 027 028import static gwt.material.design.jquery.client.api.JQuery.$; 029 030/** 031 * Table scaffolding that will construct the Panels for the table foundation. 032 * 033 * @author Ben Dol 034 */ 035public abstract class TableScaffolding { 036 037 private Panel tableBody; 038 private Panel topPanel; 039 private Panel infoPanel; 040 private Panel toolPanel; 041 private Table table; 042 043 public void build() { 044 tableBody = createTableBody(); 045 topPanel = createTopPanel(); 046 infoPanel = createInfoPanel(); 047 toolPanel = createToolPanel(); 048 table = createTable(); 049 } 050 051 abstract protected Panel createTableBody(); 052 053 public Panel getTableBody() { 054 return tableBody; 055 } 056 057 abstract protected Panel createTopPanel(); 058 059 public Panel getTopPanel() { 060 return topPanel; 061 } 062 063 abstract protected Panel createInfoPanel(); 064 065 public Panel getInfoPanel() { 066 return infoPanel; 067 } 068 069 abstract protected Panel createToolPanel(); 070 071 public Panel getToolPanel() { 072 return toolPanel; 073 } 074 075 abstract protected Table createTable(); 076 077 public Table getTable() { 078 return table; 079 } 080 081 /** 082 * Apply the scaffolding together. 083 * @param container the base container for the scaffolding. 084 */ 085 protected void apply(HasWidgets container) { 086 container.clear(); 087 container.add(topPanel); 088 container.add(tableBody); 089 090 topPanel.add(infoPanel); 091 topPanel.add(toolPanel); 092 tableBody.add(table); 093 094 table.addHead(new MaterialWidget(DOM.createElement("thead"))); 095 table.addBody(new MaterialWidget(DOM.createElement("tbody"))); 096 } 097}