--- /dev/null
+/*****************************************************************************
+ * Copyright Igor Barma, Eric Brun, Alexandre Desoubeaux, Christian Martel,
+ * (2 décembre 2008)
+ *
+ * Ce logiciel est un programme informatique servant à l'évaluation des
+ * compétences.
+ *
+ * Ce logiciel est régi par la licence CeCILL soumise au droit français et
+ * respectant les principes de diffusion des logiciels libres. Vous pouvez
+ * utiliser, modifier et/ou redistribuer ce programme sous les conditions
+ * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
+ * sur le site "http://www.cecill.info".
+ *
+ * En contrepartie de l'accessibilité au code source et des droits de copie,
+ * de modification et de redistribution accordés par cette licence, il n'est
+ * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
+ * seule une responsabilité restreinte pèse sur l'auteur du programme, le
+ * titulaire des droits patrimoniaux et les concédants successifs.
+ *
+ * A cet égard l'attention de l'utilisateur est attirée sur les risques
+ * associés au chargement, à l'utilisation, à la modification et/ou au
+ * développement et à la reproduction du logiciel par l'utilisateur étant
+ * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
+ * manipuler et qui le réserve donc à des développeurs et des professionnels
+ * avertis possédant des connaissances informatiques approfondies. Les
+ * utilisateurs sont donc invités à charger et tester l'adéquation du
+ * logiciel à leurs besoins dans des conditions permettant d'assurer la
+ * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
+ * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
+ *
+ * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
+ * pris connaissance de la licence CeCILL, et que vous en avez accepté les
+ * termes.
+ *******************************************************************************/
+package com.pentila.evalcomp.client.evalFolder;
+
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.gwt.i18n.client.NumberFormat;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.gwtext.client.util.Format;
+import com.pentila.evalcomp.client.ConnexionServer;
+import com.pentila.evalcomp.client.i18n.Messages;
+import com.pentila.evalcomp.client.services.examen.SmartExamenScore;
+import com.pentila.evalcomp.client.utilities.Tools;
+import com.pentila.evalcomp.client.widget.SmartWindow;
+import com.pentila.evalcomp.domain.transit.TCompositeDataMap;
+import com.smartgwt.client.core.Function;
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.types.HeaderControls;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.types.SummaryFunctionType;
+import com.smartgwt.client.widgets.HeaderControl;
+import com.smartgwt.client.widgets.grid.CellFormatter;
+import com.smartgwt.client.widgets.grid.ListGrid;
+import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.grid.SummaryFunction;
+import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent;
+import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+public class SmartExamenValidation extends VLayout {
+
+
+ private String userUid;
+ private Long planId;
+ private Long refId;
+
+ private ListGrid grid;
+
+ NumberFormat format = NumberFormat.getFormat("0.00%");
+ private TCompositeDataMap TCDM;
+
+ protected Function callBackFunction = null;
+
+ private Boolean showDetail = true;
+
+ public SmartExamenValidation(String uid, Long planId, Long refId){
+ super();
+ this.userUid = uid;
+ this.planId = planId;
+ this.refId = refId;
+
+ initializeInterface();
+ }
+
+ public SmartExamenValidation(String uid, Long planId, Long refId, Boolean showDetail){
+ super();
+ this.userUid = uid;
+ this.planId = planId;
+ this.refId = refId;
+ this.showDetail = showDetail;
+ initializeInterface();
+ }
+
+ private void initializeInterface() {
+
+ grid = new ListGrid();
+
+ grid.setAutoFetchData(true);
+
+ grid.setShowAllRecords(true);
+ grid.setHeight100();
+ grid.setWidth100();
+ grid.setShowGridSummary(true);
+
+ addMember(grid);
+
+
+ grid.addRecordDoubleClickHandler(new RecordDoubleClickHandler(){
+
+ public void onRecordDoubleClick(RecordDoubleClickEvent event) {
+
+ Record record = event.getRecord();
+
+ final SmartWindow window = new SmartWindow();
+
+ window.setTitle(record.getAttribute("camp") + " / " + record.getAttribute("examenName") );
+ //window.setClosable(true);
+ //window.setMaximizable(true);
+
+ window.setWidth(800);
+ window.setHeight(600);
+ com.smartgwt.client.widgets.events.ClickHandler clickHandler = new com.smartgwt.client.widgets.events.ClickHandler() {
+ public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
+
+ if (window.getMaximized() != null && window.getMaximized()){
+
+ window.restore();
+
+ }else{
+
+ window.maximize();
+ }
+
+ }
+ };
+ HeaderControl maximize = new HeaderControl(HeaderControl.MAXIMIZE, clickHandler);
+
+ window.setHeaderControls(HeaderControls.HEADER_LABEL , HeaderControls.MINIMIZE_BUTTON,HeaderControls.MAXIMIZE_BUTTON, maximize, HeaderControls.CLOSE_BUTTON);
+
+ SmartExamenScore scoreGrid = new SmartExamenScore(new Long(record.getAttribute("EIID")), showDetail);
+ scoreGrid.initializeInterface();
+
+ window.addItem(scoreGrid);
+
+ scoreGrid.update();
+ window.setCanDragReposition(true);
+ window.setCanDragResize(true);
+ window.centerInPage();
+ window.show();
+
+
+ }
+
+ });
+
+
+
+ }
+
+ public void update(){
+
+ AsyncCallback callback = new AsyncCallback(){
+
+ public void onFailure(Throwable arg0) {
+ // TODO Auto-generated method stub
+ Tools.hideLoading();
+ }
+
+ public void onSuccess(Object result) {
+ Tools.hideLoading();
+ TCompositeDataMap T = (TCompositeDataMap) result;
+
+ updateGrid(T);
+ if (callBackFunction != null){
+ callBackFunction.execute();
+ }
+ }
+
+
+
+ };
+ Tools.showLoading(Messages.getString("MAJ"),
+ Messages.getString("Chargement"));
+ ConnexionServer.validationService.getUserExamenValidation(this.userUid, this.planId, this.refId, callback);
+
+ }
+
+ private void updateGrid(TCompositeDataMap T) {
+
+ this.TCDM = T;
+
+ int i = 0;
+
+ ListGridField[] array = new ListGridField[T.getIndexes().size()];
+
+ CellFormatter cf = new CellFormatter(){
+
+ public String format(Object value, ListGridRecord record,
+ int rowNum, int colNum) {
+
+
+ if (value instanceof Number){
+ Float f = 0f;
+ f = Float.parseFloat(value.toString());
+ return format.format(f);
+ }
+ return value.toString();
+
+ }
+
+ };
+
+
+ for (String header : T.getHeaders()){
+
+ if (header == null || header.equals("")){
+ continue;
+ }
+
+ ListGridField lgf = new ListGridField(T.getIndexes().get(i), header);
+
+ if (i == 0){
+ lgf.setSummaryValueTitle("Validation");
+ lgf.setSummaryFunction(SummaryFunctionType.TITLE);
+ }else{
+ lgf.setIcon(Tools.getBaseURL() + "images/" + "domaine10.png" );
+ lgf.setIconWidth(6);
+ lgf.setIconHeight(10);
+ }
+
+ if (i>0){
+ lgf.setType(ListGridFieldType.FLOAT);
+
+ lgf.setCellFormatter(cf);
+ lgf.setSummaryFunction(new SummaryFunction() {
+ public Object getSummaryValue(Record[] records, ListGridField field) {
+ String ret = "";
+ try{
+ int index = grid.getFieldNum(field.getName());
+
+ int size = TCDM.getDataMap().length;
+
+ String scoreDomain = TCDM.getDataMap()[size-2][index];
+ String VDomain = TCDM.getDataMap()[size-1][index];
+
+ Boolean b = Boolean.parseBoolean(VDomain);
+
+ String imgName = "cancel-16x16.png";
+
+ if (b){
+ imgName = "ok-16x16.png";
+ }
+ Float f = 0f;
+ f = Float.parseFloat(scoreDomain);
+ ret = Format
+ .format(
+ "<div style=\"margin-top:10px; margin-bottom: 10px;text-align : center\">{2}<br><br><img src=\"{0}images/{1}\"></div>", new String[] { Tools.getBaseURL(), imgName , format.format(f)});
+ }catch (Exception e){
+
+ }
+
+ return ret;
+ }
+
+ });
+ //lgf.setSummaryFunction(SummaryFunctionType.MAX);
+ }
+
+
+
+ array[i++] = lgf;
+
+ }
+
+ grid.setFields(array);
+
+
+ int size = T.getDataMap().length;
+
+ if ("validation".equals(T.getDataMap()[size-1][0])){
+ size = size - 2;
+ }
+
+ ListGridRecord[] ar = new ListGridRecord[size];
+
+ for (i = 0; i < size ; i++){
+
+ String[] examen = T.getDataMap()[i];
+
+
+ ListGridRecord lgr = new ListGridRecord();
+
+ int j = 0;
+ for (String index : T.getIndexes()){
+ String val = examen[j++];
+ try{
+ Float f = Float.parseFloat(val);
+
+ lgr.setAttribute(index, f);
+
+ }catch (Exception e){
+
+ lgr.setAttribute(index, val);
+ }
+
+
+
+
+
+ }
+
+ ar[i] = lgr;
+
+ }
+
+ grid.setData(ar);
+ //grid.redraw();
+
+
+ }
+
+ public void setCallBackFunction(Function callBack){
+ this.callBackFunction = callBack;
+ }
+
+ public Map<String, Integer> getStatsDomain(){
+ Map<String, Integer> map = new HashMap<String, Integer>();
+
+ int size = this.TCDM.getDataMap().length;
+
+ if ("validation".equals(this.TCDM.getDataMap()[size-1][0])){
+
+ map.put("valid", 0);
+ map.put("invalid", 0);
+ map.put("wait", 0);
+ map.put("total", 0);
+
+
+ int i =0;
+
+
+ String[] line = this.TCDM.getDataMap()[size-1];
+
+ for (Long index : this.TCDM.getHeadersIds() ){
+
+ if (index != null){
+ String v = line[i];
+
+
+
+ if (v.equals("true")) {
+
+ map.put("valid", map.get("valid") + 1);
+
+ }else if (v.equals("false")){
+ map.put("invalid", map.get("invalid") + 1);
+
+ }else{
+ map.put("wait", map.get("wait") + 1);
+
+ }
+ map.put("total", map.get("total") + 1);
+ }
+
+ i++;
+ }
+
+ }
+
+ return map;
+ }
+}