--- /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.evaluation;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.gwtext.client.core.EventObject;
+import com.gwtext.client.core.Ext;
+import com.gwtext.client.core.SortDir;
+import com.gwtext.client.data.ArrayReader;
+import com.gwtext.client.data.DataProxy;
+import com.gwtext.client.data.FieldDef;
+import com.gwtext.client.data.MemoryProxy;
+import com.gwtext.client.data.ObjectFieldDef;
+import com.gwtext.client.data.Reader;
+import com.gwtext.client.data.Record;
+import com.gwtext.client.data.RecordDef;
+import com.gwtext.client.data.SortState;
+import com.gwtext.client.data.Store;
+import com.gwtext.client.data.StringFieldDef;
+import com.gwtext.client.dd.DragData;
+import com.gwtext.client.dd.DragSource;
+import com.gwtext.client.dd.DropTarget;
+import com.gwtext.client.dd.DropTargetConfig;
+import com.gwtext.client.util.Format;
+import com.gwtext.client.widgets.Panel;
+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.GridDragData;
+import com.gwtext.client.widgets.grid.GridPanel;
+import com.gwtext.client.widgets.grid.Renderer;
+import com.pentila.evalcomp.client.i18n.Messages;
+import com.pentila.evalcomp.client.mainTab.IHasExamen;
+import com.pentila.evalcomp.client.utilities.GridPanelDropable;
+import com.pentila.evalcomp.client.utilities.Tools;
+import com.pentila.evalcomp.domain.definition.EvaluationDefinition;
+import com.pentila.evalcomp.domain.examen.Examen;
+import com.pentila.evalcomp.domain.examen.ExamenDef;
+import com.pentila.evalcomp.domain.transit.TExamen;
+
+
+/**
+ * The Class MethodEvalDefWidget.
+ */
+public class ExamenDefWidget extends GridPanelDropable {
+
+ /** The methodEval panel. */
+
+ private Panel examenPanel;
+
+ /** The provider. */
+ private IHasExamen provider;
+
+ RecordDef recordDef = new RecordDef(new FieldDef[] {
+ new StringFieldDef("id"),
+ new StringFieldDef("name"),
+ new ObjectFieldDef("object") });
+
+ private Store store;
+
+ private ColumnModel colModel;
+
+
+ private Renderer render = new Renderer() {
+ public String render(Object value, CellMetadata cellMetadata,
+ Record record, int rowIndex, int colNum, Store store) {
+
+
+ String icon = "<img src=\"" + Tools.getBaseURL()
+ + "images/examen16.png\"> {0}";
+
+ return Format.format(icon, new String[] { record
+ .getAsString("name"), });
+ }
+ };
+
+
+ /**
+ * Instantiates a new plan def widget.
+ *
+ * @param provider the provider
+ * @param meDef the me def
+ */
+ public ExamenDefWidget(IHasExamen provider, Set<Examen> sExamen) {
+ super();
+ this.provider = provider;
+ this.initializeInterface();
+ //this.updateInterface(sExamen);
+ }
+
+ /**
+ * Initialize interface.
+ */
+ private void initializeInterface() {
+
+ this.setTitle(Messages.getString("Examens"));
+ this.setIconCls("iconExamen32");
+
+ DataProxy proxy = new MemoryProxy(new Object[0][]);
+ Reader reader = new ArrayReader(recordDef);
+ store = new Store(proxy, reader);
+ store.setSortInfo(new SortState("name", SortDir.ASC));
+ store.load();
+ this.setStore(store);
+
+
+ ColumnConfig cc = new ColumnConfig("Nom", "name", 213, true, render);
+
+ colModel = new ColumnModel(new ColumnConfig[]{cc});
+
+ this.setColumnModel(colModel);
+
+ this.setWidth(220);
+ this.setHeight(300);
+
+
+
+ EvalManagementTab emt = (EvalManagementTab)this.provider;
+
+ if (!emt.isReadOnly()){
+ this.setEnableDragDrop(true);
+ this.setDdGroup("evalCompDDGroup");
+
+ DropTargetConfig cfg = new DropTargetConfig();
+ cfg.setdDdGroup("evalCompDDGroup");
+
+
+ new DropTarget(this, cfg) {
+ @Override
+ public boolean notifyDrop(DragSource source, EventObject e,
+ DragData data) {
+ EvalManagementTab emt = (EvalManagementTab)provider;
+ if (emt.currentEvalShown.getState() != EvaluationDefinition.INITIAL){
+ return false;
+ }
+ try {
+ GridDragData myData = (GridDragData) data;
+ GridPanel myGrid = (GridPanel) Ext.getCmp(myData.getGrid()
+ .getId());
+ if (myGrid.getId().startsWith("examenGridPalette")) {
+
+ Record[] arrayRecords = myGrid.getSelectionModel().getSelections();
+
+
+
+ removeClass("targetDragRed");
+ return dropAction(arrayRecords);
+
+ }
+ } catch (Exception ex) {
+
+ return false;
+ }
+ return false;
+ }
+
+ @Override
+ public String notifyOver(DragSource source, EventObject e,
+ DragData data) {
+ EvalManagementTab emt = (EvalManagementTab)provider;
+ if (emt.currentEvalShown.getState() != EvaluationDefinition.INITIAL){
+ return "";
+ }
+ try {
+ GridDragData myData = (GridDragData) data;
+ GridPanel myGrid = (GridPanel) Ext.getCmp(myData.getGrid()
+ .getId());
+ if (myGrid.getId().startsWith("examenGridPalette")) {
+
+ Record[] rows = myGrid.getSelectionModel().getSelections();
+ for (Record row : rows) {
+
+ TExamen im = (TExamen) row.getAsObject("object");
+
+ if (!(im instanceof TExamen)){
+ return "";
+ }
+ }
+
+ return "x-dd-drop-ok";
+ }
+ return "";
+ } catch (Exception ex) {
+ return "";
+ }
+ }
+ };
+
+
+ }
+
+ }
+
+ /**
+ * Update interface.
+ *
+ * @param meDef
+ * the me def
+ */
+ public void updateInterface(final Set<ExamenDef> sExamen) {
+
+ Object[][] objectList = new Object[sExamen.size()][];
+ int i = 0;
+ for (ExamenDef examenDef : sExamen){
+
+ objectList[i++] = new Object[]{examenDef.getId().toString(), examenDef.getName(), examenDef};
+
+ }
+
+ DataProxy proxy = new MemoryProxy(objectList);
+ this.getStore().setDataProxy(proxy);
+ this.getStore().reload();
+
+
+ }
+
+ /**
+ * Drop action.
+ *
+ * @param rec
+ * the rec
+ *
+ * @return true, if successful
+ */
+ public boolean dropAction(Record[] array) {
+
+ Set<Examen> se = new HashSet<Examen>();
+
+
+ for (Record record : array){
+
+ TExamen texamen = (TExamen)record.getAsObject("object");
+
+ se.add(texamen.getExamen());
+
+ }
+
+
+
+
+ return provider.associateExamens(se);
+ }
+
+ public boolean isTrashable(Object ...objects) {
+ EvalManagementTab emt = (EvalManagementTab)this.provider;
+ if (emt != null && !emt.isReadOnly() && emt.getCurrentEvalShown().getState() == EvaluationDefinition.INITIAL){
+ return true;
+ }
+ return false;
+ }
+
+
+ public void trashedElements(Object ...objects) {
+ Record[] rows = this.getSelectionModel().getSelections();
+ Set<ExamenDef> se = new HashSet<ExamenDef>();
+
+ for (Record record : rows){
+ se.add((ExamenDef)record.getAsObject("object"));
+ }
+
+ provider.removeExamens(se);
+ }
+
+ public Panel getMePanel() {
+ return examenPanel;
+ }
+
+ public void setMePanel(Panel mePanel) {
+ this.examenPanel = mePanel;
+ }
+
+
+}