Search in sources :

Example 11 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus 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 12 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanel method showResourcesContextualMenu.

/**
 * Show the contextual menu on the resources changed on a revision.
 *
 * @param affectedFilesTable The table with the files from a committed on a
 *                           revision.
 * @param point              The point where to show the contextual menu.
 */
protected void showResourcesContextualMenu(JTable affectedFilesTable, Point point) {
    int rowAtPoint = affectedFilesTable.rowAtPoint(point);
    if (rowAtPoint != -1) {
        updateTableSelection(affectedFilesTable, rowAtPoint);
        HistoryTableAffectedFilesModel model = (HistoryTableAffectedFilesModel) affectedFilesTable.getModel();
        int convertedSelectedRow = affectedFilesTable.convertRowIndexToModel(rowAtPoint);
        FileStatus file = model.getFileStatus(convertedSelectedRow);
        HistoryCommitTableModel historyTableModel = (HistoryCommitTableModel) historyTable.getModel();
        CommitCharacteristics commitCharacteristics = historyTableModel.getAllCommits().get(historyTable.getSelectedRow());
        JPopupMenu jPopupMenu = new JPopupMenu();
        contextualMenuPresenter.populateContextActionsForFile(jPopupMenu, file, commitCharacteristics, false);
        jPopupMenu.show(affectedFilesTable, point.x, point.y);
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu)

Example 13 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanel method historyDoubleClickAction.

/**
 * Opens the first action in the contextual menu when an element inside the
 * history table is double clicked.
 *
 * @param rowAtPoint Position of the element in the history table.
 */
private void historyDoubleClickAction(int rowAtPoint) {
    HistoryCommitTableModel historyTableModel = (HistoryCommitTableModel) historyTable.getModel();
    int convertedSelectedRow = historyTable.convertRowIndexToModel(rowAtPoint);
    CommitCharacteristics commitCharacteristics = historyTableModel.getAllCommits().get(convertedSelectedRow);
    try {
        Optional<FileStatus> optionalFileStatus = contextualMenuPresenter.getFileStatus(activeFilePath, commitCharacteristics);
        if (optionalFileStatus.isPresent()) {
            FileStatus fileStatus = optionalFileStatus.get();
            List<Action> contextualActions = contextualMenuPresenter.getFileContextualActions(fileStatus, commitCharacteristics, false);
            if (!contextualActions.isEmpty()) {
                contextualActions.get(0).actionPerformed(null);
            }
        }
    } catch (IOException | GitAPIException e1) {
        PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(e1.getMessage());
        LOGGER.error(e1.getMessage(), e1);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) FileStatus(com.oxygenxml.git.service.entities.FileStatus) IOException(java.io.IOException) Point(java.awt.Point)

Example 14 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class HistoryViewContextualMenuPresenter method getFileURL.

/**
 * Builds an URL that identifies a file at a specific revision.
 *
 * @param revisionID Revision ID.
 * @param fileStatus FIle info.
 *
 * @return The URL, if one was built.
 *
 * @throws NoRepositorySelected No repository is loaded.
 * @throws IOException Problems identifying the revision.
 */
private Optional<URL> getFileURL(String revisionID, FileStatus fileStatus) throws NoRepositorySelected, IOException {
    URL fileURL = null;
    String fileStatusLocation = fileStatus.getFileLocation();
    if (fileStatus.getChangeType() == GitChangeType.REMOVED) {
        Repository repository = GitAccess.getInstance().getRepository();
        RevCommit[] parentsRevCommits = RevCommitUtil.getParents(repository, revisionID);
        // If it's a merge, we look for the one parent with the actual file in it.
        Optional<RevCommit> previousVersionCommit = Arrays.stream(parentsRevCommits).filter(revCommit -> {
            try {
                return RevCommitUtil.getObjectID(repository, revCommit.getId().getName(), fileStatusLocation) != null;
            } catch (IOException e1) {
                // Unable to find a parent with the given path.
                PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Unable to open file because of " + e1.getMessage());
            }
            return false;
        }).findFirst();
        if (previousVersionCommit.isPresent()) {
            fileURL = GitRevisionURLHandler.encodeURL(previousVersionCommit.get().getId().getName(), fileStatusLocation);
        }
    } else if (fileStatus.getChangeType() == GitChangeType.MISSING) {
        fileURL = GitRevisionURLHandler.encodeURL(VersionIdentifier.INDEX_OR_LAST_COMMIT, fileStatusLocation);
    } else if (!GitAccess.UNCOMMITED_CHANGES.getCommitId().equals(revisionID)) {
        fileURL = GitRevisionURLHandler.encodeURL(revisionID, fileStatusLocation);
    } else {
        fileURL = FileUtil.getFileURL(fileStatusLocation);
    }
    return Optional.ofNullable(fileURL);
}
Also used : CreateBranchFromCommitAction(com.oxygenxml.git.view.history.actions.CreateBranchFromCommitAction) EditorPageConstants(ro.sync.exml.editor.EditorPageConstants) Arrays(java.util.Arrays) RevCommit(org.eclipse.jgit.revwalk.RevCommit) VersionIdentifier(com.oxygenxml.git.protocol.VersionIdentifier) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) Action(javax.swing.Action) ResetBranchToCommitAction(com.oxygenxml.git.view.history.actions.ResetBranchToCommitAction) FileStatus(com.oxygenxml.git.service.entities.FileStatus) MessageFormat(java.text.MessageFormat) DiffPresenter(com.oxygenxml.git.view.DiffPresenter) Translator(com.oxygenxml.git.translator.Translator) GitAccess(com.oxygenxml.git.service.GitAccess) FileStatusOverDiffEntry(com.oxygenxml.git.service.entities.FileStatusOverDiffEntry) RevertCommitAction(com.oxygenxml.git.view.history.actions.RevertCommitAction) JMenuItem(javax.swing.JMenuItem) Tags(com.oxygenxml.git.translator.Tags) LinkedList(java.util.LinkedList) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) JPopupMenu(javax.swing.JPopupMenu) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) IOException(java.io.IOException) RevCommitUtilBase(com.oxygenxml.git.service.RevCommitUtilBase) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) GitOperationScheduler(com.oxygenxml.git.service.GitOperationScheduler) AbstractAction(javax.swing.AbstractAction) GitRevisionURLHandler(com.oxygenxml.git.protocol.GitRevisionURLHandler) PluginWorkspaceProvider(ro.sync.exml.workspace.api.PluginWorkspaceProvider) CreateTagAction(com.oxygenxml.git.view.history.actions.CreateTagAction) CheckoutCommitAction(com.oxygenxml.git.view.history.actions.CheckoutCommitAction) Optional(java.util.Optional) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) FileUtil(com.oxygenxml.git.utils.FileUtil) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) Repository(org.eclipse.jgit.lib.Repository) RevCommitUtil(com.oxygenxml.git.service.RevCommitUtil) Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException) URL(java.net.URL) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 15 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class HistoryViewContextualMenuPresenter method populateActions4SingleSelection.

/**
 * Contributes the contextual actions for the given file, at the given revision/commit.
 *
 * @param jPopupMenu            Contextual menu in which to put the actions.
 * @param filePath              File path.
 * @param commitCharacteristics Revision/commit data.
 *
 * @throws IOException If it fails.
 * @throws GitAPIException If it fails.
 */
private void populateActions4SingleSelection(JPopupMenu jPopupMenu, String filePath, CommitCharacteristics commitCharacteristics) throws IOException, GitAPIException {
    if (filePath != null) {
        Optional<FileStatus> fileStatusOptional = getFileStatus(filePath, commitCharacteristics);
        fileStatusOptional.ifPresent(fileStatus -> populateContextActionsForFile(jPopupMenu, fileStatus, commitCharacteristics, true));
    }
    if (filePath != null) {
        jPopupMenu.addSeparator();
    }
    String commitId = commitCharacteristics.getCommitId();
    if (!GitAccess.UNCOMMITED_CHANGES.getCommitId().equals(commitId)) {
        jPopupMenu.add(new CreateBranchFromCommitAction(commitId));
        jPopupMenu.add(new CreateTagAction(commitId));
        jPopupMenu.add(new CheckoutCommitAction(commitCharacteristics.getPlotCommit()));
        jPopupMenu.addSeparator();
        jPopupMenu.add(new RevertCommitAction(commitCharacteristics));
        jPopupMenu.add(new ResetBranchToCommitAction(commitCharacteristics));
    }
}
Also used : RevertCommitAction(com.oxygenxml.git.view.history.actions.RevertCommitAction) FileStatus(com.oxygenxml.git.service.entities.FileStatus) CheckoutCommitAction(com.oxygenxml.git.view.history.actions.CheckoutCommitAction) ResetBranchToCommitAction(com.oxygenxml.git.view.history.actions.ResetBranchToCommitAction) CreateTagAction(com.oxygenxml.git.view.history.actions.CreateTagAction) CreateBranchFromCommitAction(com.oxygenxml.git.view.history.actions.CreateBranchFromCommitAction)

Aggregations

FileStatus (com.oxygenxml.git.service.entities.FileStatus)210 File (java.io.File)136 Test (org.junit.Test)77 ArrayList (java.util.ArrayList)58 GitController (com.oxygenxml.git.view.event.GitController)53 List (java.util.List)50 Repository (org.eclipse.jgit.lib.Repository)49 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)38 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)33 JButton (javax.swing.JButton)33 SelectedResourcesProvider (com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider)26 IOException (java.io.IOException)25 AbstractAction (javax.swing.AbstractAction)24 JDialog (javax.swing.JDialog)24 GitResourceContextualMenu (com.oxygenxml.git.view.staging.GitResourceContextualMenu)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 URL (java.net.URL)18 Action (javax.swing.Action)18 CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)16