- menu bar component

- top menu
This commit is contained in:
Nikolai Gorodnov 2009-02-02 09:22:53 +00:00
parent ff2d63c3a6
commit 3a8459a134
14 changed files with 900 additions and 61 deletions

View File

@ -3,6 +3,7 @@
<stylesheet src="css/link/link.css"/>
<stylesheet src="css/pagingtable/pagingtable.css"/>
<stylesheet src="css/menubar/menubar.css"/>
<entry-point class="com.haulmont.cuba.toolkit.gwt.client.WidgetSet"/>
</module>

View File

@ -13,20 +13,25 @@ import com.itmill.toolkit.terminal.gwt.client.DefaultWidgetSet;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.google.gwt.user.client.ui.Widget;
import com.haulmont.cuba.toolkit.gwt.client.ui.IPagingTable;
import com.haulmont.cuba.toolkit.gwt.client.ui.IMenuBar;
public class WidgetSet extends DefaultWidgetSet {
protected String resolveWidgetTypeName(UIDL uidl) {
final String tag = uidl.getTag();
if ("pagingtable".equals(tag)) {
return "com.haulmont.cuba.webtoolkit.gwt.client.ui.IPagingTable";
return "com.haulmont.cuba.toolkit.gwt.client.ui.IPagingTable";
} else if ("menubar".equals(tag)) {
return "com.haulmont.cuba.toolkit.gwt.client.ui.IMenuBar";
}
return super.resolveWidgetTypeName(uidl);
}
public Widget createWidget(UIDL uidl) {
final String className = resolveWidgetTypeName(uidl);
if ("com.haulmont.cuba.webtoolkit.gwt.client.ui.IPagingTable".equals(className)) {
if ("com.haulmont.cuba.toolkit.gwt.client.ui.IPagingTable".equals(className)) {
return new IPagingTable();
} else if ("com.haulmont.cuba.toolkit.gwt.client.ui.IMenuBar".equals(className)) {
return new IMenuBar();
}
return super.createWidget(uidl);
}

View File

@ -0,0 +1,131 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
*
* Author: Nikolay Gorodnov
* Created: 29.01.2009 11:28:46
* $Id$
*/
package com.haulmont.cuba.toolkit.gwt.client.ui;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.DOM;
import java.util.Iterator;
public class IMenuBar
extends Composite
implements Paintable
{
public static final String CLASSNAME = "i-menubar";
public static final String CLASSNAME_SUBMENU = CLASSNAME + "-submenu";
private ApplicationConnection client;
private String uidlId;
private Panel panel = new FlowPanel();
private boolean autoOpen, vertical, clickListen;
public IMenuBar() {
panel.addStyleName(CLASSNAME);
initWidget(panel);
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if (client.updateComponent(this, uidl, true)) {
return;
}
this.client = client;
uidlId = uidl.getId();
if (uidl.hasAttribute("autoOpen")) {
autoOpen = uidl.getBooleanAttribute("autoOpen");
}
if (uidl.hasAttribute("vertical")) {
vertical = uidl.getBooleanAttribute("vertical");
}
if (uidl.hasAttribute("clickListen")) {
clickListen = uidl.getBooleanAttribute("clickListen");
}
updateMenuFromUIDL(uidl);
}
private void updateMenuFromUIDL(UIDL uidl) {
final MenuBar menuBar = new MenuBar(vertical);
menuBar.setAutoOpen(autoOpen);
updateMenuBar(menuBar, uidl);
panel.add(menuBar);
}
private void updateMenuBar(MenuBar menuBar, UIDL uidl) {
final Iterator it = uidl.getChildIterator();
while (it.hasNext()) {
final UIDL data = (UIDL) it.next();
if ("menu".equals(data.getTag())) {
createMenuBar(menuBar, data);
} else if ("item".equals(data.getTag())) {
createMenuItem(menuBar, data);
}
}
}
private void createMenuBar(MenuBar parent, UIDL uidl) {
final MenuBar menuBar = new MenuBarWrapper(!vertical);
menuBar.setAutoOpen(parent.getAutoOpen());
updateMenuBar(menuBar, uidl);
parent.addItem(uidl.getStringAttribute("caption"), menuBar);
}
private void createMenuItem(MenuBar parent, UIDL uidl) {
final String caption = uidl.getStringAttribute("caption");
final String key = uidl.getStringAttribute("key");
parent.addItem(caption, new CommandWrapper(key).getCommand());
}
class CommandWrapper {
private final Command cmd;
private final String key;
public CommandWrapper(String k) {
key = k;
cmd = new Command() {
public void execute() {
if (clickListen) {
client.updateVariable(uidlId, "clickedKey", key, true);
}
}
};
}
public Command getCommand() {
return cmd;
}
}
class MenuBarWrapper extends MenuBar {
MenuBarWrapper(boolean vertical) {
super(vertical);
Element el = getElement();
Element outer = DOM.createDiv();
DOM.setElementProperty(outer, "className", CLASSNAME_SUBMENU);
setElement(outer);
DOM.appendChild(outer, el);
}
}
}

View File

@ -7,6 +7,9 @@ import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.*;
import com.itmill.toolkit.terminal.gwt.client.*;
import com.itmill.toolkit.terminal.gwt.client.ui.Table;
import com.itmill.toolkit.terminal.gwt.client.ui.ActionOwner;
import com.itmill.toolkit.terminal.gwt.client.ui.Action;
import com.itmill.toolkit.terminal.gwt.client.ui.IContextMenu;
import com.haulmont.cuba.toolkit.gwt.client.Tools;
import java.util.*;
@ -68,6 +71,8 @@ public class IPagingTable
private String height = null;
private String width = null;
private Set visibleColumns = new HashSet(); //Contains visible columns ids. They need for a header and a body rendering
private static Console log = ApplicationConnection.getConsole();
public IPagingTable() {
@ -344,7 +349,7 @@ public class IPagingTable
}
//todo ìèí øèðèíà êîëîíêè 50ïêñ
//todo ðàçðóëèòü âàðèàíò êîãäà øèðèíà òàáëèöû áîëüøå ñâîáîäíîãî ìåñòà
//todo ðàçðóëèòü âàðèàíò êîãäà øèðèíà òàáëèöû áîëüøå ñâîáîäíîãî ìåñòà
// last loop: set possibly modified values or reset if new tBody
@ -501,7 +506,7 @@ public class IPagingTable
}
}
class TableHeader extends Panel {
class TableHeader extends Panel implements ActionOwner {
private final Element headerBody = DOM.createDiv();
private final Element columnsSelector = DOM.createDiv();
@ -509,6 +514,8 @@ public class IPagingTable
private final Map availableCells = new HashMap();
private final Vector visibleCells = new Vector();
private VisibleColumnsMenu columnsMenu = null;
TableHeader() {
setElement(DOM.createDiv());
setStyleName(CLASSNAME + "-header-wrap");
@ -525,9 +532,9 @@ public class IPagingTable
public void updateHeaderFromUIDL(UIDL uidl) {
final Iterator it = uidl.getChildIterator();
// visibleColumns.clear();
// int colIndex = (rowHeaders ? 1 : 0);
// visibleCells.clear();
visibleColumns.clear(); //clear visible columns
while (it.hasNext()) {
final UIDL col = (UIDL) it.next();
if (!col.hasAttribute("collapsed")) {
@ -542,9 +549,9 @@ public class IPagingTable
} else {
c.setCaption(caption);
}
}
// colIndex++;
visibleColumns.add(c.getCid());
}
}
}
@ -558,6 +565,13 @@ public class IPagingTable
return DOM.getElementPropertyInt(columnsSelector, "offsetWidth");
}
private VisibleColumnsMenu getColumnsMenu() {
if (columnsMenu == null) {
columnsMenu = new VisibleColumnsMenu();
}
return columnsMenu;
}
public boolean remove(Widget child) {
if (visibleCells.contains(child)) {
visibleCells.remove(child);
@ -574,12 +588,104 @@ public class IPagingTable
public void onBrowserEvent(Event event) {
if (DOM.compare(DOM.eventGetTarget(event), columnsSelector)) {
Window.alert("Columns menu will be here");
// final int left = DOM.getAbsoluteLeft(columnSelector);
// final int top = DOM.getAbsoluteTop(columnSelector)
// + DOM.getElementPropertyInt(columnSelector,
// "offsetHeight");
// client.getContextMenu().showAt(this, left, top);
final int left = DOM.getAbsoluteLeft(columnsSelector);
final int top = DOM.getAbsoluteTop(columnsSelector)
+ DOM.getElementPropertyInt(columnsSelector,
"offsetHeight");
getColumnsMenu().showAt(this, left, top);
}
}
public Action[] getActions() {
final Action[] actions = new Action[availableCells.size() + 1];
final Iterator it = availableCells.values().iterator();
int i = 0;
while (it.hasNext()) {
final Cell cell = (Cell) it.next();
final Action a = new VisibleColumnAction(cell.getCid(), false);
a.setCaption(cell.getCaption());
actions[i++] = a;
}
actions[i] = new ApplyVisibleColumnsAction("Apply");
return actions;
}
public ApplicationConnection getClient() {
return client;
}
public String getPaintableId() {
return uidlId;
}
class VisibleColumnAction
extends Action
{
private String cid;
private boolean collapsed;
VisibleColumnAction(String cid, boolean collapsed) {
super(TableHeader.this);
this.cid = cid;
this.collapsed = collapsed;
}
public void execute() {
Window.alert("Column " + cid + " click");
}
public String getCid() {
return cid;
}
public boolean isCollapsed() {
return collapsed;
}
public String getHTML() {
final StringBuffer sb = new StringBuffer();
if (collapsed) {
sb.append("<span class=\"" + CLASSNAME + "-column-off\">");
} else {
sb.append("<span class=\"" + CLASSNAME + "-column-on\">");
}
sb.append(super.getHTML());
sb.append("</span>");
return sb.toString();
}
}
class ApplyVisibleColumnsAction
extends Action
{
ApplyVisibleColumnsAction(String caption) {
super(TableHeader.this);
setCaption(caption);
}
public void execute() {
getColumnsMenu().hide();
Window.alert("Apply clicked");
}
public String getHTML() {
return "<button class=\""
+ CLASSNAME
+ "-columns-apply\">"
+ getCaption()
+ "</button>";
}
}
class VisibleColumnsMenu extends IContextMenu {
VisibleColumnsMenu() {
super();
setActionOwner(TableHeader.this);
setStyleName(CLASSNAME + "-menu");
}
}
@ -619,7 +725,7 @@ public class IPagingTable
public void setCaption(String newCaption) {
if (!caption.equals(newCaption)) {
this.caption = newCaption;
DOM.setInnerHTML(captionContainer,
DOM.setInnerHTML(captionContainer,
"<span class=\""
+ CLASSNAME
+ "-caption\">"
@ -698,7 +804,7 @@ public class IPagingTable
public int availableWidth() {
return DOM.getElementPropertyInt(sizer, "offsetWidth");
}
public void updateBodyFromUIDL(UIDL uidl) {
final Iterator it = uidl.getChildIterator();
// rows.clear();

View File

@ -0,0 +1,39 @@
.i-menubar, .i-menubar-submenu {
font-family: "Trebuchet MS", geneva, helvetica, arial, tahoma, verdana, sans-serif;
background-color: #f6f7f7;
color: #464f52;
font-size: 14px;
}
.i-menubar-submenu {
border-right: 2px solid #c6cbcc;
border-bottom: 2px solid #c6cbcc;
border-top: 1px solid #d0d4d5;
border-left: 1px solid #d0d4d5;
}
.i-menubar-submenu .gwt-MenuBar {
margin: 5px;
}
.i-menubar .gwt-MenuItem, .i-menubar-submenu .gwt-MenuItem {
padding: 2px 0;
cursor: pointer;
vertical-align: middle;
}
.i-menubar table, .i-menubar-submenu table {
border-collapse: collapse;
margin: 0;
padding: 0;
}
.i-menubar {
border: 1px solid #d0d4d5;
padding-left: 30px;
}
.i-menubar .gwt-MenuItem {
padding: 0 20px 0 5px;
border-left: 1px solid #d0d4d5;
}
.i-menubar .gwt-MenuItem-selected {
text-decoration: underline;
}
.i-menubar-submenu .gwt-MenuItem-selected {
background-color: #e9eced;
}

View File

@ -194,20 +194,68 @@
/* rowe in column selector */
.i-on div {
.i-page-table-column-on div {
background-image: url(img/check.gif);
background-repeat: no-repeat;
background-position: 2px center;
text-indent: 6px;
}
.i-off div {
.i-page-table-column-off div {
text-indent: 6px;
}
.i-page-table-columns-apply {
padding: 0 5px;
margin: 0 10px 5px;
}
.i-page-table-menu {
font-family: "Trebuchet MS", geneva, helvetica, arial, tahoma, verdana, sans-serif;
background-color: #f6f7f7;
color: #464f52;
font-size: 12px;
line-height: 14px;
}
.i-page-table-menu .gwt-MenuBar {
border-right: 2px solid #c6cbcc;
border-bottom: 2px solid #c6cbcc;
border-top: 1px solid #d0d4d5;
border-left: 1px solid #d0d4d5;
}
.i-page-table-menu .gwt-MenuItem {
padding: 2px 0;
cursor: pointer;
vertical-align: middle;
}
.i-page-table-menu .gwt-MenuItem div {
/*border: 1px solid #f6f7f7;*/
padding: 1px 20px 1px 8px;
cursor: pointer;
vertical-align: middle;
white-space: nowrap;
}
.i-page-table-menu table {
border-collapse:collapse;
margin:0;
padding:0;
}
.i-page-table-menu .gwt-MenuItem img {
margin-right: 10px;
vertical-align: middle;
}
/* IE6 hack */
* html .i-page-table-scrollposition {
background: transparent;
/*
AlphaImageLoader uses src attribute relative to host page, not CSS
We need multiple different filters because we cannot be sure how host page is served compared to theme resources
*/
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../../ITMILL/themes/demo/table/img/scroll-position-bg.png", sizingMethod="scale");
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../ITMILL/themes/demo/table/img/scroll-position-bg.png", sizingMethod="scale");
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="ITMILL/themes/demo/table/img/scroll-position-bg.png", sizingMethod="scale");
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/ITMILL/themes/demo/table/img/scroll-position-bg.png", sizingMethod="scale");
}
.i-page-length-editor {

View File

@ -17,46 +17,57 @@
<setting name="EXPLODED_ENABLED" value="false" />
<setting name="JAR_URL" value="file://" />
<setting name="JAR_ENABLED" value="false" />
<setting name="BUILD_MODULE_ON_FRAME_DEACTIVATION" value="false" />
<setting name="BUILD_EXTERNAL_DEPENDENCIES" value="false" />
<setting name="EXCLUDE_EXPLODED_DIRECTORY" value="true" />
<setting name="RUN_JASPER_VALIDATION" value="false" />
<setting name="BUILD_ONLY_WEB_RESOURCES" value="false" />
</building>
<packaging>
<containerElement type="module" name="core">
<attribute name="method" value="0" />
<attribute name="URI" value="/WEB-INF/classes" />
</containerElement>
<containerElement type="module" name="gui">
<attribute name="method" value="0" />
<attribute name="URI" value="/WEB-INF/classes" />
</containerElement>
<containerElement type="module" name="web">
<attribute name="method" value="0" />
<attribute name="URI" value="/WEB-INF/classes" />
</containerElement>
<containerElement type="module" name="web-war">
<attribute name="method" value="1" />
<attribute name="URI" value="/WEB-INF/classes" />
</containerElement>
<containerElement type="library" name="chile" level="project">
<attribute name="method" value="0" />
<attribute name="URI" value="/WEB-INF/lib" />
</containerElement>
<containerElement type="library" name="common" level="project">
<attribute name="method" value="0" />
<attribute name="URI" value="/WEB-INF/lib" />
</containerElement>
<containerElement type="library" name="gwt" level="project">
<attribute name="method" value="0" />
<attribute name="URI" value="&lt;N/A&gt;" />
</containerElement>
<containerElement type="library" name="server" level="project">
<attribute name="method" value="0" />
<attribute name="URI" value="&lt;N/A&gt;" />
</containerElement>
<containerElement type="library" name="test" level="project">
<attribute name="method" value="0" />
<attribute name="URI" value="&lt;N/A&gt;" />
</containerElement>
<containerElement type="library" level="module">
<attribute name="method" value="0" />
<attribute name="URI" value="&lt;N/A&gt;" />
<url>jar://$APPLICATION_HOME_DIR$/lib/j2ee.jar!/</url>
</containerElement>
</packaging>
</configuration>
</facet>
<facet type="gwt" name="GWT">
<configuration>
<setting name="additionalCompilerParameters" value="" />
<setting name="compilerMaxHeapSize" value="128" />
<setting name="compilerOutputPath" value="" />
<setting name="gwtScriptOutputStyle" value="DETAILED" />
<setting name="gwtSdkUrl" value="" />
<setting name="runGwtCompilerOnMake" value="true" />
</configuration>
</facet>
<facet type="gwt" name="GWT">
<configuration>
<setting name="additionalCompilerParameters" value="" />
<setting name="compilerMaxHeapSize" value="128" />
<setting name="compilerOutputPath" value="" />
<setting name="gwtScriptOutputStyle" value="DETAILED" />
<setting name="gwtSdkUrl" value="" />
<setting name="runGwtCompilerOnMake" value="true" />
</configuration>
</facet>
<facet type="gwt" name="GWT">
<configuration>
<setting name="additionalCompilerParameters" value="" />
<setting name="compilerMaxHeapSize" value="128" />
<setting name="compilerOutputPath" value="" />
<setting name="gwtScriptOutputStyle" value="DETAILED" />
<setting name="gwtSdkUrl" value="file://$MODULE_DIR$/../../../demoapp/modules/web-war/gwt" />
<setting name="runGwtCompilerOnMake" value="true" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
@ -79,6 +90,7 @@
<orderEntry type="module" module-name="web" />
<orderEntry type="module" module-name="gui" />
<orderEntry type="library" name="gwt" level="project" />
<orderEntryProperties />
</component>
</module>

View File

@ -13,6 +13,10 @@
<param-name>application</param-name>
<param-value>com.haulmont.cuba.web.App</param-value>
</init-param>
<init-param>
<param-name>widgetset</param-name>
<param-value>com.haulmont.cuba.toolkit.gwt.WidgetSet</param-value>
</init-param>
</servlet>
<servlet-mapping>

View File

@ -7,4 +7,5 @@
<menu id="administration">
<item id="core$Server.browse" class="com.haulmont.cuba.web.app.ui.DemoScreen"/>
</menu>
<item id="demo$table" class="com.haulmont.cuba.web.app.ui.DemoTableScreen"/>
</menu-config>

View File

@ -12,16 +12,25 @@ package com.haulmont.cuba.web;
import com.haulmont.cuba.web.log.LogWindow;
import com.haulmont.cuba.web.resource.Messages;
import com.haulmont.cuba.web.toolkit.ui.MenuBar;
import com.haulmont.cuba.gui.config.MenuItem;
import com.haulmont.cuba.gui.WindowManager;
import com.itmill.toolkit.ui.*;
import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.event.ItemClickEvent;
import java.util.Locale;
import java.util.List;
import java.util.Collections;
import org.dom4j.Element;
public class AppWindow extends Window
{
private Connection connection;
private ExpandLayout rootLayout;
private MenuBar menuBar;
private TabSheet tabSheet;
public AppWindow(Connection connection) {
@ -54,16 +63,16 @@ public class AppWindow extends Window
titleLayout.setSpacing(true);
titleLayout.setHeight(-1);
Button navBtn = new Button(Messages.getString("navBtn"),
new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
Navigator navigator = new Navigator(AppWindow.this);
addWindow(navigator);
}
}
);
navBtn.setStyleName(Button.STYLE_LINK);
titleLayout.addComponent(navBtn);
// Button navBtn = new Button(Messages.getString("navBtn"),
// new Button.ClickListener() {
// public void buttonClick(Button.ClickEvent event) {
// Navigator navigator = new Navigator(AppWindow.this);
// addWindow(navigator);
// }
// }
// );
// navBtn.setStyleName(Button.STYLE_LINK);
// titleLayout.addComponent(navBtn);
Label label = new Label(String.format(Messages.getString("loggedInLabel"),
connection.getSession().getName(), connection.getSession().getProfile()));
@ -105,14 +114,69 @@ public class AppWindow extends Window
viewLogBtn.setStyleName(Button.STYLE_LINK);
titleLayout.addComponent(viewLogBtn);
titleLayout.expand(navBtn);
// titleLayout.expand(navBtn);
rootLayout.addComponent(titleLayout);
menuBar = new MenuBar();
initMenuBar();
rootLayout.addComponent(menuBar);
tabSheet = new TabSheet();
tabSheet.setSizeFull();
rootLayout.addComponent(tabSheet);
rootLayout.expand(tabSheet);
}
private void initMenuBar() {
List<MenuItem> rootItems = App.getInstance().getMenuConfig().getRootItems();
for (MenuItem menuItem : rootItems) {
createMenuItem(menuItem, null);
}
menuBar.addListener(new ItemClickEvent.ItemClickListener() {
public void itemClick(ItemClickEvent event) {
MenuItem menuItem = (MenuItem) event.getItemId();
final String caption = menuItem.getCaption();
final Element element = menuItem.getDescriptor();
final String template = element.attributeValue("template");
if (template != null) {
App.getInstance().getScreenManager().openWindow(
template,
WindowManager.OpenType.NEW_TAB,
Collections.singletonMap("caption", caption));
} else {
final String className = element.attributeValue("class");
if (className != null) {
try {
App.getInstance().getScreenManager().openWindow(
Class.forName(className),
WindowManager.OpenType.NEW_TAB,
Collections.singletonMap("caption", caption));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
}
});
}
private void createMenuItem(MenuItem menuItem, MenuItem parenItem) {
menuBar.addItem(menuItem);
if (parenItem != null) {
menuBar.setParent(menuItem, parenItem);
}
if (menuItem.getChildren().size() == 0) {
menuBar.setChildrenAllowed(menuItem, false);
}
else {
menuBar.setChildrenAllowed(menuItem, true);
for (MenuItem item : menuItem.getChildren()) {
createMenuItem(item, menuItem);
}
}
}
}

View File

@ -0,0 +1,200 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
*
* Author: Nikolay Gorodnov
* Created: 29.01.2009 14:49:58
* $Id$
*/
package com.haulmont.cuba.web.app.ui;
import com.haulmont.cuba.web.toolkit.ui.PagingTable;
import com.haulmont.cuba.web.ui.Window;
import com.itmill.toolkit.data.Item;
import com.itmill.toolkit.data.Property;
import com.itmill.toolkit.data.util.BeanItem;
import com.itmill.toolkit.data.util.ObjectProperty;
import com.itmill.toolkit.ui.CustomComponent;
import com.itmill.toolkit.ui.ExpandLayout;
import com.itmill.toolkit.ui.Layout;
import com.itmill.toolkit.ui.ComponentContainer;
import java.util.*;
public class DemoTableScreen extends Window {
public void init() {
((ComponentContainer) component).addComponent(new TableExample());
}
class TableExample extends CustomComponent {
TableExample() {
Layout main = new ExpandLayout();
setCompositionRoot(main);
List<ListBeanContainer.Value> values = new ArrayList<ListBeanContainer.Value>();
for (int i = 0; i < 100; i++) {
final ListBeanContainer.Value value = new ListBeanContainer.Value();
value.setId(String.valueOf(i));
value.setName("Name " + String.valueOf(i));
value.setValue("Value " + String.valueOf(i));
values.add(value);
}
com.itmill.toolkit.data.Container dataSource = new ListBeanContainer(values);
PagingTable table = new PagingTable("Paging Table Example", dataSource);
table.setPageLength(10);
table.setHeight("300px");
table.setWidth("700px");
table.setItemCaptionPropertyId("id");
table.setShowPageLengthEditor(true);
table.setVisibleColumns(dataSource.getContainerPropertyIds().toArray());
main.addComponent(table);
}
}
static class ListBeanContainer implements com.itmill.toolkit.data.Container {
private static Collection propertyIds = new ArrayList(3);
static {
propertyIds.add("id");
propertyIds.add("name");
propertyIds.add("value");
}
private List itemIds;
private Map id2row;
public ListBeanContainer(List items) {
if (items == null) {
items = new ArrayList(0);
}
initItems(items);
}
private void initItems(List items) {
itemIds = new ArrayList(items.size());
id2row = new HashMap(items.size());
for (final Iterator iterator = items.iterator(); iterator.hasNext();) {
final Object o = iterator.next();
ListBeanContainer.ListItem item = null;
if (o instanceof ListBeanContainer.ListItem) {
item = (ListBeanContainer.ListItem) o;
} else if (o instanceof Value) {
item = new ListItem((Value) o);
}
if (item != null) {
final String itemId = item.getBean().getId();
itemIds.add(itemId);
id2row.put(itemId, item);
}
}
}
public Item getItem(Object itemId) {
return (Item) id2row.get(itemId);
}
public Collection getContainerPropertyIds() {
return Collections.unmodifiableCollection(propertyIds);
}
public Collection getItemIds() {
return Collections.unmodifiableCollection(itemIds);
}
public Property getContainerProperty(
Object itemId,
Object propertyId
) {
final ListBeanContainer.ListItem item = (ListBeanContainer.ListItem) id2row.get(itemId);
if (item != null) {
return item.getItemProperty(propertyId);
}
return new ObjectProperty("");
}
public Class getType(Object propertyId) {
return String.class;
}
public int size() {
return itemIds.size();
}
public boolean containsId(Object itemId) {
return (getItem(itemId) != null);
}
public Item addItem(Object itemId) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public Object addItem() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public boolean removeItem(Object itemId) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public boolean addContainerProperty(Object propertyId, Class type, Object defaultValue) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public boolean removeAllItems() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public static class Value {
private String id;
private String name;
private String value;
public Value() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
public static class ListItem extends BeanItem {
public ListItem(ListBeanContainer.Value value) {
super(value, propertyIds);
}
public ListBeanContainer.Value getBean() {
return (ListBeanContainer.Value) super.getBean();
}
}
}
}

View File

@ -4,6 +4,8 @@ menu-config.security=Security
menu-config.sec$Group.browse=Groups
menu-config.sec$Role.browse=Roles
menu-config.sec$User.browse=Users
menu-config.demo=Demo
menu-config.demo$table=Paging Table Demo
application.caption=CUBA Application

View File

@ -0,0 +1,219 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
*
* Author: Nikolay Gorodnov
* Created: 27.01.2009 16:11:44
* $Id$
*/
package com.haulmont.cuba.web.toolkit.ui;
import com.itmill.toolkit.data.Container;
import com.itmill.toolkit.data.util.ContainerHierarchicalWrapper;
import com.itmill.toolkit.data.util.IndexedContainer;
import com.itmill.toolkit.event.ItemClickEvent;
import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;
import com.itmill.toolkit.ui.AbstractSelect;
import java.util.*;
public class MenuBar extends AbstractSelect
implements Container.Hierarchical, ItemClickEvent.ItemClickSource
{
public static final String TAG_NAME = "menubar";
private boolean vertical;
private boolean autoOpen = false;
private int clickListenerCount = 0;
public MenuBar() {
this(false);
}
public MenuBar(boolean vertical) {
this(vertical, null);
}
public MenuBar(boolean vertical, Container dataSource) {
setVertical(vertical);
setContainerDataSource(dataSource);
}
public void paintContent(PaintTarget target) throws PaintException {
// super.paintContent(target);
if (isVertical()) {
target.addAttribute("vertical", vertical);
}
if (isAutoOpen()) {
target.addAttribute("autoOpen", autoOpen);
}
if (clickListenerCount > 0) {
target.addAttribute("clickListen", true);
}
final Stack iteratorStack = new Stack();
final Collection rootIds = rootItemIds();
if (rootIds != null) {
iteratorStack.push(rootIds.iterator());
}
while (!iteratorStack.isEmpty()) {
final Iterator i = (Iterator) iteratorStack.peek();
if (!i.hasNext())
{
iteratorStack.pop();
if (!iteratorStack.isEmpty()) {
target.endTag("menu");
}
} else {
Object itemId = i.next();
final boolean allowChildren = areChildrenAllowed(itemId);
if (allowChildren) {
target.startTag("menu");
} else {
target.startTag("item");
}
final String key = itemIdMapper.key(itemId);
target.addAttribute("key", key);
target.addAttribute("caption", getItemCaption(itemId));
if (hasChildren(itemId)
&& areChildrenAllowed(itemId)) {
iteratorStack.push(getChildren(itemId).iterator());
} else {
if (allowChildren) {
target.endTag("menu");
} else {
target.endTag("item");
}
}
}
}
}
public void changeVariables(Object source, Map variables) {
if (clickListenerCount > 0 && variables.containsKey("clickedKey")) {
String key = (String) variables.get("clickedKey");
Object id = itemIdMapper.get(key);
// MouseEventDetails details = MouseEventDetails.deSerialize((String) variables
// .get("clickEvent"));
fireEvent(new ItemClickEvent(this, getItem(id), id, null, null));
}
// if (variables.containsKey("selected")) {
// variables = new HashMap(variables);
// variables.remove("selected");
// }
// super.changeVariables(source, variables);
}
public void setContainerDataSource(Container newDataSource) {
if (newDataSource == null) {
newDataSource = new ContainerHierarchicalWrapper(
new IndexedContainer());
}
if (Container.Hierarchical.class.isAssignableFrom(newDataSource
.getClass())) {
super.setContainerDataSource(newDataSource);
} else {
super.setContainerDataSource(new ContainerHierarchicalWrapper(
newDataSource));
}
}
public Collection getChildren(Object itemId) {
return ((Hierarchical) items).getChildren(itemId);
}
public Object getParent(Object itemId) {
return ((Hierarchical) items).getParent(itemId);
}
public Collection rootItemIds() {
return ((Hierarchical) items).rootItemIds();
}
public boolean setParent(Object itemId, Object newParentId) throws UnsupportedOperationException {
boolean success = ((Hierarchical) items).setParent(itemId, newParentId);
if (success) {
requestRepaint();
}
return success;
}
public boolean areChildrenAllowed(Object itemId) {
return ((Hierarchical) items).areChildrenAllowed(itemId);
}
public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed) throws UnsupportedOperationException {
boolean success = ((Hierarchical) items).setChildrenAllowed(itemId, areChildrenAllowed);
if (success) {
requestRepaint();
}
return success;
}
public boolean isRoot(Object itemId) {
return ((Hierarchical) items).isRoot(itemId);
}
public boolean hasChildren(Object itemId) {
return ((Hierarchical) items).hasChildren(itemId);
}
public void addListener(ItemClickEvent.ItemClickListener listener) {
addListener(ItemClickEvent.class, listener,
ItemClickEvent.ITEM_CLICK_METHOD);
clickListenerCount++;
if (clickListenerCount == 1) {
requestRepaint();
}
}
public void removeListener(ItemClickEvent.ItemClickListener listener) {
if (clickListenerCount > 0) {
removeListener(ItemClickEvent.class, listener,
ItemClickEvent.ITEM_CLICK_METHOD);
clickListenerCount--; //todo fix the Tree class. There was clickListenerCount++;
if (clickListenerCount == 0) {
requestRepaint();
}
}
}
public boolean isAutoOpen() {
return autoOpen;
}
public void setAutoOpen(boolean autoOpen) {
this.autoOpen = autoOpen;
}
public boolean isVertical() {
return vertical;
}
public void setVertical(boolean vertical) {
this.vertical = vertical;
}
public String getTag() {
return TAG_NAME;
}
}

View File

@ -32,6 +32,7 @@ public class PagingTable extends AbstractSelect {
private static final int CELL_FIRSTCOL = 4;
private final List visibleColumns = new LinkedList();
private final Set collapsedColumns = new HashSet();
private final Map columnHeaders = new HashMap();
@ -42,12 +43,18 @@ public class PagingTable extends AbstractSelect {
private boolean showPageLengthEditor = false;
private boolean columnsCollapsingAllowed = true;
private Object[][] pageBuffer = null;
public PagingTable(String caption, Container dataSource) {
super(caption, dataSource);
}
public Object[] getAvailableColumns() {
return getContainerPropertyIds().toArray();
}
public void setVisibleColumns(Object[] columns) {
setVisibleColumns(columns, true);
}
@ -189,7 +196,7 @@ public class PagingTable extends AbstractSelect {
if (cols > 0) {
for (int colIndex = 0; colIndex < cols; colIndex++)
{
Object value = new String("");
Object value = "";
final Property p = getContainerProperty(id, colIds[colIndex]);
if (p != null) {
value = p.getValue();