Removed old FieldGroup implementation - web legacy module #PL-2306

This commit is contained in:
Yuriy Artamonov 2013-10-28 09:14:06 +00:00
parent 36f9408d6e
commit e4a87aa18d
2 changed files with 0 additions and 360 deletions

View File

@ -1,94 +0,0 @@
/*
* Copyright (c) 2008-2013 Haulmont. All rights reserved.
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
*/
package com.haulmont.cuba.toolkit.gwt.client.ui;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.Container;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.ui.VForm;
public class VFieldGroup extends VForm {
protected Element captionWrapper = DOM.createDiv();
protected Element expander = DOM.createDiv();
protected boolean expanded;
protected boolean collapsable;
public VFieldGroup() {
super();
DOM.removeChild(legend, caption);
DOM.appendChild(legend, captionWrapper);
DOM.appendChild(captionWrapper, expander);
DOM.appendChild(captionWrapper, caption);
DOM.setElementProperty(captionWrapper, "className", CLASSNAME + "-caption");
DOM.sinkEvents(expander, Event.ONCLICK);
setStyleName("v-fieldgroup");
setStyleName(fieldSet, "v-fieldgroup-fieldset");
}
protected void renderContent(UIDL uidl, ApplicationConnection client) {
final UIDL layoutUidl = uidl.getChildUIDL(0);
if (layoutUidl != null) {
Container newLo = (Container) client.getPaintable(layoutUidl);
if (lo == null) {
lo = newLo;
add((Widget) lo, fieldContainer);
} else if (lo != newLo) {
client.unregisterPaintable(lo);
remove((Widget) lo);
lo = newLo;
add((Widget) lo, fieldContainer);
}
lo.updateFromUIDL(layoutUidl, client);
}
}
protected void renderDOM(UIDL uidl, ApplicationConnection client) {
collapsable = uidl.getBooleanAttribute("collapsable");
if (collapsable) {
DOM.setStyleAttribute(expander, "display", "");
removeStyleDependentName("nocollapsable");
} else {
addStyleDependentName("nocollapsable");
DOM.setStyleAttribute(expander, "display", "none");
}
if (uidl.getBooleanAttribute("expanded") != expanded) {
toggleExpand();
}
super.renderDOM(uidl, client);
}
@Override
public void onBrowserEvent(Event event) {
if (DOM.eventGetType(event) == Event.ONCLICK && DOM.eventGetTarget(event) == expander) {
toggleExpand();
if (collapsable) {
if (expanded) {
client.updateVariable(id, "expand", true, true);
} else {
client.updateVariable(id, "collapse", true, true);
}
}
DOM.eventCancelBubble(event, true);
} else {
super.onBrowserEvent(event);
}
}
protected void toggleExpand() {
expanded = !expanded;
if (expanded) {
captionWrapper.addClassName("expanded");
} else {
captionWrapper.removeClassName("expanded");
}
}
}

View File

@ -1,266 +0,0 @@
/*
* Copyright (c) 2008-2013 Haulmont. All rights reserved.
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
*/
package com.haulmont.cuba.web.toolkit.ui;
import com.haulmont.cuba.toolkit.gwt.client.ui.VFieldGroup;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.ui.*;
import java.io.Serializable;
import java.util.*;
@SuppressWarnings("serial")
@ClientWidget(VFieldGroup.class)
public class FieldGroup extends Form {
private boolean expanded = true;
private boolean collapsable;
private int currentX = 0;
private int currentY = 0;
private List<ExpandCollapseListener> listeners = null;
public FieldGroup() {
this(DefaultFieldFactory.get());
}
public FieldGroup(FormFieldFactory fieldFactory) {
super();
setFormFieldFactory(fieldFactory);
setLayout(new FieldGroupLayout());
}
public boolean isExpanded() {
return !collapsable || expanded;
}
public void setExpanded(boolean expanded) {
if (collapsable) {
this.expanded = expanded;
getLayout().setVisible(expanded);
requestRepaint();
}
}
public boolean isCollapsable() {
return collapsable;
}
public void setCollapsable(boolean collapsable) {
this.collapsable = collapsable;
if (!expanded) {
setExpanded(true);
}
}
@Override
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
target.addAttribute("collapsable", isCollapsable());
if (isCollapsable()) {
target.addAttribute("expanded", isExpanded());
}
}
@Override
public void changeVariables(Object source, Map<String, Object> variables) {
super.changeVariables(source, variables);
if (isCollapsable()) {
if (variables.containsKey("expand")) {
setExpanded(true);
getLayout().requestRepaintAll();
fireExpandListeners();
} else if (variables.containsKey("collapse")) {
setExpanded(false);
fireCollapseListeners();
}
}
}
public void setItemDataSource(Item newDataSource, Collection propertyIds) {
if (layout instanceof GridLayout) {
GridLayout gl = (GridLayout) layout;
if (gridlayoutCursorX == -1) {
// first setItemDataSource, remember initial cursor
gridlayoutCursorX = gl.getCursorX();
gridlayoutCursorY = gl.getCursorY();
} else {
// restore initial cursor
gl.setCursorX(gridlayoutCursorX);
gl.setCursorY(gridlayoutCursorY);
}
}
// Removes all fields first from the form
removeAllProperties();
// Sets the datasource
itemDatasource = newDataSource;
// If the new datasource is null, just set null datasource
if (itemDatasource == null) {
return;
}
// Adds all the properties to this form
for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
final Object id = i.next();
final Property property = itemDatasource.getItemProperty(id);
if (id != null && property != null) {
final Field f = fieldFactory.createField(itemDatasource, id,
this);
if (f != null) {
f.setPropertyDataSource(property);
addField(id, f);
}
}
}
}
@Override
public void addField(Object propertyId, Field field) {
addField(propertyId, field, currentX, currentY);
}
public void addField(Object propertyId, Field field, int col) {
addField(propertyId, field, col, currentY);
}
public void addField(Object propertyId, Field field, int col, int row) {
if (col < 0 || col >= getCols() || row < 0 || row >= getRows()) {
throw new IndexOutOfBoundsException();
}
currentX = col;
currentY = row;
super.addField(propertyId, field);
if (isReadOnly() != field.isReadOnly() && isReadOnly()) {
field.setReadOnly(isReadOnly());
}
if (row < getRows()) {
currentY++;
} else if (col < getCols()) {
currentX++;
}
}
@Override
protected void attachField(Object propertyId, Field field) {
if (propertyId == null || field == null) {
return;
}
final FieldGroupLayout layout = getLayout();
layout.addComponent(field, currentX, currentY);
}
public void addCustomField(Object propertyId, CustomFieldGenerator fieldGenerator) {
addCustomField(propertyId, fieldGenerator, currentX, currentY);
}
public void addCustomField(Object propertyId, CustomFieldGenerator fieldGenerator, int col) {
addCustomField(propertyId, fieldGenerator, col, currentY);
}
public void addCustomField(Object propertyId, CustomFieldGenerator fieldGenerator, int col, int row) {
Field field = fieldGenerator.generateField(itemDatasource, propertyId, this);
addField(propertyId, field, col, row);
}
@Override
public void setLayout(Layout newLayout) {
if (newLayout == null) {
newLayout = new FieldGroupLayout();
}
if (newLayout instanceof FieldGroupLayout) {
super.setLayout(newLayout);
getLayout().setWidth("100%");
getLayout().setSpacing(true);
} else {
throw new IllegalArgumentException("FieldGroup supports only FieldGroupLayout");
}
}
@Override
public FieldGroupLayout getLayout() {
return (FieldGroupLayout) super.getLayout();
}
public float getColumnExpandRatio(int col) {
return getLayout().getColumnExpandRatio(col);
}
public void setColumnExpandRatio(int col, float ratio) {
getLayout().setColumnExpandRatio(col, ratio);
}
public int getCols() {
return getLayout().getColumns();
}
public void setCols(int cols) {
getLayout().setColumns(cols);
}
public int getRows() {
return getLayout().getRows();
}
public void setRows(int rows) {
getLayout().setRows(rows);
}
public void addListener(ExpandCollapseListener listener) {
if (listeners == null) {
listeners = new ArrayList<ExpandCollapseListener>();
}
listeners.add(listener);
}
public void removeListener(ExpandCollapseListener listener) {
if (listeners != null) {
listeners.remove(listener);
if (listeners.isEmpty()) {
listeners = null;
}
}
}
protected void fireExpandListeners() {
if (listeners != null) {
for (final ExpandCollapseListener listener : listeners) {
listener.onExpand(this);
}
}
}
protected void fireCollapseListeners() {
if (listeners != null) {
for (final ExpandCollapseListener listener : listeners) {
listener.onCollapse(this);
}
}
}
public interface ExpandCollapseListener extends Serializable {
void onExpand(FieldGroup component);
void onCollapse(FieldGroup component);
}
public interface CustomFieldGenerator extends Serializable {
com.vaadin.ui.Field generateField(Item item, Object propertyId, FieldGroup component);
}
}