mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-05 04:38:10 +08:00
PL-7593 Ability to style GroupBox as Vaadin Panel
This commit is contained in:
parent
b7c8e3c910
commit
366b036c44
@ -38,6 +38,7 @@ public class DesktopGroupBox extends DesktopAbstractBox implements GroupBoxLayou
|
||||
protected List<ExpandedStateChangeListener> expandedStateChangeListeners;
|
||||
|
||||
protected boolean settingsEnabled = true;
|
||||
protected boolean shownAsPanel;
|
||||
|
||||
public DesktopGroupBox() {
|
||||
collapsiblePanel = new CollapsiblePanel(super.getComposition());
|
||||
@ -222,6 +223,16 @@ public class DesktopGroupBox extends DesktopAbstractBox implements GroupBoxLayou
|
||||
collapsiblePanel.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShownAsPanel(boolean shownAsPanel) {
|
||||
this.shownAsPanel = shownAsPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShownAsPanel() {
|
||||
return shownAsPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expandsWidth() {
|
||||
return orientation == Orientation.VERTICAL;
|
||||
|
@ -31,4 +31,14 @@ public interface GroupBoxLayout
|
||||
|
||||
Orientation getOrientation();
|
||||
void setOrientation(Orientation orientation);
|
||||
|
||||
/**
|
||||
* Set layout style as Vaadin Panel
|
||||
* @param shownAsPanel
|
||||
*/
|
||||
void setShownAsPanel(boolean shownAsPanel);
|
||||
/**
|
||||
* @return true if layout looks like Vaadin Panel
|
||||
*/
|
||||
boolean isShownAsPanel();
|
||||
}
|
@ -1642,6 +1642,7 @@
|
||||
<xs:attribute name="collapsable" type="xs:boolean"/>
|
||||
<xs:attribute name="collapsed" type="xs:boolean"/>
|
||||
<xs:attribute name="orientation" type="orientation"/>
|
||||
<xs:attribute name="shownAsPanel" type="xs:boolean"/>
|
||||
</xs:complexType>
|
||||
|
||||
<!-- Frame -->
|
||||
|
@ -18,6 +18,7 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.GuiDevelopmentException;
|
||||
import com.haulmont.cuba.gui.components.GroupBoxLayout;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class GroupBoxLayoutLoader extends ContainerLoader<GroupBoxLayout> {
|
||||
@ -54,6 +55,7 @@ public class GroupBoxLayoutLoader extends ContainerLoader<GroupBoxLayout> {
|
||||
loadSpacing(resultComponent, element);
|
||||
|
||||
loadSubComponentsAndExpand(resultComponent, element);
|
||||
loadShownAsPanel(resultComponent, element);
|
||||
}
|
||||
|
||||
protected void loadOrientation(GroupBoxLayout component, Element element) {
|
||||
@ -71,4 +73,11 @@ public class GroupBoxLayoutLoader extends ContainerLoader<GroupBoxLayout> {
|
||||
throw new GuiDevelopmentException("Invalid groupBox orientation value: " + orientation, context.getFullFrameId());
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadShownAsPanel(GroupBoxLayout component, Element element) {
|
||||
String shownAsPanel = element.attributeValue("shownAsPanel");
|
||||
if (StringUtils.isNotEmpty(shownAsPanel)) {
|
||||
component.setShownAsPanel(Boolean.parseBoolean(shownAsPanel));
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ import com.vaadin.shared.ui.Connect;
|
||||
|
||||
@Connect(CubaGroupBox.class)
|
||||
public class CubaGroupBoxConnector extends PanelConnector {
|
||||
protected boolean widgetInitialized = false;
|
||||
|
||||
@Override
|
||||
public CubaGroupBoxWidget getWidget() {
|
||||
@ -50,23 +51,20 @@ public class CubaGroupBoxConnector extends PanelConnector {
|
||||
getRpcProxy(CubaGroupBoxServerRpc.class).collapse();
|
||||
}
|
||||
};
|
||||
|
||||
LayoutManager layoutManager = getLayoutManager();
|
||||
layoutManager.registerDependency(this, widget.captionStartDeco);
|
||||
layoutManager.registerDependency(this, widget.captionEndDeco);
|
||||
layoutManager.registerDependency(this, widget.captionTextNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnregister() {
|
||||
super.onUnregister();
|
||||
|
||||
LayoutManager layoutManager = getLayoutManager();
|
||||
CubaGroupBoxWidget widget = getWidget();
|
||||
if (!getState().shownAsPanel && widgetInitialized) {
|
||||
LayoutManager layoutManager = getLayoutManager();
|
||||
CubaGroupBoxWidget widget = getWidget();
|
||||
|
||||
layoutManager.unregisterDependency(this, widget.captionStartDeco);
|
||||
layoutManager.unregisterDependency(this, widget.captionEndDeco);
|
||||
layoutManager.unregisterDependency(this, widget.captionTextNode);
|
||||
layoutManager.unregisterDependency(this, widget.captionStartDeco);
|
||||
layoutManager.unregisterDependency(this, widget.captionEndDeco);
|
||||
layoutManager.unregisterDependency(this, widget.captionTextNode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,20 +76,29 @@ public class CubaGroupBoxConnector extends PanelConnector {
|
||||
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
|
||||
super.updateFromUIDL(uidl, client);
|
||||
|
||||
// replace VPanel class names
|
||||
CubaGroupBoxWidget widget = getWidget();
|
||||
if (!getState().shownAsPanel) {
|
||||
// replace VPanel class names
|
||||
CubaGroupBoxWidget widget = getWidget();
|
||||
|
||||
Tools.replaceClassNames(widget.captionNode, VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
Tools.replaceClassNames(widget.captionWrap, VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
Tools.replaceClassNames(widget.contentNode, VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
Tools.replaceClassNames(widget.bottomDecoration, VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
Tools.replaceClassNames(widget.getElement(), VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
Tools.replaceClassNames(widget.captionNode, VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
Tools.replaceClassNames(widget.captionWrap, VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
Tools.replaceClassNames(widget.contentNode, VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
Tools.replaceClassNames(widget.bottomDecoration, VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
Tools.replaceClassNames(widget.getElement(), VPanel.CLASSNAME, widget.getStylePrimaryName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void layout() {
|
||||
CubaGroupBoxWidget panel = getWidget();
|
||||
if (!getState().shownAsPanel) {
|
||||
layoutGroupBox();
|
||||
} else {
|
||||
super.layout();
|
||||
}
|
||||
}
|
||||
|
||||
protected void layoutGroupBox() {
|
||||
CubaGroupBoxWidget panel = getWidget();
|
||||
boolean bordersVisible = panel.captionStartDeco.getOffsetWidth() > 0 || panel.captionEndDeco.getOffsetWidth() > 0;
|
||||
|
||||
Style captionWrapStyle = panel.captionWrap.getStyle();
|
||||
@ -157,6 +164,19 @@ public class CubaGroupBoxConnector extends PanelConnector {
|
||||
|
||||
widget.setCollapsable(getState().collapsable);
|
||||
widget.setExpanded(getState().expanded);
|
||||
widget.setShownAsPanel(getState().shownAsPanel);
|
||||
|
||||
if (!widgetInitialized) {
|
||||
widget.init();
|
||||
if (!getState().shownAsPanel) {
|
||||
LayoutManager layoutManager = getLayoutManager();
|
||||
layoutManager.registerDependency(this, widget.captionStartDeco);
|
||||
layoutManager.registerDependency(this, widget.captionEndDeco);
|
||||
layoutManager.registerDependency(this, widget.captionTextNode);
|
||||
}
|
||||
|
||||
widgetInitialized = true;
|
||||
}
|
||||
|
||||
if (stateChangeEvent.hasPropertyChanged("caption")) {
|
||||
getLayoutManager().setNeedsMeasure(this);
|
||||
|
@ -17,9 +17,9 @@
|
||||
|
||||
package com.haulmont.cuba.web.toolkit.ui.client.groupbox;
|
||||
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.Style;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.ui.HasEnabled;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.Tools;
|
||||
@ -33,6 +33,8 @@ public class CubaGroupBoxWidget extends VPanel implements HasEnabled {
|
||||
|
||||
protected boolean collapsable = false;
|
||||
|
||||
protected boolean shownAsPanel = false;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
protected ExpandHandler expandHandler;
|
||||
@ -50,31 +52,35 @@ public class CubaGroupBoxWidget extends VPanel implements HasEnabled {
|
||||
setStyleName(primaryStyleName);
|
||||
|
||||
captionWrap = captionNode.getParentElement().cast();
|
||||
captionTextNode = (Element) captionNode.getChild(0);
|
||||
}
|
||||
|
||||
captionNode.setClassName(primaryStyleName + "-caption");
|
||||
contentNode.setClassName(primaryStyleName + "-content");
|
||||
bottomDecoration.setClassName(primaryStyleName + "-deco");
|
||||
expander.setClassName(primaryStyleName + "-expander");
|
||||
public void init() {
|
||||
if (!isShownAsPanel()) {
|
||||
captionNode.setClassName(getStylePrimaryName() + "-caption");
|
||||
contentNode.setClassName(getStylePrimaryName() + "-content");
|
||||
bottomDecoration.setClassName(getStylePrimaryName() + "-deco");
|
||||
expander.setClassName(getStylePrimaryName() + "-expander");
|
||||
|
||||
contentNode.getStyle().clearPosition();
|
||||
contentNode.getStyle().clearPosition();
|
||||
|
||||
setExpanded(true);
|
||||
setExpanded(true);
|
||||
|
||||
captionStartDeco.appendChild(DOM.createDiv());
|
||||
captionStartDeco.setClassName(primaryStyleName + "-caption-start-deco");
|
||||
captionWrap.insertFirst(captionStartDeco);
|
||||
captionStartDeco.appendChild(DOM.createDiv());
|
||||
captionStartDeco.setClassName(getStylePrimaryName() + "-caption-start-deco");
|
||||
captionWrap.insertFirst(captionStartDeco);
|
||||
|
||||
captionEndDeco.appendChild(DOM.createDiv());
|
||||
captionEndDeco.setClassName(primaryStyleName + "-caption-end-deco");
|
||||
captionWrap.appendChild(captionEndDeco);
|
||||
captionEndDeco.appendChild(DOM.createDiv());
|
||||
captionEndDeco.setClassName(getStylePrimaryName() + "-caption-end-deco");
|
||||
captionWrap.appendChild(captionEndDeco);
|
||||
|
||||
captionNode.insertFirst(expander);
|
||||
captionNode.insertFirst(expander);
|
||||
|
||||
captionTextNode = (Element) captionNode.getChild(1);
|
||||
captionTextNode.setClassName(primaryStyleName + "-caption-text");
|
||||
captionTextNode.setClassName(getStylePrimaryName() + "-caption-text");
|
||||
|
||||
DOM.sinkEvents(expander, Event.ONCLICK);
|
||||
DOM.sinkEvents(captionTextNode, Event.ONCLICK);
|
||||
DOM.sinkEvents(expander, Event.ONCLICK);
|
||||
DOM.sinkEvents(captionTextNode, Event.ONCLICK);
|
||||
}
|
||||
}
|
||||
|
||||
public CubaGroupBoxWidget() {
|
||||
@ -164,6 +170,16 @@ public class CubaGroupBoxWidget extends VPanel implements HasEnabled {
|
||||
DOM.eventCancelBubble(event, true);
|
||||
}
|
||||
|
||||
public void setShownAsPanel(boolean shownAsPanel) {
|
||||
if (isShownAsPanel() != shownAsPanel) {
|
||||
this.shownAsPanel = shownAsPanel;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isShownAsPanel() {
|
||||
return shownAsPanel;
|
||||
}
|
||||
|
||||
public interface ExpandHandler {
|
||||
void expand();
|
||||
|
||||
|
@ -372,6 +372,16 @@ public class WebGroupBox extends WebAbstractComponent<CubaGroupBox> implements G
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShownAsPanel(boolean shownAsPanel) {
|
||||
component.setShownAsPanel(shownAsPanel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShownAsPanel() {
|
||||
return component.isShownAsPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return component.getCaption();
|
||||
|
@ -201,4 +201,22 @@ public class CubaGroupBox extends Panel implements ComponentContainer {
|
||||
public interface ExpandChangeHandler {
|
||||
void expandStateChanged(boolean expanded);
|
||||
}
|
||||
|
||||
public void setShownAsPanel(boolean shownAsPanel) {
|
||||
if (getState(false).shownAsPanel != shownAsPanel) {
|
||||
if (shownAsPanel) {
|
||||
setStyleName("v-panel");
|
||||
setPrimaryStyleName("v-panel");
|
||||
} else {
|
||||
setStyleName("cuba-groupbox");
|
||||
setPrimaryStyleName("cuba-groupbox");
|
||||
}
|
||||
|
||||
getState().shownAsPanel = shownAsPanel;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isShownAsPanel() {
|
||||
return getState(false).shownAsPanel;
|
||||
}
|
||||
}
|
@ -27,4 +27,6 @@ public class CubaGroupBoxState extends PanelState {
|
||||
public boolean collapsable = false;
|
||||
|
||||
public boolean expanded = true;
|
||||
|
||||
public boolean shownAsPanel = false;
|
||||
}
|
Loading…
Reference in New Issue
Block a user