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    
015    import java.util.Comparator;
016    
017    import org.apache.cayenne.DataObjectUtils;
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.TestCase;
025    import net.codescore.ui.admin.probs.TestCaseWindow;
026    import net.codescore.ui.components.list.ZKObjectList;
027    
028    public class TestCaseRenderer extends AbstractRenderer<TestCase> {
029            private class ScoreboardSorter extends ListComparator<TestCase> {
030                    public ScoreboardSorter(final Direction d) {
031                            super(1, d);
032                    }
033    
034                    @Override
035                    public int compare(final TestCase o1, final TestCase o2) {
036                            return checkDir(o1.compareTo(o2));
037                    }
038    
039            }
040    
041            private Listhead header;
042    
043            public TestCaseRenderer(final ZKObjectList<TestCase> list) {
044                    super(list);
045            }
046    
047            @Override
048            public void doAction(final Window callBackWin, final TestCase obj) {
049                    final TestCaseWindow tcw = new TestCaseWindow(obj);
050                    tcw.setParent(callBackWin);
051                    tcw.doPopup();
052            }
053    
054            @Override
055            public Comparator<TestCase> getComparator(final int col, final Direction dir) {
056                    return new ScoreboardSorter(dir);
057            }
058    
059            @Override
060            public Listhead getHeader() {
061                    if (header == null) {
062                            header = new Listhead();
063                            final Listheader teamName = new Listheader("Test Case #");
064                            teamName.setParent(header);
065                            teamName.setSortAscending(getComparator(1, Direction.Asc));
066                            teamName.setSortDescending(getComparator(1, Direction.Desc));
067                    }
068                    return header;
069            }
070    
071            @Override
072            public void render(final Listitem arg0, final Object arg1) throws Exception {
073                    if (arg1 instanceof TestCase) {
074                            final TestCase tc = (TestCase) arg1;
075                            final int tcid = DataObjectUtils.intPKForObject(tc);
076                            final Listcell tN = new Listcell(tcid + "");
077                            tN.setParent(arg0);
078                    } else
079                            throw new IllegalArgumentException(
080                                    "This render can only render TestCase!");
081            }
082    
083    }