PL-7056 Implement unwrap method for component

This commit is contained in:
Yuriy Artamonov 2016-04-15 14:58:48 +04:00
parent b65767dba3
commit 0d3469e16c
9 changed files with 83 additions and 4 deletions

View File

@ -35,8 +35,6 @@ import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.util.Locale;
/**
*/
public abstract class DesktopAbstractComponent<C extends JComponent>
implements
DesktopComponent, Component.Wrapper, Component.HasXmlDescriptor, Component.BelongToFrame {
@ -392,4 +390,14 @@ public abstract class DesktopAbstractComponent<C extends JComponent>
return text;
}
}
@Override
public <X> X unwrap(Class<X> internalComponentClass) {
return (X) getComponent();
}
@Override
public <X> X unwrapComposition(Class<X> internalCompositionClass) {
return (X) getComposition();
}
}

View File

@ -365,6 +365,16 @@ public class DesktopPopupButton extends DesktopAbstractActionsHolderComponent<JB
public void setStyleName(String name) {
}
@Override
public <X> X unwrap(Class<X> internalComponentClass) {
return null;
}
@Override
public <X> X unwrapComposition(Class<X> internalCompositionClass) {
return null;
}
@Override
public String getCaption() {
return action.getCaption();

View File

@ -1082,6 +1082,16 @@ public class DesktopWindow implements Window, Component.Disposable,
public void setStyleName(String name) {
}
@Override
public <X> X unwrap(Class<X> internalComponentClass) {
return (X) getComponent();
}
@Override
public <X> X unwrapComposition(Class<X> internalCompositionClass) {
return (X) getComposition();
}
@Override
public void setMargin(boolean enable) {
layoutAdapter.setMargin(enable);

View File

@ -525,6 +525,16 @@ public class AbstractFrame implements Frame, Frame.Wrapper, Component.Wrapper, C
this.styleName = styleName;
}
@Override
public <X> X unwrap(Class<X> internalComponentClass) {
return (X) getComponent();
}
@Override
public <X> X unwrapComposition(Class<X> internalCompositionClass) {
return (X) getComponent();
}
@Override
public void setSpacing(boolean enabled) {
frame.setSpacing(enabled);

View File

@ -111,6 +111,9 @@ public interface Component {
/** Set style name. Styles implementation is client-type-specific */
void setStyleName(String styleName);
<X> X unwrap(Class<X> internalComponentClass);
<X> X unwrapComposition(Class<X> internalCompositionClass);
/**
* Component which can contain other components
*/

View File

@ -753,5 +753,15 @@ public interface Table<E extends Entity>
public void setStyleName(String styleName) {
throw new UnsupportedOperationException();
}
@Override
public <X> X unwrap(Class<X> internalComponentClass) {
return null;
}
@Override
public <X> X unwrapComposition(Class<X> internalCompositionClass) {
return null;
}
}
}

View File

@ -35,8 +35,6 @@ import javax.annotation.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*/
public class ParamWrapper implements Component.HasValue {
public static final Pattern LIKE_PATTERN = Pattern.compile("\\slike\\s+" + ParametersHelper.QUERY_PARAMETERS_RE);
@ -261,6 +259,16 @@ public class ParamWrapper implements Component.HasValue {
public void setStyleName(String name) {
}
@Override
public <X> X unwrap(Class<X> internalComponentClass) {
return null;
}
@Override
public <X> X unwrapComposition(Class<X> internalCompositionClass) {
return null;
}
@Override
public Frame getFrame() {
return null;

View File

@ -205,6 +205,16 @@ public class WebWindow implements Window, Component.Wrapper,
getContainer().addStyleName("cuba-window-layout");
}
@Override
public <X> X unwrap(Class<X> internalComponentClass) {
return (X) getComponent();
}
@Override
public <X> X unwrapComposition(Class<X> internalCompositionClass) {
return (X) getComposition();
}
@Override
public void setSpacing(boolean enabled) {
if (getContainer() instanceof Layout.SpacingHandler) {

View File

@ -278,4 +278,14 @@ public abstract class WebAbstractComponent<T extends com.vaadin.ui.Component>
public void setXmlDescriptor(Element element) {
this.element = element;
}
@Override
public <X> X unwrap(Class<X> internalComponentClass) {
return (X) getComponent();
}
@Override
public <X> X unwrapComposition(Class<X> internalCompositionClass) {
return (X) getComposition();
}
}