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.parts;
014    
015    import org.zkoss.zul.*;
016    
017    import net.codescore.dbo.Comment;
018    import net.codescore.dbo.JudgeSolution;
019    import net.codescore.dbo.Person;
020    import net.codescore.dbo.Problem;
021    import net.codescore.dbo.TestCase;
022    import net.codescore.managers.PersonManager;
023    import net.codescore.ui.i18n.T;
024    
025    public class ProblemDetail extends Window {
026            private Groupbox commBox, casesBox, solutionsBox, descBox, sampleBox;
027            private Html description;
028            private final Problem prob;
029            private Window sampIn, sampOut;
030            private boolean showSampleData = true, showComments = false,
031                    showTestCases = false, showSolution = false;
032    
033            public ProblemDetail(Problem p) {
034                    this(p, true, false, false, false);
035            }
036    
037            public ProblemDetail(Problem p, boolean sampData, boolean comments,
038                    boolean testCases, boolean solutions) {
039                    prob = p;
040                    showSampleData = sampData;
041                    showComments = comments;
042                    showTestCases = testCases;
043                    showSolution = solutions;
044                    setTitle(p.getName() + " (" + p.getUnixName() + ")");
045                    setWidth("100%");
046                    initDesc();
047                    if (showSampleData) {
048                            initSamples();
049                    }
050                    if (showComments) {
051                            initComments();
052                    }
053                    if (showSolution) {
054                            initSolutions();
055                    }
056                    if (showTestCases) {
057                            initTestCases();
058                    }
059            }
060    
061            public void onAddComment() {
062                    Person person =
063                            PersonManager.getPersonByName(prob.getObjectContext(),
064                                    "Adam Cornett"); // THIS IS A TESTING HACK!
065                    AddCommentWindow acw = new AddCommentWindow(prob, person);
066                    acw.setParent(this);
067                    acw.doPopup();
068            }
069    
070            private void initComments() {
071                    commBox = new Groupbox();
072                    commBox.setMold("3d");
073                    commBox.setParent(this);
074                    commBox.setOpen(false);
075                    Caption cap = new Caption();
076                    cap.setLabel(T._("problem.comments.winTitle"));
077                    cap.setParent(commBox);
078                    Toolbarbutton addC = new Toolbarbutton("Add Comment");
079                    addC.setParent(cap);
080                    addC.addForward(null, this, "onAddComment");
081                    for (Comment c : prob.getComments()) {
082                            CommentDetail cd = new CommentDetail(c);
083                            cd.setParent(commBox);
084                    }
085            }
086    
087            private void initDesc() {
088                    descBox = new Groupbox();
089                    descBox.setMold("3d");
090                    descBox.setParent(this);
091                    descBox.setOpen(false);
092                    Caption cap = new Caption();
093                    cap.setLabel(T._("problem.description.wintitle"));
094                    cap.setParent(descBox);
095                    description = new Html();
096                    description.setContent(prob.getDescription());
097                    description.setParent(descBox);
098            }
099    
100            private void initSamples() {
101                    sampleBox = new Groupbox();
102                    sampleBox.setMold("3d");
103                    sampleBox.setParent(this);
104                    sampleBox.setOpen(false);
105                    Caption cap = new Caption();
106                    cap.setLabel("Sample Data");
107                    cap.setParent(sampleBox);
108                    Hbox sampBox = new Hbox();
109                    sampBox.setParent(sampleBox);
110                    sampIn = new Window();
111                    sampIn.setWidth("281px");
112                    sampIn.setTitle(T._("problem.sampleIn"));
113                    Textbox sampInBox = new Textbox(prob.getSampleInput());
114                    sampInBox.setReadonly(true);
115                    sampInBox.setRows(10);
116                    sampInBox.setWidth("280px");
117                    sampInBox.setParent(sampIn);
118                    sampIn.setParent(sampBox);
119    
120                    sampOut = new Window();
121                    sampOut.setWidth("281px");
122                    sampOut.setTitle(T._("problem.sampleOut"));
123                    Textbox sampOutBox = new Textbox(prob.getSampleOutput());
124                    sampOutBox.setReadonly(true);
125                    sampOutBox.setRows(10);
126                    sampOutBox.setWidth("280px");
127                    sampOutBox.setParent(sampOut);
128                    sampOut.setParent(sampBox);
129            }
130    
131            private void initSolutions() {
132                    solutionsBox = new Groupbox();
133                    solutionsBox.setParent(this);
134                    solutionsBox.setOpen(false);
135                    solutionsBox.setMold("3d");
136                    Caption cap = new Caption();
137                    cap.setLabel("Judges Solutions");
138                    cap.setParent(solutionsBox);
139                    Tabbox tb = new Tabbox();
140                    tb.setParent(solutionsBox);
141                    Tabs tbs = new Tabs();
142                    tbs.setParent(tb);
143                    Tabpanels panels = new Tabpanels();
144                    panels.setParent(tb);
145                    int i = 1;
146                    for (JudgeSolution s : prob.getSolutions()) {
147                            Tab tab = new Tab("#" + i);
148                            i++;
149                            tab.setParent(tbs);
150                            Tabpanel panel = new Tabpanel();
151                            panel.setParent(panels);
152                            SubmissionDetail ds = new SubmissionDetail(s);
153                            ds.setParent(panel);
154                    }
155    
156            }
157    
158            private void initTestCases() {
159                    casesBox = new Groupbox();
160                    casesBox.setParent(this);
161                    casesBox.setOpen(false);
162                    Caption cap = new Caption();
163                    cap.setLabel(T._("problem.testcases.winTitle"));
164                    Tabbox box = new Tabbox();
165                    box.setParent(casesBox);
166                    box.setMold("accordion");
167                    Tabs tbs = new Tabs();
168                    tbs.setParent(box);
169                    Tabpanels panels = new Tabpanels();
170                    panels.setParent(box);
171                    int i = 1;
172                    for (TestCase c : prob.getTestCases()) {
173                            Tab t = new Tab("#" + i);
174                            t.setParent(tbs);
175                            Tabpanel panel = new Tabpanel();
176                            panel.setParent(panels);
177                            TestCaseDetail dtc = new TestCaseDetail(c);
178                            dtc.setParent(panel);
179                            i++;
180                    }
181            }
182    }