@Override public String apply(E entity) { return entity != null ? metadataTools.getInstanceName(entity) : ""; } }
protected String convertToTextView(V value) { if (value == null) { return ""; } if (optionCaptionProvider != null) { return optionCaptionProvider.apply(value); } return metadataTools.getInstanceName(value); }
protected String getSubstitutedUserCaption(User user) { if (userNameFormatter != null) { return userNameFormatter.apply(user); } else { return metadataTools.getInstanceName(user); } }
protected String getInstanceCaption(V instance) { if (instance == null) { return ""; } if (optionCaptionProvider != null) { return optionCaptionProvider.apply(instance); } return metadata.getTools().getInstanceName(instance); }
/** * @deprecated Use {@link MetadataTools#getInstanceName(com.haulmont.chile.core.model.Instance)} instead. * @return Instance name as defined by {@link com.haulmont.chile.core.annotations.NamePattern} * or <code>toString()</code>. * @param instance instance */ @Deprecated public static String getInstanceName(Instance instance) { MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME, MetadataTools.class); return metadataTools.getInstanceName(instance); }
protected String generateItemCaption(E item) { if (itemCaptionProvider != null) { return itemCaptionProvider.apply(item); } return metadata.getTools().getInstanceName(item); }
protected String stringify(Object value, MetaProperty metaProperty) { if (value == null) return ""; else if (value instanceof Instance) { return metadataTools.getInstanceName((Instance) value); } else if (value instanceof Date) { Datatype datatype = metaProperty.getRange().asDatatype(); return datatype.format(value); } else if (value instanceof Iterable) { StringBuilder sb = new StringBuilder(); sb.append("["); for (Object obj : (Iterable) value) { sb.append(stringify(obj, metaProperty)).append(","); } if (sb.length() > 1) sb.deleteCharAt(sb.length() - 1); sb.append("]"); return sb.toString(); } else { return String.valueOf(value); } }
Object value = getValue(instance, path.replace("." + INSTANCE_NAME_KEY, "")); if (value instanceof Instance) { return metadataTools.getInstanceName((Instance) value); return metadataTools.getInstanceName(instance); } catch (Exception e) { log.trace("Suppressed error from underlying EntityMap instance.getInstanceName", e);
@Override public String apply(Object o) { if (!(o instanceof Entity)) { return ""; } Entity entity = (Entity) o; if (captionMode == CaptionMode.PROPERTY && captionProperty != null) { if (entity.getMetaClass().getPropertyPath(captionProperty) == null) { throw new IllegalArgumentException(String.format("Couldn't find property with name '%s'", captionProperty)); } Object propertyValue = entity.getValueEx(captionProperty); return propertyValue != null ? propertyValue.toString() : " "; } return metadata.getTools().getInstanceName(entity); }
/** * Formats a value according to the value type. * * @param value object to format * @return formatted value as string */ public String format(@Nullable Object value) { if (value == null) { return ""; } else if (value instanceof Instance) { return getInstanceName((Instance) value); } else if (value instanceof Enum) { return messages.getMessage((Enum) value, userSessionSource.getLocale()); } else if (value instanceof Collection) { //noinspection unchecked return ((Collection<Object>) value).stream() .map(this::format) .collect(Collectors.joining(", ")); } else { Datatype datatype = datatypeRegistry.get(value.getClass()); if (datatype != null) { return datatype.format(value, userSessionSource.getLocale()); } return value.toString(); } }
protected void addProperty(JsonObject jsonObject, String property, Object value, JsonSerializationContext context) { Object formattedValue; if (value instanceof Entity) { formattedValue = metadata.getTools().getInstanceName((Instance) value); } else if (value instanceof EnumClass) { formattedValue = messages.getMessage((Enum) value); } else if (value instanceof Date) { formattedValue = DATE_FORMATTER.format((Date) value); } else { formattedValue = value; } jsonObject.add(property, context.serialize(formattedValue)); }
String instanceName = null; try { instanceName = metadataTools.getInstanceName(entity); } catch (Exception ignored) {
.collect(Collectors.joining(", ")); } else { return metadataTools.getInstanceName((Entity) modelValue);
protected void initComponent() { component.addClickListener(event -> { if (clickHandler != null) { clickHandler.onClick(WebEntityLinkField.this); } else { openEntityEditor(); } }); component.setCaptionFormatter((value, locale) -> { if (value == null) { return ""; } if (value instanceof Instance) { return metadataTools.getInstanceName((Instance) value); } Datatype datatype = Datatypes.getNN(value.getClass()); if (locale != null) { return datatype.format(value, locale); } return datatype.format(value); }); }
protected void loadAllProperties() { Metadata metadata = AppBeans.get(Metadata.class); if (!loaded) { MetaClass metaClass = instance.getMetaClass(); String pkName = metadata.getTools().getPrimaryKeyName(metaClass); for (MetaProperty property : metaClass.getProperties()) { if (view != null && view.getProperty(property.getName()) != null) { explicitData.put(property.getName(), getValue(instance, property.getName())); } else if (view != null && Objects.equals(pkName, property.getName())) { explicitData.put(property.getName(), getValue(instance, property.getName())); } else if (view == null) { explicitData.put(property.getName(), getValue(instance, property.getName())); } } if (instanceNameAvailable(metaClass)) explicitData.put(INSTANCE_NAME_KEY, metadata.getTools().getInstanceName(instance)); else explicitData.put(INSTANCE_NAME_KEY, null); loaded = true; } }
return messages.getMessage((Enum) value); } else if (value instanceof Instance) { return getInstanceName((Instance) value); } else if (value instanceof Collection) {
String groupInstanceName = metadata.getTools().getInstanceName(getItem().getGroup()); setCaption(formatMessage("caption", groupInstanceName));
formattedValue = StringUtils.EMPTY; } else if (value instanceof Entity) { formattedValue = metadata.getTools().getInstanceName((Instance) value); } else if (value instanceof EnumClass) { formattedValue = messages.getMessage((Enum) value);
/** * Hook to be implemented in subclasses. Called by the framework after committing datasources. * The default implementation notifies about commit and calls {@link #postInit()} if the window is not closing. * * @param committed whether any data were actually changed and committed * @param close whether the window is going to be closed * @return true to continue, false to abort */ protected boolean postCommit(boolean committed, boolean close) { if (committed && !close) { if (showSaveNotification) { Entity entity = getItem(); MetadataTools metadataTools = getBeanLocator().get(MetadataTools.class); showNotification( messages.formatMainMessage("info.EntitySave", messages.getTools().getEntityCaption(entity.getMetaClass()), metadataTools.getInstanceName(entity)), NotificationType.TRAY); } postInit(); afterWindowApplyPostInit(); } return true; }
public void saveScreenHistory(Screen frameOwner) { WindowContext windowContext = frameOwner.getWindow().getContext(); if (security.isEntityOpPermitted(ScreenHistoryEntity.class, EntityOp.CREATE) && (frameOwner instanceof EditorScreen) && windowContext.getLaunchMode() != OpenMode.DIALOG && (screenIds.contains(frameOwner.getId()))) { String caption = frameOwner.getWindow().getCaption(); UUID entityId = null; Entity entity = ((EditorScreen) frameOwner).getEditedEntity(); if (entity != null) { if (PersistenceHelper.isNew(entity)) { return; } if (StringUtils.isBlank(caption)) { caption = messages.getTools().getEntityCaption(entity.getMetaClass()) + " " + metadata.getTools().getInstanceName(entity); } entityId = (UUID) entity.getId(); } ScreenHistoryEntity screenHistoryEntity = metadata.create(ScreenHistoryEntity.class); screenHistoryEntity.setCaption(StringUtils.abbreviate(caption, 255)); screenHistoryEntity.setUrl(makeLink(frameOwner)); screenHistoryEntity.setEntityId(entityId); addAdditionalFields(screenHistoryEntity, entity); CommitContext cc = new CommitContext(Collections.singleton(screenHistoryEntity)); dataManager.commit(cc); } }