--- /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.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+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.Ext;
+import com.gwtext.client.core.Function;
+import com.gwtext.client.core.UrlParam;
+import com.gwtext.client.data.Node;
+import com.gwtext.client.data.NodeTraversalCallback;
+import com.gwtext.client.util.Format;
+import com.gwtext.client.widgets.Button;
+import com.gwtext.client.widgets.Panel;
+import com.gwtext.client.widgets.Tool;
+import com.gwtext.client.widgets.Toolbar;
+import com.gwtext.client.widgets.ToolbarButton;
+import com.gwtext.client.widgets.Window;
+import com.gwtext.client.widgets.event.ButtonListenerAdapter;
+import com.gwtext.client.widgets.event.PanelListenerAdapter;
+import com.gwtext.client.widgets.event.WindowListenerAdapter;
+import com.gwtext.client.widgets.layout.FitLayout;
+import com.gwtext.client.widgets.tree.TreeDragData;
+import com.gwtext.client.widgets.tree.TreeFilter;
+import com.gwtext.client.widgets.tree.TreeNode;
+import com.gwtext.client.widgets.tree.TreePanel;
+import com.gwtext.client.widgets.tree.TreeTraversalCallback;
+import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter;
+import com.gwtextux.client.widgets.upload.UploadDialog;
+import com.gwtextux.client.widgets.upload.UploadDialogListenerAdapter;
+import com.pentila.evalcomp.client.ConnexionServer;
+import com.pentila.evalcomp.client.i18n.Messages;
+import com.pentila.evalcomp.client.mainTab.ReferentielTab;
+import com.pentila.evalcomp.client.plan.widget.TrashableTreePanel;
+import com.pentila.evalcomp.client.utilities.ITabManager;
+import com.pentila.evalcomp.client.utilities.Tools;
+import com.pentila.evalcomp.client.utilities.TrashableContainer;
+import com.pentila.evalcomp.client.utilities.UserTools;
+import com.pentila.evalcomp.client.widget.ExtWindow;
+import com.pentila.evalcomp.domain.definition.Competence;
+import com.pentila.evalcomp.domain.definition.Domain;
+import com.pentila.evalcomp.domain.definition.EvaluationObject;
+import com.pentila.evalcomp.domain.definition.Referentiel;
+import com.pentila.evalcomp.domain.plan.Plan;
+import com.pentila.evalcomp.domain.plan.PlanRef;
+
+
+/**
+ * The Class ReferentielPalettePanel.
+ */
+public class ReferentielPalettePanel extends AbstractPalettePanel implements TrashableContainer {
+
+
+ /** the plan filter object. */
+ private Plan planFilter = null;
+
+ /** The ref palette initialized. */
+ private boolean refPaletteInitialized;
+
+ /** The root node. */
+ private TreeNode rootNode = null;
+
+ /** The tree filter. */
+ private TreeFilter treeFilter;
+
+ /** The tree referentiel. */
+ private TrashableTreePanel treeReferentiel;
+
+
+ /**
+ * Instantiates a new referentiel palette panel.
+ */
+ public ReferentielPalettePanel(){
+ this(null);
+ }
+
+ /**
+ * Instantiates a new referentiel palette panel.
+ *
+ * @param itManager
+ * the it manager
+ */
+ public ReferentielPalettePanel(ITabManager itManager) {
+ super();
+
+ this.setTitle(Messages.getString("Referentiels"));
+ this.setIconCls("iconReferentiel16");
+ this.itManager = itManager;
+
+
+
+ this.addTool(new Tool(Tool.REFRESH, new Function() {
+ public void execute() {
+ initializeRootNode();
+ }
+ }, Messages.getString("Rafraichir")));
+
+ this.addListener(new PanelListenerAdapter() {
+ @Override
+ public boolean doBeforeExpand(Panel panel, boolean animate) {
+ if (refPaletteInitialized == false) {
+ initializeRootNode();
+ }
+ return true;
+ }
+ });
+
+ }
+
+ /**
+ * Creates the tree competence.
+ *
+ * @param myComp
+ * the my comp
+ * @param isRefPalette
+ * the is ref palette
+ *
+ * @return the tree node
+ */
+ public static TreeNode createTreeCompetence(Competence myComp,
+ boolean isRefPalette) {
+ TreeNode node = new TreeNode();
+ node.setText(myComp.getName());
+ String iconC = "iconCompetence16";
+ if (!myComp.getRequired()){
+ iconC = "iconCompetence16Green";
+ }
+
+ node.setIconCls(iconC);
+
+
+ node.setTooltip(myComp.getDescription());
+
+ node.setAttribute("evalObject", myComp);
+
+ if (isRefPalette) {
+ node.setAttribute("isRefPalette", "true");
+ } else {
+ node.setAttribute("isRefPalette", "false");
+ }
+
+ return node;
+ }
+
+ /**
+ * Creates the tree domains.
+ *
+ * @param myDom
+ * the my dom
+ * @param isRefPalette
+ * the is ref palette
+ *
+ * @return the tree node
+ */
+ public static TreeNode createTreeDomains(Domain myDom, boolean isRefPalette) {
+ TreeNode node = new TreeNode();
+ node.setText(myDom.getName());
+ node.setAttribute("evalObject", myDom);
+
+ if (isRefPalette) {
+ node.setAttribute("isRefPalette", "true");
+ } else {
+ node.setAttribute("isRefPalette", "false");
+ }
+
+ node.setIconCls("iconDomaine16");
+ node.setTooltip(myDom.getDescription());
+
+ List<Domain> listDom = new ArrayList<Domain>(myDom.getDomains());
+ Collections.sort(listDom, new Comparator<Domain>() {
+
+ public int compare(Domain dom1, Domain dom2) {
+ return dom1.getName().compareTo(dom2.getName());
+ }
+
+ });
+ for (Domain dom : listDom) {
+ node.appendChild(createTreeDomains(dom, isRefPalette));
+ }
+
+ List<Competence> listComp = new ArrayList<Competence>(myDom.getCompetences());
+ Collections.sort(listComp, new Comparator<Competence>() {
+
+ public int compare(Competence comp1, Competence comp2) {
+ return comp1.getName().compareTo(comp2.getName());
+ }
+
+ });
+ for (Competence comp : listComp) {
+ node.appendChild(createTreeCompetence(comp, isRefPalette));
+ }
+ return node;
+ }
+
+ /**
+ * Creates the tree refs.
+ *
+ * @param myRef
+ * the my ref
+ * @param isRefPalette
+ * the is ref palette
+ *
+ * @return the tree node
+ */
+ public static TreeNode createTreeRefs(Referentiel myRef,
+ boolean isRefPalette) {
+ TreeNode node = new TreeNode();
+ node.setText(myRef.getName());
+ node.setAttribute("evalObject", myRef);
+
+ if (isRefPalette) {
+ node.setAttribute("isRefPalette", "true");
+ } else {
+ node.setAttribute("isRefPalette", "false");
+ }
+
+ node.setIconCls("iconReferentiel16");
+ node.setTooltip(myRef.getDescription());
+
+ List<Domain> listDom = new ArrayList<Domain>(myRef.getDomains());
+ Collections.sort(listDom, new Comparator<Domain>() {
+
+ public int compare(Domain dom1, Domain dom2) {
+ return dom1.getName().compareTo(dom2.getName());
+ }
+
+ });
+
+ for (Domain dom : listDom) {
+ node.appendChild(createTreeDomains(dom, isRefPalette));
+ }
+ return node;
+ }
+
+ /**
+ * Gets the eval obj tree node.
+ *
+ * @param obj
+ * the obj
+ * @param isRefPalette
+ * the is ref palette
+ *
+ * @return the eval obj tree node
+ */
+ public static TreeNode getEvalOBJTreeNode(EvaluationObject obj,
+ boolean isRefPalette) {
+ TreeNode child = null;
+
+ if (obj instanceof Referentiel) {
+ child = ReferentielPalettePanel.createTreeRefs((Referentiel) obj,
+ isRefPalette);
+ }
+ if (obj instanceof Domain) {
+ child = ReferentielPalettePanel.createTreeDomains((Domain) obj,
+ isRefPalette);
+ }
+ if (obj instanceof Competence) {
+ child = ReferentielPalettePanel.createTreeCompetence(
+ (Competence) obj, isRefPalette);
+ }
+
+ return child;
+ }
+
+ /**
+ * Highlight target.
+ *
+ * @param b
+ * the b
+ */
+ private static void highlightTarget(boolean b) {
+ /*
+ if (b) {
+ EvalManagementTab.evalSubW.addStyleName("targetDragRed");
+ } else {
+ EvalManagementTab.evalSubW.removeClass("targetDragRed");
+ EvalManagementTab.evalSubW.removeClass("targetDragGreen");
+ }
+ */
+
+ }
+
+ /**
+ * Initialize palette.
+ */
+ public void initializePalette() {
+
+
+ setLayout(new FitLayout());
+ this.setBorder(false);
+ treeReferentiel = new TrashableTreePanel(this);
+
+ treeReferentiel.setId(Ext.generateId("refTreePalette"));
+
+ treeReferentiel.setLines(true);
+ treeReferentiel.setRootVisible(false);
+ treeReferentiel.setAnimate(true);
+ treeReferentiel.setEnableDrag(true);
+ treeReferentiel.setAutoScroll(true);
+
+
+ treeReferentiel.setDdGroup("evalCompDDGroup");
+
+ treeReferentiel.addListener(new TreePanelListenerAdapter() {
+ @Override
+ public void onDblClick(TreeNode node, EventObject e) {
+ // on affiche le panel referentiel
+ e.stopEvent();
+
+ final ReferentielTab rt = new ReferentielTab();
+ String name = rt.showEvaluationObjectNode(node);
+
+ ExtWindow window = new ExtWindow();
+
+ rt.setCls("associateRessourceExtWindow");
+ window.setTitle(Format.format(Messages.getString("user_detail"),
+ new String[] { name }));
+ window.setClosable(true);
+ window.setMaximizable(true);
+ window.setWidth(630);
+ window.setHeight(470);
+ window.setLayout(new FitLayout());
+
+
+ window.addListener(new WindowListenerAdapter(){
+ public void onResize(Window source, int width, int height){
+
+ rt.reSize(width-20, height-30);
+
+
+ }
+ });
+
+ window.add(rt);
+
+ window.show();
+ }
+
+ @Override
+ public void onEndDrag(TreePanel treePanel, TreeNode node) {
+ highlightTarget(false);
+ }
+
+ @Override
+ public void onStartDrag(TreePanel treePanel, TreeNode node) {
+ highlightTarget(true);
+ }
+ });
+
+ if (Tools.interfaceShown == Tools.EVAL_INST_INTERFACE) {
+ Toolbar topToolbarRef = new Toolbar();
+
+ ToolbarButton addRefButton = new ToolbarButton();
+ addRefButton.setIcon(Tools.getBaseURL()
+ + "images/referentiel16_add.png");
+ addRefButton.setTooltip(Messages
+ .getString("Ajouter_un_referentiel"));
+ addRefButton.addListener(new ButtonListenerAdapter() {
+ @Override
+ public void onClick(Button button, EventObject e) {
+ uploadReferentiel();
+ }
+ });
+
+ topToolbarRef.addButton(addRefButton);
+ treeReferentiel.setTopToolbar(topToolbarRef);
+ }
+ rootNode = new TreeNode();
+ treeReferentiel.setRootNode(rootNode);
+
+ // define a filter on the tree
+ treeFilter = new TreeFilter(treeReferentiel);
+
+ // content.add(treeReferentiel);
+ add(treeReferentiel);
+
+ }
+
+ /**
+ * Initialize root node.
+ */
+ public void initializeRootNode() {
+ treeReferentiel.getRootNode().setAttribute("treePanelRef", this);
+
+ AsyncCallback callback = new AsyncCallback() {
+
+ public void onFailure(Throwable caught) {
+ Tools.hideLoadingRegion(getId());
+ System.out
+ .println("Probleme dans la recuperation du referentiel"); //$NON-NLS-1$
+ }
+
+ public void onSuccess(Object result) {
+
+
+
+ for (Node tn : treeReferentiel.getRootNode().getChildNodes()) {
+ tn.remove();
+ }
+
+ List<Referentiel> listRef = new ArrayList<Referentiel>(
+ (Set<Referentiel>) result);
+ Collections.sort(listRef, new Comparator<Referentiel>() {
+
+ public int compare(Referentiel ref1, Referentiel ref2) {
+ return ref1.getName().compareTo(ref2.getName());
+ }
+
+ });
+ for (Referentiel ref : listRef) {
+ treeReferentiel.getRootNode().appendChild(
+ createTreeRefs(ref, true));
+ }
+
+ refPaletteInitialized = true;
+ updatePlanFilter();
+ Tools.hideLoadingRegion(getId());
+ }
+ };
+
+ Tools
+ .showLoadingRegion(
+ getId(),
+ Messages.getString("MAJ_referentiels"), Messages.getString("Chargement"));
+
+ if (UserTools.getUser().hasRole(Tools.ROLE_GEST_INST)
+ || UserTools.getUser().hasRole(Tools.ROLE_GEST_SCO)) {
+ RequestBuilder rb = ConnexionServer.evaluationObjectService
+ .getReferentiels(callback);
+ rb.setHeader("code", "A5");
+ ConnexionServer.doSend(rb);
+ } else if (Tools.interfaceShown == Tools.EVAL_PEDA_INTERFACE
+ && UserTools.getUser().hasRole(Tools.ROLE_GEST_PEDA)) {
+ RequestBuilder rb = ConnexionServer.evaluationObjectService
+ .getReferentiels(UserTools.getUser().getUid(),
+ Tools.ROLE_GEST_PEDA, callback);
+ rb.setHeader("code", "A5");
+ ConnexionServer.doSend(rb);
+ } else {
+ RequestBuilder rb = ConnexionServer.evaluationObjectService
+ .getReferentiels(UserTools.getUser().getUid(), "%",
+ callback);
+ rb.setHeader("code", "A5");
+ ConnexionServer.doSend(rb);
+ }
+ }
+
+ /**
+ * Sets the plan filter.
+ *
+ * @param plan
+ * the new plan filter
+ */
+ public void setPlanFilter(Plan plan) {
+ this.planFilter = plan;
+ if (refPaletteInitialized) {
+ updatePlanFilter();
+ }
+ }
+
+ /**
+ * Update plan filter.
+ */
+ public void updatePlanFilter() {
+
+ TreeTraversalCallback cbShow = new TreeTraversalCallback() {
+
+ public boolean execute(TreeNode node) {
+ Object refObj = node.getAttributeAsObject("evalObject");
+ if (refObj instanceof Referentiel) {
+ Referentiel ref = (Referentiel) refObj;
+
+ for (PlanRef pRef : planFilter.getPlanRefs()) {
+ if (pRef.getReferentiel().getId().equals(ref.getId())) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+ };
+ if (planFilter == null || planFilter.getPlanRefLock() == false) {
+ treeFilter.clear();
+ } else {
+ // on met update le grid
+ treeFilter.filterBy(cbShow);
+ }
+
+ NodeTraversalCallback cbMark = new NodeTraversalCallback() {
+
+ public boolean execute(Node node) {
+ Object obj = node.getAttributeAsObject("evalObject");
+ if (obj instanceof Referentiel || obj instanceof Domain
+ || obj instanceof Competence) {
+
+ EvaluationObject evalObj = (EvaluationObject) obj;
+ if (planFilter == null
+ || planFilter.getPlanRefLock() == true) {
+ ((TreeNode) node).getUI().removeClass("nodeRefMarked");
+ return true;
+ }
+ for (PlanRef pRef : planFilter.getPlanRefs()) {
+ if (pRef.getReferentiel().getId().equals(
+ evalObj.getReferentiel().getId())) {
+ ((TreeNode) node).getUI().addClass("nodeRefMarked");
+ return true;
+ }
+ }
+ }
+ return true;
+ }
+
+ };
+
+ treeReferentiel.getRootNode().eachChild(cbMark);
+
+ }
+
+ /* Upload d'un referentiel */
+ /**
+ * Upload referentiel.
+ */
+ private void uploadReferentiel() {
+ UploadDialog dialog = new UploadDialog();
+ dialog.setUrl("uploadWSFile");
+
+ UrlParam param[] = new UrlParam[1];
+
+ param[0] = new UrlParam("type", "refUpload");
+
+ dialog.setBaseParams(param);
+
+ dialog.setPostVarName("file");
+
+ dialog.addListener(new UploadDialogListenerAdapter() {
+
+ @Override
+ public void onUploadComplete(UploadDialog source) {
+
+ initializeRootNode();
+ }
+ });
+
+ dialog.show();
+ }
+
+
+ public void deleteEO(EvaluationObject eo){
+ AsyncCallback callback = new AsyncCallback(){
+
+ public void onFailure(Throwable arg0) {
+ Tools.hideLoadingRegion(getId());
+
+ }
+
+ public void onSuccess(Object arg0) {
+
+ initializeRootNode();
+ Tools.hideLoadingRegion(getId());
+ }
+
+ };
+ Tools
+ .showLoadingRegion(
+ getId(),
+ Messages.getString("MAJ_referentiels"), Messages.getString("Chargement"));
+ ConnexionServer.evaluationObjectService.deleteEvaluationObject(eo.getId(), callback);
+ }
+
+
+ public boolean isTrashable(Object... objects) {
+ if (UserTools.getUser().hasRole("ROLE_TECH")){
+ return true;
+ }
+ return false;
+ }
+
+ public void trashedElements(Object... objects) {
+
+ for (Object object : objects){
+ TreeDragData myData = (TreeDragData) object;
+ TreeNode node = myData.getTreeNode();
+ EvaluationObject eo = (EvaluationObject) node.getAttributeAsObject("evalObject");
+
+ deleteEO(eo);
+
+ }
+
+
+ }
+
+}