Search in sources :

Example 1 with HistoryTableAffectedFilesModel

use of com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel in project oxygen-git-client-addon by oxygenxml.

the class UIUtil method createResourcesTable.

/**
 * Creates a git resource table widget and install renderers on it.
 *
 * @param fileTableModel The model for the table.
 * @param contextMenuShowing Can tell if a contextual menu is showing over the table.
 *
 * @return The table that presents the resources.
 */
public static JTable createResourcesTable(AbstractTableModel fileTableModel, BooleanSupplier contextMenuShowing) {
    JTable table = new Table() {

        @Override
        public JToolTip createToolTip() {
            return UIUtil.createMultilineTooltip(this).orElseGet(super::createToolTip);
        }
    };
    table.setModel(fileTableModel);
    table.getColumnModel().setColumnMargin(0);
    table.setTableHeader(null);
    table.setShowGrid(false);
    Icon icon = Icons.getIcon(Icons.GIT_ADD_ICON);
    int iconWidth = icon.getIconWidth();
    int colWidth = iconWidth + RESOURCE_TABLE_ICON_COLUMN_EXTRA_WIDTH;
    TableColumn statusCol = table.getColumnModel().getColumn(StagingResourcesTableModel.FILE_STATUS_COLUMN);
    statusCol.setMinWidth(colWidth);
    statusCol.setPreferredWidth(colWidth);
    statusCol.setMaxWidth(colWidth);
    boolean isForHistoryTable = fileTableModel instanceof HistoryTableAffectedFilesModel;
    table.setDefaultRenderer(Object.class, isForHistoryTable ? new HistoryAffectedFileCellRender(contextMenuShowing) : new StagingResourcesTableCellRenderer(contextMenuShowing));
    return table;
}
Also used : HistoryTableAffectedFilesModel(com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel) Table(ro.sync.exml.workspace.api.standalone.ui.Table) JTable(javax.swing.JTable) JTable(javax.swing.JTable) StagingResourcesTableCellRenderer(com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer) Icon(javax.swing.Icon) TableColumn(javax.swing.table.TableColumn) HistoryAffectedFileCellRender(com.oxygenxml.git.view.history.HistoryAffectedFileCellRender)

Example 2 with HistoryTableAffectedFilesModel

use of com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanelTestBase method assertAffectedFiles.

/**
 * Asserts the presented affected files.
 *
 * @param historyPanel History table.
 * @param expected The expected content.
 */
protected void assertAffectedFiles(HistoryPanel historyPanel, String expected) {
    JTable affectedFilesTable = historyPanel.getAffectedFilesTable();
    HistoryTableAffectedFilesModel affectedFilesModel = (HistoryTableAffectedFilesModel) affectedFilesTable.getModel();
    String dumpFS = dumpFS(affectedFilesModel.getFilesStatuses());
    assertEquals(expected, dumpFS);
}
Also used : HistoryTableAffectedFilesModel(com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel) JTable(javax.swing.JTable)

Example 3 with HistoryTableAffectedFilesModel

use of com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanel2Test method testAffectedFiles_ShowCopyRenames.

/**
 * Tests the affected files presented when a revision is selected inside the history panel.
 *
 * @throws Exception If it fails.
 */
@Test
public void testAffectedFiles_ShowCopyRenames() throws Exception {
    generateRepositoryAndLoad(getClass().getClassLoader().getResource("scripts/history_script_follow_move.txt"), new File("target/gen/HistoryPanelTest/testAffectedFiles_ShowCopyRenames"));
    List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String dump = dumpHistory(commitsCharacteristics, true);
    String expected = "[ Move , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Initial , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , null ]\n" + "";
    assertEquals(expected, dump);
    historyPanel.showRepositoryHistory();
    waitForScheduler();
    flushAWT();
    sleep(500);
    JTable historyTable = historyPanel.getHistoryTable();
    HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
    dump = dumpHistory(model.getAllCommits(), true);
    assertEquals(expected, dump);
    // -----------
    // Select an entry in the revision table.
    // -----------
    expected = "[ Move , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]";
    expected = replaceDate(expected);
    selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 0, expected);
    // -----------
    // Assert the affected files
    // -----------
    assertAffectedFiles(historyPanel, "(changeType=RENAME, fileLocation=child/file.txt)\n");
    // ---------------
    // Invoke the Diff action to see if the built URLs are O.K.
    // ---------------
    HistoryTableAffectedFilesModel affectedFilesModel = (HistoryTableAffectedFilesModel) historyPanel.getAffectedFilesTable().getModel();
    FileStatus fileStatus = affectedFilesModel.getFilesStatuses().get(0);
    CommitCharacteristics cc = model.getAllCommits().get(0);
    Action action = getCompareWithPreviousAction(fileStatus, cc);
    action.actionPerformed(null);
    assertEquals("Unexpected number of URLs intercepted in the comparison support:" + urls2compare.toString(), 2, urls2compare.size());
    URL left = urls2compare.get(0);
    URL right = urls2compare.get(1);
    assertEquals("git://" + model.getAllCommits().get(0).getCommitId() + "/child/file.txt", left.toString());
    assertEquals("git://" + model.getAllCommits().get(1).getCommitId() + "/file.txt", right.toString());
}
Also used : HistoryTableAffectedFilesModel(com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel) Action(javax.swing.Action) HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JTable(javax.swing.JTable) File(java.io.File) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) URL(java.net.URL) Test(org.junit.Test)

Example 4 with HistoryTableAffectedFilesModel

use of com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanel2Test method testAffectedFiles_ShowRenames.

/**
 * Tests the affected files presented when a revision is selected inside the history panel.
 *
 * @throws Exception If it fails.
 */
@Test
public void testAffectedFiles_ShowRenames() throws Exception {
    generateRepositoryAndLoad(getClass().getClassLoader().getResource("scripts/history_script_rename.txt"), new File("target/gen/HistoryPanelTest/testAffectedFiles_ShowRenames"));
    List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String dump = dumpHistory(commitsCharacteristics, true);
    String expected = "[ Rename. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , null ]\n" + "";
    assertEquals(expected, dump);
    historyPanel.showRepositoryHistory();
    waitForScheduler();
    flushAWT();
    sleep(300);
    JTable historyTable = historyPanel.getHistoryTable();
    HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
    dump = dumpHistory(model.getAllCommits(), true);
    assertEquals(expected, dump);
    // -----------
    // Select an entry in the revision table.
    // -----------
    expected = "[ Rename. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]";
    expected = replaceDate(expected);
    selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 0, expected);
    // -----------
    // Assert the affected files
    // -----------
    assertAffectedFiles(historyPanel, "(changeType=RENAME, fileLocation=file_renamed.txt)\n");
    // ---------------
    // Invoke the Diff action to see if the built URLs are O.K.
    // ---------------
    HistoryTableAffectedFilesModel affectedFilesModel = (HistoryTableAffectedFilesModel) historyPanel.getAffectedFilesTable().getModel();
    FileStatus fileStatus = affectedFilesModel.getFilesStatuses().get(0);
    CommitCharacteristics cc = model.getAllCommits().get(0);
    Action action = getCompareWithPreviousAction(fileStatus, cc);
    action.actionPerformed(null);
    assertEquals("Unexpected number of URLs intercepted in the comparison support:" + urls2compare.toString(), 2, urls2compare.size());
    URL left = urls2compare.get(0);
    URL right = urls2compare.get(1);
    assertEquals("git://" + model.getAllCommits().get(0).getCommitId() + "/file_renamed.txt", left.toString());
    assertEquals("git://" + model.getAllCommits().get(1).getCommitId() + "/file.txt", right.toString());
}
Also used : HistoryTableAffectedFilesModel(com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel) Action(javax.swing.Action) HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JTable(javax.swing.JTable) File(java.io.File) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) URL(java.net.URL) Test(org.junit.Test)

Aggregations

HistoryTableAffectedFilesModel (com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel)4 JTable (javax.swing.JTable)4 FileStatus (com.oxygenxml.git.service.entities.FileStatus)2 CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)2 HistoryCommitTableModel (com.oxygenxml.git.view.history.HistoryCommitTableModel)2 File (java.io.File)2 URL (java.net.URL)2 Action (javax.swing.Action)2 Test (org.junit.Test)2 HistoryAffectedFileCellRender (com.oxygenxml.git.view.history.HistoryAffectedFileCellRender)1 StagingResourcesTableCellRenderer (com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer)1 Icon (javax.swing.Icon)1 TableColumn (javax.swing.table.TableColumn)1 Table (ro.sync.exml.workspace.api.standalone.ui.Table)1