Display two tables. Table 1(Assigned Authors) and Table 2 (Unassigned Authors).

Hi,
I want to display two tables side by side.

Both tables belong to same datasource (ex. Authors). The Authors are assigned to another Datasource say (Scientific Papers). The assigned authors will work on that Scientific Paper.

I want to display first table (ex. Assigned Authors) that shows list of authors assigned to that particular “scientific paper” by ID.

I want to display the second table (ex. Unassigned Authors) that shows total list of Authors who are not assigned to that “scientific paper”.

I would like to use an “Add Button” to Assign Authors who belong to table two(Unassigned Authors). Both tables should refresh based on Add/Removal of Authors.

I would like to know the Query structure to display the two tables. Table 1 (Authors assigned to scientific paper by ID). Table 2 (Authors who are not assigned to that scientific paper but can be part of other papers)

I also would like to know on how to assign an Author from Table 2(Unassigned) to Table 1(Assigned) using Add Button. I want both tables to refresh dynamically when changes are made using Add/Remove Button.

Thanks for your guidance.

Hello,

I’ll prepare a small project to demonstrate how your task can be done.

Best regards,
Daniil.

Setting the Query for Table 1 and Table 2 is one of the main hurdle. TwinColumn is good solution but I want to do it using Tables.

Thank you for your time and support.

First of all, I should say that you will have to use a number of datasource for all purposes

<!-- This datasource is used as options datasource for the LookupPickerField component
to choose a scientific paper -->
<collectionDatasource id="scientificPapersDs"
                      allowCommit="false"
                      class="com.company.authorsandpapers.entity.ScientificPaper"
                      view="_minimal">
    <query>
        <!&#91;CDATA&#91;select e from authorsandpapers$ScientificPaper e&#93;&#93;>
    </query>
</collectionDatasource>

<!-- This datasource is used to display all unassigned authors -->
<collectionDatasource id="authorsDs"
                      class="com.company.authorsandpapers.entity.Author"
                      view="author-view">
    <query>
        select e from authorsandpapers$Author e where e.scientificPapers is empty
    </query>
</collectionDatasource>

<!-- This datasource is used to display all authors that are assigned to a scientific paper
that is chosen in the LookupPickerField component -->
<collectionDatasource id="authorsByPaperDs"
                      class="com.company.authorsandpapers.entity.Author"
                      view="author-view">
    <query>
        select e from authorsandpapers$Author e
        join e.scientificPapers sp where sp.id = :component$paper
    </query>
</collectionDatasource>

A screen layout is presented by a few components: the LookupPickerField to choose a ScientificPaper, two Tables to display Authors and two buttons to assign/unassign Authors:

<lookupPickerField id="paper"
                   metaClass="authorsandpapers$ScientificPaper"
                   nullOptionVisible="false"
                   optionsDatasource="scientificPapersDs"/>
<hbox id="hBox"
      spacing="true"
      width="100%">
    <table id="assignedAuthors"
           height="100%"
           width="100%">
        <actions>
            <action id="unassignAuthor"
                    trackSelection="true"
                    invoke="unassignAuthor"/>
        </actions>
        <buttonsPanel>
            <button action="assignedAuthors.unassignAuthor"
                    caption="Unassign author"/>
        </buttonsPanel>
        <columns>
            <column id="firstName"/>
            <column id="lastName"/>
            <column id="phone"/>
        </columns>
        <rows datasource="authorsByPaperDs"/>
    </table>
    <table id="unassignedAuthors"
           height="100%"
           width="100%">
        <actions>
            <action id="assignAuthor"
                    trackSelection="true"
                    invoke="assignAuthor"/>
        </actions>
        <buttonsPanel>
            <button action="unassignedAuthors.assignAuthor"
                    caption="Assign author"/>
        </buttonsPanel>
        <columns>
            <column id="firstName"/>
            <column id="lastName"/>
            <column id="phone"/>
        </columns>
        <rows datasource="authorsDs"/>
    </table>
</hbox>

Also, you have to refresh a datasource that contains assigned authors while changing the LookupPickerField value, and implement assigning/unassigning:

@Inject
private LookupPickerField paper;

@Inject
private CollectionDatasource<Author, UUID> authorsByPaperDs;
@Inject
private CollectionDatasource<Author, UUID> authorsDs;

@Inject
private Table<Author> assignedAuthors;
@Inject
private Table<Author> unassignedAuthors;

@Override
public void init(Map<String, Object> params) {
    paper.addValueChangeListener(ignored ->
            authorsByPaperDs.refresh());
}

public void assignAuthor() {
    ScientificPaper scientificPaper = paper.getValue();

    if (scientificPaper == null) {
        showNotification("You should choose a paper before!");
        return;
    }

    Author author = unassignedAuthors.getSingleSelected();

    //noinspection ConstantConditions
    author.getScientificPapers().add(scientificPaper);

    Author commitedAuthor = authorsByPaperDs.getDataSupplier().commit(author);

    authorsByPaperDs.includeItem(commitedAuthor);
    authorsDs.excludeItem(author);
}

public void unassignAuthor() {
    Author author = assignedAuthors.getSingleSelected();

    ScientificPaper scientificPaper = paper.getValue();

    //noinspection ConstantConditions
    author.getScientificPapers().remove(scientificPaper);

    Author commitedAuthor = authorsByPaperDs.getDataSupplier().commit(author);

    authorsDs.includeItem(commitedAuthor);
    authorsByPaperDs.excludeItem(author);
}

In the 7.0 Release you will be able to use new presentation data layer: YouTrack.

Best regards,
Daniil.

Thanks Daniil.

I have one more question.

On Table 1 (Assigned Authors). I would like to display list of Papers (other ScientificPapers) that belong to that Assigned Author in a row using generatecolumn.

I can use Popup Button to display the list of Paper belonging to Author (Example Assigned Author) and use addaction to perform action (like opening that paper by id).

The issue is : Table 1 needs 3 collection Datasource. authorsByPaperDs, authorsDs and scientificPapersDs.

All 3 datasources are linked by One to Many Relationship. Author can have multiple Papers. Assigned Author can have multiple papers. ScientificPapers can have multiple Assigned Authors.

I believe this can be achieved using DataManager.

Some sample implementation or idea for adding a generatedcolumn to AssignedAuthor Table which shows list of all Scientific Papers belonging to each Assigned Author in a row using DataManager will be helpful.

I am aware of the method for generating a column and adding an action.

I am not aware on how to add the list (Assigned Author with list of ScientificPapers) using DataManager to the new column of Assigned Author Table.

Thanks for your guidance.

Lokesh