--- /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.services.validation;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import com.gwtext.client.util.Format;
+import com.pentila.evalcomp.client.evalFolder.EvaluationFolderPanel;
+import com.pentila.evalcomp.client.i18n.Messages;
+import com.pentila.evalcomp.client.services.certification.SmartCertificationNumericGrid;
+import com.pentila.evalcomp.client.utilities.Tools;
+import com.pentila.evalcomp.client.utilities.UserTools;
+import com.pentila.evalcomp.client.widget.SmartWindow;
+import com.pentila.evalcomp.domain.definition.Level;
+import com.pentila.evalcomp.domain.definition.MethodEval;
+import com.pentila.evalcomp.domain.instance.CompetenceInstance;
+import com.pentila.evalcomp.domain.instance.EvaluationSubjectInstance;
+import com.pentila.evalcomp.domain.transit.TCompetence;
+import com.pentila.evalcomp.domain.transit.TCompetenceInstance;
+import com.pentila.evalcomp.domain.transit.TDomain;
+import com.pentila.evalcomp.domain.transit.TUserCompositeValidation;
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.AutoFitWidthApproach;
+import com.smartgwt.client.types.GroupStartOpen;
+import com.smartgwt.client.types.HeaderControls;
+import com.smartgwt.client.types.ListGridEditEvent;
+import com.smartgwt.client.types.Overflow;
+import com.smartgwt.client.types.RowEndEditAction;
+import com.smartgwt.client.types.VerticalAlignment;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.HeaderControl;
+import com.smartgwt.client.widgets.IButton;
+import com.smartgwt.client.widgets.RichTextEditor;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.grid.CellFormatter;
+import com.smartgwt.client.widgets.grid.GroupNode;
+import com.smartgwt.client.widgets.grid.GroupTitleRenderer;
+import com.smartgwt.client.widgets.grid.HeaderSpan;
+import com.smartgwt.client.widgets.grid.HoverCustomizer;
+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.events.CellContextClickEvent;
+import com.smartgwt.client.widgets.grid.events.CellContextClickHandler;
+import com.smartgwt.client.widgets.grid.events.CellDoubleClickEvent;
+import com.smartgwt.client.widgets.grid.events.CellDoubleClickHandler;
+import com.smartgwt.client.widgets.grid.events.EditorExitEvent;
+import com.smartgwt.client.widgets.grid.events.EditorExitHandler;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.menu.Menu;
+import com.smartgwt.client.widgets.menu.MenuItem;
+import com.smartgwt.client.widgets.menu.MenuItemIfFunction;
+import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
+import com.smartgwt.client.widgets.tile.TileLayout;
+
+
+/**
+ * The Class EvalGrid.
+ */
+public class SmartValidationUserGrid extends ListGrid{
+
+
+ /** The T. */
+ TUserCompositeValidation T;
+
+
+ /** The modified. */
+ Map<Integer, List<String>> modified = new HashMap<Integer, List<String>>();
+
+
+ /** The read only. */
+ boolean readOnly = false;
+
+ /** The provider. */
+ SmartCertificationNumericGrid provider;
+
+ /** The undo. */
+ Map<String, String> undo = new HashMap<String, String>();
+
+ /** The login. */
+ String login = "";
+
+ /** The map domain. */
+ private HashMap<Long, Map<String, Integer>> mapDomain;
+
+ private int selectedCIRowIndex = -1;
+ private String selectedCIIndex = "";
+
+ /** The hide validation. */
+ private boolean hideValidation = false;
+
+ /** The show detail ed. */
+ private boolean showDetailED = true;
+
+
+ /** The position from parent. */
+ private boolean positionFromParent = true;
+
+ /** The user name. */
+ private String userName = "";
+
+
+ private boolean readOnlyValidation;
+
+ /**
+ * Instantiates a new eval grid.
+ *
+ * @param login the login
+ * @param username the username
+ * @param provider the provider
+ * @param T the t
+ * @param readOnly the read only
+ */
+ public SmartValidationUserGrid(String login, String username, SmartCertificationNumericGrid provider, TUserCompositeValidation T, boolean readOnly, boolean readOnlyValidation) {
+ super();
+ this.login = login;
+ this.provider = provider;
+ this.userName = username;
+
+ this.readOnly = readOnly;
+ this.readOnlyValidation = readOnlyValidation;
+ this.T = T;
+
+ }
+
+
+ /**
+ * Instantiates a new smart validation user grid.
+ *
+ * @param login the login
+ * @param username the username
+ * @param provider the provider
+ * @param T the t
+ * @param readOnly the read only
+ * @param hideValidation the hide validation
+ */
+ public SmartValidationUserGrid(String login, String username, SmartCertificationNumericGrid provider, TUserCompositeValidation T, boolean readOnly, boolean readOnlyValidation, boolean hideValidation) {
+ this(login, username, provider, T, readOnly, readOnlyValidation);
+ this.hideValidation = hideValidation;
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.smartgwt.client.widgets.grid.ListGrid#getCellStyle(com.smartgwt.client.widgets.grid.ListGridRecord, int, int)
+ */
+ @Override
+ protected String getCellStyle(ListGridRecord record, int rowNum, int colNum) {
+
+ String index = getIndexFromField(colNum);
+
+ if (getFieldName(colNum).equals("CI" + index)){
+
+ Object v = record.getAttributeAsObject("CIObject" + index);
+
+ if (v!= null && !v.equals("")){
+ TCompetenceInstance ci = (TCompetenceInstance) v ;
+
+ if (ci.getState() != CompetenceInstance.TRANSMITTED){
+
+ return "grey_cell";
+ }
+
+ }
+ }
+
+ return super.getCellStyle(record, rowNum, colNum);
+
+ }
+
+
+
+ /**
+ * Initialize interface.
+ */
+ public void initializeInterface(){
+
+ //setWidth(900);
+ setWidth100();
+
+ setAutoFetchData(true);
+
+ this.setShowAllRecords(true);
+
+ this.setEditEvent(ListGridEditEvent.CLICK);
+ this.setListEndEditAction(RowEndEditAction.NEXT);
+ this.setAutoSaveEdits(false);
+
+ this.setGroupStartOpen(GroupStartOpen.ALL);
+ this.setGroupByField("domain");
+ this.setCanReorderFields(false);
+ this.setCanCollapseGroup(false);
+ setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
+ setAutoFitFieldWidths(true);
+
+ LinkedHashMap<String, List<String>> m = new LinkedHashMap<String, List<String>>();
+
+ int nbFolder = 0;
+
+
+ for (String code : T.getCampagnsKeys()){
+
+ String campName = T.getMapCampagns().get(code);
+
+ if (!m.containsKey(campName)){
+ List<String> aa = new ArrayList<String>();
+
+
+ m.put(campName, aa);
+ }
+
+ for (String idESI : T.getMapEDESI().get(code)){
+ String name = "CI" + idESI;
+
+ m.get(campName).add(name);
+
+ nbFolder ++;
+ }
+
+ }
+
+
+ setHeaderHeight(40);
+ HeaderSpan[] hs = new HeaderSpan[m.size()];
+
+ int t = 0;
+
+
+
+ for (Entry<String, List<String>> z : m.entrySet()){
+
+ String [] values = new String[z.getValue().size()];
+ int u = 0;
+ for (String rt : z.getValue()){
+ values[u++] = rt;
+ }
+
+ hs[t++] = new HeaderSpan(z.getKey() , values);
+
+ }
+
+ setHeaderSpans(
+ hs);
+
+ int i = 0;
+
+ int arraySize = nbFolder + 6 - 3;
+
+ if (hideValidation){
+ arraySize--;
+ }
+
+ this.setHoverWidth(300);
+
+ ListGridField[] array = new ListGridField[arraySize];
+
+ ListGridField competence = new ListGridField("competence", Messages.getString("Competence"), 120);
+ competence.setHoverCustomizer(new HoverCustomizer() {
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+
+ Long v = record.getAttributeAsLong("competenceId");
+ String infos = "";
+ if (v != null){
+ TCompetence tc = T.getMapCompetences().get(v);
+
+ return tc.getDescription();
+ }
+
+ return infos;
+ }
+ });
+
+ competence.setCellFormatter(new CellFormatter(){
+
+ public String format(Object value, ListGridRecord record,
+ int rowNum, int colNum) {
+ String icon = Tools.getBaseURL() +"images/";
+
+ Long v = record.getAttributeAsLong("competenceId");
+
+ if (v != null){
+ TCompetence tc = T.getMapCompetences().get(v);
+ if (tc.isRequired()){
+ icon += "competence16.png";
+
+ }else{
+ icon += "competence16Green.png";
+
+ }
+ }
+
+ String ret = "<img src=\""+ icon+ "\"/> "+ value;
+ return ret;
+
+ }
+
+ });
+
+ competence.setCanEdit(false);
+ competence.setCanHide(false);
+ competence.setFrozen(true);
+ competence.setShowHover(true);
+ competence.setCanGroupBy(false);
+ array[i++] = competence;
+
+ for (String code : T.getCampagnsKeys()){
+
+ int folderNb = 1;
+
+ for (String idESI : T.getMapEDESI().get(code)) {
+
+ Long idL = new Long(idESI.split("-", 2)[0]);
+
+ EvaluationSubjectInstance ESI = T.getMapESI().get(idL);
+ String folderName = ESI.getName();
+
+ if (folderName == null){
+ folderName = Messages.getString("Dossier") + " " + folderNb;
+ }
+
+ folderNb ++;
+
+ ListGridField lgf = new ListGridField( "CI" + idESI, folderName );
+
+ lgf.setAttribute("CI-index", idESI );
+ lgf.setAttribute("EDCode", code);
+ lgf.setAlign(Alignment.CENTER);
+ lgf.setCanGroupBy(false);
+ lgf.setShowHover(true);
+ lgf.setCanHide(false);
+ lgf.setCanSort(false);
+
+ // Here this point is an lost speed point
+ lgf.setWidth("100%");
+ //lgf.setAutoFitWidth(true);
+
+ String htmlFolder = "";
+ if(ESI.getName() != null && !ESI.getName().equals(""))
+ {
+ htmlFolder = "<b>" + folderName + " ( " + Tools.getDateFormated(ESI.getCreationDate(), null);
+
+ if (ESI.getDescription() != null){
+ htmlFolder += " ) : </b><p align=\"justify\" style=\"width: 500px\">" + ESI.getDescription() + "</p>";
+ }else{
+ htmlFolder += " )</b>";
+ }
+ }
+ else
+ {
+ htmlFolder = folderName;
+ }
+
+ lgf.setPrompt(htmlFolder );
+
+
+ lgf.setHoverCustomizer(new HoverCustomizer() {
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+
+ String index = getIndexFromField(colNum);
+
+ Object v = record.getAttributeAsObject("CIObject" + index);
+ String infos = "";
+
+ if (v != null && !v.equals("")){
+ TCompetenceInstance ci = (TCompetenceInstance) v;
+ String trans = "";
+ if (ci.isValidable()) {
+
+ trans = " (Validable)";
+ } else if (ci.getState() != CompetenceInstance.TRANSMITTED) {
+
+ trans = " (Résultat non transmis)";
+ }else if (!ci.isValidable()){
+
+ trans = " (Non validable)";
+ }
+ if (ci.getEvaluateurName() != null) {
+ infos = Format.format(Messages
+ .getString("evalue_par_x_le_date"),
+ new String[] { ci.getEvaluateurName(),
+ "" + Tools.getDateFormated( ci.getLastModified() , "format_date_JJMMYYYYHHMM")});
+ }
+
+ infos = infos + trans;
+
+ }
+ return infos;
+ }
+ });
+
+ if (!readOnly){
+ lgf.setCanEdit(true);
+
+ lgf.addEditorExitHandler(new EditorExitHandler(){
+
+ public void onEditorExit(EditorExitEvent event) {
+
+ if (event.getNewValue() != null){
+
+ Record record = event.getRecord();
+
+ String newValue = (String)event.getNewValue();
+
+ int colIndex = event.getColNum();
+
+ String index = getIndexFromField(colIndex);
+
+ record.setAttribute("CI" + index, newValue);
+
+ Long lid = new Long(newValue);
+ TCompetenceInstance CI = (TCompetenceInstance) record.getAttributeAsObject("CIObject" + index);
+
+ if (CI == null || CI.getState() != CompetenceInstance.TRANSMITTED) {
+ return;
+ }
+
+ MethodEval me = CI.getLevel().getMethodEval();
+ for (Level l : me.getLevels()) {
+ if (l.getId().equals(lid)) {
+ CI.setLevel(l);
+ CI.setModified(true);
+
+
+ if (!modified.containsKey(event.getRowNum())){
+ modified.put(event.getRowNum(), new ArrayList<String>());
+ }
+ modified.get(event.getRowNum()).add(index);
+ updateValidationRecords( record );
+
+ break;
+ }
+ }
+
+ }
+ }});
+ }
+ array[i++] = lgf;
+ }
+ }
+
+
+ if (!hideValidation){
+
+ ListGridField val = new ListGridField( "validation" ,Messages.getString("Validation"), 50);
+ val.setCanEdit(false);
+ val.setAlign(Alignment.CENTER);
+ val.setCanHide(false);
+ val.setCanGroupBy(false);
+
+ val.setCellFormatter(new CellFormatter(){
+
+ public String format(Object value, ListGridRecord record,
+ int rowNum, int colNum) {
+
+ String v = record.getAttributeAsString("validation");
+
+ String imgName = "cancel-16x16.png";
+
+ if (v != null && v.equals(""+TUserCompositeValidation.INVALIDATE)){
+ imgName = "cancel-16x16.png";
+ }else if (v != null && v.equals(""+TUserCompositeValidation.VALIDATE)){
+ imgName = "ok-16x16.png";
+ }else {
+ imgName = "wait-16x16.png";
+ }
+ return Format
+ .format(
+ "<img src=\"{0}images/{1}\">", new String[] { Tools.getBaseURL(), imgName });
+ }
+
+ });
+ val.setShowHover(true);
+ val.setHoverCustomizer(new HoverCustomizer() {
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+
+ String state = Messages.getString("non_validee");
+
+ String v = record.getAttributeAsString("validation");
+
+ if (v != null){
+
+ if (v.equals(""+TUserCompositeValidation.VALIDATE)) {
+ state = Messages.getString("validee");
+
+ }else if (v.equals(""+TUserCompositeValidation.INVALIDATE)){
+ state = Messages.getString("non_validee");
+
+ }else{
+ state = Messages.getString("wait_result");
+
+ }
+ }
+
+ return state;
+ }
+ });
+
+ array[i++] = val;
+
+ }
+ ListGridField dom = new ListGridField("domain");
+ dom.setCanEdit(false);
+ dom.setHidden(true);
+ dom.setCanHide(false);
+
+ dom.setGroupTitleRenderer(new GroupTitleRenderer() {
+
+
+ public String getGroupTitle(Object groupValue, GroupNode groupNode,
+ ListGridField field, String fieldName, ListGrid grid) {
+
+ Record[] array = groupNode.getGroupMembers();
+
+ Record first = array[0];
+
+ String ret = "<img src=\""+ Tools.getBaseURL() + "images/" + "domaine10.png" + "\"> " +Messages.getString("Domaine") + " " + groupValue;
+
+ if (!hideValidation && T != null && T.getExpressionDomain() != null && T.getMethodValidationParameters() != null){
+
+ String val = first.getAttributeAsString("validationDomain");
+
+ if (val != null && !val.equals("2") ){
+ String imgName= "cancel-16x16.png";
+ if (val.equals("1")){
+ imgName = "ok-16x16.png";
+ }
+
+ ret = ret + " <img src=\""+ Tools.getBaseURL() + "images/" + imgName + "\">";
+ }
+
+ }
+
+ return ret;
+
+ }
+ });
+
+
+ array[i++] = dom;
+
+ this.addCellDoubleClickHandler(new CellDoubleClickHandler(){
+
+ public void onCellDoubleClick(CellDoubleClickEvent event) {
+ ListGridField field = getField(event.getColNum());
+
+
+
+
+ if (!readOnlyValidation){
+
+
+
+ // On peut acceder car on ai téoriquement valideur
+ if (provider != null && field.getName().equals("validation")){
+
+
+
+ ListGridRecord record = event.getRecord();
+
+ String issuerUid = UserTools.getUser().getUid();
+
+ Long idComp = record.getAttributeAsLong("competenceId");
+
+ String value = record.getAttributeAsString("validation");
+
+ if (value.equals("0") || value.equals("1")){
+
+
+
+ askQuestion(issuerUid, idComp, record, event.getX(), event.getY());
+ }else if (value.equals("2")){
+ T.getUserValidationState().remove(idComp);
+
+ provider.deleteDemand(login, issuerUid, idComp, false);
+ updateValidationRecords( record );
+ }
+
+
+
+
+ }
+ }
+
+ if (field.getName().startsWith("CI")){
+ // Acces au detail du dossier
+
+
+
+
+ final SmartWindow window = new SmartWindow();
+ window.setOverflow(Overflow.AUTO);
+
+ TileLayout tileLayout = new TileLayout();
+ tileLayout.setTileWidth(200);
+ tileLayout.setTileHeight(150);
+ tileLayout.setWidth100();
+ tileLayout.setTilesPerLine(3);
+
+ ClickHandler clickHandler = new ClickHandler() {
+ public void onClick(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);
+
+
+ window.setWidth(800);
+ window.setHeight(600);
+
+ window.setAutoSize(false);
+
+ window.setCanDragReposition(true);
+ window.setCanDragResize(true);
+
+
+
+ if (positionFromParent){
+
+ window.setTop(getAbsoluteTop()+10);
+ window.setLeft(getAbsoluteLeft()+10);
+
+
+ }else{
+ window.centerInPage();
+ }
+ //window.setLayout(new FitLayout());
+ String sIdESI =field.getAttributeAsString("CI-index");
+
+ Long idESI = new Long(sIdESI.split("-",2)[0]);
+
+ String campCode = field.getAttributeAsString("EDCode");
+ String campName = T.getMapCampagns().get(campCode);
+
+
+ String title = " : " + T.getPlanName() +" / " + campName +" / " + field.getTitle();
+
+ if (userName != null && !userName.equals("")){
+ title = Messages.getString("Dossier") + " de " + userName + title;
+ }else{
+ title = Messages.getString("Dossier") + title;
+ }
+
+ window.setTitle(title);
+
+ EvaluationFolderPanel efp = new EvaluationFolderPanel(login, field.getTitle(), idESI, isShowDetailED());
+
+ //efp.setAutoScroll(true);
+ efp.update();
+ efp.setWidth100();
+ efp.setHeight100();
+
+ window.addItem(efp);
+
+
+ tileLayout.addTile(window);
+ window.show();
+
+
+
+ }
+
+ }
+
+ });
+
+
+
+
+ if (!readOnly){
+
+ final Menu menu = new Menu();
+ menu.setWidth(150);
+
+ MenuItem forceItem = new MenuItem(Messages.getString("Forcer_la_transmission"));
+ forceItem.setCheckIfCondition(new MenuItemIfFunction() {
+ public boolean execute(Canvas target, Menu menu, MenuItem item) {
+ return true;
+ }
+ });
+ forceItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
+ public void onClick(MenuItemClickEvent event) {
+
+
+ Record r = getRecord(selectedCIRowIndex);
+
+ if (r != null){
+ Object cio = r.getAttributeAsObject("CIObject" + selectedCIIndex);
+ if (cio != null && !cio.equals("")){
+ TCompetenceInstance ci = (TCompetenceInstance)cio;
+
+ ci.setModified(true);
+ ci.setState(CompetenceInstance.TRANSMITTED);
+ if (!modified.containsKey(selectedCIRowIndex)){
+ modified.put(selectedCIRowIndex, new ArrayList<String>());
+ }
+ modified.get(selectedCIRowIndex).add(selectedCIIndex);
+ updateValidationRecords( r );
+ }
+
+ }
+
+ }
+ });
+
+ menu.addItem(forceItem);
+
+ this.addCellContextClickHandler(new CellContextClickHandler(){
+
+ public void onCellContextClick(CellContextClickEvent event) {
+
+ selectedCIRowIndex = -1;
+ selectedCIIndex = "";
+
+ int colIndex= event.getColNum();
+ String index = getIndexFromField(colIndex);
+
+ Record r = event.getRecord();
+
+ if (r != null && !r.equals("") && r.getAttributeAsObject("CIObject" + index) != null ){
+ TCompetenceInstance ci = (TCompetenceInstance) r.getAttributeAsObject("CIObject"+index);
+
+
+ if (ci.getState() == CompetenceInstance.INITIAL){
+
+ selectedCIRowIndex = event.getRowNum();
+ selectedCIIndex = index;
+ }else{
+
+ event.cancel();
+ }
+
+ }else{
+
+ event.cancel();
+ }
+
+ }
+
+ });
+
+ this.setContextMenu(menu);
+ }
+
+
+
+ this.setFields(array);
+
+
+ setAlternateRecordStyles(true);
+ if (!readOnly){
+ setEditEvent(ListGridEditEvent.CLICK);
+ setEditByCell(true);
+ setCanEdit(true);
+ }
+ this.setHoverWidth(300);
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see com.smartgwt.client.widgets.grid.ListGrid#canEditCell(int, int)
+ */
+ protected boolean canEditCell(int row, int col){
+
+ if (readOnly){
+
+ return false;
+ }
+
+ ListGridRecord lgr = this.getRecord(row);
+
+ String index = getIndexFromField(col);
+
+ Object cio = lgr.getAttributeAsObject("CIObject" + index);
+
+ if (lgr != null && cio != null && !cio.equals("")){
+ TCompetenceInstance ci = (TCompetenceInstance) cio;
+
+ if (ci.getState() == CompetenceInstance.TRANSMITTED){
+ return true;
+ }
+
+
+ }
+
+ return false;
+ }
+
+ /**
+ * Compute local map for competence.
+ *
+ * @param record the record
+ * @return the map
+ */
+ public Map<String, Integer> computeLocalMapForCompetence(Record record){
+ int nbtotal = 0;
+ int nbvalidable = 0;
+ int nbnonvalidable = 0;
+
+ for ( String property : record.getAttributes()){
+
+
+ if (property.startsWith("CIObject")){
+ Object o = record.getAttributeAsObject(property);
+
+ if (o != null && !o.equals("")){
+ TCompetenceInstance ci = (TCompetenceInstance) o;
+ if (ci.isValidable()) {
+ nbvalidable++;
+ } else {
+ nbnonvalidable++;
+ }
+
+ }
+ nbtotal++;;
+ }
+
+
+ }
+ Map<String, Integer> localMap = new HashMap<String, Integer>();
+
+ localMap.put("nbtotal", nbtotal);
+ localMap.put("nbvalidable", nbvalidable);
+ localMap.put("nbnonvalidable", nbnonvalidable);
+
+ return localMap;
+ }
+
+
+
+
+ /**
+ * Update validation records.
+ *
+ * @param record the record
+ */
+ public void updateValidationRecords(Record record){
+
+ String competenceValidationValue = computeValidationValue(record);
+
+ record.setAttribute("validation", competenceValidationValue);
+
+ Map<String, Integer> localDomain = mapDomain.get(record.getAttributeAsLong("domainId"));
+
+ if (competenceValidationValue.equals("0") || competenceValidationValue.equals("2")){
+ localDomain.put("nbcompetencedomainwrong", localDomain.get("nbcompetencedomainwrong") + 1);
+ localDomain.put("nbcompetencedomainok", localDomain.get("nbcompetencedomainok") - 1);
+ }else{
+ localDomain.put("nbcompetencedomainok", localDomain.get("nbcompetencedomainok") + 1);
+ localDomain.put("nbcompetencedomainwrong", localDomain.get("nbcompetencedomainwrong") - 1);
+ }
+
+ String resDomain = computeValidationDomainValue(localDomain);
+
+ for (Record r : getRecords()){
+
+ Long currentDomain = r.getAttributeAsLong("domainId");
+ if (currentDomain.equals(record.getAttributeAsLong("domainId"))){
+ r.setAttribute("validationDomain", resDomain);
+
+ r.setAttribute("domain", r.getAttribute("domain"));
+ }
+
+ }
+
+ this.redraw();
+
+ }
+
+
+
+ /**
+ * Update.
+ *
+ * @param T the t
+ */
+ public void update(TUserCompositeValidation T){
+ this.T = T;
+
+ // <Domain id <"variablename", nummberof>>
+ mapDomain = new HashMap<Long, Map<String, Integer>>();
+
+ ListGridRecord[] array = new ListGridRecord[T.getCompetences().size()];
+
+ int i = 0;
+
+ Set<String> ss = new HashSet<String>();
+
+ for (Entry<Long, Map<String, TCompetenceInstance>> entry : T.getMap()
+ .entrySet()){
+
+ ListGridRecord lgr = new ListGridRecord();
+
+ Long competenceId = entry.getKey();
+ String competenceName = T.getCompetenceName(competenceId);
+ Map<String, TCompetenceInstance> mm = entry.getValue();
+
+ lgr.setAttribute("competence", competenceName);
+
+ int nbtotal = 0;
+ int nbvalidable = 0;
+ int nbnonvalidable = 0;
+ // Positions
+
+ int j = 1;
+
+ TDomain tdom = T.getMapCompetenceDomain().get(competenceId);
+ for (String code : T.getCampagnsKeys()){
+
+ for (String idESI : T.getMapEDESI().get(code)) {
+ String index = getIndexFromField(j);
+
+ if (mm.containsKey(idESI)) {
+
+ TCompetenceInstance ci = mm.get(idESI);
+
+ if (!ss.contains("CI" + index)){
+ ss.add("CI" + index);
+ ListGridField lgf = this.getField("CI" + index);
+
+ LinkedHashMap<String, String>map = new LinkedHashMap<String, String>();
+
+ List<Level> ll = new ArrayList<Level>(ci.getLevel().getMethodEval().getLevels());
+
+ Collections.sort(ll, new Comparator<Level>(){
+
+ public int compare(Level l1, Level l2) {
+ return l1.getValue() - l2.getValue();
+ }
+
+ });
+
+ for (Level l : ll) {
+ String name = l.getName();
+
+ if (l.getInitial()){
+ name = "<span style='color:#000000;'>" +name+ "</span>";
+ }else if (l.isThreshold() || l.isGreaterThanThreshold()) {
+ name = "<span style='color:#008600;'>" +name+ "</span>";
+ }else{
+ name = "<span style='color:#FF0000;'>" +name+ "</span>";
+ }
+
+ map.put(l.getId().toString(), name);
+
+ }
+
+ lgf.setValueMap(map);
+ }
+
+ lgr.setAttribute("CI" + index , ci.getLevel().getId().toString());
+
+ lgr.setAttribute("CIObject" + index , ci);
+
+ nbtotal++;
+ if (ci.isValidable()) {
+ nbvalidable++;
+ } else {
+ nbnonvalidable++;
+ }
+
+ } else {
+ lgr.setAttribute("CI" + index , "");
+ }
+ j++;
+
+ }
+ }
+ // Add Validation field
+
+ lgr.setAttribute("domainId", tdom.getId());
+ lgr.setAttribute("domain", tdom.getName());
+ lgr.setAttribute("competenceId", competenceId);
+
+ if (!hideValidation){
+ Map<String, Integer> localMap = new HashMap<String, Integer>();
+
+ localMap.put("nbtotal", nbtotal);
+ localMap.put("nbvalidable", nbvalidable);
+ localMap.put("nbnonvalidable", nbnonvalidable);
+
+ String resCompetence = computeValidationValue(competenceId, localMap);
+
+
+ lgr.setAttribute("validation", resCompetence);
+
+ if (!mapDomain.containsKey(tdom.getId())){
+
+
+ Map<String, Integer> c = new HashMap<String, Integer>();
+
+ c.put("nbcompetencedomainok", 0);
+ c.put("nbcompetencedomainwrong", 0);
+ c.put("nbcompetencedomain", 0);
+
+
+ mapDomain.put(tdom.getId(),c);
+
+ }
+
+ Map<String, Integer> count = mapDomain.get(tdom.getId());
+
+ count.put("nbcompetencedomain", count.get("nbcompetencedomain") + 1);
+
+ if (resCompetence.equals("0") || resCompetence.equals("2")){
+ count.put("nbcompetencedomainwrong", count.get("nbcompetencedomainwrong") + 1);
+ }else{
+ count.put("nbcompetencedomainok", count.get("nbcompetencedomainok") + 1);
+ }
+ }
+
+ array[i++] = lgr;
+
+ }
+
+ if (!hideValidation){
+ for (ListGridRecord record : array){
+
+ Long domainId = record.getAttributeAsLong("domainId");
+
+ String resDomain = computeValidationDomainValue(mapDomain.get(domainId));
+
+ record.setAttribute("validationDomain", resDomain);
+
+ }
+ }
+
+ this.setData(array);
+
+ }
+
+
+
+
+ /**
+ * Compute validation value.
+ *
+ * @param record the record
+ * @return the string
+ */
+ public String computeValidationValue(Record record){
+
+ Long competenceId = record.getAttributeAsLong("competenceId");
+
+ Map<String, Integer> localMap = computeLocalMapForCompetence(record);
+
+ return computeValidationValue(competenceId, localMap);
+
+
+ }
+
+ /**
+ * Compute validation value.
+ *
+ * @param competenceId the competence id
+ * @param localMap the local map
+ * @return the string
+ */
+ public String computeValidationValue(Long competenceId, Map<String, Integer> localMap){
+ Integer state = null;
+ if (T.getUserValidationState().containsKey(competenceId)){
+ state = T.getUserValidationState().get(competenceId);
+ }
+
+ if (state != null){
+ return "" + state;
+ }
+
+ boolean result = false;
+
+ try{
+ result = applyMethodValidation(T.getExpression(), localMap);
+ }catch (Exception e){
+ }
+
+ if (result){
+ return "1";
+ }
+ return "0";
+ }
+
+
+ /**
+ * Compute validation domain value.
+ *
+ * @param localMap the local map
+ * @return the string
+ */
+ public String computeValidationDomainValue(Map<String, Integer> localMap){
+
+ String result = "0";
+
+ try{
+ boolean b = applyMethodValidation(T.getExpressionDomain(), localMap);
+
+ if (b){
+ result = "1";
+ }
+ }catch (Exception e){
+ //e.printStackTrace();
+ result = "2";
+ }
+
+ return result;
+
+
+ }
+
+ /**
+ * Apply method validation.
+ *
+ * @param expression the expression
+ * @param localMap the local map
+ * @return true, if successful
+ */
+ public boolean applyMethodValidation(String expression, Map<String, Integer> localMap){
+
+ String params = buildEvalScript(localMap);
+ String paramsNull = buildEvalScriptNULL(localMap);
+ return applyMethodValidationFinal(expression, params, paramsNull);
+
+ }
+
+
+ /**
+ * Apply method validation final.
+ *
+ * @param expression the expression
+ * @param evalItems the eval items
+ * @param evalItemsNull the eval items null
+ * @return true, if successful
+ */
+ public native boolean applyMethodValidationFinal(String expression, String evalItems, String evalItemsNull) /*-{
+
+ var nbtotal = -1;
+ try{
+ eval(evalItems);
+ }catch(e){
+ }
+ try{
+ if (nbtotal == 0){
+ return false;
+ }
+ }catch (e){
+ }
+
+ eval('var exp = '+expression);
+
+ try{
+ return exp;
+ }catch(e){
+ }
+ return false;
+ }-*/;
+
+
+
+ /**
+ * Builds the eval script.
+ *
+ * @param localMap the local map
+ * @return the string
+ */
+ public String buildEvalScript(Map<String, Integer> localMap){
+
+ String ev = "";
+
+ for (Entry<String, Integer> entry : T.getMethodValidationParameters().entrySet()){
+
+ ev = ev + "var " + entry.getKey()+ "=" + entry.getValue() + ";";
+
+ }
+ for (Entry<String, Integer> entry : localMap.entrySet()){
+
+ ev = ev + "var " + entry.getKey()+ "=" + entry.getValue() + ";";
+
+ }
+
+ return ev;
+
+
+ }
+
+ /**
+ * Builds the eval script null.
+ *
+ * @param localMap the local map
+ * @return the string
+ */
+ public String buildEvalScriptNULL(Map<String, Integer> localMap){
+
+ String ev = "";
+
+ for (Entry<String, Integer> entry : T.getMethodValidationParameters().entrySet()){
+
+ ev = ev + "var " + entry.getKey()+ "=null;";
+
+ }
+ for (Entry<String, Integer> entry : localMap.entrySet()){
+
+ ev = ev + "var " + entry.getKey()+ "=null;";
+
+ }
+
+ return ev;
+
+ }
+
+
+ /* *//** Gets the competence instances.
+ *
+ * @return the competence instances
+ */
+ public Set<TCompetenceInstance> getCompetenceInstances() {
+
+
+
+ Set<TCompetenceInstance> sci = new HashSet<TCompetenceInstance>();
+
+ if (readOnly){
+ return sci;
+ }
+
+ for ( Entry<Integer, List<String>> entry : modified.entrySet()){
+
+ int row = entry.getKey();
+
+ Record record = this.getRecord(row);
+ List<String> li = entry.getValue();
+ for (String col : li){
+
+ Object cio = record.getAttributeAsObject("CIObject" + col);
+
+
+ if (cio != null && !cio.equals("")){
+ TCompetenceInstance ci = (TCompetenceInstance) cio;
+ if (ci.isModified()){
+ sci.add(ci);
+ ci.setModified(false);
+ }
+
+ }
+
+ }
+
+ }
+
+ modified.clear();
+
+ return sci;
+
+ }
+
+ /**
+ * Gets the index from field.
+ *
+ * @param colIndex the col index
+ * @return the index from field
+ */
+ private String getIndexFromField(int colIndex){
+
+ ListGridField f = getField(colIndex);
+
+ if (f != null && f.getAttributeAsString("CI-index") != null){
+ return f.getAttributeAsString("CI-index");
+ }
+ return "";
+
+ }
+
+
+ /**
+ * Checks if is show detail ed.
+ *
+ * @return true, if is show detail ed
+ */
+ public boolean isShowDetailED() {
+ return showDetailED;
+ }
+
+
+ /**
+ * Sets the show detail ed.
+ *
+ * @param showDetailED the new show detail ed
+ */
+ public void setShowDetailED(boolean showDetailED) {
+ this.showDetailED = showDetailED;
+ }
+
+ /**
+ * Sets the position from parent.
+ *
+ * @param flag the new position from parent
+ */
+ public void setPositionFromParent(boolean flag){
+ this.positionFromParent = flag;
+ }
+
+
+ /**
+ * Gets the stats.
+ *
+ * @return the stats
+ */
+ public Map<String,Integer> getStats(){
+
+ Map<String, Integer> map = new HashMap<String, Integer>();
+
+ map.put("valid", 0);
+ map.put("invalid", 0);
+ map.put("wait", 0);
+ map.put("total", 0);
+
+ for (ListGridRecord lgr : this.getRecords()){
+
+ String v = lgr.getAttributeAsString("validation");
+ if (v.equals(""+TUserCompositeValidation.VALIDATE)) {
+
+ map.put("valid", map.get("valid") + 1);
+
+ }else if (v.equals(""+TUserCompositeValidation.INVALIDATE)){
+ map.put("invalid", map.get("invalid") + 1);
+
+ }else{
+ map.put("wait", map.get("wait") + 1);
+
+ }
+ map.put("total", map.get("total") + 1);
+ }
+
+
+ return map;
+ }
+
+
+ public Map<String, Integer> getStatsDomain(){
+ Map<String, Integer> map = new HashMap<String, Integer>();
+
+ map.put("valid", 0);
+ map.put("invalid", 0);
+ map.put("wait", 0);
+ map.put("total", 0);
+
+ Set<Long> ids = new HashSet<Long>();
+
+ for (ListGridRecord lgr : this.getRecords()){
+ Long domainId = lgr.getAttributeAsLong("domainId");
+
+ if (!ids.contains(domainId)){
+
+ ids.add(domainId);
+
+ String v = lgr.getAttribute("validationDomain");
+
+ if (v.equals("1")){
+ map.put("valid", map.get("valid") + 1);
+ }else if (v.equals("0")){
+ map.put("invalid", map.get("invalid") + 1);
+ }else{
+ map.put("wait", map.get("wait") + 1);
+ }
+
+ map.put("total", map.get("total") + 1);
+
+ }
+
+ }
+
+ return map;
+ }
+
+ private void askQuestion(final String issuerUid, final Long idComp, final ListGridRecord record, int x, int y){
+ final SmartWindow window = new SmartWindow();
+ window.setTitle(Messages.getString("motivation"));
+ window.setTop(y);
+ window.setLeft(x);
+ window.setWidth(600);
+ window.setHeight(500);
+ 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);
+ //window.setLayout(new FitLayout());
+ window.setCanDragReposition(true);
+ window.setCanDragResize(true);
+
+ final VLayout superContainer = new VLayout();
+ superContainer.setWidth100();
+ superContainer.setHeight100();
+
+
+
+ final RichTextEditor richTextEditor = new RichTextEditor();
+ // richTextEditor.setHeight(155);
+ richTextEditor.setOverflow(Overflow.HIDDEN);
+ richTextEditor.setCanDragResize(true);
+ richTextEditor.setShowEdges(true);
+
+ // Standard control group options include
+ // "fontControls", "formatControls", "styleControls" and "colorControls"
+ //richTextEditor.setControlGroups(new String[]{"fontControls", "styleControls"});
+ richTextEditor.setValue("");
+ superContainer.addMember(richTextEditor);
+
+ final HLayout hlayout = new HLayout();
+ hlayout.setHeight(20);
+ hlayout.setWidth100();
+ hlayout.setAlign(Alignment.RIGHT);
+ hlayout.setAlign(VerticalAlignment.CENTER);
+
+ superContainer.addMember(hlayout);
+
+
+ IButton validerButton = new IButton(Messages.getString("Valider"));
+
+ validerButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler(){
+
+ public void onClick(ClickEvent event) {
+
+ String motiv = richTextEditor.getValue();
+
+
+ T.getUserValidationState().put(idComp, TUserCompositeValidation.WAIT);
+ provider.askDemand(login, issuerUid, idComp, motiv);
+
+
+
+
+
+ updateValidationRecords( record );
+
+ window.hide();
+ }
+
+
+
+ });
+
+
+
+ hlayout.addMember(validerButton);
+
+ IButton cancelButton = new IButton(Messages.getString("Annuler"));
+
+ cancelButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler(){
+
+ public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
+ window.hide();
+
+ }
+
+ });
+
+
+ hlayout.addMember(cancelButton);
+
+ window.addItem(superContainer);
+ window.show();
+
+
+ }
+
+}