2014-01-11 66 views
0

嗨我是新的闊葉樹,並試圖理解它,所以在通過broadleaf commerce的代碼時,我發現@AdminPresentation超過了實體字段以及很多@Admin的相關信息,例如@AdminPresentationAdornedTargetCollection,@AdminPresentationCollection等相關注釋,請解釋一下什麼是這些註釋或任何參考鏈接瞭解這些註釋的作用是非常有幫助的在broadleafCommerce中使用@AdminPresentation有什麼用途

import org.apache.commons.collections.CollectionUtils; 
    import org.apache.commons.collections.Predicate; 
    import org.broadleafcommerce.common.admin.domain.AdminMainEntity; 
    import org.broadleafcommerce.common.media.domain.Media; 
    import org.broadleafcommerce.common.persistence.ArchiveStatus; 
    import org.broadleafcommerce.common.persistence.Status; 
    import org.broadleafcommerce.common.presentation.AdminPresentation; 
    import org.broadleafcommerce.common.presentation.AdminPresentationAdornedTargetCollection; 
    import org.broadleafcommerce.common.presentation.AdminPresentationClass; 
    import org.broadleafcommerce.common.presentation.AdminPresentationCollection; 
    import org.broadleafcommerce.common.presentation.AdminPresentationMap; 
    import org.broadleafcommerce.common.presentation.AdminPresentationOperationTypes; 
    import org.broadleafcommerce.common.presentation.AdminPresentationToOneLookup; 
    import org.broadleafcommerce.common.presentation.PopulateToOneFieldsEnum; 
    import org.broadleafcommerce.common.presentation.RequiredOverride; 
    import org.broadleafcommerce.common.presentation.client.AddMethodType; 
    import org.broadleafcommerce.common.presentation.client.OperationType; 
    import org.broadleafcommerce.common.presentation.client.VisibilityEnum; 
    import org.broadleafcommerce.common.util.DateUtil; 
    import org.broadleafcommerce.common.vendor.service.type.ContainerShapeType; 
    import org.broadleafcommerce.common.vendor.service.type.ContainerSizeType; 
@Entity 
@Inheritance(strategy = InheritanceType.JOINED) 
@javax.persistence.Table(name="BLC_PRODUCT") 
//multi-column indexes don't appear to get exported correctly when declared at the field level, so declaring here as a workaround 
@org.hibernate.annotations.Table(appliesTo = "BLC_PRODUCT", indexes = { 
    @Index(name = "PRODUCT_URL_INDEX", 
      columnNames = {"URL","URL_KEY"} 
    ) 
}) 
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blStandardElements") 
@AdminPresentationClass(populateToOneFields = PopulateToOneFieldsEnum.TRUE, friendlyName = "baseProduct") 
@SQLDelete(sql="UPDATE BLC_PRODUCT SET ARCHIVED = 'Y' WHERE PRODUCT_ID = ?") 
public class ProductImpl implements Product, Status, AdminMainEntity { 

    private static final Log LOG = LogFactory.getLog(ProductImpl.class); 
    /** The Constant serialVersionUID. */ 
    private static final long serialVersionUID = 1L; 

    /** The id. */ 
    @Id 
    @GeneratedValue(generator= "ProductId") 
    @GenericGenerator(
     name="ProductId", 
     strategy="org.broadleafcommerce.common.persistence.IdOverrideTableGenerator", 
     parameters = { 
      @Parameter(name="segment_value", value="ProductImpl"), 
      @Parameter(name="entity_name", value="org.broadleafcommerce.core.catalog.domain.ProductImpl") 
     } 
    ) 
    @Column(name = "PRODUCT_ID") 
    @AdminPresentation(friendlyName = "ProductImpl_Product_ID", visibility = VisibilityEnum.HIDDEN_ALL) 
    protected Long id; 

    @Column(name = "URL") 
    @AdminPresentation(friendlyName = "ProductImpl_Product_Url", order = Presentation.FieldOrder.URL, 
     group = Presentation.Group.Name.General, groupOrder = Presentation.Group.Order.General, 
     prominent = true, gridOrder = 3, columnWidth = "200px", 
     requiredOverride = RequiredOverride.REQUIRED) 
    protected String url; 

    @Column(name = "URL_KEY") 
    @AdminPresentation(friendlyName = "ProductImpl_Product_UrlKey", 
     tab = Presentation.Tab.Name.Advanced, tabOrder = Presentation.Tab.Order.Advanced, 
     group = Presentation.Group.Name.General, groupOrder = Presentation.Group.Order.General, 
     excluded = true) 
    protected String urlKey; 

    @Column(name = "DISPLAY_TEMPLATE") 
    @AdminPresentation(friendlyName = "ProductImpl_Product_Display_Template", 
     tab = Presentation.Tab.Name.Advanced, tabOrder = Presentation.Tab.Order.Advanced, 
     group = Presentation.Group.Name.Advanced, groupOrder = Presentation.Group.Order.Advanced) 
    protected String displayTemplate; 

    @Column(name = "MODEL") 
    @AdminPresentation(friendlyName = "ProductImpl_Product_Model", 
     tab = Presentation.Tab.Name.Advanced, tabOrder = Presentation.Tab.Order.Advanced, 
     group = Presentation.Group.Name.Advanced, groupOrder = Presentation.Group.Order.Advanced) 
    protected String model; 

    @Column(name = "MANUFACTURE") 
    @AdminPresentation(friendlyName = "ProductImpl_Product_Manufacturer", order = Presentation.FieldOrder.MANUFACTURER, 
     group = Presentation.Group.Name.General, groupOrder = Presentation.Group.Order.General, 
     prominent = true, gridOrder = 4) 
    protected String manufacturer; 

    @Column(name = "TAX_CODE") 
    protected String taxCode; 

    @Column(name = "IS_FEATURED_PRODUCT", nullable=false) 
    @AdminPresentation(friendlyName = "ProductImpl_Is_Featured_Product", requiredOverride = RequiredOverride.NOT_REQUIRED, 
     tab = Presentation.Tab.Name.Marketing, tabOrder = Presentation.Tab.Order.Marketing, 
     group = Presentation.Group.Name.Badges, groupOrder = Presentation.Group.Order.Badges) 
    protected Boolean isFeaturedProduct = false; 

    @OneToOne(optional = false, targetEntity = SkuImpl.class, cascade={CascadeType.ALL}, mappedBy = "defaultProduct") 
    @Cascade(value={org.hibernate.annotations.CascadeType.ALL}) 
    protected Sku defaultSku; 

    @Column(name = "CAN_SELL_WITHOUT_OPTIONS") 
    @AdminPresentation(friendlyName = "ProductImpl_Can_Sell_Without_Options", 
     tab = Presentation.Tab.Name.Advanced, tabOrder = Presentation.Tab.Order.Advanced, 
     group = Presentation.Group.Name.Advanced, groupOrder = Presentation.Group.Order.Advanced) 
    protected Boolean canSellWithoutOptions = false; 

    @Transient 
    protected List<Sku> skus = new ArrayList<Sku>(); 

    @Transient 
    protected String promoMessage; 

    @OneToMany(mappedBy = "product", targetEntity = CrossSaleProductImpl.class, cascade = {CascadeType.ALL}) 
    @Cascade(value={org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN}) 
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blStandardElements") 
    @OrderBy(value="sequence") 
    @AdminPresentationAdornedTargetCollection(friendlyName = "crossSaleProductsTitle", order = 1000, 
     tab = Presentation.Tab.Name.Marketing, tabOrder = Presentation.Tab.Order.Marketing, 
     targetObjectProperty = "relatedSaleProduct", 
     sortProperty = "sequence", 
     maintainedAdornedTargetFields = { "promotionMessage" }, 
     gridVisibleFields = { "defaultSku.name", "promotionMessage" }) 
    protected List<RelatedProduct> crossSaleProducts = new ArrayList<RelatedProduct>(); 

    @OneToMany(mappedBy = "product", targetEntity = UpSaleProductImpl.class, cascade = {CascadeType.ALL}) 
    @Cascade(value={org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN}) 
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blStandardElements") 
    @OrderBy(value="sequence") 
    @AdminPresentationAdornedTargetCollection(friendlyName = "upsaleProductsTitle", order = 2000, 
     tab = Presentation.Tab.Name.Marketing, tabOrder = Presentation.Tab.Order.Marketing, 
     targetObjectProperty = "relatedSaleProduct", 
     sortProperty = "sequence", 
     maintainedAdornedTargetFields = { "promotionMessage" }, 
     gridVisibleFields = { "defaultSku.name", "promotionMessage" }) 
    protected List<RelatedProduct> upSaleProducts = new ArrayList<RelatedProduct>(); 

    @OneToMany(fetch = FetchType.LAZY, targetEntity = SkuImpl.class, mappedBy="product") 
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blStandardElements") 
    @BatchSize(size = 50) 
    @AdminPresentationCollection(friendlyName="ProductImpl_Additional_Skus", order = 1000, 
     tab = Presentation.Tab.Name.ProductOptions, tabOrder = Presentation.Tab.Order.ProductOptions) 
    protected List<Sku> additionalSkus = new ArrayList<Sku>(); 

    @ManyToOne(targetEntity = CategoryImpl.class) 
    @JoinColumn(name = "DEFAULT_CATEGORY_ID") 
    @Index(name="PRODUCT_CATEGORY_INDEX", columnNames={"DEFAULT_CATEGORY_ID"}) 
    @AdminPresentation(friendlyName = "ProductImpl_Product_Default_Category", order = Presentation.FieldOrder.DEFAULT_CATEGORY, 
     group = Presentation.Group.Name.General, groupOrder = Presentation.Group.Order.General, 
     prominent = true, gridOrder = 2, 
     requiredOverride = RequiredOverride.REQUIRED) 
    @AdminPresentationToOneLookup() 
    protected Category defaultCategory; 

    @OneToMany(targetEntity = CategoryProductXrefImpl.class, mappedBy = "categoryProductXref.product") 
    @Cascade(value={org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.PERSIST}) 
    @OrderBy(value="displayOrder") 
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blStandardElements") 
    @BatchSize(size = 50) 
    @AdminPresentationAdornedTargetCollection(friendlyName = "allParentCategoriesTitle", order = 3000, 
     tab = Presentation.Tab.Name.Marketing, tabOrder = Presentation.Tab.Order.Marketing, 
     joinEntityClass = "org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl", 
     targetObjectProperty = "categoryProductXref.category", 
     parentObjectProperty = "categoryProductXref.product", 
     sortProperty = "displayOrder", 
     gridVisibleFields = { "name" }) 
    protected List<CategoryProductXref> allParentCategoryXrefs = new ArrayList<CategoryProductXref>(); 

    @OneToMany(mappedBy = "product", targetEntity = ProductAttributeImpl.class, cascade = { CascadeType.ALL }, orphanRemoval = true) 
    @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="blStandardElements") 
    @MapKey(name="name") 
    @BatchSize(size = 50) 
    @AdminPresentationMap(friendlyName = "productAttributesTitle", 
     tab = Presentation.Tab.Name.Advanced, tabOrder = Presentation.Tab.Order.Advanced, 
     deleteEntityUponRemove = true, forceFreeFormKeys = true, keyPropertyFriendlyName = "ProductAttributeImpl_Attribute_Name" 
    ) 
    protected Map<String, ProductAttribute> productAttributes = new HashMap<String, ProductAttribute>(); 

    @ManyToMany(fetch = FetchType.LAZY, targetEntity = ProductOptionImpl.class) 
    @JoinTable(name = "BLC_PRODUCT_OPTION_XREF", 
     joinColumns = @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "PRODUCT_ID"), 
     inverseJoinColumns = @JoinColumn(name = "PRODUCT_OPTION_ID", referencedColumnName = "PRODUCT_OPTION_ID")) 
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blStandardElements") 
    @BatchSize(size = 50) 
    @AdminPresentationCollection(friendlyName = "productOptionsTitle", 
     tab = Presentation.Tab.Name.ProductOptions, tabOrder = Presentation.Tab.Order.ProductOptions, 
     addType = AddMethodType.LOOKUP, 
     manyToField = "products", 
     operationTypes = @AdminPresentationOperationTypes(removeType = OperationType.NONDESTRUCTIVEREMOVE)) 
    protected List<ProductOption> productOptions = new ArrayList<ProductOption>(); 

    @Embedded 
    protected ArchiveStatus archiveStatus = new ArchiveStatus(); 

    } 


} 

回答

4

的@admin的目的...註釋是允許的簡單方法在Admin中呈現類字段。

例如,friendlyName將指定在管理中呈現時將顯示的所述字段的名稱。如果我要延長產品,並添加一個新的領域productOrigin像

@AdminPresentation(friendlyName = "Product Origin") 
public String productOrigin; 

這將在管理與名稱產品產地的文本框顯示允許我們將數據輸入到我們的新的領域,其將持續到數據庫。所有的都有一個簡單的註釋。

以類似的方式,選項卡將指定在tabOrder以什麼順序顯示選項卡時指定哪個選項卡來顯示該字段。請注意,如果您爲以前不存在的選項卡提供新名稱,則會創建一個新選項卡。如果您查看AdminPresentation.java,您可以找到源代碼,並且可以瞭解每個參數提供的內容。

@AdminPresentation是最簡單的情況,因爲它用於呈現未鏈接到其他類的字段。您在提供的類中看到的其他元素用於呈現更復雜的關係,如顯示列表父級類別(@ AdminPresentationAdornedTargetCollection)。

希望這會有所幫助! Jerry

相關問題