--- /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.plan.widget;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.gwtext.client.core.EventObject;
+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.widgets.Component;
+import com.gwtext.client.widgets.Container;
+import com.gwtext.client.widgets.MessageBox;
+import com.gwtext.client.widgets.TabPanel;
+import com.gwtext.client.widgets.event.TabPanelListenerAdapter;
+import com.gwtext.client.widgets.tree.TreeDragData;
+import com.gwtext.client.widgets.tree.TreeNode;
+import com.pentila.evalcomp.client.ConnexionServer;
+import com.pentila.evalcomp.client.i18n.Messages;
+import com.pentila.evalcomp.client.plan.PlanManagementTab;
+import com.pentila.evalcomp.domain.definition.Referentiel;
+import com.pentila.evalcomp.domain.plan.Plan;
+import com.pentila.evalcomp.domain.plan.PlanRef;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class RoleDefWidget.
+ */
+public class PlanTabPanelRefWidget extends TabPanel {
+
+ /** The plan. */
+ private Plan currentPlanShown = null;
+
+ /** The readOnly flag. */
+ private Boolean readOnly = true;
+
+ /** The remove panel ref flag. */
+ Boolean removePanelRefFlag = false;
+
+ /** The plan management tab. */
+ private PlanManagementTab planManagementTab;
+
+ /**
+ * Instantiates a new tabPlanRef widget.
+ *
+ * @param planManagementTab the plan management tab
+ * @param plan the plan
+ * @param ro the ro
+ */
+ public PlanTabPanelRefWidget(PlanManagementTab planManagementTab, Plan plan, Boolean ro) {
+ super();
+ this.currentPlanShown = plan;
+ this.readOnly = ro;
+ this.planManagementTab = planManagementTab;
+ this.initializeInterface();
+ }
+
+ /**
+ * Adds the new plan ref.
+ *
+ * @param ref
+ * the ref
+ */
+ public void addNewPlanRef(Referentiel ref) {
+ if (ref != null && currentPlanShown != null) {
+ PlanRef pRef = new PlanRef();
+ pRef.setReferentiel(ref);
+ pRef.setPlan(currentPlanShown);
+
+ AsyncCallback callback = new AsyncCallback() {
+
+ public void onFailure(Throwable caught) {
+ // do some UI stuff to show failure
+ System.out
+ .println("Probleme dans la sauvegarde du plan ref");
+ }
+
+ public void onSuccess(Object result) {
+ if (result != null) {
+ PlanRef pr = (PlanRef) result;
+ currentPlanShown.getPlanRefs().add(pr);
+
+ planManagementTab.updateRefInterface();
+ /*PlanPanelRefWidget pprw = new PlanPanelRefWidget(pt, pr,
+ readOnly);
+ add(pprw);
+ pprw.updateInfoFields();
+
+
+ activate(pprw.getId());
+
+ scrollToTab(pprw, true);*/
+ }
+
+ }
+ };
+ ConnexionServer.planService.addPlanRefToPlan(currentPlanShown
+ .getId(), pRef, callback);
+ }
+
+ }
+
+ /**
+ * Delete plan ref.
+ *
+ * @param pprw
+ * the pprw
+ */
+ private void deletePlanRef(final PlanPanelRefWidget pprw) {
+ if (pprw != null && currentPlanShown != null) {
+ AsyncCallback callback = new AsyncCallback() {
+
+ public void onFailure(Throwable caught) {
+ // do some UI stuff to show failure
+ System.out
+ .println("Probleme dans la sauvegarde du plan ref"); //$NON-NLS-1$
+ }
+
+ public void onSuccess(Object result) {
+ removePanelRefFlag = true;
+ currentPlanShown.getPlanRefs().remove(pprw.getPlanRef());
+ remove(pprw, true);
+
+ }
+ };
+ ConnexionServer.planService.removePlanRef(
+ pprw.getPlanRef().getId(), callback);
+
+ }
+ }
+
+ /**
+ * Initialize interface.
+ */
+ private void initializeInterface() {
+ this.setResizeTabs(true);
+ this.setMinTabWidth(115);
+ this.setTabWidth(135);
+ this.setEnableTabScroll(true);
+ this.setDeferredRender(false);
+ this.setWidth("700px");
+
+
+ this.setHeight(540);
+ this.setActiveTab(0);
+
+ if (!readOnly){
+
+
+ DropTargetConfig cfg = new DropTargetConfig();
+ cfg.setdDdGroup("evalCompDDGroup");
+
+ new DropTarget(this, cfg) {
+ @Override
+ public boolean notifyDrop(DragSource source, EventObject e,
+ DragData data) {
+ if (data instanceof TreeDragData){
+ TreeDragData treeDragData = (TreeDragData) data;
+ TreeNode treeNode = treeDragData.getTreeNode();
+ Object obj = treeNode.getAttributeAsObject("evalObject");
+ if (obj instanceof Referentiel) {
+ Referentiel refChoosed = (Referentiel) obj;
+ addNewPlanRef(refChoosed);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public String notifyOver(DragSource source, EventObject e,
+ DragData data) {
+ if (data instanceof TreeDragData){
+ TreeDragData treeDragData = (TreeDragData) data;
+ TreeNode treeNode = treeDragData.getTreeNode();
+ Object obj = treeNode.getAttributeAsObject("evalObject");
+ if (obj instanceof Referentiel) {
+ return "x-dd-drop-ok";
+ }
+ }
+ return "";
+ }
+ };
+
+
+ }
+
+
+ this.addListener(new TabPanelListenerAdapter() {
+ @Override
+ public boolean doBeforeRemove(final Container self,
+ final Component component) {
+
+ if (removePanelRefFlag) {
+ removePanelRefFlag = false;
+ return true;
+ } else {
+ MessageBox
+ .confirm(
+ Messages.getString("Confirmation"),
+ Messages
+ .getString("Voulez_vous_reelement_supprimer_ce_referentiel_"),
+ new MessageBox.ConfirmCallback() {
+ public void execute(String btnID) {
+ if (btnID.equals("yes")) {
+ deletePlanRef((PlanPanelRefWidget) component);
+ }
+ }
+ });
+ return false;
+ }
+ }
+ });
+
+
+
+
+ for (PlanRef pr : currentPlanShown.getPlanRefs()) {
+
+ PlanPanelRefWidget pprw = new PlanPanelRefWidget(this, pr, readOnly);
+ this.add(pprw);
+ pprw.updateInfoFields();
+ }
+
+ }
+
+ /**
+ * Gets the current plan shown.
+ *
+ * @return the current plan shown
+ */
+ public Plan getCurrentPlanShown() {
+ return currentPlanShown;
+ }
+
+}