/* AddressBookBinder.java * * Copyright (c) 2002, OSK Group * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by OSK Group */ package gzz.modules.email; import gzz.*; import gzz.client.*; import gzz.zzutil.*; public class AddressBookBinder { /** Insert a new row over/under the current cell. * @param c The cell the cursor is on, currently. * @param dir Whether to create the new row above (-1) * or below (+1) the cursor. * @returns The cell the cursor should be moved to * (on the new row). */ public Cell insertRow(Cell c, int dir) { Dim d_1 = c.space.getDim(Ids.d_1); Dim d_2 = c.space.getDim(Ids.d_2); Cell m = c.N(d_2, dir); Cell n = c; while(n.s(d_1, 1) != null) { n = n.s(d_1, 1); Cell o = n.N(d_2, dir); m.connect(d_1, 1, o); m = o; } m = c.s(d_2, dir); n = c; while(n.s(d_1, -1) != null) { n = n.s(d_1, -1); Cell o = n.N(d_2, dir); m.connect(d_1, -1, o); m = o; } return c.s(d_2, dir); } public void test(Space s) { Cell home = s.getHomeCell(); Dim d_1 = s.getDim(Ids.d_1); Dim d_2 = s.getDim(Ids.d_2); home.setText("Name"); Cell a = home.N(d_1,1); a.setText("e-mail"); Cell b = a.N(d_1,1); b.setText("date of birth"); Cell f = insertRow(home, 1); Cell c = home.s(d_2, 1); if(c == null) throw new Error(); Cell d = c.s(d_1, 1); if(d == null) throw new Error(); Cell e = d.s(d_1, 1); if(e == null) throw new Error(); if(!a.s(d_2, 1).equals(d)) throw new Error(); if(!b.s(d_2, 1).equals(e)) throw new Error(); if(!f.equals(c)) throw new Error(); } }