Search in sources :

Example 1 with FileHistoryPresenter

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

the class HistoryPanelTest method testAffectedFilesForeground.

/**
 * Tests the affected files foreground when a file or folder is searched.
 * <br><br>
 * EXM: EXM-48807
 *
 * @author Alex_Smarandache
 *
 * @throws Exception If it fails.
 */
@Test
public void testAffectedFilesForeground() throws Exception {
    URL script = getClass().getClassLoader().getResource("scripts/history_script.txt");
    File wcTree = new File("target/gen/HistoryPanelTest/testAffectedFiles");
    RepoGenerationScript.generateRepository(script, wcTree);
    try {
        GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
        List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
        String dump = dumpHistory(commitsCharacteristics);
        String expected = "[ Root file changed. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Root file. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 4 , AlexJitianu , null ]\n" + "";
        expected = replaceDate(expected);
        assertEquals(expected, dump);
        historyPanel.showRepositoryHistory();
        waitForScheduler();
        flushAWT();
        sleep(300);
        JTable historyTable = historyPanel.getHistoryTable();
        HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
        dump = dumpHistory(model.getAllCommits());
        assertEquals(expected, dump);
        // -----------
        // Select an entry in the revision table.
        // -----------
        selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 2, "[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]");
        // -----------
        // Assert the affected files
        // -----------
        assertAffectedFiles(historyPanel, "(changeType=ADD, fileLocation=f2/file1.txt)\n" + "(changeType=CHANGED, fileLocation=f2/file2.txt)\n" + "(changeType=REMOVED, fileLocation=f2/file4.txt)\n" + "(changeType=RENAME, fileLocation=f2/file3_renamed.txt)\n" + "");
        JTable affectedFiles = historyPanel.getAffectedFilesTable();
        TableCellRenderer render = affectedFiles.getDefaultRenderer(FileStatus.class);
        FileHistoryPresenter presentedPath = new FileHistoryPresenter("f2/file4.txt");
        ((HistoryAffectedFileCellRender) render).setFilePresenter(presentedPath);
        Color foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(0, 1), false, true, 0, 1).getForeground();
        assertEquals(UIUtil.NOT_SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(1, 1), false, true, 1, 1).getForeground();
        assertEquals(UIUtil.NOT_SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(2, 1), false, true, 2, 1).getForeground();
        assertEquals(UIUtil.SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(3, 1), false, true, 3, 1).getForeground();
        assertEquals(UIUtil.NOT_SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        presentedPath.setFilePath("f2");
        for (int i = 0; i < affectedFiles.getColumnCount(); i++) {
            foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(i, 1), false, true, 1, 1).getForeground();
            assertEquals(UIUtil.SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        }
        presentedPath.setFilePath(null);
        for (int i = 0; i < affectedFiles.getColumnCount(); i++) {
            foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(i, 1), false, true, 1, 1).getForeground();
            assertEquals(UIUtil.SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        }
    } finally {
        GitAccess.getInstance().closeRepo();
        FileUtils.deleteDirectory(wcTree);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) JTable(javax.swing.JTable) Color(java.awt.Color) FileHistoryPresenter(com.oxygenxml.git.view.history.FileHistoryPresenter) File(java.io.File) URL(java.net.URL) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) HistoryAffectedFileCellRender(com.oxygenxml.git.view.history.HistoryAffectedFileCellRender) Test(org.junit.Test)

Aggregations

CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)1 FileHistoryPresenter (com.oxygenxml.git.view.history.FileHistoryPresenter)1 HistoryAffectedFileCellRender (com.oxygenxml.git.view.history.HistoryAffectedFileCellRender)1 HistoryCommitTableModel (com.oxygenxml.git.view.history.HistoryCommitTableModel)1 Color (java.awt.Color)1 File (java.io.File)1 URL (java.net.URL)1 JTable (javax.swing.JTable)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1 Test (org.junit.Test)1