use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class EditAction method actionPerform.
/**
* This method is invoked by the action owner component.
*
* @param component component invoking the action
*/
@Override
public void actionPerform(Component component) {
if (beforeActionPerformedHandler != null) {
if (!beforeActionPerformedHandler.beforeActionPerformed())
return;
}
final Set selected = target.getSelected();
if (selected.size() == 1) {
Datasource parentDs = null;
final CollectionDatasource datasource = target.getDatasource();
if (datasource instanceof PropertyDatasource) {
MetaProperty metaProperty = ((PropertyDatasource) datasource).getProperty();
if (metaProperty.getType().equals(MetaProperty.Type.COMPOSITION)) {
parentDs = datasource;
}
}
Map<String, Object> params = prepareWindowParams();
internalOpenEditor(datasource, datasource.getItem(), parentDs, params);
} else if (selected.size() > 1 && bulkEditorIntegration.isEnabled()) {
boolean isBulkEditorPermitted = userSession.isSpecificPermitted(BulkEditor.PERMISSION);
if (isBulkEditorPermitted) {
// if bulk editor integration enabled and permitted for user
Map<String, Object> params = ParamsMap.of("metaClass", target.getDatasource().getMetaClass(), "selected", selected, "exclude", bulkEditorIntegration.getExcludePropertiesRegex(), "fieldValidators", bulkEditorIntegration.getFieldValidators(), "modelValidators", bulkEditorIntegration.getModelValidators());
Window bulkEditor = target.getFrame().openWindow("bulkEditor", bulkEditorIntegration.getOpenType(), params);
bulkEditor.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
target.getDatasource().refresh();
}
target.requestFocus();
Consumer<BulkEditorCloseEvent> afterEditorCloseHandler = bulkEditorIntegration.getAfterEditorCloseHandler();
if (afterEditorCloseHandler != null) {
afterEditorCloseHandler.accept(new BulkEditorCloseEvent(this, bulkEditor, actionId));
}
});
}
}
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class ExcludeAction method doRemove.
@SuppressWarnings("unchecked")
@Override
protected void doRemove(Set<Entity> selected, boolean autocommit) {
@SuppressWarnings({ "unchecked" }) CollectionDatasource ds = target.getDatasource();
if (ds instanceof NestedDatasource) {
// Clear reference to master entity
Datasource masterDs = ((NestedDatasource) ds).getMaster();
MetaProperty metaProperty = ((NestedDatasource) ds).getProperty();
if (masterDs != null && metaProperty != null) {
MetaProperty inverseProp = metaProperty.getInverse();
if (inverseProp != null) {
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
Class dsClass = extendedEntities.getEffectiveClass(ds.getMetaClass());
if (inversePropClass.isAssignableFrom(dsClass)) {
for (Entity item : selected) {
item.setValue(inverseProp.getName(), null);
}
}
}
}
}
for (Entity item : selected) {
ds.modifyItem(item);
ds.excludeItem(item);
}
if (autocommit && (ds.getCommitMode() != Datasource.CommitMode.PARENT)) {
try {
ds.commit();
} catch (RuntimeException e) {
ds.refresh();
throw e;
}
}
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DesktopAbstractField method getAlternativeDebugId.
@Override
protected String getAlternativeDebugId() {
if (id != null) {
return id;
}
Datasource datasource = getDatasource();
MetaPropertyPath metaPropertyPath = getMetaPropertyPath();
if (datasource != null && StringUtils.isNotEmpty(datasource.getId()) && metaPropertyPath != null) {
return getClass().getSimpleName() + "_" + datasource.getId() + "_" + metaPropertyPath.toString();
}
return getClass().getSimpleName();
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DesktopFieldGroup method bindDeclarativeFieldConfigs.
protected void bindDeclarativeFieldConfigs() {
List<Integer> reattachColumns = new ArrayList<>();
for (FieldConfig fc : getColumnOrderedFields()) {
if (!fc.isCustom() && !fc.isBound()) {
FieldConfigImpl fci = (FieldConfigImpl) fc;
Datasource targetDs = fc.getTargetDatasource();
if (targetDs == null) {
throw new IllegalStateException(String.format("Unable to get datasource for field '%s'", id));
}
FieldGroupFieldFactory.GeneratedField generatedField = fieldFactory.createField(fc);
Component fieldComponent = generatedField.getComponent();
fci.assignComponent(fieldComponent);
fci.setAttachMode(generatedField.getAttachMode());
setupFieldComponent(fci);
DesktopAbstractComponent fieldImpl = (DesktopAbstractComponent) fieldComponent;
fci.setComposition(fieldImpl);
assignTypicalAttributes(fieldComponent);
if (generatedField.getAttachMode() == FieldAttachMode.APPLY_DEFAULTS) {
applyFieldDefaults(fci);
}
int columnIndex = fci.getColumn();
if (!reattachColumns.contains(columnIndex)) {
reattachColumns.add(columnIndex);
}
}
}
if (!reattachColumns.isEmpty()) {
this.rows = detectRowsCount();
for (Integer reattachColumnIndex : reattachColumns) {
reattachColumnFields(reattachColumnIndex);
}
}
impl.revalidate();
impl.repaint();
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class WebDataGrid method createItemDatasource.
protected Datasource createItemDatasource(Entity item) {
Datasource fieldDatasource = DsBuilder.create().setAllowCommit(false).setMetaClass(datasource.getMetaClass()).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setViewName(View.LOCAL).buildDatasource();
((DatasourceImplementation) fieldDatasource).valid();
// noinspection unchecked
fieldDatasource.setItem(item);
return fieldDatasource;
}
Aggregations