下面列出了怎么用com.vaadin.server.Sizeable的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public OptionDialogBuilder withHeight(String height) {
window.setHeight(height);
if (getHeight() < 0) {
messageLabel.setHeightUndefined();
layout.setExpandRatio(messageLabel, 0);
layout.setHeightUndefined();
} else {
messageLabel.setHeight(100, Sizeable.Unit.PERCENTAGE);
layout.setHeight(100, Sizeable.Unit.PERCENTAGE);
layout.setExpandRatio(messageLabel, 1);
}
return this;
}
@Override
public MessageDialogBuilder withHeight(String height) {
window.setHeight(height);
if (getHeight() < 0) {
messageLabel.setHeightUndefined();
layout.setExpandRatio(messageLabel, 0);
layout.setHeightUndefined();
} else {
messageLabel.setHeight(100, Sizeable.Unit.PERCENTAGE);
layout.setHeight(100, Sizeable.Unit.PERCENTAGE);
layout.setExpandRatio(messageLabel, 1);
}
return this;
}
protected void applyScrollBarsPolicy(ScrollBarPolicy scrollBarPolicy) {
switch (scrollBarPolicy) {
case VERTICAL:
getContent().setHeightUndefined();
getContent().setWidth(100, Sizeable.Unit.PERCENTAGE);
break;
case HORIZONTAL:
getContent().setHeight(100, Sizeable.Unit.PERCENTAGE);
getContent().setWidthUndefined();
break;
case BOTH:
getContent().setSizeUndefined();
break;
case NONE:
getContent().setSizeFull();
break;
}
}
@Override
public void setRowsCount(RowsCount rowsCount) {
if (this.rowsCount != null && topPanel != null) {
topPanel.removeComponent(this.rowsCount.unwrap(com.vaadin.ui.Component.class));
}
this.rowsCount = rowsCount;
if (rowsCount != null) {
if (topPanel == null) {
topPanel = createTopPanel();
topPanel.setWidth(100, Sizeable.Unit.PERCENTAGE);
componentComposition.addComponentAsFirst(topPanel);
}
rowsCount.setWidthAuto();
com.vaadin.ui.Component rc = rowsCount.unwrap(com.vaadin.ui.Component.class);
topPanel.addComponent(rc);
if (rowsCount instanceof VisibilityChangeNotifier) {
((VisibilityChangeNotifier) rowsCount).addVisibilityChangeListener(event ->
updateCompositionStylesTopPanelVisible()
);
}
}
updateCompositionStylesTopPanelVisible();
}
@Inject
protected void setDelegate(FilterDelegate delegate) {
this.delegate = delegate;
delegate.setFilter(this);
ComponentContainer layout = delegate.getLayout();
layout.setParent(this);
component = layout.unwrapComposition(com.vaadin.ui.Component.class);
component.setWidth(100, Sizeable.Unit.PERCENTAGE);
component.addStyleName(FILTER_STYLENAME);
delegate.setExpandedStateChangeListener(e ->
fireExpandStateChange(e.isExpanded(), e.isUserOriginated())
);
delegate.setCaptionChangedListener(this::updateCaptions);
}
protected CubaButton createActionButton(Action action) {
CubaButton button = new CubaButton();
button.setWidth(100, Sizeable.Unit.PERCENTAGE);
button.setPrimaryStyleName(CONTEXT_MENU_BUTTON_STYLENAME);
setPopupButtonAction(button, action);
AppUI ui = AppUI.getCurrent();
if (ui != null) {
if (ui.isTestMode()) {
button.setCubaId(action.getId());
}
if (ui.isPerformanceTestMode()) {
String debugId = getDebugId();
if (debugId != null) {
TestIdManager testIdManager = ui.getTestIdManager();
button.setId(testIdManager.getTestId(debugId + "_" + action.getId()));
}
}
}
return button;
}
/**
* Called when a component changed location within the layout
*
* @param event
* The drag and drop event
*/
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event
.getTargetDetails();
DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
.getTransferable();
Component component = transferable.getComponent();
// Get top-left pixel position
int leftPixelPosition = details.getRelativeLeft();
int topPixelPosition = details.getRelativeTop();
ComponentPosition position = layout.getPosition(component);
position.setLeft((float) leftPixelPosition, Sizeable.UNITS_PIXELS);
position.setTop((float) topPixelPosition, Sizeable.UNITS_PIXELS);
}
/**
* Shows a distribution set select window for the given target filter query
*
* @param tfqId
* target filter query id
*/
public void showForTargetFilter(final Long tfqId) {
this.tfqId = tfqId;
final TargetFilterQuery tfq = targetFilterQueryManagement.get(tfqId)
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, tfqId));
final VerticalLayout verticalLayout = initView();
final DistributionSet distributionSet = tfq.getAutoAssignDistributionSet();
final ActionType actionType = tfq.getAutoAssignActionType();
setInitialControlValues(distributionSet, actionType);
// build window after values are set to view elements
final CommonDialogWindow window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.caption(i18n.getMessage(UIMessageIdProvider.CAPTION_SELECT_AUTO_ASSIGN_DS)).content(verticalLayout)
.layout(verticalLayout).i18n(i18n).saveDialogCloseListener(this).buildCommonDialogWindow();
window.setId(UIComponentIdProvider.DIST_SET_SELECT_WINDOW_ID);
window.setWidth(40.0F, Sizeable.Unit.PERCENTAGE);
UI.getCurrent().addWindow(window);
window.setVisible(true);
}
public static Component projectLogoComp(String projectShortname, Integer projectId, String projectAvatarId, int size) {
AbstractComponent wrapper;
if (!StringUtils.isBlank(projectAvatarId)) {
wrapper = new Image(null, new ExternalResource(StorageUtils.getResourcePath
(String.format("%s/%s_%d.png", PathUtils.getProjectLogoPath(AppUI.getAccountId(), projectId),
projectAvatarId, size))));
} else {
ELabel projectIcon = new ELabel(projectShortname.substring(0, 1)).withStyleName(WebThemes.TEXT_ELLIPSIS, ValoTheme.LABEL_LARGE, "center");
projectIcon.setWidth(size, Sizeable.Unit.PIXELS);
projectIcon.setHeight(size, Sizeable.Unit.PIXELS);
wrapper = new MVerticalLayout(projectIcon).withAlign(projectIcon, Alignment.MIDDLE_CENTER).withMargin(false);
}
wrapper.setWidth(size, Sizeable.Unit.PIXELS);
wrapper.setHeight(size, Sizeable.Unit.PIXELS);
wrapper.addStyleName(WebThemes.CIRCLE_BOX);
wrapper.setDescription(UserUIContext.getMessage(GenericI18Enum.OPT_CHANGE_IMAGE));
return wrapper;
}
public static Component clientLogoComp(Client client, int size) {
AbstractComponent wrapper;
if (!StringUtils.isBlank(client.getAvatarid())) {
wrapper = new Image(null, new ExternalResource(StorageUtils.getEntityLogoPath(AppUI.getAccountId(), client.getAvatarid(), 100)));
} else {
String clientName = client.getName();
clientName = (clientName.length() > 3) ? clientName.substring(0, 3) : clientName;
ELabel projectIcon = new ELabel(clientName).withStyleName(WebThemes.TEXT_ELLIPSIS, "center");
wrapper = new VerticalLayout();
((VerticalLayout) wrapper).addComponent(projectIcon);
((VerticalLayout) wrapper).setComponentAlignment(projectIcon, Alignment.MIDDLE_CENTER);
}
wrapper.setWidth(size, Sizeable.Unit.PIXELS);
wrapper.setHeight(size, Sizeable.Unit.PIXELS);
wrapper.addStyleName(WebThemes.CIRCLE_BOX);
wrapper.setDescription(UserUIContext.getMessage(GenericI18Enum.OPT_CHANGE_IMAGE));
return wrapper;
}
public OptionDialogBuilderImpl() {
window = new CubaWindow();
window.setModal(true);
window.setClosable(false);
window.setResizable(false);
messageLabel = new CubaLabel();
messageLabel.setWidth(100, Sizeable.Unit.PERCENTAGE);
layout = new VerticalLayout();
layout.setStyleName("c-app-option-dialog");
layout.setMargin(false);
layout.setSpacing(true);
buttonsContainer = new HorizontalLayout();
buttonsContainer.setMargin(false);
buttonsContainer.setSpacing(true);
layout.addComponent(messageLabel);
layout.addComponent(buttonsContainer);
layout.setExpandRatio(messageLabel, 1);
layout.setComponentAlignment(buttonsContainer, Alignment.BOTTOM_RIGHT);
window.setContent(layout);
ThemeConstants theme = ui.getApp().getThemeConstants();
window.setWidth(theme.get("cuba.web.WebWindowManager.optionDialog.width"));
}
@Override
public OptionDialogBuilder withWidth(String width) {
window.setWidth(width);
if (getWidth() < 0) {
messageLabel.setWidthUndefined();
layout.setWidthUndefined();
} else {
messageLabel.setWidth(100, Sizeable.Unit.PERCENTAGE);
layout.setWidth(100, Sizeable.Unit.PERCENTAGE);
}
return this;
}
public MessageDialogBuilderImpl() {
window = new CubaWindow();
window.setModal(true);
window.setResizable(false);
layout = new VerticalLayout();
layout.setStyleName("c-app-message-dialog");
layout.setMargin(false);
layout.setSpacing(true);
messageLabel = new CubaLabel();
messageLabel.setStyleName("c-app-message-dialog-text");
messageLabel.setWidth(100, Sizeable.Unit.PERCENTAGE);
DialogAction action = new DialogAction(DialogAction.Type.OK);
okButton = createButton(action);
okButton.setClickHandler(me -> {
try {
action.actionPerform(ui.getTopLevelWindow());
} finally {
ui.removeWindow(window);
}
});
layout.addComponent(messageLabel);
layout.addComponent(okButton);
layout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);
window.setContent(layout);
ThemeConstants theme = ui.getApp().getThemeConstants();
window.setWidth(theme.get("cuba.web.WebWindowManager.messageDialog.width"));
}
@Override
public MessageDialogBuilder withWidth(String width) {
window.setWidth(width);
if (getWidth() < 0) {
messageLabel.setWidthUndefined();
layout.setWidthUndefined();
} else {
messageLabel.setWidth(100, Sizeable.Unit.PERCENTAGE);
layout.setWidth(100, Sizeable.Unit.PERCENTAGE);
}
return this;
}
public WebScrollBoxLayout() {
component = new CubaScrollBoxLayout();
component.setWidth(100, Sizeable.Unit.PERCENTAGE);
component.setPrimaryStyleName(SCROLLBOX_STYLENAME);
CubaVerticalActionsLayout content = new CubaVerticalActionsLayout();
content.setWidth(100, Sizeable.Unit.PERCENTAGE);
content.setStyleName(SCROLLBOX_CONTENT_STYLENAME);
component.addComponent(content);
getContent().setMargin(false);
}
@Override
public void setHeight(String height) {
// do not try to parse string if constant passed
if (Component.AUTO_SIZE.equals(height)) {
getComposition().setHeight(-1, Sizeable.Unit.PIXELS);
} else if (Component.FULL_SIZE.equals(height)) {
getComposition().setHeight(100, Sizeable.Unit.PERCENTAGE);
} else {
getComposition().setHeight(height);
}
}
@Override
public void setWidth(String width) {
// do not try to parse string if constant passed
if (Component.AUTO_SIZE.equals(width)) {
getComposition().setWidth(-1, Sizeable.Unit.PIXELS);
} else if (Component.FULL_SIZE.equals(width)) {
getComposition().setWidth(100, Sizeable.Unit.PERCENTAGE);
} else {
getComposition().setWidth(width);
}
}
@Override
public void setButtonsPanel(ButtonsPanel panel) {
if (buttonsPanel != null && topPanel != null) {
topPanel.removeComponent(buttonsPanel.unwrap(com.vaadin.ui.Component.class));
buttonsPanel.setParent(null);
}
buttonsPanel = panel;
if (panel != null) {
if (panel.getParent() != null && panel.getParent() != this) {
throw new IllegalStateException("Component already has parent");
}
if (topPanel == null) {
topPanel = createTopPanel();
topPanel.setWidth(100, Sizeable.Unit.PERCENTAGE);
componentComposition.addComponentAsFirst(topPanel);
}
topPanel.addComponent(panel.unwrap(com.vaadin.ui.Component.class));
if (panel instanceof VisibilityChangeNotifier) {
((VisibilityChangeNotifier) panel).addVisibilityChangeListener(event ->
updateCompositionStylesTopPanelVisible()
);
}
panel.setParent(this);
}
updateCompositionStylesTopPanelVisible();
}
public static void expand(AbstractOrderedLayout layout, Component component, String height, String width) {
if (!isHorizontalLayout(layout)
&& (StringUtils.isEmpty(height) || AUTO_SIZE.equals(height) || height.endsWith("%"))) {
component.setHeight(100, Sizeable.Unit.PERCENTAGE);
}
if (!isVerticalLayout(layout)
&& (StringUtils.isEmpty(width) || AUTO_SIZE.equals(width) || width.endsWith("%"))) {
component.setWidth(100, Sizeable.Unit.PERCENTAGE);
}
layout.setExpandRatio(component, 1);
}
@Override
public void setButtonsPanel(ButtonsPanel panel) {
if (buttonsPanel != null && topPanel != null) {
topPanel.removeComponent(buttonsPanel.unwrap(Component.class));
buttonsPanel.setParent(null);
}
buttonsPanel = panel;
if (panel != null) {
if (panel.getParent() != null
&& panel.getParent() != this) {
throw new IllegalStateException("Component already has parent");
}
if (topPanel == null) {
topPanel = createTopPanel();
topPanel.setWidth(100, Sizeable.Unit.PERCENTAGE);
componentComposition.addComponentAsFirst(topPanel);
}
Component bp = panel.unwrap(Component.class);
topPanel.addComponent(bp);
topPanel.setExpandRatio(bp, 1);
if (panel instanceof VisibilityChangeNotifier) {
((VisibilityChangeNotifier) panel).addVisibilityChangeListener(event ->
updateCompositionStylesTopPanelVisible()
);
}
panel.setParent(this);
}
updateCompositionStylesTopPanelVisible();
}
protected void adjustWidth() {
if (getWidth() < 0) {
searchField.setWidthUndefined();
} else {
searchField.setWidth(100, Sizeable.Unit.PERCENTAGE);
}
}
protected void adjustHeight() {
if (getHeight() < 0) {
searchField.setHeightUndefined();
} else {
searchField.setHeight(100, Sizeable.Unit.PERCENTAGE);
}
}
@Override
public void setButtonsPanel(ButtonsPanel panel) {
if (buttonsPanel != null && topPanel != null) {
topPanel.removeComponent(WebComponentsHelper.unwrap(buttonsPanel));
buttonsPanel.setParent(null);
}
buttonsPanel = panel;
if (panel != null) {
if (panel.getParent() != null && panel.getParent() != this) {
throw new IllegalStateException("Component already has parent");
}
if (topPanel == null) {
topPanel = createTopPanel();
topPanel.setWidth(100, Sizeable.Unit.PERCENTAGE);
componentComposition.addComponentAsFirst(topPanel);
}
Component bp = panel.unwrap(Component.class);
topPanel.addComponent(bp);
topPanel.setExpandRatio(bp, 1);
if (panel instanceof VisibilityChangeNotifier) {
((VisibilityChangeNotifier) panel).addVisibilityChangeListener(event ->
updateCompositionStylesTopPanelVisible()
);
}
panel.setParent(this);
}
updateCompositionStylesTopPanelVisible();
}
@Override
public void setRowsCount(RowsCount rowsCount) {
if (this.rowsCount != null && topPanel != null) {
topPanel.removeComponent(WebComponentsHelper.unwrap(this.rowsCount));
this.rowsCount.setParent(null);
}
this.rowsCount = rowsCount;
if (rowsCount != null) {
if (rowsCount.getParent() != null && rowsCount.getParent() != this) {
throw new IllegalStateException("Component already has parent");
}
if (topPanel == null) {
topPanel = createTopPanel();
topPanel.setWidth(100, Sizeable.Unit.PERCENTAGE);
componentComposition.addComponentAsFirst(topPanel);
}
rowsCount.setWidthAuto();
Component rc = WebComponentsHelper.unwrap(rowsCount);
topPanel.addComponent(rc);
if (rowsCount instanceof VisibilityChangeNotifier) {
((VisibilityChangeNotifier) rowsCount).addVisibilityChangeListener(event ->
updateCompositionStylesTopPanelVisible()
);
}
}
updateCompositionStylesTopPanelVisible();
}
public static Sizeable.Unit toVaadinUnit(SizeUnit sizeUnit) {
checkNotNullArgument(sizeUnit);
switch (sizeUnit) {
case PIXELS:
return Sizeable.Unit.PIXELS;
case PERCENTAGE:
return Sizeable.Unit.PERCENTAGE;
default:
throw new UnsupportedOperationException("Unsupported Size Unit");
}
}
public static SizeUnit toSizeUnit(Sizeable.Unit units) {
checkNotNullArgument(units);
switch (units) {
case PIXELS:
return SizeUnit.PIXELS;
case PERCENTAGE:
return SizeUnit.PERCENTAGE;
default:
throw new UnsupportedOperationException("Unsupported Size Unit");
}
}
protected void setupDefaultSize() {
ThemeConstantsManager themeConstantsManager = beanLocator.get(ThemeConstantsManager.NAME);
ThemeConstants theme = themeConstantsManager.getConstants();
dialogWindow.setWidth(theme.get("cuba.web.WebWindowManager.dialog.width"));
dialogWindow.setHeightUndefined();
component.setWidth(100, Sizeable.Unit.PERCENTAGE);
component.setHeightUndefined();
}
@Override
public void setDialogWidth(String dialogWidth) {
dialogWindow.setWidth(WebWrapperUtils.toVaadinSize(dialogWidth));
if (dialogWindow.getWidth() < 0) {
component.setWidthUndefined();
} else {
component.setWidth(100, Sizeable.Unit.PERCENTAGE);
}
}
@Override
public void setDialogHeight(String dialogHeight) {
dialogWindow.setHeight(WebWrapperUtils.toVaadinSize(dialogHeight));
if (dialogWindow.getHeight() < 0) {
component.setHeightUndefined();
} else {
component.setHeight(100, Sizeable.Unit.PERCENTAGE);
}
}
private void confirmWithConsequencesDialog(final TargetFilterQuery tfq, final Long dsId,
final ActionType actionType) {
final ConfirmConsequencesDialog dialog = new ConfirmConsequencesDialog(tfq, dsId, accepted -> {
if (accepted) {
targetFilterQueryManagement.updateAutoAssignDS(entityFactory.targetFilterQuery()
.updateAutoAssign(tfq.getId()).ds(dsId).actionType(actionType));
eventBus.publish(this, CustomFilterUIEvent.UPDATED_TARGET_FILTER_QUERY);
}
});
dialog.setWidth(40.0F, Sizeable.Unit.PERCENTAGE);
UI.getCurrent().addWindow(dialog);
dialog.setVisible(true);
}