use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class WebEntityLinkField method setMetaClass.
@Override
public void setMetaClass(MetaClass metaClass) {
final Datasource ds = getDatasource();
if (ds != null) {
throw new IllegalStateException("Datasource is not null");
}
this.metaClass = metaClass;
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class WebFieldGroup 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());
com.vaadin.ui.Field fieldImpl = getFieldImplementation(fieldComponent);
fci.setComposition(fieldImpl);
assignTypicalAttributes(fieldComponent);
if (generatedField.getAttachMode() == FieldAttachMode.APPLY_DEFAULTS) {
applyFieldDefaults(fci);
}
assignDebugId(fc, fieldImpl);
int columnIndex = fci.getColumn();
if (!reattachColumns.contains(columnIndex)) {
reattachColumns.add(columnIndex);
}
}
}
if (!reattachColumns.isEmpty()) {
component.setRows(detectRowsCount());
for (Integer reattachColumnIndex : reattachColumns) {
reattachColumnFields(reattachColumnIndex);
}
}
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class PermissionUiHelper method createPermissionItem.
/**
* Add or edit permission item in datasource
* @param ds Datasource
* @param roleDs Role datasource
* @param permissionTarget Permission identifier
* @param type Permission type
* @param value Permission value
*/
public static void createPermissionItem(CollectionDatasource<Permission, UUID> ds, Datasource<Role> roleDs, final String permissionTarget, PermissionType type, Integer value) {
Permission permission = null;
for (Permission p : ds.getItems()) {
if (Objects.equals(p.getTarget(), permissionTarget)) {
permission = p;
break;
}
}
if (permission == null) {
// restore entity instead of create
if (ds instanceof RestorablePermissionDatasource) {
RestorablePermissionDatasource datasource = (RestorablePermissionDatasource) ds;
permission = datasource.findRemovedEntity(p -> p != null && Objects.equals(p.getTarget(), permissionTarget));
if (permission != null) {
datasource.restoreEntity(permission);
}
}
}
if (permission == null) {
Metadata metadata = AppBeans.get(Metadata.NAME);
Permission newPermission = metadata.create(Permission.class);
newPermission.setRole(roleDs.getItem());
newPermission.setTarget(permissionTarget);
newPermission.setType(type);
newPermission.setValue(value);
ds.addItem(newPermission);
} else {
permission.setValue(value);
}
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DesktopPickerField method setMetaClass.
@Override
public void setMetaClass(MetaClass metaClass) {
Datasource ds = getDatasource();
if (ds != null)
throw new IllegalStateException("Datasource is not null");
this.metaClass = metaClass;
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class WindowManager method openEditor.
public Window.Editor openEditor(WindowInfo windowInfo, Entity item, OpenType openType, Map<String, Object> params, Datasource parentDs) {
if (params == null) {
params = Collections.emptyMap();
}
checkCanOpenWindow(windowInfo, openType, params);
Integer hashCode = getHash(windowInfo, params);
String template = windowInfo.getTemplate();
if (openType.getOpenMode() != OpenMode.DIALOG) {
Window existingWindow = getWindow(hashCode);
if (existingWindow != null) {
params = createParametersMap(windowInfo, params);
String caption = loadCaption(existingWindow, params);
String description = loadDescription(existingWindow, params);
showWindow(existingWindow, caption, description, openType, false);
return (Window.Editor) existingWindow;
}
}
params = createParametersMap(windowInfo, params);
WindowParams.ITEM.set(params, item instanceof Datasource ? ((Datasource) item).getItem() : item);
Window window;
if (template != null) {
window = createWindow(windowInfo, openType, params, LayoutLoaderConfig.getEditorLoaders(), false);
} else {
Class windowClass = windowInfo.getScreenClass();
if (windowClass != null) {
window = createWindow(windowInfo, params);
if (!(window instanceof Window.Editor)) {
throw new IllegalStateException(String.format("Class %s does't implement Window.Editor interface", windowClass));
}
} else {
throw new IllegalStateException("Invalid WindowInfo: " + windowInfo);
}
}
((Window.Editor) window).setParentDs(parentDs);
StopWatch setItemWatch = new Slf4JStopWatch(windowInfo.getId() + "#" + LifeCycle.SET_ITEM, LoggerFactory.getLogger(UIPerformanceLogger.class));
((Window.Editor) window).setItem(item);
setItemWatch.stop();
String caption = loadCaption(window, params);
String description = loadDescription(window, params);
showWindow(window, caption, description, openType, false);
userActionsLog.trace("Editor {} was opened", windowInfo.getId());
return (Window.Editor) window;
}
Aggregations