--- /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.widget;
+
+import java.util.Map;
+import java.util.Set;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.gwtext.client.core.EventObject;
+import com.gwtext.client.core.SortDir;
+import com.gwtext.client.data.ArrayReader;
+import com.gwtext.client.data.FieldDef;
+import com.gwtext.client.data.ObjectFieldDef;
+import com.gwtext.client.data.Record;
+import com.gwtext.client.data.RecordDef;
+import com.gwtext.client.data.Store;
+import com.gwtext.client.data.StringFieldDef;
+import com.gwtext.client.util.Format;
+import com.gwtext.client.widgets.PagingToolbar;
+import com.gwtext.client.widgets.Panel;
+import com.gwtext.client.widgets.Window;
+import com.gwtext.client.widgets.form.ComboBox;
+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.RowSelectionModel;
+import com.gwtext.client.widgets.grid.event.GridCellListener;
+import com.gwtextux.client.data.PagingMemoryProxy;
+import com.pentila.evalcomp.client.ConnexionServer;
+import com.pentila.evalcomp.client.palette.WorkspacePalettePanel;
+import com.pentila.evalcomp.client.utilities.Tools;
+import com.pentila.evalcomp.client.widget.ExtWindow;
+import com.pentila.evalcomp.domain.transit.RessourceItem;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class RessourceSearchWindow.
+ */
+public class RessourceSearchWindow extends ExtWindow {
+
+ /** The wpp. */
+ WorkspacePalettePanel wpp;
+
+ /** The cb. */
+ ComboBox cb;
+
+ /** The data proxy. */
+ PagingMemoryProxy dataProxy;
+
+ /** The grid. */
+ private GridPanel grid;
+
+ /** The obj list. */
+ Object[][] objList;
+
+ /** The render topic. */
+ private Renderer renderTopic = new Renderer() {
+ public String render(Object value, CellMetadata cellMetadata,
+ Record record, int rowIndex, int colNum, Store store) {
+
+ RessourceItem ri = (RessourceItem) record.getAsObject("object");
+
+ String url = Tools.getRessourceAccessURL() + "?pluginKey="
+ + ri.getPluginKey() + "&ressourceKey="
+ + ri.getRessourceKey() + "&mode=";
+ return Format.format(
+ "<b>{0}</b><br/><a href=\"{1}\" target=\"blank\">voir</a>",
+ new String[] { record.getAsString("title"), url });
+ }
+ };
+
+ /** The store. */
+ Store store;
+
+ /**
+ * Instantiates a new ressource search window.
+ *
+ * @param wpp the wpp
+ */
+ public RessourceSearchWindow(WorkspacePalettePanel wpp) {
+ super();
+ cb = new ComboBox();
+ this.wpp = wpp;
+ initializeInterface();
+ }
+
+ /**
+ * Gets the combo box.
+ *
+ * @return the combo box
+ */
+ public ComboBox getComboBox() {
+ return cb;
+ }
+
+ /**
+ * Initialize interface.
+ */
+ public void initializeInterface() {
+
+ this.setTitle("Résultats de recherche"); //$NON-NLS-1$
+ this.setClosable(true);
+ this.setWidth(700);
+
+ this.setPlain(true);
+ this.setModal(false);
+ this.setCloseAction(Window.HIDE);
+
+ this.setAutoScroll(true);
+
+ Panel panel = new Panel();
+ panel.setBorder(false);
+ panel.setPaddings(15);
+
+ objList = new Object[][] {};
+ dataProxy = new PagingMemoryProxy(objList);
+
+ final RecordDef recordDef = new RecordDef(new FieldDef[] {
+ new StringFieldDef("title"), new StringFieldDef("author"),
+ new StringFieldDef("path"), new ObjectFieldDef("object"),
+
+ });
+ final ArrayReader reader = new ArrayReader(500, recordDef);
+
+ store = new Store(dataProxy, reader, true);
+ store.setDefaultSort("title", SortDir.ASC);
+
+ ColumnConfig topicColumn = new ColumnConfig("Titre", "title", 420,
+ false, renderTopic, "topic");
+ topicColumn.setCss("white-space:normal;");
+
+ ColumnConfig authorColumn = new ColumnConfig("Auteur", "author", 200);
+
+ ColumnModel columnModel = new ColumnModel(new ColumnConfig[] {
+ topicColumn, authorColumn,
+
+ });
+ columnModel.setDefaultSortable(true);
+
+ grid = new GridPanel();
+
+
+ grid.setHeight(300);
+
+ grid.setStore(store);
+ grid.setColumnModel(columnModel);
+ grid.setTrackMouseOver(false);
+ grid.setLoadMask(true);
+ grid.setSelectionModel(new RowSelectionModel());
+ grid.setFrame(true);
+ grid.setStripeRows(true);
+ grid.setIconCls("grid-icon");
+
+ grid.addGridCellListener(new GridCellListener() {
+
+ public void onCellClick(GridPanel grid, int rowIndex, int colIndex,
+ EventObject e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onCellContextMenu(GridPanel grid, int rowIndex,
+ int cellIndex, EventObject e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onCellDblClick(GridPanel grid, int rowIndex,
+ int colIndex, EventObject e) {
+
+ RessourceItem ressourceItem = (RessourceItem) grid
+ .getSelectionModel().getSelected()
+ .getAsObject("object");
+ ;
+ wpp.addSearchItem(ressourceItem);
+
+ }
+
+ });
+
+ PagingToolbar pagingToolbar = new PagingToolbar(store);
+ pagingToolbar.setPageSize(25);
+ pagingToolbar.setDisplayInfo(true);
+ pagingToolbar.setDisplayMsg("résultats {0} - {1} sur {2}");
+ pagingToolbar.setEmptyMsg("Pas de résultats");
+
+ grid.setBottomToolbar(pagingToolbar);
+
+ panel.add(grid);
+ add(panel);
+ }
+
+ /**
+ * Update.
+ *
+ * @param query
+ * the query
+ * @param size
+ * the size
+ * @param start
+ * the start
+ */
+ public void update(String query, Integer size, Integer start) {
+
+ // reposit name, pluginKey
+ Map<String, String> infos = wpp.getSearchInfos();
+
+ String name = infos.get("repositname");
+ String pluginKey = infos.get("pluginkey");
+
+ this.setTitle("Résultats de recherche");
+ if (!name.equals("")) {
+ this.setTitle(this.getTitle() + " sur << " + name + " >>");
+ }
+
+ AsyncCallback callback = new AsyncCallback() {
+
+ public void onFailure(Throwable caught) {
+ // EvalCompAdmin.loadingWidget.hideLoading();
+ System.out
+ .println("Probleme dans la recuperation query ressource"); //$NON-NLS-1$
+ Tools.hideLoadingRegion("grid-search-WS");
+ }
+
+ public void onSuccess(Object result) {
+ Set<RessourceItem> sri = (Set<RessourceItem>) result;
+ Object[][] so = new Object[sri.size()][];
+ int i = 0;
+ for (RessourceItem ri : sri) {
+
+ String names = "";
+ int j = 0;
+ for (String name : ri.getOwners()) {
+
+ names = names + name;
+ if (j == ri.getOwners().size() - 1) {
+ names = names + ".";
+ } else {
+ names = names + ", ";
+ }
+
+ }
+
+ so[i] = new Object[] { ri.getName(), names,
+ ri.getRessourceKey(), ri };
+ i++;
+ }
+
+ objList = so;
+
+ dataProxy = new PagingMemoryProxy(objList);
+ store.setDataProxy(dataProxy);
+
+ store.reload();
+ Tools.hideLoadingRegion("grid-search-WS");
+
+ }
+ };
+
+ Tools.showLoadingRegion("grid-search-WS", "Recherche en cours ....", "");
+
+ ConnexionServer.ressourceService.query(query, size, start, pluginKey,
+ callback);
+ }
+
+}