--- /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.dashboard;
+
+import java.util.Map;
+import java.util.Set;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.gwtext.client.data.ArrayReader;
+import com.gwtext.client.data.FieldDef;
+import com.gwtext.client.data.MemoryProxy;
+import com.gwtext.client.data.ObjectFieldDef;
+import com.gwtext.client.data.Record;
+import com.gwtext.client.data.RecordDef;
+import com.gwtext.client.data.SimpleStore;
+import com.gwtext.client.data.Store;
+import com.gwtext.client.data.StringFieldDef;
+import com.gwtext.client.widgets.form.ComboBox;
+import com.gwtext.client.widgets.form.FieldSet;
+import com.gwtext.client.widgets.form.NumberField;
+import com.gwtext.client.widgets.form.TextField;
+import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
+import com.gwtext.client.widgets.grid.CellMetadata;
+import com.gwtext.client.widgets.grid.ColumnConfig;
+import com.gwtext.client.widgets.grid.ColumnModel;
+import com.gwtext.client.widgets.grid.EditorGridPanel;
+import com.gwtext.client.widgets.grid.Renderer;
+import com.pentila.evalcomp.client.ConnexionServer;
+import com.pentila.evalcomp.client.i18n.Messages;
+import com.pentila.evalcomp.client.utilities.Tools;
+import com.pentila.evalcomp.domain.Group;
+import com.pentila.evalcomp.domain.User;
+import com.pentila.evalcomp.domain.transit.TReferentiel;
+import com.rednels.ofcgwt.client.ChartWidget;
+import com.rednels.ofcgwt.client.model.ChartData;
+import com.rednels.ofcgwt.client.model.elements.PieChart;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class OFCGroupDashboardFieldSet. GUI part that show a group stats chart
+ */
+public class OFCGroupDashboardFieldSet extends FieldSet {
+
+ /** The chart. */
+ PieChart chart = null;
+
+ /** The content. */
+ private VerticalPanel content;
+
+ /** The content chart. */
+ private VerticalPanel contentChart;
+
+ /** The grid legend. */
+ EditorGridPanel grid = null;
+
+ /** The referentiel choosed. */
+ private TReferentiel tRef = null;
+
+ /** The user used to search group. */
+ private User user = null;
+
+ /**
+ * Instantiates a new oFC group dashboard field set.
+ *
+ * @param tref
+ * the referentiel used to update the dashboard
+ * @param user
+ * the user used to update the dashboard
+ * @param ownDashboard
+ * Set if the user is looking is own dashborad or not
+ */
+ public OFCGroupDashboardFieldSet(TReferentiel tref, User user,
+ boolean ownDashboard) {
+ super();
+
+ if (ownDashboard) {
+ this.setTitle(Messages.getString("Les_resultats_de_vos_groupes"));
+ } else {
+ this.setTitle(Messages.getString("Les_resultats_de_ses_groupes"));
+ }
+ this.setIconCls("iconGroup16");
+
+ this.tRef = tref;
+ this.user = user;
+
+ content = new VerticalPanel();
+ content.setSpacing(5);
+ this.add(content);
+
+ this.initializeGroupCombo();
+
+ }
+
+ /**
+ * Initialize group comboBox from user informations.
+ */
+ private void initializeGroupCombo() {
+
+ AsyncCallback callback = new AsyncCallback() {
+ public void onFailure(Throwable caught) {
+ System.out
+ .println("Probleme dans la récup des groupes du user");
+ }
+
+ public void onSuccess(Object result) {
+ Set<Group> tSetGrp = (Set<Group>) result;
+
+ Object[][] objList = new Object[tSetGrp.size()][];
+
+ for (int i = 0; i < tSetGrp.size(); i++) {
+ Group tGrp = (Group) tSetGrp.toArray()[i];
+ Object[] monObjet = new Object[] { tGrp.getUid(), tGrp };
+ objList[i] = monObjet;
+ }
+
+ SimpleStore storeGrp = new SimpleStore(0, new FieldDef[] {
+ new StringFieldDef("labelGrp"),
+ new ObjectFieldDef("objectGrp") }, objList);
+ storeGrp.load();
+ storeGrp.sort("labelGrp");
+
+ ComboBox cb = new ComboBox();
+
+ cb.setForceSelection(true);
+ cb.setStore(storeGrp);
+ cb.setDisplayField("labelGrp");
+
+ cb.setMode(ComboBox.LOCAL);
+ cb.setEditable(false);
+ cb.setTriggerAction(ComboBox.ALL);
+ cb.setTypeAhead(true);
+ cb.setSelectOnFocus(true);
+ cb.setWidth(180);
+ cb.setHideTrigger(false);
+
+ cb.addListener(new ComboBoxListenerAdapter() {
+ @Override
+ public void onSelect(ComboBox comboBox, Record record,
+ int index) {
+ initializeGrpStat((Group) record
+ .getAsObject("objectGrp"));
+ }
+ });
+
+ HorizontalPanel cbHpan = new HorizontalPanel();
+ cbHpan.setSpacing(3);
+ Label choixGrpLabel = new Label(Messages.getString("Groupe"));
+ choixGrpLabel.setStyleName("label-padding-right");
+ cbHpan.add(choixGrpLabel);
+ cbHpan.add(cb);
+ content.add(cbHpan);
+
+ contentChart = new VerticalPanel();
+
+ content.add(contentChart);
+
+ if (storeGrp.getTotalCount() != 0) {
+ cb.setValue(storeGrp.getAt(0).getAsString("labelGrp"));
+ initializeGrpStat((Group) storeGrp.getAt(0).getAsObject(
+ "objectGrp"));
+ }
+
+ }
+ };
+ ConnexionServer.entityService.getGroupsOfUser(user.getUid(), callback);
+
+ }
+
+ /**
+ * Initialize grp results GUI, chart and legend from stats data.
+ *
+ * @param stats
+ * A map that store datas to show. Used keys are "validable" and
+ * "nonvalidable".
+ */
+ private void initializeGrpResults(Map<String, Integer> stats) {
+
+
+ if (stats == null){
+
+
+ contentChart.add(new Label(Messages.getString("Le_nombre_de_membres_de_ce_groupe_est_trop_important")));
+
+
+ }else{
+ Float valid = stats.get("validable").floatValue();
+
+ Float nonValid = stats.get("nonvalidable").floatValue();
+
+ Integer tmpVal = (int) (((valid * new Float(100)) / (valid + nonValid)) * new Float(
+ 100));
+ valid = (tmpVal.floatValue() / 100);
+
+ nonValid = 100 - valid;
+
+
+ Object[][] objList = new Object[][] {
+ new Object[] {
+ "validables", "" + valid + "%", Messages.getString("couleur_OFC_validables") },
+ new Object[] {
+ "non validables", "" + nonValid + "%", Messages.getString("couleur_OFC_nonvalidables") }, };
+
+ MemoryProxy proxy = new MemoryProxy(objList);
+ RecordDef recordDef = new RecordDef(
+ new FieldDef[] {
+ new StringFieldDef("competence"), new StringFieldDef("percent"),
+ new StringFieldDef("legend") });
+
+ ArrayReader reader = new ArrayReader(recordDef);
+ final Store store = new Store(proxy, reader);
+ store.load();
+
+
+
+ ChartWidget chart = new ChartWidget();
+
+ String swfurl = Tools.getBaseURL() + "ofcgwt/open-flash-chart.swf";
+
+ chart.setFlashUrl("");
+ chart.setUrlPrefix(swfurl);
+ chart.setCacheFixEnabled(true);
+
+
+ ChartData cd = new ChartData();
+ cd.setBackgroundColour("#ffffff");
+ PieChart pie = new PieChart();
+ pie.setAlpha(0.3f);
+ pie.setNoLabels(true);
+ pie.setTooltip("#label#: #percent#");
+ pie.setAnimateOnShow(true);
+ pie.setGradientFill(true);
+ pie.setColours(
+ Messages.getString("couleur_OFC_validables"), Messages.getString("couleur_OFC_nonvalidables"));
+ pie.addSlices(new PieChart.Slice(
+ stats.get("validable"), Messages.getString("Valides")));
+ pie.addSlices(new PieChart.Slice(
+ stats.get("nonvalidable"), Messages.getString("Non_valides")));
+ cd.addElements(pie);
+ chart.setSize("240", "240");
+ chart.setJsonData(cd.toString());
+
+ contentChart.add(chart);
+
+ ColumnConfig responseConfig = new ColumnConfig("",
+ "competence", 80, true);
+ TextField textField = new TextField();
+ textField.setSelectOnFocus(true);
+
+ NumberField numberField = new NumberField();
+ numberField.setSelectOnFocus(true);
+
+ ColumnConfig countConfig = new ColumnConfig(" %", "percent", 50,
+ true);
+
+
+ ColumnConfig legendConfig = new ColumnConfig(" ", "legend", 5, true);
+ legendConfig.setRenderer(new Renderer() {
+ public String render(Object value, CellMetadata cellMetadata,
+ Record record, int rowIndex, int colNum, Store store) {
+ cellMetadata.setHtmlAttribute("style=\"background:" + value
+ + ";\"");
+ return "";
+ }
+ });
+
+ ColumnModel columnModel = new ColumnModel(new ColumnConfig[] {
+ responseConfig, countConfig, legendConfig });
+
+ grid = new EditorGridPanel();
+ grid.setStore(store);
+
+ grid.setColumnModel(columnModel);
+ grid.setWidth(225);
+ grid.setEnableColumnHide(false);
+ grid.setEnableColumnMove(false);
+ grid.setEnableColumnResize(false);
+ grid.getView().setForceFit(true);
+ contentChart.add(grid);
+ }
+
+ }
+
+ /**
+ * Ask stats about the group choosed to instanceManager.
+ *
+ * @param tGrp
+ * the group choosed
+ */
+ private void initializeGrpStat(Group tGrp) {
+
+ contentChart.clear();
+
+ AsyncCallback callback = new AsyncCallback() {
+ public void onFailure(Throwable caught) {
+ System.out.println("Probleme dans la maj des eval Folder");
+ }
+
+ public void onSuccess(Object result) {
+
+ Map<String, Integer> stats = (Map<String, Integer>) result;
+ initializeGrpResults(stats);
+
+ }
+ };
+ ConnexionServer.instanceService.getGroupStat(tGrp.getUid(),
+ tRef.getId(), 500, callback);
+ }
+
+}