Coverage Report - sk.baka.webvm.Problems
 
Classes in this File Line Coverage Branch Coverage Complexity
Problems
0%
0/5
N/A
1.5
Problems$1
N/A
N/A
1.5
Problems$ProblemsListView
0%
0/12
0%
0/4
1.5
Problems$ProblemsModel
0%
0/2
N/A
1.5
 
 1  
 /**
 2  
  * Copyright 2009 Martin Vysny.
 3  
  *
 4  
  * This file is part of WebVM.
 5  
  *
 6  
  * WebVM is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License, or
 9  
  * (at your option) any later version.
 10  
  *
 11  
  * WebVM is distributed in the hope that it will be useful,
 12  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14  
  * GNU General Public License for more details.
 15  
  *
 16  
  * You should have received a copy of the GNU General Public License
 17  
  * along with WebVM.  If not, see <http://www.gnu.org/licenses/>.
 18  
  */
 19  
 package sk.baka.webvm;
 20  
 
 21  
 import sk.baka.webvm.analyzer.ProblemReport;
 22  
 import java.util.List;
 23  
 import org.apache.wicket.behavior.SimpleAttributeModifier;
 24  
 import org.apache.wicket.markup.html.basic.Label;
 25  
 import org.apache.wicket.markup.html.list.ListItem;
 26  
 import org.apache.wicket.markup.html.list.ListView;
 27  
 import org.apache.wicket.model.IModel;
 28  
 import org.apache.wicket.model.LoadableDetachableModel;
 29  
 
 30  
 /**
 31  
  * Shows the "Problems" page and provides the problems analysis.
 32  
  * @author Martin Vysny
 33  
  */
 34  
 public final class Problems extends WebVMPage {
 35  
 
 36  
     private static final long serialVersionUID = 1L;
 37  
 
 38  
     /**
 39  
      * Creates new instance
 40  
      */
 41  0
     public Problems() {
 42  0
         final IModel<List<ProblemReport>> model = new ProblemsModel();
 43  0
         final ListView<ProblemReport> list = new ProblemsListView("problemList", model);
 44  0
         border.add(list);
 45  0
     }
 46  
 
 47  
     /**
 48  
      * Provides a list of model. Stateless.
 49  
      */
 50  0
     private static class ProblemsModel extends LoadableDetachableModel<List<ProblemReport>> {
 51  
 
 52  
         private static final long serialVersionUID = 1L;
 53  
 
 54  
         @Override
 55  
         protected List<ProblemReport> load() {
 56  0
             return WicketApplication.getAnalyzer().getProblems(WicketApplication.getHistory().getVmstatHistory());
 57  
         }
 58  
     }
 59  
     public static final String DARK_GREEN = "#28cb17";
 60  
     public static final String LIGHT_RED = "#d24343";
 61  
 
 62  
     /**
 63  
      * Shows a list of problem reports.
 64  
      */
 65  
     private static class ProblemsListView extends ListView<ProblemReport> {
 66  
 
 67  
         public ProblemsListView(String id, IModel<? extends List<? extends ProblemReport>> model) {
 68  0
             super(id, model);
 69  0
         }
 70  
         private static final long serialVersionUID = 1L;
 71  
 
 72  
         @Override
 73  
         protected void populateItem(ListItem<ProblemReport> item) {
 74  0
             final ProblemReport pr = item.getModelObject();
 75  0
             item.add(new Label("problemClass", pr.pclass));
 76  0
             final Label l = new Label("problemSeverity", pr.isProblem ? "WARN" : "OK");
 77  0
             l.add(new SimpleAttributeModifier("bgcolor", pr.isProblem ? LIGHT_RED : DARK_GREEN));
 78  0
             item.add(l);
 79  0
             final Label desc = new Label("problemDesc", pr.desc);
 80  0
             desc.setEscapeModelStrings(false);
 81  0
             item.add(desc);
 82  0
             item.add(new Label("problemDiagnosis", pr.diagnosis));
 83  0
         }
 84  
     }
 85  
 }
 86