001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.extensions.markup.html.repeater.tree.table; 018 019import org.apache.wicket.Component; 020import org.apache.wicket.behavior.Behavior; 021import org.apache.wicket.markup.ComponentTag; 022import org.apache.wicket.markup.repeater.Item; 023import org.apache.wicket.model.IModel; 024import org.apache.wicket.request.Response; 025 026/** 027 * A border for a node component which renders nested <code>DIV</code>s to simulate the structure of 028 * parental branches inside a tabular layout. 029 * 030 * @see NodeModel 031 * @see TreeColumn#populateItem(Item, String, IModel) 032 * @author svenmeier 033 */ 034public class NodeBorder extends Behavior 035{ 036 037 private static final long serialVersionUID = 1L; 038 039 private boolean[] branches; 040 041 /** 042 * @param branches 043 * branch 044 */ 045 public NodeBorder(boolean[] branches) 046 { 047 this.branches = branches; 048 } 049 050 @Override 051 public void beforeRender(Component component) 052 { 053 Response response = component.getResponse(); 054 055 for (int i = 0; i < branches.length; i++) 056 { 057 if (i > 0) 058 { 059 response.write("<div class=\"tree-subtree\">"); 060 } 061 062 if (branches[i]) 063 { 064 response.write("<div class=\"tree-branch tree-branch-mid\">"); 065 } 066 else 067 { 068 response.write("<div class=\"tree-branch tree-branch-last\">"); 069 } 070 } 071 } 072 073 @Override 074 public void onComponentTag(Component component, ComponentTag tag) 075 { 076 tag.append("class", "tree-node", " "); 077 } 078 079 @Override 080 public void afterRender(Component component) 081 { 082 Response response = component.getResponse(); 083 084 for (int i = 0; i < branches.length; i++) 085 { 086 if (i > 0) 087 { 088 response.write("</div>"); 089 } 090 response.write("</div>"); 091 } 092 } 093}