Search in sources :

Example 1 with HistoryAffectedFileCellRender

use of com.oxygenxml.git.view.history.HistoryAffectedFileCellRender 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 HistoryAffectedFileCellRender

use of com.oxygenxml.git.view.history.HistoryAffectedFileCellRender 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

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