mariodavid / cuba-component-attachable

CUBA component that lets you add attachments to any entity
Apache License 2.0
7 stars 2 forks source link
attachments cuba-component cuba-platform

Download license Build Status Coverage Status

CUBA Platform Component - Attachable

This application component lets you easily add attachments to any entity in your application.

Just add @WithAttachments on the browse screen of your entity and the rest will be done by this app-component.

1-browse-with-attachments

Installation

  1. attachable is available in the CUBA marketplace
  2. Select a version of the add-on which is compatible with the platform version used in your project:
Platform Version Add-on Version
7.2.x 0.9.x
7.1.x 0.7.x - 0.8.x
7.0.x 0.6.x
6.10.x 0.5.x
6.9.x 0.2.x - 0.4.x
6.8.x 0.1.x

The latest version is: Download

Add custom application component to your project:

Supported DBMS

The following databases are supported by this application component:

All other DBMS systems are supported in the way, that CUBA studio automatically creates DDL scripts. Therefore it is totally possible to use the application component even without dedicated SQL scripts directly from this application component.

Using the application component

Browse Screens

Annotate your browse screens with the @WithAttachments annotation or by implementing the WithAttachmentsSupport interface, depending on which version of CUBA screen APIs is used in the target screen.

@WithAttachments annotation (CUBA 6 screens)

@WithAttachments(listComponent = "productsTable")
class ProductBrowse extends AnnotatableAbstractLookup {
}

For the @WithAttachments annotation you need to define the list component on which it should add the attachments button. Normally this is the id of the table you defined in your browse screen.

This annotation will create a button in the buttonsPanel of the table and add the Attachments button after the default CUBA buttons.

The @WithAttachments annotations can be customized through the following attributes:

WithAttachmentsSupport interface (CUBA 7 screens)


public class CustomerBrowse extends StandardLookup<Customer> implements WithAttachmentsSupport {

    @Inject
    protected GroupTable<Customer> customersTable;

    @Inject
    protected ButtonsPanel buttonsPanel;

    @Override
    public ListComponent getListComponentForAttachments() {
        return customersTable;
    }

    @Override
    public ButtonsPanel getButtonsPanelForAttachments() {
        return buttonsPanel;
    }

    @Override
    public WindowManager.OpenType attachmentListOpenType() {
        return WindowManager.OpenType.NEW_TAB;
    }
}

In the Interface variant the following attributes have to be defined by implementing methods instead of annotation attributes:

Edit Screens (CUBA 7 screens)

Besides using Attachments in the Browse Screen of the Entity, it is also possible to show Attachments as part of an Edit Screen.

In order to do display attachments of a particular Entity there is a fragment which can be used in the Edit Screen:

<fragment screen="ddca_EntityAttachmentsFragment">
    <properties>
        <property name="attachableDc" ref="customerDc"/>
    </properties>
</fragment>

It is required to pass in the reference to the attachableDc of the entity (customerDc in the example above).

An example can be found in the customer-edit.xml.

Example usage

To see this application component in action, check out this example: cuba-example-using-attachable.

Attachment list

The attachment button will show all attachments that have been added to a particular selected entity. It allows to add, edit & remove attachments to this entity. 2-attachments-list

Attachment preview

Furthermore it gives the user the option to preview the attachment directly in the browser or download the attachment.

3-attachment-preview

The ability to do the preview depends on the attachment type and the browser capabilities.

Configuration options

The application components adds the following application properties, that can be changed in the corresponding screen (Administration > Application Properties):