use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class FragmentHelper method createFakeWindowInfo.
@SuppressWarnings("unchecked")
public WindowInfo createFakeWindowInfo(String src, String fragmentId) {
Element screenElement = DocumentHelper.createElement("screen");
screenElement.addAttribute("template", src);
screenElement.addAttribute("id", fragmentId);
Element windowElement = screenXmlLoader.load(src, fragmentId, Collections.emptyMap());
Class<? extends ScreenFragment> fragmentClass;
String className = windowElement.attributeValue("class");
if (StringUtils.isNotEmpty(className)) {
fragmentClass = (Class<? extends ScreenFragment>) scripting.loadClassNN(className);
} else {
fragmentClass = AbstractFrame.class;
}
return new WindowInfo(fragmentId, new WindowAttributesProvider() {
@Override
public WindowInfo.Type getType(WindowInfo wi) {
return WindowInfo.Type.FRAGMENT;
}
@Override
public String getTemplate(WindowInfo wi) {
return src;
}
@Nonnull
@Override
public Class<? extends FrameOwner> getControllerClass(WindowInfo wi) {
return fragmentClass;
}
@Override
public WindowInfo resolve(WindowInfo windowInfo) {
return windowInfo;
}
}, screenElement);
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class DeclarativeColumnGenerator method generateCell.
@Override
public Component generateCell(Entity entity) {
if (unableToFindMethod) {
return null;
}
Frame frame = table.getFrame();
if (frame == null) {
throw new IllegalStateException("Table should be attached to frame");
}
FrameOwner controller = frame.getFrameOwner();
if (controller instanceof LegacyFragmentAdapter) {
controller = ((LegacyFragmentAdapter) controller).getRealScreen();
}
if (method == null) {
method = findGeneratorMethod(controller.getClass(), methodName);
if (method == null) {
this.unableToFindMethod = true;
String tableId = table.getId() == null ? "" : table.getId();
throw new IllegalStateException(String.format("No suitable method named %s for column generator of table %s", methodName, tableId));
}
}
try {
return (Component) method.invoke(controller, entity);
} catch (Exception e) {
throw new RuntimeException("Exception in declarative Table column generator " + methodName, e);
}
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class DsContextImpl method get.
@Override
public Datasource get(String id) {
checkNotNullArgument(id, "Null datasource ID");
id = aliasesMap.getOrDefault(id, id);
Datasource ds = null;
if (!id.contains(".")) {
ds = datasourceMap.get(id);
if (ds == null && parent != null) {
ds = parent.get(id);
}
} else {
if (windowContext != null) {
String nestedFramePath = id.substring(0, id.indexOf("."));
Component nestedFrame = getFrameContext().getFrame().getComponent(nestedFramePath);
if (nestedFrame instanceof Frame) {
String nestedDsId = id.substring(id.indexOf(".") + 1);
FrameOwner frameOwner = ((Frame) nestedFrame).getFrameOwner();
if (frameOwner instanceof LegacyFrame) {
ds = ((LegacyFrame) frameOwner).getDsContext().get(nestedDsId);
}
}
}
}
return ds;
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class AbstractTableLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadEditable(resultComponent, element);
loadValidators(resultComponent, element);
loadSettingsEnabled(resultComponent, element);
loadAlign(resultComponent, element);
loadStyleName(resultComponent, element);
loadHeight(resultComponent, element);
loadWidth(resultComponent, element);
loadHtmlSanitizerEnabled(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadContextHelp(resultComponent, element);
loadTabIndex(resultComponent, element);
loadSortable(resultComponent, element);
loadReorderingAllowed(resultComponent, element);
loadColumnControlVisible(resultComponent, element);
loadAggregatable(resultComponent, element);
loadAggregationStyle(resultComponent, element);
loadPresentations(resultComponent, element);
loadActions(resultComponent, element);
loadContextMenuEnabled(resultComponent, element);
loadMultiLineCells(resultComponent, element);
loadColumnHeaderVisible(resultComponent, element);
loadShowSelection(resultComponent, element);
loadTextSelectionEnabled(resultComponent, element);
loadResponsive(resultComponent, element);
loadCss(resultComponent, element);
loadEmptyStateMessage(resultComponent, element);
loadEmptyStateLinkMessage(resultComponent, element);
loadMinHeight(resultComponent, element);
loadMinWidth(resultComponent, element);
Element columnsElement = element.element("columns");
Element rowsElement = element.element("rows");
if (rowsElement != null) {
String rowHeaderMode = rowsElement.attributeValue("rowHeaderMode");
if (StringUtils.isBlank(rowHeaderMode)) {
rowHeaderMode = rowsElement.attributeValue("headerMode");
if (StringUtils.isNotBlank(rowHeaderMode)) {
log.warn("Attribute headerMode is deprecated. Use rowHeaderMode.");
}
}
if (!StringUtils.isEmpty(rowHeaderMode)) {
resultComponent.setRowHeaderMode(Table.RowHeaderMode.valueOf(rowHeaderMode));
}
}
String rowHeaderMode = element.attributeValue("rowHeaderMode");
if (!StringUtils.isEmpty(rowHeaderMode)) {
resultComponent.setRowHeaderMode(Table.RowHeaderMode.valueOf(rowHeaderMode));
}
loadButtonsPanel(resultComponent);
// must be before datasource setting
loadRowsCount(resultComponent, element);
MetaClass metaClass;
CollectionContainer collectionContainer = null;
DataLoader dataLoader = null;
Datasource datasource = null;
String containerId = element.attributeValue("dataContainer");
if (containerId != null) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
if (container instanceof CollectionContainer) {
collectionContainer = (CollectionContainer) container;
} else {
throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
}
metaClass = collectionContainer.getEntityMetaClass();
if (collectionContainer instanceof HasLoader) {
dataLoader = ((HasLoader) collectionContainer).getLoader();
}
} else if (rowsElement != null) {
String datasourceId = rowsElement.attributeValue("datasource");
if (StringUtils.isBlank(datasourceId)) {
throw new GuiDevelopmentException("Table 'rows' element doesn't have 'datasource' attribute", context, "Table ID", element.attributeValue("id"));
}
datasource = getComponentContext().getDsContext().get(datasourceId);
if (datasource == null) {
throw new GuiDevelopmentException("Can't find datasource by name: " + datasourceId, context);
}
if (!(datasource instanceof CollectionDatasource)) {
throw new GuiDevelopmentException("Not a CollectionDatasource: " + datasourceId, context);
}
metaClass = datasource.getMetaClass();
} else {
String metaClassStr = element.attributeValue("metaClass");
if (Strings.isNullOrEmpty(metaClassStr)) {
throw new GuiDevelopmentException("Table doesn't have data binding", context, "Table ID", element.attributeValue("id"));
}
metaClass = getMetadata().getClassNN(metaClassStr);
}
List<Table.Column> availableColumns;
if (columnsElement != null) {
View view = collectionContainer != null ? collectionContainer.getView() : datasource != null ? datasource.getView() : getViewRepository().getView(metaClass.getJavaClass(), View.LOCAL);
availableColumns = loadColumns(resultComponent, columnsElement, metaClass, view);
} else {
availableColumns = new ArrayList<>();
}
for (Table.Column column : availableColumns) {
resultComponent.addColumn(column);
loadValidators(resultComponent, column);
loadRequired(resultComponent, column);
}
if (collectionContainer != null) {
if (dataLoader instanceof CollectionLoader) {
addDynamicAttributes(resultComponent, metaClass, null, (CollectionLoader) dataLoader, availableColumns);
} else if (collectionContainer instanceof CollectionPropertyContainer) {
addDynamicAttributes(resultComponent, metaClass, null, null, availableColumns);
}
// noinspection unchecked
resultComponent.setItems(createContainerTableSource(collectionContainer));
} else if (datasource != null) {
addDynamicAttributes(resultComponent, metaClass, datasource, null, availableColumns);
resultComponent.setDatasource((CollectionDatasource) datasource);
} else {
addDynamicAttributes(resultComponent, metaClass, null, null, availableColumns);
// noinspection unchecked
resultComponent.setItems(createEmptyTableItems(metaClass));
}
for (Table.Column column : availableColumns) {
if (column.getXmlDescriptor() != null) {
String generatorMethod = column.getXmlDescriptor().attributeValue("generator");
if (StringUtils.isNotEmpty(generatorMethod)) {
// noinspection unchecked
resultComponent.addGeneratedColumn(String.valueOf(column), beanLocator.getPrototype(DeclarativeColumnGenerator.NAME, resultComponent, generatorMethod));
}
}
}
String multiselect = element.attributeValue("multiselect");
if (StringUtils.isNotEmpty(multiselect)) {
resultComponent.setMultiSelect(Boolean.parseBoolean(multiselect));
}
if (collectionContainer instanceof CollectionPropertyContainer) {
DataLoader masterDataLoader = DataLoadersHelper.getMasterDataLoader((Nested) collectionContainer);
masterDataLoaderPostLoadListener = masterDataLoader instanceof InstanceLoader ? ((InstanceLoader) masterDataLoader).addPostLoadListener(this::onMasterDataLoaderPostLoad) : masterDataLoader instanceof CollectionLoader ? ((CollectionLoader) masterDataLoader).addPostLoadListener(this::onMasterDataLoaderPostLoad) : null;
}
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class AbstractDataGridLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadSettingsEnabled(resultComponent, element);
loadAlign(resultComponent, element);
loadStyleName(resultComponent, element);
loadHeight(resultComponent, element);
loadWidth(resultComponent, element);
loadHtmlSanitizerEnabled(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadContextHelp(resultComponent, element);
loadEditorEnabled(resultComponent, element);
loadEditorBuffered(resultComponent, element);
loadEditorSaveCaption(resultComponent, element);
loadEditorCancelCaption(resultComponent, element);
loadEditorCrossFieldEnabled(resultComponent, element);
loadActions(resultComponent, element);
loadContextMenuEnabled(resultComponent, element);
loadColumnsHidingAllowed(resultComponent, element);
loadColumnResizeMode(resultComponent, element);
loadSortable(resultComponent, element);
loadResponsive(resultComponent, element);
loadCss(resultComponent, element);
loadReorderingAllowed(resultComponent, element);
loadHeaderVisible(resultComponent, element);
loadFooterVisible(resultComponent, element);
loadTextSelectionEnabled(resultComponent, element);
loadBodyRowHeight(resultComponent, element);
loadHeaderRowHeight(resultComponent, element);
loadFooterRowHeight(resultComponent, element);
loadEmptyStateMessage(resultComponent, element);
loadEmptyStateLinkMessage(resultComponent, element);
loadAggregatable(resultComponent, element);
loadAggregationPosition(resultComponent, element);
loadMinHeight(resultComponent, element);
loadMinWidth(resultComponent, element);
Element columnsElement = element.element("columns");
loadButtonsPanel(resultComponent);
// must be before datasource setting
loadRowsCount(resultComponent, element);
MetaClass metaClass;
CollectionContainer collectionContainer = null;
DataLoader dataLoader = null;
Datasource datasource = null;
String containerId = element.attributeValue("dataContainer");
String datasourceId = element.attributeValue("datasource");
if (!Strings.isNullOrEmpty(containerId)) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
if (container instanceof CollectionContainer) {
collectionContainer = (CollectionContainer) container;
} else {
throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
}
metaClass = collectionContainer.getEntityMetaClass();
if (collectionContainer instanceof HasLoader) {
dataLoader = ((HasLoader) collectionContainer).getLoader();
}
} else if (!Strings.isNullOrEmpty(datasourceId)) {
datasource = getComponentContext().getDsContext().get(datasourceId);
if (datasource == null) {
throw new GuiDevelopmentException("Can't find datasource by name: " + datasourceId, context);
}
if (!(datasource instanceof CollectionDatasource)) {
throw new GuiDevelopmentException("Not a CollectionDatasource: " + datasource, context);
}
metaClass = datasource.getMetaClass();
} else {
String metaClassStr = element.attributeValue("metaClass");
if (Strings.isNullOrEmpty(metaClassStr)) {
throw new GuiDevelopmentException("DataGrid doesn't have data binding", context, "DataGrid ID", element.attributeValue("id"));
}
metaClass = getMetadata().getClassNN(metaClassStr);
}
List<Column> availableColumns;
if (columnsElement != null) {
View view = collectionContainer != null ? collectionContainer.getView() : datasource != null ? datasource.getView() : getViewRepository().getView(metaClass.getJavaClass(), View.LOCAL);
availableColumns = loadColumns(resultComponent, columnsElement, metaClass, view);
} else {
availableColumns = new ArrayList<>();
}
if (collectionContainer != null) {
if (dataLoader instanceof CollectionLoader) {
addDynamicAttributes(resultComponent, metaClass, null, (CollectionLoader) dataLoader, availableColumns);
}
// noinspection unchecked
resultComponent.setItems(createContainerDataGridSource(collectionContainer));
} else if (datasource != null) {
addDynamicAttributes(resultComponent, metaClass, datasource, null, availableColumns);
resultComponent.setDatasource((CollectionDatasource) datasource);
} else {
addDynamicAttributes(resultComponent, metaClass, null, null, availableColumns);
// noinspection unchecked
resultComponent.setItems(createEmptyDataGridItems(metaClass));
}
loadSelectionMode(resultComponent, element);
loadFrozenColumnCount(resultComponent, element);
loadTabIndex(resultComponent, element);
if (collectionContainer instanceof CollectionPropertyContainer) {
DataLoader masterDataLoader = DataLoadersHelper.getMasterDataLoader((Nested) collectionContainer);
masterDataLoaderPostLoadListener = masterDataLoader instanceof InstanceLoader ? ((InstanceLoader) masterDataLoader).addPostLoadListener(this::onMasterDataLoaderPostLoad) : masterDataLoader instanceof CollectionLoader ? ((CollectionLoader) masterDataLoader).addPostLoadListener(this::onMasterDataLoaderPostLoad) : null;
}
}
Aggregations