mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 10:17:43 +08:00
Ability for GroupTable grouped static by defined in 'group' tag columns #PL-2153
This commit is contained in:
parent
105a1bd796
commit
7ed21813ea
@ -60,7 +60,7 @@ def desktopModule = project(':cuba-desktop')
|
||||
def uiTestModule = project(':cuba-test-ui')
|
||||
def portalModule = project(':cuba-portal')
|
||||
|
||||
def vaadinVersion = '7.0.5.h.M3'
|
||||
def vaadinVersion = '7.0.5.h.M4'
|
||||
|
||||
def servletApi = [group: 'org.apache.tomcat', name: 'servlet-api', version: '6.0.20']
|
||||
def groovyArtifact = [group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.10']
|
||||
|
@ -67,6 +67,15 @@ public class DesktopGroupTable extends DesktopAbstractTable<JXTable> implements
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFixedGrouping() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFixedGrouping(boolean groupingByUserEnabled) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSortable(boolean sortable) {
|
||||
super.setSortable(sortable);
|
||||
@ -78,4 +87,4 @@ public class DesktopGroupTable extends DesktopAbstractTable<JXTable> implements
|
||||
super.setEditable(editable);
|
||||
impl.setEditable(editable);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,16 +2,15 @@
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Nikolay Gorodnov
|
||||
* Created: 18.11.2009 14:44:36
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
import com.haulmont.cuba.gui.data.GroupInfo;
|
||||
|
||||
/**
|
||||
* @author gorodnov
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface GroupTable extends Table {
|
||||
|
||||
String NAME = "groupTable";
|
||||
@ -25,4 +24,7 @@ public interface GroupTable extends Table {
|
||||
void collapse(GroupInfo groupId);
|
||||
|
||||
boolean isExpanded(GroupInfo groupId);
|
||||
}
|
||||
|
||||
boolean isFixedGrouping();
|
||||
void setFixedGrouping(boolean fixedGrouping);
|
||||
}
|
@ -777,6 +777,8 @@
|
||||
<xs:attributeGroup ref="hasVisibility"/>
|
||||
|
||||
<xs:attributeGroup ref="isTableComponent"/>
|
||||
|
||||
<xs:attribute name="fixedGrouping" type="xs:boolean" use="optional"/>
|
||||
</xs:complexType>
|
||||
|
||||
<!-- Filter -->
|
||||
|
@ -2,48 +2,59 @@
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Nikolay Gorodnov
|
||||
* Created: 25.11.2009 13:37:46
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.GroupTable;
|
||||
import com.haulmont.cuba.gui.components.IFrame;
|
||||
import com.haulmont.cuba.gui.components.Table;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author gorodnov
|
||||
* @version $Id$
|
||||
*/
|
||||
public class GroupTableLoader extends AbstractTableLoader<GroupTable> {
|
||||
|
||||
public GroupTableLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
protected GroupTable createComponent(
|
||||
ComponentsFactory factory
|
||||
) throws InstantiationException, IllegalAccessException {
|
||||
@Override
|
||||
protected GroupTable createComponent(ComponentsFactory factory)
|
||||
throws InstantiationException, IllegalAccessException {
|
||||
return factory.createComponent("groupTable");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Table.Column> loadColumns(
|
||||
final Table component,
|
||||
Element columnsElement,
|
||||
CollectionDatasource ds
|
||||
) {
|
||||
final List<Table.Column> columns = new ArrayList<Table.Column>();
|
||||
public Component loadComponent(ComponentsFactory factory, Element element, Component parent)
|
||||
throws InstantiationException, IllegalAccessException {
|
||||
GroupTable component = (GroupTable) super.loadComponent(factory, element, parent);
|
||||
|
||||
String fixedGroupingString = element.attributeValue("fixedGrouping");
|
||||
if (StringUtils.isNotEmpty(fixedGroupingString)) {
|
||||
component.setFixedGrouping(Boolean.valueOf(fixedGroupingString));
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Table.Column> loadColumns(final Table component, Element columnsElement, CollectionDatasource ds) {
|
||||
final List<Table.Column> columns = new ArrayList<>();
|
||||
|
||||
final Element groupElement = columnsElement.element("group");
|
||||
if (groupElement != null) {
|
||||
columns.addAll(super.loadColumns(component, groupElement, ds));
|
||||
final List<Object> groupProperties = new ArrayList<Object>(columns.size());
|
||||
final List<Object> groupProperties = new ArrayList<>(columns.size());
|
||||
for (Table.Column column : columns) {
|
||||
groupProperties.add(column.getId());
|
||||
}
|
||||
@ -57,4 +68,4 @@ public class GroupTableLoader extends AbstractTableLoader<GroupTable> {
|
||||
columns.addAll(super.loadColumns(component, columnsElement, ds));
|
||||
return columns;
|
||||
}
|
||||
}
|
||||
}
|
@ -186,6 +186,16 @@ public class WebGroupTable extends WebAbstractTable<CubaGroupTable>
|
||||
return component.isExpanded(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFixedGrouping() {
|
||||
return component.isFixedGrouping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFixedGrouping(boolean fixedGrouping) {
|
||||
component.setFixedGrouping(fixedGrouping);
|
||||
}
|
||||
|
||||
protected class GroupTableDsWrapper extends SortableCollectionDsWrapper
|
||||
implements GroupTableContainer,
|
||||
AggregationContainer {
|
||||
|
@ -26,9 +26,11 @@ import java.util.*;
|
||||
*/
|
||||
public class CubaGroupTable extends CubaTable implements GroupTableContainer {
|
||||
|
||||
private KeyMapper groupIdMap = new KeyMapper();
|
||||
protected KeyMapper groupIdMap = new KeyMapper();
|
||||
|
||||
private GroupPropertyValueFormatter groupPropertyValueFormatter;
|
||||
protected GroupPropertyValueFormatter groupPropertyValueFormatter;
|
||||
|
||||
protected boolean fixedGrouping = true;
|
||||
|
||||
@Override
|
||||
public void setContainerDataSource(Container newDataSource) {
|
||||
@ -70,23 +72,30 @@ public class CubaGroupTable extends CubaTable implements GroupTableContainer {
|
||||
boolean needsResetPageBuffer = false;
|
||||
Object[] newGroupProperties = null;
|
||||
|
||||
if (variables.containsKey("columnorder") && !variables.containsKey("groupedcolumns")) {
|
||||
newGroupProperties = new Object[0];
|
||||
} else if (variables.containsKey("groupedcolumns")) {
|
||||
final Object[] ids = (Object[]) variables.get("groupedcolumns");
|
||||
final Object[] groupProperties = new Object[ids.length];
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
groupProperties[i] = columnIdMap.get(ids[i].toString());
|
||||
}
|
||||
newGroupProperties = groupProperties;
|
||||
// Deny group by generated columns
|
||||
if (!columnGenerators.isEmpty()) {
|
||||
List<Object> notGeneratedProperties = new ArrayList<>();
|
||||
for (Object id : newGroupProperties) {
|
||||
if (!columnGenerators.containsKey(id) || (id instanceof MetaPropertyPath))
|
||||
notGeneratedProperties.add(id);
|
||||
if (!fixedGrouping) {
|
||||
if (variables.containsKey("columnorder") && !variables.containsKey("groupedcolumns")) {
|
||||
newGroupProperties = new Object[0];
|
||||
} else if (variables.containsKey("groupedcolumns")) {
|
||||
final Object[] ids = (Object[]) variables.get("groupedcolumns");
|
||||
final Object[] groupProperties = new Object[ids.length];
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
groupProperties[i] = columnIdMap.get(ids[i].toString());
|
||||
}
|
||||
newGroupProperties = notGeneratedProperties.toArray();
|
||||
newGroupProperties = groupProperties;
|
||||
// Deny group by generated columns
|
||||
if (!columnGenerators.isEmpty()) {
|
||||
List<Object> notGeneratedProperties = new ArrayList<>();
|
||||
for (Object id : newGroupProperties) {
|
||||
if (!columnGenerators.containsKey(id) || (id instanceof MetaPropertyPath)) {
|
||||
notGeneratedProperties.add(id);
|
||||
}
|
||||
}
|
||||
newGroupProperties = notGeneratedProperties.toArray();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (variables.containsKey("columnorder") || variables.containsKey("groupedcolumns")) {
|
||||
markAsDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,6 +244,33 @@ public class CubaGroupTable extends CubaTable implements GroupTableContainer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setColumnOrder(Object[] columnOrder) {
|
||||
Collection<?> groupProperties = getGroupProperties();
|
||||
if (!groupProperties.isEmpty()) {
|
||||
// check order of grouped and not grouped columns
|
||||
int i = 1;
|
||||
while (i < columnOrder.length && isValidOrderPosition(groupProperties, columnOrder, i)) {
|
||||
i++;
|
||||
}
|
||||
if (i < columnOrder.length) {
|
||||
// found not grouped column on left side of grouped
|
||||
markAsDirty();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.setColumnOrder(columnOrder);
|
||||
}
|
||||
|
||||
protected boolean isValidOrderPosition(Collection<?> groupProperties, Object[] columnOrder, int index) {
|
||||
if (!groupProperties.contains(columnOrder[index]))
|
||||
return true;
|
||||
|
||||
return groupProperties.contains(columnOrder[index]) &&
|
||||
groupProperties.contains(columnOrder[index - 1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<?> getGroupProperties() {
|
||||
Collection<?> groupProperties = ((GroupTableContainer) items).getGroupProperties();
|
||||
@ -335,6 +371,15 @@ public class CubaGroupTable extends CubaTable implements GroupTableContainer {
|
||||
return ((GroupTableContainer) items).isExpanded(id);
|
||||
}
|
||||
|
||||
public boolean isFixedGrouping() {
|
||||
return fixedGrouping;
|
||||
}
|
||||
|
||||
public void setFixedGrouping(boolean fixedGrouping) {
|
||||
this.fixedGrouping = fixedGrouping;
|
||||
markAsDirty();
|
||||
}
|
||||
|
||||
public GroupPropertyValueFormatter getGroupPropertyValueFormatter() {
|
||||
return groupPropertyValueFormatter;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user