mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
PL-8424 Provide Vaadin LayoutClickListener functionality
This commit is contained in:
parent
7f3007a4e7
commit
7ca2695d1e
@ -448,4 +448,12 @@ public abstract class DesktopAbstractBox
|
||||
public void setDescription(String description) {
|
||||
impl.setToolTipText(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutClickListener(LayoutClickListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLayoutClickListener(LayoutClickListener listener) {
|
||||
}
|
||||
}
|
@ -410,4 +410,12 @@ public class DesktopGridLayout extends DesktopAbstractComponent<JPanel> implemen
|
||||
public void setDescription(String description) {
|
||||
impl.setToolTipText(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutClickListener(LayoutClickListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLayoutClickListener(LayoutClickListener listener) {
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface BoxLayout extends ExpandingLayout, Component.OrderedContainer, Component.Spacing, Component.Margin,
|
||||
Component.BelongToFrame, Component.HasCaption, Component.HasIcon {
|
||||
Component.BelongToFrame, Component.HasCaption, Component.HasIcon, Component.LayoutClickNotifier {
|
||||
/**
|
||||
* @deprecated Use {@link VBoxLayout#NAME}
|
||||
*/
|
||||
|
@ -24,6 +24,7 @@ import org.dom4j.Element;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.EventObject;
|
||||
|
||||
/**
|
||||
* Root of the GenericUI components hierarchy
|
||||
@ -305,6 +306,37 @@ public interface Component {
|
||||
void setDescription(String description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Layout having a mouse click listener
|
||||
*/
|
||||
interface LayoutClickNotifier {
|
||||
void addLayoutClickListener(LayoutClickListener listener);
|
||||
void removeLayoutClickListener(LayoutClickListener listener);
|
||||
}
|
||||
|
||||
interface LayoutClickListener {
|
||||
void layoutClick(LayoutClickEvent event);
|
||||
}
|
||||
|
||||
class LayoutClickEvent extends EventObject {
|
||||
private final Component childComponent;
|
||||
|
||||
public LayoutClickEvent(Container clickedComponent, Component childComponent) {
|
||||
super(clickedComponent);
|
||||
this.childComponent = childComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getSource() {
|
||||
return (Container) super.getSource();
|
||||
}
|
||||
|
||||
public Component getChildComponent() {
|
||||
return childComponent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Object having a border
|
||||
*/
|
||||
|
@ -17,7 +17,9 @@
|
||||
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface CssLayout extends Component.OrderedContainer, Component.BelongToFrame, Component.HasCaption, Component.HasIcon {
|
||||
public interface CssLayout extends Component.OrderedContainer, Component.BelongToFrame, Component.HasCaption,
|
||||
Component.HasIcon, Component.LayoutClickNotifier
|
||||
{
|
||||
|
||||
String NAME = "cssLayout";
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface FlowBoxLayout extends Component.OrderedContainer, Component.BelongToFrame, Component.Margin,
|
||||
Component.Spacing, Component.HasCaption, Component.HasIcon {
|
||||
Component.Spacing, Component.HasCaption, Component.HasIcon, Component.LayoutClickNotifier {
|
||||
|
||||
String NAME = "flowBox";
|
||||
}
|
@ -18,7 +18,8 @@
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface GridLayout
|
||||
extends Component.Container, Component.Spacing, Component.Margin, Component.BelongToFrame, Component.HasIcon, Component.HasCaption
|
||||
extends Component.Container, Component.Spacing, Component.Margin, Component.BelongToFrame,
|
||||
Component.HasIcon, Component.HasCaption, Component.LayoutClickNotifier
|
||||
{
|
||||
String NAME = "grid";
|
||||
|
||||
|
@ -21,6 +21,7 @@ import com.haulmont.cuba.gui.ComponentsHelper;
|
||||
import com.haulmont.cuba.gui.components.BoxLayout;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Frame;
|
||||
import com.vaadin.event.LayoutEvents;
|
||||
import com.vaadin.shared.ui.MarginInfo;
|
||||
import com.vaadin.ui.AbstractComponent;
|
||||
import com.vaadin.ui.AbstractOrderedLayout;
|
||||
@ -31,9 +32,11 @@ import java.util.*;
|
||||
|
||||
import static com.haulmont.cuba.web.gui.components.WebComponentsHelper.convertAlignment;
|
||||
|
||||
public abstract class WebAbstractBox extends WebAbstractComponent<AbstractOrderedLayout> implements BoxLayout {
|
||||
public abstract class WebAbstractBox extends WebAbstractComponent<AbstractOrderedLayout> implements BoxLayout,
|
||||
Component.LayoutClickNotifier {
|
||||
|
||||
protected List<Component> ownComponents = new ArrayList<>();
|
||||
protected LayoutEvents.LayoutClickListener layoutClickListener;
|
||||
|
||||
@Override
|
||||
public void add(Component childComponent) {
|
||||
@ -219,4 +222,37 @@ public abstract class WebAbstractBox extends WebAbstractComponent<AbstractOrdere
|
||||
((AbstractComponent) getComposition()).setDescription(description);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutClickListener(LayoutClickListener listener) {
|
||||
getEventRouter().addListener(LayoutClickListener.class, listener);
|
||||
if (layoutClickListener == null) {
|
||||
layoutClickListener = (LayoutEvents.LayoutClickListener) event -> {
|
||||
Component childComponent = findChildComponent(WebAbstractBox.this, event.getChildComponent());
|
||||
LayoutClickEvent layoutClickEvent = new LayoutClickEvent(WebAbstractBox.this, childComponent);
|
||||
|
||||
getEventRouter().fireEvent(LayoutClickListener.class, LayoutClickListener::layoutClick, layoutClickEvent);
|
||||
};
|
||||
component.addLayoutClickListener(layoutClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
protected Component findChildComponent(BoxLayout layout, com.vaadin.ui.Component clickedComponent) {
|
||||
for (Component component : layout.getComponents()) {
|
||||
if (WebComponentsHelper.unwrap(component) == clickedComponent) {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLayoutClickListener(LayoutClickListener listener) {
|
||||
getEventRouter().removeListener(LayoutClickListener.class, listener);
|
||||
|
||||
if (!getEventRouter().hasListeners(LayoutClickListener.class)) {
|
||||
component.removeLayoutClickListener(layoutClickListener);
|
||||
layoutClickListener = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ import com.haulmont.bali.util.Preconditions;
|
||||
import com.haulmont.cuba.gui.ComponentsHelper;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Frame;
|
||||
import com.vaadin.event.LayoutEvents;
|
||||
import com.vaadin.ui.AbstractComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -29,9 +30,10 @@ import java.util.*;
|
||||
|
||||
public class WebAbstractOrderedLayout<T extends com.vaadin.ui.CssLayout>
|
||||
extends WebAbstractComponent<T>
|
||||
implements Component.OrderedContainer, Component.BelongToFrame, Component.HasCaption, Component.HasIcon {
|
||||
implements Component.OrderedContainer, Component.BelongToFrame, Component.HasCaption, Component.HasIcon, Component.LayoutClickNotifier {
|
||||
|
||||
protected List<Component> ownComponents = new ArrayList<>();
|
||||
protected Collection<Component> ownComponents = new LinkedHashSet<>();
|
||||
protected LayoutEvents.LayoutClickListener layoutClickListener;
|
||||
|
||||
@Override
|
||||
public void add(Component childComponent) {
|
||||
@ -175,4 +177,37 @@ public class WebAbstractOrderedLayout<T extends com.vaadin.ui.CssLayout>
|
||||
((AbstractComponent) getComposition()).setDescription(description);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutClickListener(LayoutClickListener listener) {
|
||||
getEventRouter().addListener(LayoutClickListener.class, listener);
|
||||
if (layoutClickListener == null) {
|
||||
layoutClickListener = (LayoutEvents.LayoutClickListener) event -> {
|
||||
Component childComponent = findChildComponent(WebAbstractOrderedLayout.this, event.getChildComponent());
|
||||
LayoutClickEvent layoutClickEvent = new LayoutClickEvent(WebAbstractOrderedLayout.this, childComponent);
|
||||
|
||||
getEventRouter().fireEvent(LayoutClickListener.class, LayoutClickListener::layoutClick, layoutClickEvent);
|
||||
};
|
||||
component.addLayoutClickListener(layoutClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
protected Component findChildComponent(Container layout, com.vaadin.ui.Component clickedComponent) {
|
||||
for (Component component : layout.getComponents()) {
|
||||
if (WebComponentsHelper.unwrap(component) == clickedComponent) {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLayoutClickListener(LayoutClickListener listener) {
|
||||
getEventRouter().removeListener(LayoutClickListener.class, listener);
|
||||
|
||||
if (!getEventRouter().hasListeners(LayoutClickListener.class)) {
|
||||
component.removeLayoutClickListener(layoutClickListener);
|
||||
layoutClickListener = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Frame;
|
||||
import com.haulmont.cuba.gui.components.GridLayout;
|
||||
import com.haulmont.cuba.web.toolkit.ui.CubaGridLayout;
|
||||
import com.vaadin.event.LayoutEvents;
|
||||
import com.vaadin.shared.ui.MarginInfo;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -33,6 +34,7 @@ import static com.haulmont.cuba.web.gui.components.WebComponentsHelper.convertAl
|
||||
public class WebGridLayout extends WebAbstractComponent<CubaGridLayout> implements GridLayout {
|
||||
|
||||
protected List<Component> ownComponents = new ArrayList<>();
|
||||
protected LayoutEvents.LayoutClickListener layoutClickListener;
|
||||
|
||||
public WebGridLayout() {
|
||||
component = new CubaGridLayout();
|
||||
@ -221,4 +223,38 @@ public class WebGridLayout extends WebAbstractComponent<CubaGridLayout> implemen
|
||||
public void setSpacing(boolean enabled) {
|
||||
component.setSpacing(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutClickListener(LayoutClickListener listener) {
|
||||
getEventRouter().addListener(LayoutClickListener.class, listener);
|
||||
|
||||
if (layoutClickListener == null) {
|
||||
layoutClickListener = (LayoutEvents.LayoutClickListener) event -> {
|
||||
Component childComponent = findChildComponent(WebGridLayout.this, event.getChildComponent());
|
||||
LayoutClickEvent layoutClickEvent = new LayoutClickEvent(WebGridLayout.this, childComponent);
|
||||
|
||||
getEventRouter().fireEvent(LayoutClickListener.class, LayoutClickListener::layoutClick, layoutClickEvent);
|
||||
};
|
||||
component.addLayoutClickListener(layoutClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
protected Component findChildComponent(GridLayout layout, com.vaadin.ui.Component clickedComponent) {
|
||||
for (Component component : layout.getComponents()) {
|
||||
if (WebComponentsHelper.unwrap(component) == clickedComponent) {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLayoutClickListener(LayoutClickListener listener) {
|
||||
getEventRouter().removeListener(LayoutClickListener.class, listener);
|
||||
|
||||
if (!getEventRouter().hasListeners(LayoutClickListener.class)) {
|
||||
component.removeLayoutClickListener(layoutClickListener);
|
||||
layoutClickListener = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user