mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 18:27:56 +08:00
Label should implement com.haulmont.cuba.gui.components.Component.HasCaption #PL-6071
This commit is contained in:
parent
986205bc7a
commit
86f87f39da
@ -15,6 +15,7 @@ import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.MetadataTools;
|
||||
import com.haulmont.cuba.core.global.UserSessionSource;
|
||||
import com.haulmont.cuba.desktop.sys.DesktopToolTipManager;
|
||||
import com.haulmont.cuba.gui.ComponentsHelper;
|
||||
import com.haulmont.cuba.gui.components.Formatter;
|
||||
import com.haulmont.cuba.gui.components.Label;
|
||||
@ -260,4 +261,25 @@ public class DesktopLabel extends DesktopAbstractComponent<JLabel> implements La
|
||||
Preconditions.checkNotNullArgument(metaPropertyPath, "Could not resolve property path '%s' in '%s'", property, metaClass);
|
||||
this.metaProperty = metaPropertyPath.getMetaProperty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaption(String caption) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return impl.getToolTipText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
impl.setToolTipText(description);
|
||||
DesktopToolTipManager.getInstance().registerTooltip(impl);
|
||||
}
|
||||
}
|
@ -120,6 +120,18 @@ public class DesktopToolTipManager extends MouseAdapter {
|
||||
btn.addMouseListener(componentMouseListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register tooltip for {@link javax.swing.JLabel}.
|
||||
* Tooltip is displayed when the user hovers over a label
|
||||
* ToolTip text is taken from {@link javax.swing.JComponent#getToolTipText()}.
|
||||
*
|
||||
* @param lbl Label to register
|
||||
*/
|
||||
public void registerTooltip(final JLabel lbl) {
|
||||
lbl.removeMouseListener(componentMouseListener);
|
||||
lbl.addMouseListener(componentMouseListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register tooltip for ToolTipButton.
|
||||
* Tooltip is displayed when the user presses the button
|
||||
@ -179,7 +191,7 @@ public class DesktopToolTipManager extends MouseAdapter {
|
||||
toolTipWindow = toolTip;
|
||||
|
||||
tooltipShowing = true;
|
||||
if ((!(field instanceof ToolTipButton)) && (field instanceof AbstractButton)) {
|
||||
if ((!(field instanceof ToolTipButton)) && ((field instanceof AbstractButton) || (field instanceof JLabel))) {
|
||||
toolTip.addMouseListener(this);
|
||||
field.addMouseListener(this);
|
||||
}
|
||||
@ -199,7 +211,7 @@ public class DesktopToolTipManager extends MouseAdapter {
|
||||
|
||||
private class ComponentMouseListener extends MouseAdapter {
|
||||
|
||||
private AbstractButton btn;
|
||||
private JComponent cmp;
|
||||
|
||||
{
|
||||
showTimer.setRepeats(false);
|
||||
@ -207,7 +219,7 @@ public class DesktopToolTipManager extends MouseAdapter {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (!tooltipShowing)
|
||||
showTooltip(btn, btn.getToolTipText());
|
||||
showTooltip(cmp, cmp.getToolTipText());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -217,13 +229,13 @@ public class DesktopToolTipManager extends MouseAdapter {
|
||||
if (window != null) {
|
||||
if (e.getSource() != component && e.getSource() != toolTipWindow && component instanceof AbstractButton) {
|
||||
hideTooltip();
|
||||
btn = (AbstractButton) e.getSource();
|
||||
cmp = (JComponent) e.getSource();
|
||||
showTimer.start();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!tooltipShowing) {
|
||||
btn = (AbstractButton) e.getSource();
|
||||
cmp = (JComponent) e.getSource();
|
||||
showTimer.start();
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ package com.haulmont.cuba.gui.components;
|
||||
* @author abramov
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface Label extends DatasourceComponent, Component.HasFormatter {
|
||||
public interface Label extends DatasourceComponent, Component.HasFormatter, Component.HasCaption {
|
||||
|
||||
String NAME = "label";
|
||||
|
||||
|
@ -530,6 +530,7 @@
|
||||
<xs:attributeGroup ref="hasSize"/>
|
||||
<xs:attributeGroup ref="hasAlign"/>
|
||||
<xs:attributeGroup ref="hasStyle"/>
|
||||
<xs:attributeGroup ref="hasCaption"/>
|
||||
|
||||
<xs:attributeGroup ref="hasDatasource"/>
|
||||
<xs:attribute name="value" type="xs:string" default="msg://"/>
|
||||
|
@ -51,6 +51,9 @@ public class LabelLoader extends AbstractDatasourceComponentLoader {
|
||||
component.setValue(caption);
|
||||
}
|
||||
|
||||
loadCaption(component, element);
|
||||
loadDescription(component, element);
|
||||
|
||||
loadWidth(component, element, Component.AUTO_SIZE);
|
||||
loadHeight(component, element, Component.AUTO_SIZE);
|
||||
|
||||
|
@ -219,4 +219,24 @@ public class WebLabel extends WebAbstractComponent<com.vaadin.ui.Label> implemen
|
||||
Preconditions.checkNotNullArgument(metaPropertyPath, "Could not resolve property path '%s' in '%s'", property, metaClass);
|
||||
this.metaProperty = metaPropertyPath.getMetaProperty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaption(String caption) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return component.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
component.setDescription(description);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user