--- /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.palette;
+
+import java.util.Set;
+
+import com.google.gwt.http.client.RequestBuilder;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.gwtext.client.core.EventObject;
+import com.gwtext.client.core.Function;
+import com.gwtext.client.data.FieldDef;
+import com.gwtext.client.data.ObjectFieldDef;
+import com.gwtext.client.data.Record;
+import com.gwtext.client.data.SimpleStore;
+import com.gwtext.client.data.Store;
+import com.gwtext.client.data.StringFieldDef;
+import com.gwtext.client.util.Format;
+import com.gwtext.client.widgets.Panel;
+import com.gwtext.client.widgets.Tool;
+import com.gwtext.client.widgets.event.PanelListenerAdapter;
+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.GridPanel;
+import com.gwtext.client.widgets.grid.Renderer;
+import com.gwtext.client.widgets.grid.event.GridListenerAdapter;
+import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;
+import com.gwtext.client.widgets.layout.FitLayout;
+import com.pentila.evalcomp.client.ConnexionServer;
+import com.pentila.evalcomp.client.i18n.Messages;
+import com.pentila.evalcomp.client.utilities.GridPanelDropable;
+import com.pentila.evalcomp.client.utilities.ITabManager;
+import com.pentila.evalcomp.client.utilities.Tools;
+import com.pentila.evalcomp.client.utilities.UserTools;
+import com.pentila.evalcomp.domain.transit.TReferentiel;
+
+/**
+ * The Class DashboardPalettePanel. Create a widget to access the dashboard of a
+ * user.
+ */
+public class DashboardPalettePanel extends AbstractPalettePanel {
+
+ /** The cfg column model dashboard. */
+ private ColumnModel cfgColumnModelDashboard;
+
+ /** The cfg columns dashboard. */
+ private ColumnConfig[] cfgColumnsDashboard;
+
+
+ /** The dashboard palette initialized. */
+ private boolean dashboardPaletteInitialized = false;
+
+
+
+ /** The store dashboard. */
+ private Store storeDashboard;
+
+ /** The dashboard grid. */
+ public GridPanelDropable dashboardGrid;
+
+
+ /** The render dashboard. */
+ private Renderer renderDashboard = new Renderer() {
+ public String render(Object value, CellMetadata cellMetadata,
+ Record record, int rowIndex, int colNum, Store store) {
+
+ String dashboardName = record.getAsString("dashboardName");
+
+ if (dashboardName.length() > 20) {
+ cellMetadata.setHtmlAttribute("ext:qtip=\"" + dashboardName + "\"");
+ }
+
+ return Format
+ .format(
+ "<img src=\"" + Tools.getBaseURL()
+ + "images/book_open16.png\"> {0}", new String[] { dashboardName, });
+ }
+ };
+
+
+ /**
+ * Instantiates a new dashboard palette panel.
+ */
+ public DashboardPalettePanel(){
+ this(null);
+ }
+
+ /**
+ * Instantiates a new dashboard palette panel.
+ *
+ * @param itManager
+ * the it manager
+ */
+ public DashboardPalettePanel(ITabManager itManager) {
+ super();
+ this.itManager = itManager;
+ this.setTitle(Messages.getString("Mes_tableaux_de_bord"));
+ this.setIconCls("iconTableauDeBord16");
+
+
+ ColumnConfig cc = new ColumnConfig(Messages
+ .getString("Nom"),
+ "dashboardName");
+ cc.setSortable(true);
+ cc.setRenderer(renderDashboard);
+ cc.setDataIndex("dashboardName");
+
+ cfgColumnsDashboard = new ColumnConfig[] { cc };
+ cfgColumnModelDashboard = new ColumnModel(cfgColumnsDashboard);
+
+ this.addTool(new Tool(Tool.REFRESH, new Function() {
+ public void execute() {
+ updateDashboardGrid();
+ }
+ }, Messages.getString("Rafraichir"))); //$NON-NLS-1$
+
+ this.addListener(new PanelListenerAdapter() {
+ @Override
+ public boolean doBeforeExpand(Panel panel, boolean animate) {
+ if (dashboardPaletteInitialized == false) {
+ dashboardPaletteInitialized = true;
+ updateDashboardGrid();
+ }
+
+ return true;
+ }
+ });
+ }
+
+ /**
+ * Initialize palette GUI.
+ */
+ public void initializePalette() {
+ setLayout(new FitLayout());
+ this.setBorder(false);
+ // init Grp
+ storeDashboard = new SimpleStore(new String[] { "dashboardName" }, //$NON-NLS-1$
+ new Object[][] {});
+ storeDashboard.load();
+
+ dashboardGrid = new GridPanelDropable(){
+ public boolean isTrashable(Object ...objects){
+ return false;
+ }
+
+ public void trashedElements(Object ...objects){
+
+ }
+ };
+
+
+ dashboardGrid.setBorder(false);
+ dashboardGrid.setStore(storeDashboard);
+ dashboardGrid.setColumnModel(cfgColumnModelDashboard);
+ dashboardGrid.setEnableDragDrop(false);
+
+ dashboardGrid.setEnableColumnHide(false);
+ dashboardGrid.setEnableColumnMove(false);
+ dashboardGrid.setEnableColumnResize(false);
+ dashboardGrid.setEnableHdMenu(false);
+
+ dashboardGrid.getView().setAutoFill(true);
+ dashboardGrid.getView().setForceFit(true);
+
+ dashboardGrid.addGridRowListener(new GridRowListenerAdapter() {
+ @Override
+ public void onRowContextMenu(GridPanel grid, int rowIndex,
+ EventObject e) {
+ e.stopEvent();
+ }
+
+ @Override
+ public void onRowDblClick(GridPanel grid, int rowIndex,
+ EventObject e) {
+ TReferentiel dashboard = (TReferentiel) dashboardGrid
+ .getStore().getRecordAt(rowIndex).getAsObject(
+ "dashboardObject"); //$NON-NLS-1$
+ ClickOn(dashboard.getId());
+ }
+
+ });
+
+ dashboardGrid.addGridListener(new GridListenerAdapter() {
+ @Override
+ public void onContextMenu(EventObject e) {
+ e.stopEvent();
+ }
+ });
+
+
+ this.add(dashboardGrid);
+ }
+
+ /**
+ * Update dashboard grid.
+ */
+ public void updateDashboardGrid() {
+
+ AsyncCallback callback = new AsyncCallback() {
+
+ public void onFailure(Throwable caught) {
+ System.out.println("Probleme dans la maj des tableaux de bord"); //$NON-NLS-1$
+ Tools.hideLoadingRegion(getId());
+ }
+
+ public void onSuccess(Object result) {
+ Set<TReferentiel> trefSet = (Set<TReferentiel>) result;
+ Object[][] objList = new Object[trefSet.size()][];
+ for (int i = 0; i < trefSet.size(); i++) {
+ TReferentiel e = (TReferentiel) trefSet.toArray()[i];
+ Object[] monObjet = new Object[] { i,
+ Messages.getString("Referentiel") + e.getName(), e }; //$NON-NLS-1$
+ objList[i] = monObjet;
+ }
+
+ storeDashboard = new SimpleStore(0, new FieldDef[] {
+ new StringFieldDef("dashboardNum"), //$NON-NLS-1$
+ new StringFieldDef("dashboardName"), //$NON-NLS-1$
+ new ObjectFieldDef("dashboardObject") }, objList); //$NON-NLS-1$
+ storeDashboard.load();
+ storeDashboard.sort("evalFolderName"); //$NON-NLS-1$
+ dashboardGrid.reconfigure(storeDashboard,
+ cfgColumnModelDashboard);
+ dashboardPaletteInitialized = true;
+ Tools.hideLoadingRegion(getId());
+
+ }
+ };
+ Tools
+ .showLoadingRegion(
+ getId(),
+ Messages.getString("MAJ_tableaux_de_bord"), Messages.getString("Chargement")); //$NON-NLS-1$ //$NON-NLS-2$
+ ConnexionServer.instanceService.getUserReferentiels(UserTools.getUser()
+ .getUid(), callback);
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.client.palette.AbstractPalettePanel#ClickOn(java.lang.Long)
+ */
+ public void ClickOn(Long idReferentiel) {
+
+ AsyncCallback callback = new AsyncCallback() {
+
+ public void onFailure(Throwable arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onSuccess(Object result) {
+ TReferentiel trr = (TReferentiel) result;
+
+ itManager.showDashboard(trr);
+ }
+
+ };
+
+ RequestBuilder rb = ConnexionServer.instanceService
+ .getUserReferentiel(UserTools.getUser().getUid(), idReferentiel, callback);
+ rb.setHeader("code", "A29");
+ ConnexionServer.doSend(rb);
+
+
+ }
+
+}