001    /*
002     * Copyright (C) 2008 Adam Cornett This program is free software; you can
003     * redistribute it and/or modify it under the terms of the GNU General Public
004     * License as published by the Free Software Foundation; either version 3 of the
005     * License, or (at your option) any later version. This program is distributed
006     * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
007     * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
008     * See the GNU General Public License for more details. You should have received
009     * a copy of the GNU General Public License along with this program; if not, see
010     * <http://www.gnu.org/licenses>.
011     */
012    
013    package net.codescore.ui.components.list.renderers;
014    import static net.codescore.ui.i18n.T._;
015    
016    import java.util.Comparator;
017    
018    import org.zkoss.zul.Listcell;
019    import org.zkoss.zul.Listhead;
020    import org.zkoss.zul.Listheader;
021    import org.zkoss.zul.Listitem;
022    import org.zkoss.zul.Window;
023    
024    import net.codescore.dbo.Team;
025    import net.codescore.ui.components.list.ZKObjectList;
026    
027    public class SimpleTeamRenderer extends AbstractRenderer<Team> {
028            private class TeamSorter extends ListComparator<Team> {
029                    public TeamSorter(final Direction d) {
030                            super(1, d);
031                    }
032    
033                    @Override
034                    public int compare(final Team o1, final Team o2) {
035                            return checkDir(o1.getName().compareToIgnoreCase(o2.getName()));
036                    }
037    
038            }
039    
040            public SimpleTeamRenderer(ZKObjectList<Team> list) {
041                    super(list);
042            }
043    
044            @Override
045            public void doAction(Window callBackWin, Team obj) {
046                    // TODO Auto-generated method stub
047    
048            }
049    
050            @Override
051            public Comparator<Team> getComparator(int col, Direction dir) {
052                    return new TeamSorter(dir);
053            }
054    
055            @Override
056            public Listhead getHeader() {
057                    if (header == null) {
058                            header = new Listhead();
059                            final Listheader teamName = new Listheader(_("admin.ppl.team"));
060                            teamName.setParent(header);
061                            teamName.setSortAscending(getComparator(1, Direction.Asc));
062                            teamName.setSortDescending(getComparator(1, Direction.Desc));
063                    }
064                    return header;
065            }
066    
067            @Override
068            public void render(Listitem arg0, Object arg1) throws Exception {
069                    arg0.setValue(arg1);
070                    if (arg1 instanceof Team) {
071                            final Team tc = (Team) arg1;
072                            final Listcell tN = new Listcell(tc.getName());
073                            tN.setParent(arg0);
074                    } else
075                            throw new IllegalArgumentException(
076                                    "This render can only render teams!");
077            }
078    
079    }