1 33 34 package com.icesoft.icefaces.samples.showcase.components.expandableTable; 35 36 37 import com.icesoft.icefaces.samples.showcase.util.StyleBean; 38 39 import javax.faces.event.ActionEvent; 40 import java.util.ArrayList ; 41 42 51 public class SalesGroupRecordBean extends SalesGroupRecord { 52 protected static final String DEFAULT_IMAGE_DIR = 53 "./xmlhttp/css/xp/css-images/"; 54 protected static final String SPACER_IMAGE = 55 "tree_line_blank.gif"; 56 57 protected String indentStyleClass = ""; 60 61 protected String rowStyleClass = ""; 63 64 protected StyleBean styleBean; 65 66 protected String expandImage; protected String contractImage; 70 protected ArrayList parentInventoryList; 73 74 protected boolean isExpanded; 76 77 85 public SalesGroupRecordBean(String indentStyleClass, 86 String rowStyleClass, 87 StyleBean styleBean, 88 String expandImage, 89 String contractImage, 90 ArrayList parentInventoryList, 91 boolean isExpanded) { 92 93 this.indentStyleClass = indentStyleClass; 94 this.rowStyleClass = rowStyleClass; 95 this.styleBean = styleBean; 96 this.expandImage = expandImage; 97 this.contractImage = contractImage; 98 this.parentInventoryList = parentInventoryList; 99 this.parentInventoryList.add(this); 100 this.isExpanded = isExpanded; 101 if (this.isExpanded) { 103 expandNodeAction(); 104 } 105 } 106 107 117 public SalesGroupRecordBean(String indentStyleClass, 118 String rowStyleClass) { 119 120 this.indentStyleClass = indentStyleClass; 121 this.rowStyleClass = rowStyleClass; 122 } 123 124 129 public boolean isRenderImage() { 130 return childSalesRecords != null && childSalesRecords.size() > 0; 131 } 132 133 138 public void toggleSubGroupAction(ActionEvent event) { 139 isExpanded = !isExpanded; 141 142 if (isExpanded) { 144 expandNodeAction(); 145 } 146 else { 148 contractNodeAction(); 149 } 150 } 151 152 157 public void addChildSalesGroupRecord( 158 SalesGroupRecordBean salesGroupRecord) { 159 if (this.childSalesRecords != null && salesGroupRecord != null) { 160 this.childSalesRecords.add(salesGroupRecord); 161 if (isExpanded) { 162 contractNodeAction(); 164 expandNodeAction(); 166 } 167 } 168 } 169 170 175 public void removeChildSalesGroupRecord( 176 SalesGroupRecordBean salesGroupRecord) { 177 if (this.childSalesRecords != null && salesGroupRecord != null) { 178 if (isExpanded) { 179 contractNodeAction(); 181 } 182 this.childSalesRecords.remove(salesGroupRecord); 184 if (isExpanded) { 186 contractNodeAction(); 188 expandNodeAction(); 190 } 191 } 192 } 193 194 197 private void expandNodeAction() { 198 if (childSalesRecords != null && childSalesRecords.size() > 0) { 199 int index = parentInventoryList.indexOf(this); 201 202 parentInventoryList.addAll(index + 1, childSalesRecords); 204 } 205 206 } 207 208 211 private void contractNodeAction() { 212 if (childSalesRecords != null && childSalesRecords.size() > 0) { 213 parentInventoryList.removeAll(childSalesRecords); 215 } 216 } 217 218 225 public String getIndentStyleClass() { 226 return indentStyleClass; 227 } 228 229 235 public String getRowStyleClass() { 236 return rowStyleClass; 237 } 238 239 245 public String getExpandContractImage() { 246 if(styleBean != null) { 247 String dir = styleBean.getImageDirectory(); 248 String img = isExpanded ? contractImage : expandImage; 249 return dir + img; 250 } 251 return DEFAULT_IMAGE_DIR + SPACER_IMAGE; 252 } 253 } | Popular Tags |