use of com.haulmont.cuba.gui.theme.ThemeConstants in project cuba by cuba-platform.
the class AttributeEditor method initArrayLayout.
protected void initArrayLayout(Object value, boolean isFixedSize, boolean isReadOnly) {
layout = componentsFactory.createComponent(WebVBoxLayout.class);
layout.setSpacing(true);
ThemeConstants theme = App.getInstance().getThemeConstants();
layout.setWidth(theme.get("cuba.web.jmx.AttributeEditor.arrayLayout.width"));
if (isFixedSize) {
layout.setHeight(theme.get("cuba.web.jmx.AttributeEditor.arrayLayout.height"));
}
Button btnAdd = componentsFactory.createComponent(WebButton.class);
btnAdd.setIcon("icons/plus-btn.png");
btnAdd.setDescription(messages.getMessage(getClass(), "editAttribute.array.btnAdd"));
layout.add(btnAdd);
ScrollBoxLayout scrollBoxLayout = componentsFactory.createComponent(WebScrollBoxLayout.class);
scrollBoxLayout.setWidth("100%");
scrollBoxLayout.setSpacing(true);
layout.add(scrollBoxLayout);
layout.expand(scrollBoxLayout);
btnAdd.setAction(new AbstractAction("addRow") {
@Override
public void actionPerform(Component component) {
addRow(null, scrollBoxLayout, false);
}
@Override
public String getCaption() {
return "";
}
@Override
public boolean isEnabled() {
return !isReadOnly;
}
});
if (value != null) {
List values = objectToStringArray(value);
for (Object obj : values) {
addRow(obj, scrollBoxLayout, isReadOnly);
}
}
}
use of com.haulmont.cuba.gui.theme.ThemeConstants in project cuba by cuba-platform.
the class App method applyTheme.
protected void applyTheme(String appWindowTheme) {
ThemeConstants theme = themeConstantsRepository.getConstants(appWindowTheme);
if (theme == null) {
log.warn("Unable to use theme constants '{}'", appWindowTheme);
} else {
this.themeConstants = theme;
setUserAppTheme(appWindowTheme);
}
}
use of com.haulmont.cuba.gui.theme.ThemeConstants in project cuba by cuba-platform.
the class WebWindowManager method showWindowDialog.
protected Component showWindowDialog(Window window, OpenType openType, boolean forciblyDialog) {
final CubaWindow vWindow = createDialogWindow(window);
vWindow.setStyleName("c-app-dialog-window");
if (ui.isTestMode()) {
vWindow.setCubaId("dialog_" + window.getId());
vWindow.setId(ui.getTestIdManager().getTestId("dialog_" + window.getId()));
}
Layout layout = (Layout) WebComponentsHelper.getComposition(window);
vWindow.setContent(layout);
vWindow.addPreCloseListener(event -> {
event.setPreventClose(true);
if (!isCloseWithCloseButtonPrevented(window)) {
// user has clicked on X
window.close(Window.CLOSE_ACTION_ID);
}
});
String closeShortcut = clientConfig.getCloseShortcut();
KeyCombination closeCombination = KeyCombination.create(closeShortcut);
ShortcutAction exitAction = new ShortcutAction("closeShortcutAction", closeCombination.getKey().getCode(), KeyCombination.Modifier.codes(closeCombination.getModifiers()));
Map<com.vaadin.event.Action, Runnable> actions = singletonMap(exitAction, () -> {
if (openType.getOpenMode() != OpenMode.DIALOG || BooleanUtils.isNotFalse(window.getDialogOptions().getCloseable())) {
if (isCloseWithShortcutPrevented(window)) {
return;
}
window.close(Window.CLOSE_ACTION_ID);
}
});
WebComponentsHelper.setActions(vWindow, actions);
boolean dialogParamsSizeUndefined = openType.getHeight() == null && openType.getWidth() == null;
ThemeConstants theme = app.getThemeConstants();
if (forciblyDialog && dialogParamsSizeUndefined) {
layout.setHeight(100, Unit.PERCENTAGE);
vWindow.setWidth(theme.getInt("cuba.web.WebWindowManager.forciblyDialog.width"), Unit.PIXELS);
vWindow.setHeight(theme.getInt("cuba.web.WebWindowManager.forciblyDialog.height"), Unit.PIXELS);
// resizable by default, but may be overridden in dialog params
vWindow.setResizable(BooleanUtils.isNotFalse(openType.getResizable()));
window.setHeightFull();
} else {
if (openType.getWidth() == null) {
vWindow.setWidth(theme.getInt("cuba.web.WebWindowManager.dialog.width"), Unit.PIXELS);
} else if (openType.getWidth() == AUTO_SIZE_PX) {
vWindow.setWidthUndefined();
layout.setWidthUndefined();
window.setWidthAuto();
} else {
vWindow.setWidth(openType.getWidth(), openType.getWidthUnit() != null ? WebWrapperUtils.toVaadinUnit(openType.getWidthUnit()) : Unit.PIXELS);
}
if (openType.getHeight() != null && openType.getHeight() != AUTO_SIZE_PX) {
vWindow.setHeight(openType.getHeight(), openType.getHeightUnit() != null ? WebWrapperUtils.toVaadinUnit(openType.getHeightUnit()) : Unit.PIXELS);
layout.setHeight("100%");
window.setHeightFull();
} else {
window.setHeightAuto();
}
// non resizable by default
vWindow.setResizable(BooleanUtils.isTrue(openType.getResizable()));
}
if (openType.getCloseable() != null) {
vWindow.setClosable(openType.getCloseable());
}
boolean modal = true;
if (!hasModalWindow() && openType.getModal() != null) {
modal = openType.getModal();
}
vWindow.setModal(modal);
if (vWindow.isModal()) {
boolean informationDialog = false;
if (openType.getCloseOnClickOutside() != null) {
informationDialog = openType.getCloseOnClickOutside();
}
vWindow.setCloseOnClickOutside(informationDialog);
}
if (openType.getMaximized() != null) {
if (openType.getMaximized()) {
vWindow.setWindowMode(WindowMode.MAXIMIZED);
} else {
vWindow.setWindowMode(WindowMode.NORMAL);
}
}
if (openType.getPositionX() == null && openType.getPositionY() == null) {
vWindow.center();
} else {
if (openType.getPositionX() != null) {
vWindow.setPositionX(openType.getPositionX());
}
if (openType.getPositionY() != null) {
vWindow.setPositionY(openType.getPositionY());
}
}
getDialogParams().reset();
ui.addWindow(vWindow);
return vWindow;
}
use of com.haulmont.cuba.gui.theme.ThemeConstants in project cuba by cuba-platform.
the class WebAbstractTable method initComponent.
protected void initComponent(final T component) {
component.setMultiSelect(false);
component.setImmediate(true);
component.setValidationVisible(false);
component.setShowBufferedSourceException(false);
component.setBeforePaintListener(() -> {
com.vaadin.ui.Table.CellStyleGenerator generator = component.getCellStyleGenerator();
if (generator instanceof WebAbstractTable.StyleGeneratorAdapter) {
// noinspection unchecked
((StyleGeneratorAdapter) generator).resetExceptionHandledFlag();
}
});
Messages messages = AppBeans.get(Messages.NAME);
component.setSortAscendingLabel(messages.getMainMessage("tableSort.ascending"));
component.setSortResetLabel(messages.getMainMessage("tableSort.reset"));
component.setSortDescendingLabel(messages.getMainMessage("tableSort.descending"));
setClientCaching(component);
int defaultRowHeaderWidth = 16;
ThemeConstants theme = App.getInstance().getThemeConstants();
if (theme != null) {
defaultRowHeaderWidth = theme.getInt("cuba.web.Table.defaultRowHeaderWidth");
}
// CAUTION: vaadin considers null as row header property id;
// todo get width from theme
component.setColumnWidth(null, defaultRowHeaderWidth);
contextMenuPopup.setParent(component);
component.setContextMenuPopup(contextMenuPopup);
shortcutsDelegate.setAllowEnterShortcut(false);
component.addValueChangeListener(event -> {
if (datasource == null) {
return;
}
final Set<? extends Entity> selected = getSelected();
if (selected.isEmpty()) {
Entity dsItem = datasource.getItemIfValid();
datasource.setItem(null);
if (dsItem == null) {
// in this case item change event will not be generated
refreshActionsState();
}
} else {
// reset selection and select new item
if (isMultiSelect()) {
datasource.setItem(null);
}
Entity newItem = selected.iterator().next();
Entity dsItem = datasource.getItemIfValid();
datasource.setItem(newItem);
if (Objects.equals(dsItem, newItem)) {
// in this case item change event will not be generated
refreshActionsState();
}
}
LookupSelectionChangeEvent selectionChangeEvent = new LookupSelectionChangeEvent(this);
getEventRouter().fireEvent(LookupSelectionChangeListener.class, LookupSelectionChangeListener::lookupValueChanged, selectionChangeEvent);
});
component.addShortcutListener(new ShortcutListener("tableEnter", com.vaadin.event.ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == WebAbstractTable.this.component) {
if (enterPressAction != null) {
enterPressAction.actionPerform(WebAbstractTable.this);
} else {
handleClickAction();
}
}
}
});
component.addItemClickListener(event -> {
if (event.isDoubleClick() && event.getItem() != null) {
handleClickAction();
}
});
component.setSelectable(true);
component.setTableFieldFactory(createFieldFactory());
component.setColumnCollapsingAllowed(true);
component.setColumnReorderingAllowed(true);
setEditable(false);
componentComposition = new TableComposition();
componentComposition.setTable(component);
componentComposition.setPrimaryStyleName("c-table-composition");
componentComposition.addComponent(component);
component.setCellStyleGenerator(createStyleGenerator());
component.addColumnCollapseListener(this::handleColumnCollapsed);
// force default sizes
componentComposition.setHeightUndefined();
componentComposition.setWidthUndefined();
}
Aggregations