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 java.util.Arrays; 020 021import org.apache.wicket.extensions.markup.html.repeater.tree.ITreeProvider; 022import org.apache.wicket.model.IModel; 023import org.apache.wicket.model.IWrapModel; 024 025/** 026 * A model wrapping the actual node model, carrying additional information about the parental 027 * branches. 028 * 029 * @see #getBranches() 030 * @see ITreeProvider#model(Object) 031 * 032 * @author svenmeier 033 * @param <T> 034 * type of nodes 035 */ 036public class NodeModel<T> implements IWrapModel<T> 037{ 038 039 private static final long serialVersionUID = 1L; 040 041 private IModel<T> model; 042 043 private boolean[] branches; 044 045 /** 046 * Wrap the given model. 047 * 048 * @param model 049 * model to wrap 050 * @param branches 051 */ 052 public NodeModel(IModel<T> model, boolean[] branches) 053 { 054 this.model = model; 055 this.branches = branches; 056 } 057 058 /** 059 * Get the wrapped model. 060 * 061 * @return wrapped model 062 */ 063 @Override 064 public IModel<T> getWrappedModel() 065 { 066 return model; 067 } 068 069 @Override 070 public T getObject() 071 { 072 return model.getObject(); 073 } 074 075 @Override 076 public void setObject(T object) 077 { 078 throw new UnsupportedOperationException(); 079 } 080 081 @Override 082 public void detach() 083 { 084 model.detach(); 085 } 086 087 public int getDepth() 088 { 089 return branches.length; 090 } 091 092 public boolean[] getBranches() 093 { 094 return branches; 095 } 096 097 @Override 098 public int hashCode() 099 { 100 return model.hashCode(); 101 } 102 103 @Override 104 public boolean equals(Object obj) 105 { 106 if (obj instanceof NodeModel<?>) 107 { 108 NodeModel<?> nodeModel = (NodeModel<?>)obj; 109 110 return Arrays.equals(this.branches, nodeModel.branches) && 111 this.model.equals((nodeModel).model); 112 } 113 return false; 114 } 115}