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

vjrj vjrj at ourproject.org
Fri Jul 18 14:10:57 CEST 2008


Author: vjrj
Date: 2008-07-18 14:10:54 +0200 (Fri, 18 Jul 2008)
New Revision: 802

Modified:
   sandbox3/src/main/java/org/op/client/Sandbox.java
   sandbox3/src/main/java/org/op/client/gridmenu/GridMenu.java
   sandbox3/src/main/java/org/op/client/gridmenu/GridMenuPanel.java
Log:
new GridMenuPanel tests

Modified: sandbox3/src/main/java/org/op/client/Sandbox.java
===================================================================
--- sandbox3/src/main/java/org/op/client/Sandbox.java	2008-07-18 10:24:57 UTC (rev 801)
+++ sandbox3/src/main/java/org/op/client/Sandbox.java	2008-07-18 12:10:54 UTC (rev 802)
@@ -3,7 +3,9 @@
 import org.op.client.gridmenu.GridGroup;
 import org.op.client.gridmenu.GridItem;
 import org.op.client.gridmenu.GridMenu;
+import org.op.client.gridmenu.GridMenuItem;
 import org.op.client.gridmenu.GridMenuPanel;
+import org.op.client.gridmenu.GridMenuItem.GridMenuItemListener;
 import org.ourproject.kune.platf.client.View;
 
 import com.calclab.suco.client.signal.Slot;
@@ -177,6 +179,7 @@
 	final GridMenuPanel grid = new GridMenuPanel("Nada", true, true);
 	grid.getTopBar().addButton(new ToolbarButton("boton"));
 	grid.getBottomBar().addButton(new ToolbarButton("boton 2"));
+	grid.setEndIconVisible(false);
 	grid.onDoubleClick(new Slot<String>() {
 	    public void onEvent(final String id) {
 		Window.alert("Double click, id: " + id);
@@ -197,12 +200,26 @@
 	item1.setGroup(collab);
 	item1.setTitleHtml("New fulano");
 	grid.updateItem(item1);
+	final GridMenuItem menuItem = new GridMenuItem("/arrow_in.png", "operation 1", new GridMenuItemListener() {
+	    public void onClick() {
+		Window.alert("click");
+	    }
+	});
+	final GridMenuItem menuItem2 = new GridMenuItem("/arrow_out.png", "operation 2", new GridMenuItemListener() {
+	    public void onClick() {
+		Window.alert("click");
+	    }
+	});
+	final GridMenu menu = new GridMenu();
+	menu.addMenuItem(menuItem);
+	menu.addMenuItem(menuItem2);
 	final GridItem item4bis = new GridItem(GridGroup.NoGridGroup, "4", "<a href=''>b2</a>", "fulan2",
-		"<em>fulane</em>", "<b>k3</b>", "tooltiptitle", "tooptip", new GridMenu());
+		"<em>fulane</em>", "<b>k3</b>", "tooltiptitle", "tooptip", menu);
 	grid.removeItem(item4bis);
 	grid.addItem(item4bis);
 	grid.removeItem(item4bis);
 	grid.addItem(item4bis);
+
 	return grid;
     }
 }

Modified: sandbox3/src/main/java/org/op/client/gridmenu/GridMenu.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridMenu.java	2008-07-18 10:24:57 UTC (rev 801)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridMenu.java	2008-07-18 12:10:54 UTC (rev 802)
@@ -38,15 +38,15 @@
 	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 addMenuItem(final GridMenuItem menuItem) {
+	final Item item = new Item(menuItem.getTitle());
+	item.setIconCls(menuItem.getIconCls());
+	menu.addItem(item);
+	item.addListener(new BaseItemListenerAdapter() {
 	    public void onClick(final BaseItem item, final EventObject e) {
 		DeferredCommand.addCommand(new Command() {
 		    public void execute() {
-			menuOpt.getListener().onClick();
+			menuItem.getListener().onClick();
 		    }
 		});
 	    }
@@ -63,7 +63,9 @@
     }
 
     public void showMenu(final EventObject e) {
-	menu.showAt(e.getXY());
+	if (menu.getItems().length > 0) {
+	    menu.showAt(e.getXY());
+	}
     }
 
 }

Modified: sandbox3/src/main/java/org/op/client/gridmenu/GridMenuPanel.java
===================================================================
--- sandbox3/src/main/java/org/op/client/gridmenu/GridMenuPanel.java	2008-07-18 10:24:57 UTC (rev 801)
+++ sandbox3/src/main/java/org/op/client/gridmenu/GridMenuPanel.java	2008-07-18 12:10:54 UTC (rev 802)
@@ -33,7 +33,6 @@
 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;
 
@@ -50,7 +49,7 @@
     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, GridMenu> menuMap;
     private final HashMap<String, Record> recordMap;
     private RecordDef recordDef;
     private GroupingStore store;
@@ -65,6 +64,7 @@
     private final String emptyText;
     private final GridDragConfiguration gridDragConfiguration;
     private final GridDropConfiguration gridDropConfiguration;
+    private ColumnModel columnModel;
 
     public GridMenuPanel(final String emptyText) {
 	this(emptyText, null, null, false, false);
@@ -90,7 +90,7 @@
 	panel = new Panel();
 	panel.setBorder(false);
 	panel.setLayout(new FitLayout());
-	menuMap = new HashMap<Record, GridMenu>();
+	menuMap = new HashMap<String, GridMenu>();
 	recordMap = new HashMap<String, Record>();
     }
 
@@ -102,14 +102,14 @@
 	if (grid == null) {
 	    createGrid(emptyText, gridDragConfiguration, gridDropConfiguration);
 	}
-	final Record newRecord = recordDef.createRecord(item.getId(),
+	final String id = item.getId();
+	final Record newRecord = recordDef.createRecord(id,
 		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);
+			item.getGroup().getTooltip(), id, item.getIconHtml(), item.getTitle(), item.getTitleHtml(),
+			item.getEndIconHtml(), item.getTooltipTitle(), item.getTooltip() });
+	recordMap.put(id, newRecord);
 	store.addSorted(newRecord);
-	// store.groupBy(GROUP);
-	menuMap.put(newRecord, item.getMenu());
+	menuMap.put(id, item.getMenu());
 	sort();
 	doLayoutIfNeeded();
     }
@@ -187,6 +187,14 @@
 	}
     }
 
+    public void setEndIconVisible(final boolean visible) {
+	if (grid == null) {
+	    createGrid(emptyText, gridDragConfiguration, gridDropConfiguration);
+	}
+	columnModel.setHidden(2, !visible);
+	doLayoutIfNeeded();
+    }
+
     public void setWidth(final int width) {
 	// Log.info("Grid width: " + width);
 	grid.setWidth(width - 27);
@@ -199,7 +207,8 @@
     }
 
     public void updateItem(final GridItem item) {
-	final Record record = recordMap.get(item.getId());
+	final String id = item.getId();
+	final Record record = recordMap.get(id);
 	if (record != null) {
 	    record.set(GROUP, item.getGroup().getName());
 	    record.set(GROUP_TOOLTIP_TITLE, item.getGroup().getTooltipTitle());
@@ -211,11 +220,11 @@
 	    record.set(TOOLTIPTITLE, item.getTooltipTitle());
 	    record.set(TOOLTIP, item.getTooltip());
 	    store.commitChanges();
-	    menuMap.put(record, item.getMenu());
+	    menuMap.put(id, item.getMenu());
 	    sort();
 	    doLayoutIfNeeded();
 	} else {
-	    Log.error("Trying to update a non existing item: " + item.getId());
+	    Log.error("Trying to update a non existing item: " + id);
 	}
     }
 
@@ -305,21 +314,16 @@
 	};
 
 	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("Icon", ICON_HTML, 3, false, iconHtmlRenderer, ICON_HTML),
+		new ColumnConfig("Title", TITLE_HTML, 10, 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);
+	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);
@@ -331,14 +335,15 @@
 	    }
 
 	    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);
+		final GridMenu menu = menuMap.get(record.getAsString(ID));
+		if (menu != null) {
+		    menu.showMenu(e);
+		}
 	    }
 	});
 	grid.stripeRows(true);




More information about the kune-commits mailing list