Search in sources :

Example 1 with StagingResourcesTableCellRenderer

use of com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer in project oxygen-git-client-addon by oxygenxml.

the class ListStashesDialog method createAffectedFilesTable.

/**
 * Creates table for affected files by stash.
 *
 * @return The created table.
 */
private Table createAffectedFilesTable() {
    affectedStashFilesTableModel = new FilesTableModel();
    final Comparator<FileStatus> comparator = (f1, f2) -> {
        int comparationResult = f1.getChangeType().compareTo(f2.getChangeType());
        if (comparationResult == 0) {
            // Same change type. Third level sort.
            comparationResult = f1.getFileLocation().compareTo(f2.getFileLocation());
        }
        return comparationResult;
    };
    affectedStashFilesTableModel.setComparator(comparator);
    Table filesTable = new Table(affectedStashFilesTableModel) {

        @Override
        public JToolTip createToolTip() {
            return UIUtil.createMultilineTooltip(this).orElseGet(super::createToolTip);
        }
    };
    filesTable.setFillsViewportHeight(true);
    filesTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            int selectedRow = stashesTable.getSelectedRow();
            if (selectedRow >= 0 && !evt.isPopupTrigger() && evt.getClickCount() == 2) {
                compareWithWorkingCopyAction.actionPerformed(null);
            }
        }
    });
    JPopupMenu contextualActions = new JPopupMenu();
    contextualActions.add(compareWithWorkingCopyAction);
    filesTable.setComponentPopupMenu(contextualActions);
    filesTable.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && filesTable.getSelectedRow() >= 0 && filesTable.getSelectedRow() < filesTable.getRowCount()) {
                compareWithWorkingCopyAction.actionPerformed(null);
            }
        }
    });
    addClickRightSelection(filesTable, contextualActions);
    filesTable.getColumnModel().setColumnMargin(0);
    filesTable.setTableHeader(null);
    filesTable.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 = filesTable.getColumnModel().getColumn(StagingResourcesTableModel.FILE_STATUS_COLUMN);
    statusCol.setMinWidth(colWidth);
    statusCol.setPreferredWidth(colWidth);
    statusCol.setMaxWidth(colWidth);
    filesTable.setDefaultRenderer(Object.class, new StagingResourcesTableCellRenderer(() -> false));
    return filesTable;
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Point(java.awt.Point) FileStatus(com.oxygenxml.git.service.entities.FileStatus) Button(ro.sync.exml.workspace.api.standalone.ui.Button) DiffPresenter(com.oxygenxml.git.view.DiffPresenter) Translator(com.oxygenxml.git.translator.Translator) Tags(com.oxygenxml.git.translator.Tags) MouseAdapter(java.awt.event.MouseAdapter) JFrame(javax.swing.JFrame) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Icon(javax.swing.Icon) OKCancelDialog(ro.sync.exml.workspace.api.standalone.ui.OKCancelDialog) UIConstants(com.oxygenxml.git.constants.UIConstants) GridBagConstraints(java.awt.GridBagConstraints) KeyEvent(java.awt.event.KeyEvent) FileNotFoundException(java.io.FileNotFoundException) Dimension(java.awt.Dimension) List(java.util.List) AbstractAction(javax.swing.AbstractAction) PopupMenuEvent(javax.swing.event.PopupMenuEvent) JCheckBox(javax.swing.JCheckBox) JTable(javax.swing.JTable) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) WindowConstants(javax.swing.WindowConstants) RevCommitUtil(com.oxygenxml.git.service.RevCommitUtil) ListSelectionModel(javax.swing.ListSelectionModel) Insets(java.awt.Insets) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Icons(com.oxygenxml.git.constants.Icons) TableColumnModel(javax.swing.table.TableColumnModel) UIUtil(com.oxygenxml.git.view.util.UIUtil) Action(javax.swing.Action) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) SwingUtilities(javax.swing.SwingUtilities) GitAccess(com.oxygenxml.git.service.GitAccess) StagingResourcesTableCellRenderer(com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer) Table(ro.sync.exml.workspace.api.standalone.ui.Table) JToolTip(javax.swing.JToolTip) Logger(org.slf4j.Logger) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) IOException(java.io.IOException) PopupMenuListener(javax.swing.event.PopupMenuListener) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) PluginWorkspaceProvider(ro.sync.exml.workspace.api.PluginWorkspaceProvider) JLabel(javax.swing.JLabel) Comparator(java.util.Comparator) StagingResourcesTableModel(com.oxygenxml.git.view.staging.StagingResourcesTableModel) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JTable(javax.swing.JTable) Table(ro.sync.exml.workspace.api.standalone.ui.Table) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) KeyEvent(java.awt.event.KeyEvent) StagingResourcesTableCellRenderer(com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer) Icon(javax.swing.Icon)

Example 2 with StagingResourcesTableCellRenderer

use of com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer 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 3 with StagingResourcesTableCellRenderer

use of com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer in project oxygen-git-client-addon by oxygenxml.

the class StashVisualTests method testListStashAffectedFilesTable.

/**
 * <p><b>Description:</b> Tests the "List stashes" affected files table</p>
 * <p><b>Bug ID:</b> EXM-45983</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testListStashAffectedFilesTable() throws Exception {
    // Make the first commit for the local repository
    File file = new File(LOCAL_REPO, "local.txt");
    file.createNewFile();
    setFileContent(file, "local content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
    gitAccess.commit("First local commit.");
    // Make the first commit for the remote repository
    gitAccess.setRepositorySynchronously(REMOTE_REPO);
    file = new File(REMOTE_REPO, "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    // Switch back to local repo and create local branch
    gitAccess.setRepositorySynchronously(LOCAL_REPO);
    gitAccess.createBranch(LOCAL_BRANCH);
    gitAccess.fetch();
    JFrame frame = new JFrame();
    try {
        // Init UI
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        ToolbarPanel toolbarPanel = stagingPanel.getToolbarPanel();
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        flushAWT();
        toolbarPanel.updateButtonsStates();
        refreshSupport.call();
        flushAWT();
        SplitMenuButton stashButton = toolbarPanel.getStashButton();
        String[] filesNames = { "local.txt", "local1.txt", "local2.txt", "local3.txt", "local4.txt" };
        String[] foldersName = { "folder0", "folder1", "folder2", "folder3", "folder4", "folder5", "very_very_veeeeeeeeeeeeeeeeeery_long_folder_name" };
        String path = LOCAL_REPO + "/";
        String fileWithLongPathName = "file_with_long_path.txt";
        for (int i = 0; i < foldersName.length; i++) {
            path += foldersName[i];
            file = new File(path);
            assertTrue(file.mkdir());
        }
        makeLocalChange("some_modification");
        for (int i = 1; i < filesNames.length; i++) {
            file = new File(LOCAL_REPO, filesNames[i]);
            assertTrue(file.createNewFile());
            setFileContent(file, "local content" + i);
            gitAccess.add(new FileStatus(GitChangeType.ADD, filesNames[i]));
        }
        file = new File(path, fileWithLongPathName);
        assertTrue(file.createNewFile());
        setFileContent(file, "local content");
        flushAWT();
        gitAccess.add(new FileStatus(GitChangeType.ADD, path + fileWithLongPathName));
        path = path.substring((LOCAL_REPO + "/").length());
        flushAWT();
        JMenuItem[] stashChangesItem = new JMenuItem[1];
        stashChangesItem[0] = stashButton.getItem(0);
        SwingUtilities.invokeLater(() -> stashChangesItem[0].getAction().actionPerformed(null));
        flushAWT();
        JDialog stashChangesDialog = findDialog(Tags.STASH_CHANGES);
        flushAWT();
        assertNotNull(stashChangesDialog);
        JButton doStashButton = findFirstButton(stashChangesDialog, Tags.STASH);
        flushAWT();
        assertNotNull(doStashButton);
        doStashButton.doClick();
        refreshSupport.call();
        flushAWT();
        makeLocalChange("another_modification");
        flushAWT();
        stashChangesItem[0] = stashButton.getItem(0);
        SwingUtilities.invokeLater(() -> stashChangesItem[0].getAction().actionPerformed(null));
        flushAWT();
        stashChangesDialog = findDialog(Tags.STASH_CHANGES);
        flushAWT();
        assertNotNull(stashChangesDialog);
        doStashButton = findFirstButton(stashChangesDialog, Tags.STASH);
        assertNotNull(doStashButton);
        doStashButton.doClick();
        refreshSupport.call();
        flushAWT();
        JMenuItem[] listStashesItem = new JMenuItem[1];
        listStashesItem[0] = stashButton.getItem(1);
        SwingUtilities.invokeLater(() -> listStashesItem[0].getAction().actionPerformed(null));
        ListStashesDialog listStashesDialog = (ListStashesDialog) findDialog(Tags.STASHES);
        flushAWT();
        assertNotNull(listStashesDialog);
        StagingResourcesTableCellRenderer filesRender = (StagingResourcesTableCellRenderer) listStashesDialog.getAffectedFilesTable().getDefaultRenderer(FileStatus.class);
        FilesTableModel stashFilesTableModel = (FilesTableModel) listStashesDialog.getAffectedFilesTable().getModel();
        assertEquals(GitChangeType.CHANGED, stashFilesTableModel.getValueAt(0, 0));
        assertEquals(filesNames[0], ((FileStatus) stashFilesTableModel.getValueAt(0, 1)).getFileLocation());
        stashFilesTableModel = (FilesTableModel) listStashesDialog.getAffectedFilesTable().getModel();
        SwingUtilities.invokeLater(() -> listStashesDialog.getStashesTable().setRowSelectionInterval(1, 1));
        flushAWT();
        for (int i = 0; i < filesNames.length - 1; i++) {
            assertEquals(GitChangeType.ADD, stashFilesTableModel.getValueAt(i, 0));
            assertEquals(filesNames[i + 1], ((FileStatus) stashFilesTableModel.getValueAt(i, 1)).getFileLocation());
            String toolTipFileText = ((JLabel) filesRender.getTableCellRendererComponent(listStashesDialog.getAffectedFilesTable(), stashFilesTableModel.getValueAt(i, 1), true, true, i, 1)).getToolTipText();
            assertEquals(filesNames[i + 1], toolTipFileText);
        }
        int length = filesNames.length;
        assertEquals(GitChangeType.CHANGED, stashFilesTableModel.getValueAt(length - 1, 0));
        assertEquals(filesNames[0], ((FileStatus) stashFilesTableModel.getValueAt(length - 1, 1)).getFileLocation());
        String toolTipFileText = ((JLabel) filesRender.getTableCellRendererComponent(listStashesDialog.getAffectedFilesTable(), stashFilesTableModel.getValueAt(length - 1, 1), true, true, length - 1, 1)).getToolTipText();
        assertEquals(filesNames[0], toolTipFileText);
        toolTipFileText = ((JLabel) filesRender.getTableCellRendererComponent(listStashesDialog.getAffectedFilesTable(), stashFilesTableModel.getValueAt(length, 1), true, true, length, 1)).getToolTipText();
        assertEquals(fileWithLongPathName + " - " + path, toolTipFileText);
        flushAWT();
        stashFilesTableModel = (FilesTableModel) listStashesDialog.getAffectedFilesTable().getModel();
        SwingUtilities.invokeLater(() -> listStashesDialog.getStashesTable().setRowSelectionInterval(0, 0));
        flushAWT();
        assertEquals(GitChangeType.CHANGED, stashFilesTableModel.getValueAt(0, 0));
        assertEquals(filesNames[0], ((FileStatus) stashFilesTableModel.getValueAt(0, 1)).getFileLocation());
        JButton cancelButton = findFirstButton(listStashesDialog, Tags.CLOSE);
        assertNotNull(cancelButton);
        cancelButton.doClick();
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) SplitMenuButton(ro.sync.exml.workspace.api.standalone.ui.SplitMenuButton) FilesTableModel(com.oxygenxml.git.view.stash.FilesTableModel) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) GitController(com.oxygenxml.git.view.event.GitController) ListStashesDialog(com.oxygenxml.git.view.stash.ListStashesDialog) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager) JFrame(javax.swing.JFrame) StagingResourcesTableCellRenderer(com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer) JMenuItem(javax.swing.JMenuItem) File(java.io.File) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) ToolbarPanel(com.oxygenxml.git.view.staging.ToolbarPanel) JDialog(javax.swing.JDialog)

Aggregations

StagingResourcesTableCellRenderer (com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer)3 FileStatus (com.oxygenxml.git.service.entities.FileStatus)2 Icon (javax.swing.Icon)2 JFrame (javax.swing.JFrame)2 JLabel (javax.swing.JLabel)2 JTable (javax.swing.JTable)2 TableColumn (javax.swing.table.TableColumn)2 Table (ro.sync.exml.workspace.api.standalone.ui.Table)2 Icons (com.oxygenxml.git.constants.Icons)1 UIConstants (com.oxygenxml.git.constants.UIConstants)1 GitAccess (com.oxygenxml.git.service.GitAccess)1 NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 RevCommitUtil (com.oxygenxml.git.service.RevCommitUtil)1 GitChangeType (com.oxygenxml.git.service.entities.GitChangeType)1 Tags (com.oxygenxml.git.translator.Tags)1 Translator (com.oxygenxml.git.translator.Translator)1 DiffPresenter (com.oxygenxml.git.view.DiffPresenter)1 GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)1 GitController (com.oxygenxml.git.view.event.GitController)1 HistoryAffectedFileCellRender (com.oxygenxml.git.view.history.HistoryAffectedFileCellRender)1