本文整理汇总了Java中com.haulmont.cuba.core.global.View.addProperty方法的典型用法代码示例。如果您正苦于以下问题:Java View.addProperty方法的具体用法?Java View.addProperty怎么用?Java View.addProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.haulmont.cuba.core.global.View
的用法示例。
在下文中一共展示了View.addProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intersectViews
import com.haulmont.cuba.core.global.View; //导入方法依赖的package包/类
public static View intersectViews(View first, View second) {
if (first == null)
throw new IllegalArgumentException("View is null");
if (second == null)
throw new IllegalArgumentException("View is null");
View resultView = new View(first.getEntityClass());
Collection<ViewProperty> firstProps = first.getProperties();
for (ViewProperty firstProperty : firstProps) {
if (second.containsProperty(firstProperty.getName())) {
View resultPropView = null;
ViewProperty secondProperty = second.getProperty(firstProperty.getName());
if ((firstProperty.getView() != null) && (secondProperty.getView() != null)) {
resultPropView = intersectViews(firstProperty.getView(), secondProperty.getView());
}
resultView.addProperty(firstProperty.getName(), resultPropView);
}
}
return resultView;
}
示例2: initMetaClass
import com.haulmont.cuba.core.global.View; //导入方法依赖的package包/类
protected void initMetaClass(Entity entity) {
if (!(entity instanceof BaseGenericIdEntity)) {
throw new IllegalStateException("This datasource can contain only entity with subclass of BaseGenericIdEntity");
}
BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) entity;
if (PersistenceHelper.isNew(baseGenericIdEntity) && baseGenericIdEntity.getDynamicAttributes() == null) {
baseGenericIdEntity.setDynamicAttributes(new HashMap<>());
}
@SuppressWarnings("unchecked")
Map<String, CategoryAttributeValue> dynamicAttributes = baseGenericIdEntity.getDynamicAttributes();
Preconditions.checkNotNullArgument(dynamicAttributes, "Dynamic attributes should be loaded explicitly");
if (baseGenericIdEntity instanceof Categorized) {
category = ((Categorized) baseGenericIdEntity).getCategory();
}
if (!initializedBefore && category == null) {
category = getDefaultCategory();
if (baseGenericIdEntity.getMetaClass().getProperty("category") != null) {
baseGenericIdEntity.setValue("category", category);
}
}
item = new DynamicAttributesEntity(baseGenericIdEntity, attributes);
if (PersistenceHelper.isNew(entity) || categoryChanged) {
dynamicAttributesGuiTools.initDefaultAttributeValues(baseGenericIdEntity, resolveCategorizedEntityClass());
}
view = new View(DynamicAttributesEntity.class, false);
Collection<MetaProperty> properties = metaClass.getProperties();
for (MetaProperty property : properties) {
view.addProperty(property.getName());
}
valid();
initializedBefore = true;
fireItemChanged(null);
}
示例3: buildView
import com.haulmont.cuba.core.global.View; //导入方法依赖的package包/类
protected View buildView(MetaClass metaClass, List<MetaProperty> props) {
View view = new View(metaClass.getJavaClass());
for (MetaProperty property : props) {
if (Entity.class.isAssignableFrom(property.getJavaType())) {
view.addProperty(property.getName(),
viewRepository.getView((Class) property.getJavaType(), View.MINIMAL));
} else {
view.addProperty(property.getName());
}
}
return view;
}
示例4: createFullView
import com.haulmont.cuba.core.global.View; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected View createFullView(MetaClass metaClass) {
View view = new View(metaClass.getJavaClass());
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (metadataTools.isEmbedded(metaProperty)) {
view.addProperty(metaProperty.getName(), createFullView(metaProperty.getRange().asClass()));
} else if (isReferenceField(metaProperty)) {
view.addProperty(metaProperty.getName(), viewRepository.getView(metaProperty.getRange().asClass(), View.MINIMAL));
} else if (isDataField(metaProperty)) {
view.addProperty(metaProperty.getName());
}
}
return view;
}
示例5: testQuerySubstitutions
import com.haulmont.cuba.core.global.View; //导入方法依赖的package包/类
@Test
public void testQuerySubstitutions() throws Exception {
ViewRepository viewRepository = AppBeans.get(ViewRepository.NAME);
View userView = new View(new View.ViewParams().src(viewRepository.getView(User.class, View.LOCAL)));
View substitutedUserView = new View(User.class);
substitutedUserView.addProperty("login");
View substitutionsView = new View(UserSubstitution.class);
substitutionsView.addProperty("substitutedUser", substitutedUserView);
substitutionsView.addProperty("startDate");
userView.addProperty("substitutions", substitutionsView);
User loadedUser;
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.persistence().getEntityManager();
loadedUser = em.find(User.class, user.getId(), userView);
tx.commit();
}
assertNotNull(loadedUser);
assertNotNull(loadedUser.getSubstitutions());
Assert.assertEquals(1, loadedUser.getSubstitutions().size());
UserSubstitution loadedSubstitution = loadedUser.getSubstitutions().iterator().next();
assertEquals(user, loadedSubstitution.getUser());
assertEquals(substitutedUser, loadedSubstitution.getSubstitutedUser());
}
示例6: getRelatedIds
import com.haulmont.cuba.core.global.View; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<Object> getRelatedIds(List<Object> parentIds, String parentMetaClass, String relationProperty) {
checkNotNullArgument(parentIds, "parents argument is null");
checkNotNullArgument(parentMetaClass, "parentMetaClass argument is null");
checkNotNullArgument(relationProperty, "relationProperty argument is null");
MetaClass metaClass = extendedEntities.getEffectiveMetaClass(metadata.getClassNN(parentMetaClass));
Class parentClass = metaClass.getJavaClass();
MetaProperty metaProperty = metaClass.getPropertyNN(relationProperty);
// return empty list only after all argument checks
if (parentIds.isEmpty()) {
return Collections.emptyList();
}
MetaClass propertyMetaClass = extendedEntities.getEffectiveMetaClass(metaProperty.getRange().asClass());
Class propertyClass = propertyMetaClass.getJavaClass();
List<Object> relatedIds = new ArrayList<>();
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
String parentPrimaryKey = metadata.getTools().getPrimaryKeyName(metaClass);
String queryString = "select x from " + parentMetaClass + " x where x." +
parentPrimaryKey + " in :ids";
Query query = em.createQuery(queryString);
String relatedPrimaryKey = metadata.getTools().getPrimaryKeyName(propertyMetaClass);
View view = new View(parentClass);
view.addProperty(relationProperty, new View(propertyClass).addProperty(relatedPrimaryKey));
query.setView(view);
query.setParameter("ids", parentIds);
List<Entity> resultList = query.getResultList();
for (Entity e : resultList) {
Object value = e.getValue(relationProperty);
if (value instanceof Entity) {
relatedIds.add(((Entity) value).getId());
} else if (value instanceof Collection) {
for (Object collectionItem : (Collection)value) {
relatedIds.add(((Entity) collectionItem).getId());
}
}
}
tx.commit();
} finally {
tx.end();
}
return relatedIds;
}