[kune-commits] r801 - in sandbox3: . src/main/java/org/op src/main/java/org/op/client src/main/java/org/op/client/gridmenu

vjrj vjrj at ourproject.org
Fri Jul 18 12:25:06 CEST 2008


Author: vjrj
Date: 2008-07-18 12:24:57 +0200 (Fri, 18 Jul 2008)
New Revision: 801

Added:
   sandbox3/src/main/java/org/op/client/gridmenu/
   sandbox3/src/main/java/org/op/client/gridmenu/GridDragConfiguration.java
   sandbox3/src/main/java/org/op/client/gridmenu/GridDropConfiguration.java
   sandbox3/src/main/java/org/op/client/gridmenu/GridGroup.java
   sandbox3/src/main/java/org/op/client/gridmenu/GridItem.java
   sandbox3/src/main/java/org/op/client/gridmenu/GridMenu.java
   sandbox3/src/main/java/org/op/client/gridmenu/GridMenuItem.java
   sandbox3/src/main/java/org/op/client/gridmenu/GridMenuItemCollection.java
   sandbox3/src/main/java/org/op/client/gridmenu/GridMenuPanel.java
Modified:
   sandbox3/pom.xml
   sandbox3/src/main/java/org/op/Sandbox.gwt.xml
   sandbox3/src/main/java/org/op/client/Sandbox.java
Log:
new GridMenuPanel tests

Modified: sandbox3/pom.xml
===================================================================
--- sandbox3/pom.xml	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/pom.xml	2008-07-18 10:24:57 UTC (rev 801)
@@ -119,7 +119,7 @@
     <dependency>
       <groupId>com.allen_sauer.gwt.log.gwt-log</groupId>
       <artifactId>gwt-log</artifactId>
-      <version>1.5.6</version>
+      <version>2.5.0</version>
     </dependency>
 
     <!--  ui -->

Modified: sandbox3/src/main/java/org/op/Sandbox.gwt.xml
===================================================================
--- sandbox3/src/main/java/org/op/Sandbox.gwt.xml	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/Sandbox.gwt.xml	2008-07-18 10:24:57 UTC (rev 801)
@@ -4,6 +4,8 @@
 
   <inherits name="org.ourproject.kune.platf.Kune-Platform" />
 
+  <inherits name="com.calclab.suco.Suco" />
+  
   <inherits name='com.gwtext.GwtExt' />
   <script src="js/ext/adapter/ext/ext-base.js" />
   <script src="js/ext/ext-all.js" />

Modified: sandbox3/src/main/java/org/op/client/Sandbox.java
===================================================================
--- sandbox3/src/main/java/org/op/client/Sandbox.java	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/client/Sandbox.java	2008-07-18 10:24:57 UTC (rev 801)
@@ -1,13 +1,22 @@
 package org.op.client;
 
+import org.op.client.gridmenu.GridGroup;
+import org.op.client.gridmenu.GridItem;
+import org.op.client.gridmenu.GridMenu;
+import org.op.client.gridmenu.GridMenuPanel;
 import org.ourproject.kune.platf.client.View;
 
+import com.calclab.suco.client.signal.Slot;
 import com.google.gwt.core.client.EntryPoint;
 import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.MenuBar;
+import com.gwtext.client.widgets.Button;
 import com.gwtext.client.widgets.Panel;
+import com.gwtext.client.widgets.QuickTips;
+import com.gwtext.client.widgets.ToolbarButton;
 import com.gwtext.client.widgets.Viewport;
 import com.gwtext.client.widgets.layout.FitLayout;
 
@@ -96,6 +105,12 @@
 	// form.addTab("Segundo", tab2);
 	// dialog.add(form.getForm());
 
+	QuickTips.init(); // extgwt tips
+	// final QuickTip quickTipInstance = QuickTips.getQuickTip();
+	// quickTipInstance.setDismissDelay(8000);
+	// quickTipInstance.setHideDelay(500);
+	// quickTipInstance.setInterceptTitles(true);
+
 	final Workspace wk = new Workspace();
 	// EntityCnt ent = new EntityCnt();
 
@@ -127,7 +142,7 @@
 	wk.getEntityWorkspace().setContainer(new LabelWrapper(LOREM));
 	wk.getEntityWorkspace().setContent(new LabelWrapper(LOREM));
 	wk.getEntitySummary().addInTools(new Label("doc"));
-	wk.getEntitySummary().addInSummary(new LabelWrapper(LOREM));
+	// wk.getEntitySummary().addInSummary(new LabelWrapper(LOREM));
 	wk.getEntityWorkspace().getBottomTitle().addSpacer();
 	wk.getEntityWorkspace().getBottomTitle().add(new LabelWrapper("Bottom"));
 	wk.getEntityWorkspace().getTitle().add(new LabelWrapper("Title"));
@@ -148,7 +163,46 @@
 	wk.getSiteBar().addFill();
 	wk.getSiteBar().addSeparator();
 	wk.getSiteBar().add(new LabelWrapper("sitebar-right"));
+
+	final Button button = new Button("kk");
+	button.setTooltip("tooltip");
+	wk.getEntityWorkspace().getContainerTopBar().add(button);
 	wk.setTheme(WsTheme.def);
 	wk.setTheme(WsTheme.green);
+	wk.getEntitySummary().addInSummary(createGridSample());
+	// wk.getEntitySummary().addInSummary(new GridGroupingSample());
     }
+
+    private GridMenuPanel createGridSample() {
+	final GridMenuPanel grid = new GridMenuPanel("Nada", true, true);
+	grid.getTopBar().addButton(new ToolbarButton("boton"));
+	grid.getBottomBar().addButton(new ToolbarButton("boton 2"));
+	grid.onDoubleClick(new Slot<String>() {
+	    public void onEvent(final String id) {
+		Window.alert("Double click, id: " + id);
+	    }
+	});
+	final GridGroup admins = new GridGroup("Admins", "Admins Title", "some admin tooltip", true);
+	final GridGroup collab = new GridGroup("Collabs", "Collabs Title", "some collab tooltip", true);
+	final GridItem item1 = new GridItem(admins, "1", "<a href=''>kk</a>", "fulano", "<em>fulano</em>", "<b>kk</b>",
+		"tooltiptitle", "tooptip", new GridMenu());
+	grid.addItem(item1);
+	grid.addItem(new GridItem(admins, "3", "<a href=''>kk</a>", "afulano", "<em>afulano</em>", "<b>k3</b>",
+		"tooltiptitle", "tooptip", new GridMenu()));
+	grid.addItem(new GridItem(collab, "2", "<a href=''>bb</a>", "fulana", "<em>fulana</em>", "<b>k2</b>",
+		"tooltiptitle", "tooptip", new GridMenu()));
+	final GridItem item4 = new GridItem(GridGroup.NoGridGroup, "4", "<a href=''>b2</a>", "fulan2",
+		"<em>fulane</em>", "<b>k3</b>", "tooltiptitle", "tooptip", new GridMenu());
+	grid.addItem(item4);
+	item1.setGroup(collab);
+	item1.setTitleHtml("New fulano");
+	grid.updateItem(item1);
+	final GridItem item4bis = new GridItem(GridGroup.NoGridGroup, "4", "<a href=''>b2</a>", "fulan2",
+		"<em>fulane</em>", "<b>k3</b>", "tooltiptitle", "tooptip", new GridMenu());
+	grid.removeItem(item4bis);
+	grid.addItem(item4bis);
+	grid.removeItem(item4bis);
+	grid.addItem(item4bis);
+	return grid;
+    }
 }

Added: sandbox3/src/main/java/org/op/client/gridmenu/GridDragConfiguration.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridDragConfiguration.java	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridDragConfiguration.java	2008-07-18 10:24:57 UTC (rev 801)
@@ -0,0 +1,42 @@
+/*
+ *
+ * ((e)) emite: A pure gwt (Google Web Toolkit) xmpp (jabber) library
+ *
+ * (c) 2008 The emite development team (see CREDITS for details)
+ * This file is part of emite.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.op.client.gridmenu;
+
+public class GridDragConfiguration {
+
+    private final String ddGroupId;
+    private final String dragMessage;
+
+    public GridDragConfiguration(final String ddGroupId, final String dragMessage) {
+	this.ddGroupId = ddGroupId;
+	this.dragMessage = dragMessage;
+    }
+
+    public String getDdGroupId() {
+	return ddGroupId;
+    }
+
+    public String getDragMessage() {
+	return dragMessage;
+    }
+
+}

Added: sandbox3/src/main/java/org/op/client/gridmenu/GridDropConfiguration.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridDropConfiguration.java	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridDropConfiguration.java	2008-07-18 10:24:57 UTC (rev 801)
@@ -0,0 +1,50 @@
+/*
+ *
+ * ((e)) emite: A pure gwt (Google Web Toolkit) xmpp (jabber) library
+ *
+ * (c) 2008 The emite development team (see CREDITS for details)
+ * This file is part of emite.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.op.client.gridmenu;
+
+import com.calclab.suco.client.signal.Signal;
+import com.calclab.suco.client.signal.Slot;
+
+public class GridDropConfiguration {
+
+    private final String ddGroupId;
+    private final Signal<String> onDrop;
+
+    public GridDropConfiguration(final String ddGroupId, final Slot<String> slot) {
+	this.ddGroupId = ddGroupId;
+	this.onDrop = new Signal<String>("onDrop");
+	this.onDrop(slot);
+    }
+
+    public void fire(final String id) {
+	onDrop.fire(id);
+    }
+
+    public String getDdGroupId() {
+	return ddGroupId;
+    }
+
+    public void onDrop(final Slot<String> slot) {
+	onDrop.add(slot);
+    }
+
+}

Added: sandbox3/src/main/java/org/op/client/gridmenu/GridGroup.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridGroup.java	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridGroup.java	2008-07-18 10:24:57 UTC (rev 801)
@@ -0,0 +1,41 @@
+package org.op.client.gridmenu;
+
+public class GridGroup {
+
+    public static GridGroup NoGridGroup = new GridGroup("", "", "", false);
+
+    private String name;
+    private String tooltipTitle;
+    private String tooltip;
+
+    public GridGroup(final String name, final String tooltipTitle, final String tooltip, final boolean countVisible) {
+	this.name = name;
+	this.tooltipTitle = tooltipTitle;
+	this.tooltip = tooltip;
+    }
+
+    public String getName() {
+	return name;
+    }
+
+    public String getTooltip() {
+	return tooltip;
+    }
+
+    public String getTooltipTitle() {
+	return tooltipTitle;
+    }
+
+    public void setName(final String name) {
+	this.name = name;
+    }
+
+    public void setTooltip(final String tooltip) {
+	this.tooltip = tooltip;
+    }
+
+    public void setTooltipTitle(final String tooltipTitle) {
+	this.tooltipTitle = tooltipTitle;
+    }
+
+}

Added: sandbox3/src/main/java/org/op/client/gridmenu/GridItem.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridItem.java	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridItem.java	2008-07-18 10:24:57 UTC (rev 801)
@@ -0,0 +1,101 @@
+package org.op.client.gridmenu;
+
+public class GridItem {
+
+    private GridGroup group;
+    private String id;
+    private String iconHtml;
+    private String title;
+    private String titleHtml;
+    private String endIconHtml;
+    private String tooltip;
+    private String tooltipTitle;
+    private GridMenu menu;
+
+    public GridItem(final GridGroup group, final String id, final String iconHtml, final String title,
+	    final String titleHtml, final String endIconHtml, final String tooltipTitle, final String tooltip,
+	    final GridMenu menu) {
+	this.group = group;
+	this.id = id;
+	this.iconHtml = iconHtml;
+	this.title = title;
+	this.titleHtml = titleHtml;
+	this.endIconHtml = endIconHtml;
+	this.tooltip = tooltip;
+	this.tooltipTitle = tooltipTitle;
+	this.menu = menu;
+    }
+
+    public String getEndIconHtml() {
+	return endIconHtml;
+    }
+
+    public GridGroup getGroup() {
+	return group;
+    }
+
+    public String getIconHtml() {
+	return iconHtml;
+    }
+
+    public String getId() {
+	return id;
+    }
+
+    public GridMenu getMenu() {
+	return menu;
+    }
+
+    public String getTitle() {
+	return title;
+    }
+
+    public String getTitleHtml() {
+	return titleHtml;
+    }
+
+    public String getTooltip() {
+	return tooltip;
+    }
+
+    public String getTooltipTitle() {
+	return tooltipTitle;
+    }
+
+    public void setEndIconHtml(final String endIconHtml) {
+	this.endIconHtml = endIconHtml;
+    }
+
+    public void setGroup(final GridGroup group) {
+	this.group = group;
+    }
+
+    public void setIconHtml(final String iconHtml) {
+	this.iconHtml = iconHtml;
+    }
+
+    public void setId(final String id) {
+	this.id = id;
+    }
+
+    public void setMenu(final GridMenu menu) {
+	this.menu = menu;
+    }
+
+    public void setTitle(final String title) {
+	this.title = title;
+    }
+
+    public void setTitleHtml(final String titleHtml) {
+	this.titleHtml = titleHtml;
+    }
+
+    public void setTooltip(final String tooltip) {
+	this.tooltip = tooltip;
+    }
+
+    public void setTooltipTitle(final String tooltipTitle) {
+	this.tooltipTitle = tooltipTitle;
+    }
+
+}

Added: sandbox3/src/main/java/org/op/client/gridmenu/GridMenu.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridMenu.java	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridMenu.java	2008-07-18 10:24:57 UTC (rev 801)
@@ -0,0 +1,69 @@
+/*
+ *
+ * ((e)) emite: A pure gwt (Google Web Toolkit) xmpp (jabber) library
+ *
+ * (c) 2008 The emite development team (see CREDITS for details)
+ * This file is part of emite.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.op.client.gridmenu;
+
+import java.util.Iterator;
+
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.DeferredCommand;
+import com.gwtext.client.core.EventObject;
+import com.gwtext.client.widgets.menu.BaseItem;
+import com.gwtext.client.widgets.menu.Item;
+import com.gwtext.client.widgets.menu.Menu;
+import com.gwtext.client.widgets.menu.event.BaseItemListenerAdapter;
+
+public class GridMenu {
+    private final Menu menu;
+
+    public GridMenu() {
+	menu = new Menu();
+    }
+
+    public void addMenuItem(final GridMenuItem menuOpt) {
+	final Item menuItem = new Item(menuOpt.getTitle());
+	menuItem.setIconCls(menuOpt.getIconCls());
+	menu.addItem(menuItem);
+	menuItem.addListener(new BaseItemListenerAdapter() {
+	    public void onClick(final BaseItem item, final EventObject e) {
+		DeferredCommand.addCommand(new Command() {
+		    public void execute() {
+			menuOpt.getListener().onClick();
+		    }
+		});
+	    }
+	});
+    }
+
+    @SuppressWarnings("unchecked")
+    public void setMenuItemList(final GridMenuItemCollection list) {
+	menu.removeAll();
+	for (final Iterator iterator = list.iterator(); iterator.hasNext();) {
+	    final GridMenuItem item = (GridMenuItem) iterator.next();
+	    addMenuItem(item);
+	}
+    }
+
+    public void showMenu(final EventObject e) {
+	menu.showAt(e.getXY());
+    }
+
+}

Added: sandbox3/src/main/java/org/op/client/gridmenu/GridMenuItem.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridMenuItem.java	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridMenuItem.java	2008-07-18 10:24:57 UTC (rev 801)
@@ -0,0 +1,31 @@
+package org.op.client.gridmenu;
+
+public class GridMenuItem {
+
+    public interface GridMenuItemListener {
+	public void onClick();
+    }
+
+    final String iconCls;
+    final String title;
+    final GridMenuItemListener listener;
+
+    public GridMenuItem(final String iconCls, final String title, final GridMenuItemListener listener) {
+	this.iconCls = iconCls;
+	this.title = title;
+	this.listener = listener;
+    }
+
+    public String getIconCls() {
+	return iconCls;
+    }
+
+    public GridMenuItemListener getListener() {
+	return listener;
+    }
+
+    public String getTitle() {
+	return title;
+    }
+
+}

Added: sandbox3/src/main/java/org/op/client/gridmenu/GridMenuItemCollection.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridMenuItemCollection.java	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridMenuItemCollection.java	2008-07-18 10:24:57 UTC (rev 801)
@@ -0,0 +1,30 @@
+/*
+ *
+ * ((e)) emite: A pure gwt (Google Web Toolkit) xmpp (jabber) library
+ *
+ * (c) 2008 The emite development team (see CREDITS for details)
+ * This file is part of emite.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.op.client.gridmenu;
+
+import java.util.ArrayList;
+
+public class GridMenuItemCollection extends ArrayList<GridMenuItem> {
+
+    private static final long serialVersionUID = 1L;
+
+}

Added: sandbox3/src/main/java/org/op/client/gridmenu/GridMenuPanel.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridMenuPanel.java	2008-07-12 13:46:02 UTC (rev 800)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridMenuPanel.java	2008-07-18 10:24:57 UTC (rev 801)
@@ -0,0 +1,406 @@
+package org.op.client.gridmenu;
+
+import java.util.HashMap;
+
+import com.allen_sauer.gwt.log.client.Log;
+import com.calclab.suco.client.signal.Signal;
+import com.calclab.suco.client.signal.Slot;
+import com.google.gwt.user.client.ui.Composite;
+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.GroupingStore;
+import com.gwtext.client.data.MemoryProxy;
+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.Toolbar;
+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.GridView;
+import com.gwtext.client.widgets.grid.GroupingView;
+import com.gwtext.client.widgets.grid.Renderer;
+import com.gwtext.client.widgets.grid.RowSelectionModel;
+import com.gwtext.client.widgets.grid.event.GridCellListenerAdapter;
+import com.gwtext.client.widgets.grid.event.GridRowListener;
+import com.gwtext.client.widgets.layout.FitLayout;
+
+public class GridMenuPanel extends Composite {
+    public static final String GRID_MENU_PANEL_DD = "gridMenuPanelDD";
+    public static final int DEFAULT_INITIAL_WIDTH = 150;
+    private static final String GROUP = "groupField";
+    private static final String GROUP_TOOLTIP_TITLE = "groupTooltipTitleField";
+    private static final String GROUP_TOOLTIP = "groupTooltipField";
+    private static final String ID = "idField";
+    private static final String ICON_HTML = "iconHtmlField";
+    private static final String TITLE = "titleField";
+    private static final String TITLE_HTML = "titleHtmlField";
+    private static final String END_ICON_HTML = "endIconHtmlField";
+    private static final String TOOLTIP = "tooltipField";
+    private static final String TOOLTIPTITLE = "tooltipTitleField";
+    private final HashMap<Record, GridMenu> menuMap;
+    private final HashMap<String, Record> recordMap;
+    private RecordDef recordDef;
+    private GroupingStore store;
+    private GridPanel grid;
+    private final Panel panel;
+    private final boolean grouped;
+    private final boolean withCounters;
+    private final Signal<String> onClick;
+    private final Signal<String> onDoubleClick;
+    private Toolbar topBar;
+    private Toolbar bottomBar;
+    private final String emptyText;
+    private final GridDragConfiguration gridDragConfiguration;
+    private final GridDropConfiguration gridDropConfiguration;
+
+    public GridMenuPanel(final String emptyText) {
+	this(emptyText, null, null, false, false);
+    }
+
+    public GridMenuPanel(final String emptyText, final boolean grouped, final boolean withCounters) {
+	this(emptyText, null, null, grouped, withCounters);
+    }
+
+    public GridMenuPanel(final String emptyText, final GridDragConfiguration gridDragConfiguration) {
+	this(emptyText, gridDragConfiguration, null, false, false);
+    }
+
+    public GridMenuPanel(final String emptyText, final GridDragConfiguration gridDragConfiguration,
+	    final GridDropConfiguration gridDropConfiguration, final boolean grouped, final boolean withCounters) {
+	this.emptyText = emptyText;
+	this.gridDragConfiguration = gridDragConfiguration;
+	this.gridDropConfiguration = gridDropConfiguration;
+	this.onClick = new Signal<String>("onClick");
+	this.onDoubleClick = new Signal<String>("onDoubleClick");
+	this.grouped = grouped;
+	this.withCounters = withCounters;
+	panel = new Panel();
+	panel.setBorder(false);
+	panel.setLayout(new FitLayout());
+	menuMap = new HashMap<Record, GridMenu>();
+	recordMap = new HashMap<String, Record>();
+    }
+
+    public GridMenuPanel(final String emptyText, final GridDropConfiguration gridDropConfiguration) {
+	this(emptyText, null, gridDropConfiguration, false, false);
+    }
+
+    public void addItem(final GridItem item) {
+	if (grid == null) {
+	    createGrid(emptyText, gridDragConfiguration, gridDropConfiguration);
+	}
+	final Record newRecord = recordDef.createRecord(item.getId(),
+		new Object[] { item.getGroup().getName(), item.getGroup().getTooltipTitle(),
+			item.getGroup().getTooltip(), item.getId(), item.getIconHtml(), item.getTitle(),
+			item.getTitleHtml(), item.getEndIconHtml(), item.getTooltipTitle(), item.getTooltip() });
+	recordMap.put(item.getId(), newRecord);
+	store.addSorted(newRecord);
+	// store.groupBy(GROUP);
+	menuMap.put(newRecord, item.getMenu());
+	sort();
+	doLayoutIfNeeded();
+    }
+
+    public void confDropInPanel(final Panel panel, final GridDropConfiguration gridDropConfiguration) {
+	// FIXME: This doesn't works :-/
+	// http://extjs.com/forum/showthread.php?t=18105
+	final DropTargetConfig dCfg = new DropTargetConfig();
+	dCfg.setTarget(true);
+	dCfg.setdDdGroup(gridDropConfiguration.getDdGroupId());
+	new DropTarget(panel, dCfg) {
+	    @Override
+	    public boolean notifyDrop(final DragSource src, final EventObject e, final DragData dragData) {
+		if (dragData instanceof GridDragData) {
+		    final GridDragData gridDragData = (GridDragData) dragData;
+		    final Record[] records = gridDragData.getSelections();
+		    for (int i = 0; i < records.length; i++) {
+			gridDropConfiguration.fire(records[i].getAsString(ID));
+		    }
+		}
+		return true;
+	    }
+
+	    @Override
+	    public String notifyEnter(final DragSource src, final EventObject e, final DragData data) {
+		return "x-tree-drop-ok-append";
+	    }
+
+	    @Override
+	    public String notifyOver(final DragSource src, final EventObject e, final DragData data) {
+		return "x-tree-drop-ok-append";
+	    }
+	};
+    }
+
+    public Toolbar getBottomBar() {
+	if (bottomBar == null) {
+	    bottomBar = new Toolbar();
+	    panel.setBottomToolbar(bottomBar);
+	}
+	return bottomBar;
+    }
+
+    public Toolbar getTopBar() {
+	if (topBar == null) {
+	    topBar = new Toolbar();
+	    panel.setTopToolbar(topBar);
+	}
+	return topBar;
+    }
+
+    public void onClick(final Slot<String> slot) {
+	onClick.add(slot);
+    }
+
+    public void onDoubleClick(final Slot<String> slot) {
+	onDoubleClick.add(slot);
+    }
+
+    public void removeAll() {
+	store.removeAll();
+	recordMap.clear();
+	menuMap.clear();
+    }
+
+    public void removeItem(final GridItem item) {
+	final Record record = recordMap.get(item.getId());
+	if (record != null) {
+	    menuMap.remove(record);
+	    store.remove(record);
+	    recordMap.remove(record);
+	    doLayoutIfNeeded();
+	} else {
+	    Log.error("Trying to remove a non existing item: " + item.getId());
+	}
+    }
+
+    public void setWidth(final int width) {
+	// Log.info("Grid width: " + width);
+	grid.setWidth(width - 27);
+	panel.setWidth(width - 25);
+	doLayoutIfNeeded();
+    }
+
+    public void sort() {
+	store.sort(GROUP);
+    }
+
+    public void updateItem(final GridItem item) {
+	final Record record = recordMap.get(item.getId());
+	if (record != null) {
+	    record.set(GROUP, item.getGroup().getName());
+	    record.set(GROUP_TOOLTIP_TITLE, item.getGroup().getTooltipTitle());
+	    record.set(GROUP_TOOLTIP, item.getGroup().getTooltip());
+	    record.set(ICON_HTML, item.getIconHtml());
+	    record.set(TITLE, item.getTitle());
+	    record.set(TITLE_HTML, item.getTitleHtml());
+	    record.set(END_ICON_HTML, item.getEndIconHtml());
+	    record.set(TOOLTIPTITLE, item.getTooltipTitle());
+	    record.set(TOOLTIP, item.getTooltip());
+	    store.commitChanges();
+	    menuMap.put(record, item.getMenu());
+	    sort();
+	    doLayoutIfNeeded();
+	} else {
+	    Log.error("Trying to update a non existing item: " + item.getId());
+	}
+    }
+
+    private void configureDrag(final GridDragConfiguration gridDragConfiguration) {
+	// TODO: put this in GDConf
+	grid.setEnableDragDrop(true);
+	grid.setDdGroup(gridDragConfiguration.getDdGroupId());
+	grid.setDragDropText(gridDragConfiguration.getDragMessage());
+    }
+
+    private void configureDrop(final GridDropConfiguration gridDropConfiguration) {
+	// TODO: put this in GDConf
+	grid.setEnableDragDrop(true);
+	grid.setDdGroup(gridDropConfiguration.getDdGroupId());
+	final DropTargetConfig dCfg = new DropTargetConfig();
+	dCfg.setTarget(true);
+	dCfg.setdDdGroup(gridDropConfiguration.getDdGroupId());
+	new DropTarget(grid, dCfg) {
+	    @Override
+	    public boolean notifyDrop(final DragSource src, final EventObject e, final DragData dragData) {
+		if (dragData instanceof GridDragData) {
+		    final GridDragData gridDragData = (GridDragData) dragData;
+		    final Record[] records = gridDragData.getSelections();
+		    for (int i = 0; i < records.length; i++) {
+			gridDropConfiguration.fire(records[i].getAsString(ID));
+		    }
+		}
+		return true;
+	    }
+
+	    @Override
+	    public String notifyEnter(final DragSource src, final EventObject e, final DragData data) {
+		return "x-tree-drop-ok-append";
+	    }
+
+	    @Override
+	    public String notifyOver(final DragSource src, final EventObject e, final DragData data) {
+		return "x-tree-drop-ok-append";
+	    }
+	};
+    }
+
+    private void createGrid(final String emptyText, final GridDragConfiguration gridDragConfiguration,
+	    final GridDropConfiguration gridDropConfiguration) {
+	grid = new GridPanel();
+	final FieldDef[] fieldDefs = new FieldDef[] { new StringFieldDef(GROUP),
+		new StringFieldDef(GROUP_TOOLTIP_TITLE), new StringFieldDef(GROUP_TOOLTIP), new StringFieldDef(ID),
+		new StringFieldDef(ICON_HTML), new StringFieldDef(TITLE), new StringFieldDef(TITLE_HTML),
+		new StringFieldDef(END_ICON_HTML), new StringFieldDef(TOOLTIPTITLE), new StringFieldDef(TOOLTIP) };
+	recordDef = new RecordDef(fieldDefs);
+
+	final MemoryProxy proxy = new MemoryProxy(new Object[][] {});
+
+	final ArrayReader reader = new ArrayReader(1, recordDef);
+	store = new GroupingStore(proxy, reader);
+	store.setSortInfo(new SortState(GROUP, SortDir.DESC));
+	store.setGroupField(GROUP);
+	store.setGroupOnSort(true);
+	store.load();
+	grid.setStore(store);
+
+	// TODO: Change this with a method that modify the html
+	final String commonTootipHtmlRender = "<span ext:qtitle=\"{1}\" ext:qtip=\"{2}\">{0}</span>";
+
+	final Renderer iconHtmlRenderer = new Renderer() {
+	    public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum,
+		    Store store) {
+		return Format.format(commonTootipHtmlRender, new String[] { record.getAsString(ICON_HTML),
+			record.getAsString(TOOLTIPTITLE), record.getAsString(TOOLTIP) });
+	    }
+	};
+
+	final Renderer titleHtmlRenderer = new Renderer() {
+	    public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum,
+		    Store store) {
+		return Format.format(commonTootipHtmlRender, new String[] { record.getAsString(TITLE_HTML),
+			record.getAsString(TOOLTIPTITLE), record.getAsString(TOOLTIP) });
+	    }
+	};
+
+	final Renderer endIconHtmlRenderer = new Renderer() {
+	    public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum,
+		    Store store) {
+		return Format.format(commonTootipHtmlRender, new String[] { record.getAsString(END_ICON_HTML),
+			record.getAsString(TOOLTIPTITLE), record.getAsString(TOOLTIP) });
+	    }
+	};
+
+	final ColumnConfig[] columnsConfigs = new ColumnConfig[] {
+		new ColumnConfig("Icon", ICON_HTML, 18, false, iconHtmlRenderer, ICON_HTML),
+		new ColumnConfig("Title", TITLE_HTML, 24, true, titleHtmlRenderer, TITLE_HTML),
+		new ColumnConfig("EndIcon", END_ICON_HTML, 18, false, endIconHtmlRenderer, END_ICON_HTML),
+		new ColumnConfig(GROUP, GROUP, 0) };
+	final ColumnModel columnModel = new ColumnModel(columnsConfigs);
+	grid.setColumnModel(columnModel);
+
+	grid.setAutoExpandColumn(TITLE_HTML);
+	grid.setSelectionModel(new RowSelectionModel());
+	grid.addGridCellListener(new GridCellListenerAdapter() {
+	    @Override
+	    public void onCellDblClick(final GridPanel grid, final int rowIndex, final int colIndex, final EventObject e) {
+		onDoubleClick(rowIndex);
+	    }
+	});
+	grid.addGridRowListener(new GridRowListener() {
+	    public void onRowClick(final GridPanel grid, final int rowIndex, final EventObject e) {
+		showMenu(rowIndex, e);
+		onClick(rowIndex);
+	    }
+
+	    public void onRowContextMenu(final GridPanel grid, final int rowIndex, final EventObject e) {
+		showMenu(rowIndex, e);
+	    }
+
+	    public void onRowDblClick(final GridPanel grid, final int rowIndex, final EventObject e) {
+		Log.debug("Row double click");
+		onDoubleClick(rowIndex);
+	    }
+
+	    private void showMenu(final int rowIndex, final EventObject e) {
+		final Record record = store.getRecordAt(rowIndex);
+		final GridMenu menu = menuMap.get(record);
+		menu.showMenu(e);
+	    }
+	});
+	grid.stripeRows(true);
+	grid.setAutoHeight(true);
+
+	if (grouped) {
+	    final GroupingView groupView = new GroupingView();
+	    groupView.setForceFit(true);
+	    // http://www.gwt-ext.com/forum/viewtopic.php?f=7&t=1388&p=6789&hilit=setGroupTextTpl#p6789
+	    if (withCounters) {
+		groupView.setGroupTextTpl("<span ext:qtip=\"{[values.rs[0].data[\"" + GROUP_TOOLTIP
+			+ "\"]]}\">{[values.rs[0].data[\"" + GROUP + "\"]]} ({[values.rs.length]})</span>");
+	    } else {
+		groupView.setGroupTextTpl("<span ext:qtip=\"{[values.rs[0].data[\"" + GROUP_TOOLTIP
+			+ "\"]]}\">{[values.rs[0].data[\"" + GROUP + "\"]]}</span>");
+	    }
+	    // Other sample with condition:
+	    // view.setGroupTextTpl("{text} ({[values.rs.length]}
+	    // {[values.rs.length
+	    // > 1 ? \"Items\" : \"Item\"]})");
+	    groupView.setHideGroupedColumn(true);
+	    groupView.setEmptyGroupText(emptyText);
+	    groupView.setShowGroupsText(true);
+	    groupView.setEnableNoGroups(true);
+	    groupView.setEmptyText(emptyText);
+	    groupView.setGroupByText(GROUP);
+	    groupView.setIgnoreAdd(true);
+	    groupView.setEnableGrouping(true);
+	    grid.setView(groupView);
+	} else {
+	    final GridView view = new GridView();
+	    view.setForceFit(true);
+	    grid.setView(view);
+	}
+	grid.setHideColumnHeader(true);
+	grid.setBorder(false);
+	grid.setAutoScroll(true);
+	if (gridDropConfiguration != null) {
+	    configureDrop(gridDropConfiguration);
+	}
+	if (gridDragConfiguration != null) {
+	    configureDrag(gridDragConfiguration);
+	} else {
+	    grid.setDraggable(false);
+	}
+	panel.add(grid);
+	initWidget(panel);
+    }
+
+    private void doLayoutIfNeeded() {
+	if (panel.isRendered()) {
+	    panel.doLayout();
+	}
+    }
+
+    private void onClick(final int rowIndex) {
+	final Record record = store.getRecordAt(rowIndex);
+	onClick.fire(record.getAsString(ID));
+    }
+
+    private void onDoubleClick(final int rowIndex) {
+	final Record record = store.getRecordAt(rowIndex);
+	onDoubleClick.fire(record.getAsString(ID));
+    }
+}




More information about the kune-commits mailing list