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;
}
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);
}
}
Aggregations