use of com.haulmont.cuba.gui.data.impl.DsContextImplementation in project cuba by cuba-platform.
the class EntityInspectorBrowse method createEntitiesTable.
protected void createEntitiesTable(MetaClass meta) {
if (entitiesTable != null)
tableBox.remove(entitiesTable);
if (filter != null) {
filterBox.remove(filter);
}
entitiesTable = componentsFactory.createComponent(Table.class);
entitiesTable.setFrame(frame);
if (companion != null) {
companion.setHorizontalScrollEnabled(entitiesTable, true);
}
ClientType clientType = AppConfig.getClientType();
if (clientType == ClientType.WEB) {
textSelection.setVisible(true);
textSelection.addValueChangeListener(e -> changeTableTextSelectionEnabled());
}
final SimpleDateFormat dateTimeFormat = new SimpleDateFormat(getMessage("dateTimeFormat"));
Formatter dateTimeFormatter = value -> {
if (value == null) {
return StringUtils.EMPTY;
}
return dateTimeFormat.format(value);
};
// collect properties in order to add non-system columns first
List<Table.Column> nonSystemPropertyColumns = new ArrayList<>(10);
List<Table.Column> systemPropertyColumns = new ArrayList<>(10);
for (MetaProperty metaProperty : meta.getProperties()) {
// don't show embedded, transient & multiple referred entities
if (isEmbedded(metaProperty) || metadata.getTools().isNotPersistent(metaProperty))
continue;
Range range = metaProperty.getRange();
if (range.getCardinality().isMany())
continue;
Table.Column column = new Table.Column(meta.getPropertyPath(metaProperty.getName()));
if (range.isDatatype() && range.asDatatype().getJavaClass().equals(Date.class)) {
column.setFormatter(dateTimeFormatter);
}
if (metaProperty.getJavaType().equals(String.class)) {
column.setMaxTextLength(MAX_TEXT_LENGTH);
}
if (!metadata.getTools().isSystem(metaProperty)) {
column.setCaption(getPropertyCaption(meta, metaProperty));
nonSystemPropertyColumns.add(column);
} else {
column.setCaption(metaProperty.getName());
systemPropertyColumns.add(column);
}
}
for (Table.Column column : nonSystemPropertyColumns) {
entitiesTable.addColumn(column);
}
for (Table.Column column : systemPropertyColumns) {
entitiesTable.addColumn(column);
}
if (entitiesDs != null) {
((DsContextImplementation) getDsContext()).unregister(entitiesDs);
}
entitiesDs = DsBuilder.create(getDsContext()).setId("entitiesDs").setMetaClass(meta).setView(createView(meta)).buildCollectionDatasource();
entitiesDs.setLoadDynamicAttributes(true);
entitiesDs.setSoftDeletion(!removedRecords.isChecked());
entitiesDs.setQuery(String.format("select e from %s e", meta.getName()));
entitiesTable.setDatasource(entitiesDs);
tableBox.add(entitiesTable);
entitiesTable.setSizeFull();
createButtonsPanel(entitiesTable);
RowsCount rowsCount = componentsFactory.createComponent(RowsCount.class);
rowsCount.setDatasource(entitiesDs);
entitiesTable.setRowsCount(rowsCount);
entitiesTable.setEnterPressAction(entitiesTable.getAction("edit"));
entitiesTable.setItemClickAction(entitiesTable.getAction("edit"));
entitiesTable.setMultiSelect(true);
createFilter();
}
use of com.haulmont.cuba.gui.data.impl.DsContextImplementation in project cuba by cuba-platform.
the class EntityRestore method buildLayout.
protected void buildLayout() {
Object value = entities.getValue();
if (value != null) {
MetaClass metaClass = (MetaClass) value;
MetaProperty deleteTsMetaProperty = metaClass.getProperty("deleteTs");
if (deleteTsMetaProperty != null) {
if (entitiesTable != null) {
tablePanel.remove(entitiesTable);
}
if (filter != null) {
tablePanel.remove(filter);
}
ComponentsFactory componentsFactory = AppConfig.getFactory();
entitiesTable = componentsFactory.createComponent(Table.class);
entitiesTable.setFrame(frame);
restoreButton = componentsFactory.createComponent(Button.class);
restoreButton.setId("restore");
restoreButton.setCaption(getMessage("entityRestore.restore"));
ButtonsPanel buttonsPanel = componentsFactory.createComponent(ButtonsPanel.class);
buttonsPanel.add(restoreButton);
entitiesTable.setButtonsPanel(buttonsPanel);
RowsCount rowsCount = componentsFactory.createComponent(RowsCount.class);
entitiesTable.setRowsCount(rowsCount);
final SimpleDateFormat dateTimeFormat = new SimpleDateFormat(getMessage("dateTimeFormat"));
Formatter dateTimeFormatter = propertyValue -> {
if (propertyValue == null) {
return StringUtils.EMPTY;
}
return dateTimeFormat.format(propertyValue);
};
// collect properties in order to add non-system columns first
LinkedList<Table.Column> nonSystemPropertyColumns = new LinkedList<>();
LinkedList<Table.Column> systemPropertyColumns = new LinkedList<>();
List<MetaProperty> metaProperties = new ArrayList<>();
for (MetaProperty metaProperty : metaClass.getProperties()) {
// don't show embedded & multiple referred entities
Range range = metaProperty.getRange();
if (isEmbedded(metaProperty) || range.getCardinality().isMany() || metadataTools.isSystemLevel(metaProperty) || (range.isClass() && metadataTools.isSystemLevel(range.asClass()))) {
continue;
}
metaProperties.add(metaProperty);
Table.Column column = new Table.Column(metaClass.getPropertyPath(metaProperty.getName()));
if (!metadataTools.isSystem(metaProperty)) {
column.setCaption(getPropertyCaption(metaClass, metaProperty));
nonSystemPropertyColumns.add(column);
} else {
column.setCaption(metaProperty.getName());
systemPropertyColumns.add(column);
}
if (range.isDatatype() && range.asDatatype().getJavaClass().equals(Date.class)) {
column.setFormatter(dateTimeFormatter);
}
}
for (Table.Column column : nonSystemPropertyColumns) {
entitiesTable.addColumn(column);
}
for (Table.Column column : systemPropertyColumns) {
entitiesTable.addColumn(column);
}
DsContext dsContext = getDsContext();
if (entitiesDs != null) {
((DsContextImplementation) dsContext).unregister(entitiesDs);
}
entitiesDs = DsBuilder.create(dsContext).setId("entitiesDs").setMetaClass(metaClass).setView(buildView(metaClass, metaProperties)).buildGroupDatasource();
entitiesDs.setQuery("select e from " + metaClass.getName() + " e " + "where e.deleteTs is not null order by e.deleteTs");
entitiesDs.setSoftDeletion(false);
entitiesDs.refresh();
entitiesTable.setDatasource(entitiesDs);
String filterId = metaClass.getName().replace("$", "") + "GenericFilter";
filter = componentsFactory.createComponent(Filter.class);
filter.setId(filterId);
filter.setFrame(getFrame());
StringBuilder sb = new StringBuilder("");
for (MetaProperty property : metaClass.getProperties()) {
AnnotatedElement annotatedElement = property.getAnnotatedElement();
if (annotatedElement.getAnnotation(com.haulmont.chile.core.annotations.MetaProperty.class) != null) {
sb.append(property.getName()).append("|");
}
}
Element filterElement = Dom4j.readDocument(String.format("<filter id=\"%s\">\n" + " <properties include=\".*\" exclude=\"\"/>\n" + "</filter>", filterId)).getRootElement();
String excludedProperties = sb.toString();
if (StringUtils.isNotEmpty(excludedProperties)) {
Element properties = filterElement.element("properties");
properties.attribute("exclude").setValue(excludedProperties.substring(0, excludedProperties.lastIndexOf("|")));
}
filter.setXmlDescriptor(filterElement);
filter.setUseMaxResults(true);
filter.setDatasource(entitiesDs);
entitiesTable.setSizeFull();
entitiesTable.setMultiSelect(true);
Action restoreAction = new ItemTrackingAction("restore").withCaption(getMessage("entityRestore.restore")).withHandler(event -> showRestoreDialog());
entitiesTable.addAction(restoreAction);
restoreButton.setAction(restoreAction);
tablePanel.add(filter);
tablePanel.add(entitiesTable);
tablePanel.expand(entitiesTable, "100%", "100%");
entitiesTable.refresh();
((FilterImplementation) filter).loadFiltersAndApplyDefault();
}
}
}
use of com.haulmont.cuba.gui.data.impl.DsContextImplementation in project cuba by cuba-platform.
the class WindowManager method afterShowWindow.
protected void afterShowWindow(Window window) {
if (!WindowParams.DISABLE_APPLY_SETTINGS.getBool(window.getContext())) {
window.applySettings(getSettingsImpl(window.getId()));
}
if (!WindowParams.DISABLE_RESUME_SUSPENDED.getBool(window.getContext())) {
((DsContextImplementation) window.getDsContext()).resumeSuspended();
}
if (window instanceof AbstractWindow) {
AbstractWindow abstractWindow = (AbstractWindow) window;
if (abstractWindow.isAttributeAccessControlEnabled()) {
AttributeAccessSupport attributeAccessSupport = AppBeans.get(AttributeAccessSupport.NAME);
attributeAccessSupport.applyAttributeAccess(abstractWindow, false);
}
StopWatch readyStopWatch = new Slf4JStopWatch(window.getId() + "#" + LifeCycle.READY, LoggerFactory.getLogger(UIPerformanceLogger.class));
abstractWindow.ready();
readyStopWatch.stop();
}
}
use of com.haulmont.cuba.gui.data.impl.DsContextImplementation in project cuba by cuba-platform.
the class FilteringLookupAction method afterLookupWindowOpened.
@Override
protected void afterLookupWindowOpened(Window lookupWindow) {
boolean found = ComponentsHelper.walkComponents(lookupWindow, screenComponent -> {
if (!(screenComponent instanceof Filter)) {
return false;
} else {
MetaClass actualMetaClass = ((Filter) screenComponent).getDatasource().getMetaClass();
MetaClass propertyMetaClass = extendedEntities.getEffectiveMetaClass(pickerField.getMetaClass());
if (Objects.equals(actualMetaClass, propertyMetaClass)) {
applyFilter(((Filter) screenComponent));
return true;
}
return false;
}
});
if (!found) {
target.getFrame().showNotification(messages.getMainMessage("dynamicAttributes.entity.filter.filterNotFound"), Frame.NotificationType.WARNING);
}
((DsContextImplementation) lookupWindow.getDsContext()).resumeSuspended();
}
use of com.haulmont.cuba.gui.data.impl.DsContextImplementation in project cuba by cuba-platform.
the class FoldersBean method openFolder.
@Override
public void openFolder(AbstractSearchFolder folder) {
if (StringUtils.isBlank(folder.getFilterComponentId())) {
log.warn("Unable to open folder: componentId is blank");
return;
}
String[] strings = ValuePathHelper.parse(folder.getFilterComponentId());
String screenId = strings[0];
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
WindowInfo windowInfo = windowConfig.getWindowInfo(screenId);
Map<String, Object> params = new HashMap<>();
WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
if (!StringUtils.isBlank(folder.getTabName())) {
WindowParams.DESCRIPTION.set(params, messages.getMainMessage(folder.getTabName()));
} else {
WindowParams.DESCRIPTION.set(params, messages.getMainMessage(folder.getName()));
}
WindowParams.FOLDER_ID.set(params, folder.getId());
com.haulmont.cuba.gui.components.Window window = App.getInstance().getWindowManager().openWindow(windowInfo, OpenType.NEW_TAB, params);
Filter filterComponent = null;
if (strings.length > 1) {
String filterComponentId = StringUtils.join(Arrays.copyOfRange(strings, 1, strings.length), '.');
filterComponent = (Filter) window.getComponentNN(filterComponentId);
FilterEntity filterEntity = metadata.create(FilterEntity.class);
filterEntity.setFolder(folder);
filterEntity.setComponentId(folder.getFilterComponentId());
filterEntity.setName(folder.getLocName());
filterEntity.setXml(folder.getFilterXml());
filterEntity.setApplyDefault(BooleanUtils.isNotFalse(folder.getApplyDefault()));
if (folder instanceof SearchFolder) {
filterEntity.setIsSet(((SearchFolder) folder).getIsSet());
}
filterComponent.setFilterEntity(filterEntity);
filterComponent.switchFilterMode(FilterDelegate.FilterMode.GENERIC_MODE);
}
if (filterComponent != null && folder instanceof SearchFolder) {
final SearchFolder searchFolder = (SearchFolder) folder;
if (searchFolder.getPresentation() != null) {
((com.haulmont.cuba.gui.components.Component.HasPresentations) filterComponent.getApplyTo()).applyPresentation(searchFolder.getPresentation().getId());
}
}
((DsContextImplementation) window.getDsContext()).resumeSuspended();
}
Aggregations