Search in sources :

Example 16 with NoRepositorySelected

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

the class CommitAndStatusPanel method toggleCommitButtonAndUpdateMessageArea.

/**
 * Checks if the commit button should be enabled.
 *
 * @param forceEnable <code>true</code> to make the button enable without any additional checks.
 */
void toggleCommitButtonAndUpdateMessageArea(boolean forceEnable) {
    if (forceEnable) {
        commitButton.setEnabled(true);
    } else {
        try {
            Repository repo = gitAccess.getRepository();
            final RepositoryState repositoryState = repo.getRepositoryState();
            final String mergeMessage = MessageFormat.format(translator.getTranslation(Tags.COMMIT_TO_MERGE), gitAccess.getBranchInfo().getBranchName(), repo.getConfig().getString("remote", "origin", "url"));
            // Possible time consuming operations.
            commitButtonAndMessageUpdateTask = new SwingWorker<Void, Void>() {

                boolean enable = false;

                String message = null;

                @Override
                protected Void doInBackground() throws Exception {
                    GitStatus status = gitAccess.getStatus();
                    if (repositoryState == RepositoryState.MERGING_RESOLVED && status.getStagedFiles().isEmpty() && status.getUnstagedFiles().isEmpty()) {
                        enable = true;
                        message = mergeMessage;
                    } else if (!status.getStagedFiles().isEmpty() || amendLastCommitToggle.isSelected()) {
                        enable = true;
                    }
                    return null;
                }

                @Override
                protected void done() {
                    if (message != null) {
                        commitMessageArea.setText(message);
                    }
                    commitButton.setEnabled(enable);
                }
            };
            commitButtonAndMessageUpdateTaskTimer.restart();
        } catch (NoRepositorySelected e) {
        // Remains disabled
        }
    }
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) Repository(org.eclipse.jgit.lib.Repository) RepositoryState(org.eclipse.jgit.lib.RepositoryState) RepoNotInitializedException(com.oxygenxml.git.service.RepoNotInitializedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) GitStatus(com.oxygenxml.git.service.GitStatus)

Example 17 with NoRepositorySelected

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

the class ShowBlameForUnstagedResourceAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    PluginWorkspace pluginWS = PluginWorkspaceProvider.getPluginWorkspace();
    final List<FileStatus> allSelectedResources = selResProvider.getAllSelectedResources();
    if (!allSelectedResources.isEmpty()) {
        try {
            String filePath = allSelectedResources.get(0).getFileLocation();
            File file = new File(GitAccess.getInstance().getWorkingCopy(), filePath);
            URL fileURL = file.toURI().toURL();
            WSEditor editor = pluginWS.getEditorAccess(fileURL, PluginWorkspace.MAIN_EDITING_AREA);
            if (editor == null || !editor.isModified()) {
                tryBlame(filePath);
            } else if (editor.isModified()) {
                // Ask for save
                int response = pluginWS.showConfirmDialog(translator.getTranslation(Tags.SHOW_BLAME), MessageFormat.format(translator.getTranslation(Tags.THIS_OPERATION_REQUIRES_SAVING), fileURL.toExternalForm()), new String[] { "   " + translator.getTranslation(Tags.YES) + "   ", "   " + translator.getTranslation(Tags.NO) + "   " }, new int[] { 0, 1 });
                if (response == 0) {
                    editor.save();
                    tryBlame(filePath);
                }
            }
        } catch (NoRepositorySelected | MalformedURLException ex) {
            pluginWS.showErrorMessage(ex.getMessage());
        }
    }
}
Also used : PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) MalformedURLException(java.net.MalformedURLException) FileStatus(com.oxygenxml.git.service.entities.FileStatus) WSEditor(ro.sync.exml.workspace.api.editor.WSEditor) File(java.io.File) URL(java.net.URL)

Example 18 with NoRepositorySelected

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

the class HistoryPanel method showHistory.

/**
 * Shows the commit history for the entire repository.
 *
 * @param filePath File for which to present the commit that changed him.
 * @param force    <code>true</code> to recompute the history data, even if the
 *                 view already presents the history for the given resource.
 */
private void showHistory(String filePath, boolean force) {
    SwingUtilities.invokeLater(() -> updateSelectionMode(filePath));
    if (force || // Check if we don't already present the history for this path!!!!
    !Equaler.verifyEquals(filePath, activeFilePath)) {
        this.activeFilePath = filePath;
        try {
            // Make sure we know about the remote as well, to present data about the
            // upstream branch.
            tryFetch();
            File directory = gitAccess.getWorkingCopy();
            historyLabelMessage = TRANSLATOR.getTranslation(Tags.REPOSITORY) + ": " + directory.getName() + ". " + TRANSLATOR.getTranslation(Tags.BRANCH) + ": " + gitAccess.getBranchInfo().getBranchName() + ".";
            if (filePath != null) {
                directory = new File(directory, filePath);
                historyLabelMessage += " " + TRANSLATOR.getTranslation(Tags.FILE) + ": " + directory.getName() + ".";
            }
            historyInfoLabel.setText(TreeUtil.getWordToFitInWidth(historyLabelMessage, historyInfoLabel.getFontMetrics(historyInfoLabel.getFont()), this.getWidth() / topPanel.getComponentCount()));
            historyInfoLabel.setToolTipText(historyLabelMessage);
            historyInfoLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
            // Install selection listener.
            if (revisionDataUpdater != null) {
                historyTable.getSelectionModel().removeListSelectionListener(revisionDataUpdater);
            }
            fileHistoryPresenter.setFilePath(filePath);
            SwingUtilities.invokeLater(() -> {
                final HistoryTableAffectedFilesModel dataModel = (HistoryTableAffectedFilesModel) affectedFilesTable.getModel();
                dataModel.setFilesStatus(Collections.emptyList());
                dataModel.setFilePathPresenter(fileHistoryPresenter);
            });
            HistoryAffectedFileCellRender cellRender = (HistoryAffectedFileCellRender) affectedFilesTable.getDefaultRenderer(FileStatus.class);
            cellRender.setFilePresenter(fileHistoryPresenter);
            commitDescriptionPane.setText("");
            RenameTracker renameTracker = new RenameTracker();
            final List<CommitCharacteristics> commitCharacteristicsVector = gitAccess.getCommitsCharacteristics(currentStrategy, filePath, renameTracker);
            hasUncommitedChanges = GitAccess.getInstance().getStatusCache().getStatus().hasUncommittedChanges();
            final Repository repo = gitAccess.getRepository();
            final CommitsAheadAndBehind commitsAheadAndBehind = RevCommitUtil.getCommitsAheadAndBehind(repo, repo.getFullBranch());
            // Compute the row height.
            CommitMessageTableRenderer renderer = new CommitMessageTableRenderer(repo, commitsAheadAndBehind, gitAccess.getBranchInfo().getBranchName(), getTagMap(repo), gitAccess.getBranchMap(repo, ConfigConstants.CONFIG_KEY_LOCAL), gitAccess.getBranchMap(repo, ConfigConstants.CONFIG_KEY_REMOTE));
            final int rh = getRowHeight(renderer, getFirstCommit(commitCharacteristicsVector));
            final HistoryCommitTableModel historyModel = new HistoryCommitTableModel(commitCharacteristicsVector);
            SwingUtilities.invokeLater(() -> {
                historyModel.filterChanged(filter.getText());
                historyTable.setModel(historyModel);
                updateHistoryTableWidths();
                historyTable.setDefaultRenderer(PlotCommit.class, graphCellRender);
                historyTable.setDefaultRenderer(CommitCharacteristics.class, renderer);
                historyTable.setDefaultRenderer(Date.class, new DateTableCellRenderer(UIUtil.DATE_FORMAT_PATTERN));
                TableColumn authorColumn = historyTable.getColumn(TRANSLATOR.getTranslation(Tags.AUTHOR));
                authorColumn.setCellRenderer(createAuthorColumnRenderer());
                historyTable.setRowHeight(rh);
            });
            revisionDataUpdater = new RowHistoryTableSelectionListener(getUpdateDelay(), historyTable, commitDescriptionPane, commitCharacteristicsVector, affectedFilesTable, renameTracker, fileHistoryPresenter);
            historyTable.getSelectionModel().addListSelectionListener(revisionDataUpdater);
            // Install hyperlink listener.
            if (hyperlinkListener != null) {
                commitDescriptionPane.removeHyperlinkListener(hyperlinkListener);
            }
            hyperlinkListener = new HistoryHyperlinkListener(historyTable, commitCharacteristicsVector);
            commitDescriptionPane.addHyperlinkListener(hyperlinkListener);
            // Select the local branch HEAD.
            selectLocalBranchHead(commitCharacteristicsVector, repo);
        } catch (NoRepositorySelected | IOException e) {
            LOGGER.debug(e.getMessage(), e);
            PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Unable to present history because of: " + e.getMessage());
        }
    } else {
        if (historyTable.getModel().getRowCount() == 0) {
            PluginWorkspaceProvider.getPluginWorkspace().showInformationMessage(TRANSLATOR.getTranslation(Tags.GIT_HISTORY) + ": " + StringUtils.toLowerCase(TRANSLATOR.getTranslation(Tags.NOTHING_TO_SHOW_FOR_NEW_FILES)));
        }
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) IOException(java.io.IOException) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) Repository(org.eclipse.jgit.lib.Repository) File(java.io.File)

Example 19 with NoRepositorySelected

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

the class HistoryPanel method treatEditorSavedEvent.

/**
 * Treat editor saved event.
 *
 * @param editorLocation Editor URL.
 */
private void treatEditorSavedEvent(final URL editorLocation) {
    File localFile = null;
    if ("file".equals(editorLocation.getProtocol())) {
        localFile = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().locateFile(editorLocation);
        if (localFile != null) {
            String fileInWorkPath = localFile.toString();
            fileInWorkPath = FileUtil.rewriteSeparator(fileInWorkPath);
            try {
                String selectedRepositoryPath = GitAccess.getInstance().getWorkingCopy().getAbsolutePath();
                selectedRepositoryPath = FileUtil.rewriteSeparator(selectedRepositoryPath);
                if (isShowing() && fileInWorkPath.startsWith(selectedRepositoryPath)) {
                    scheduleRefreshHistory();
                }
            } catch (NoRepositorySelected e) {
                LOGGER.debug(e.getMessage(), e);
            }
        }
    }
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) File(java.io.File)

Example 20 with NoRepositorySelected

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

the class HistoryViewContextualMenuPresenter method addCompareWithParentsAction.

/**
 * Iterate over the parent revisions and add one Compare action for each.
 *
 * @param actions List where to put the actions.
 * @param commitCharacteristics Revision information.
 * @param addFileName <code>true</code> to add the name of the file to the action name.
 * @param filePath File location relative to the WC root.
 */
private void addCompareWithParentsAction(List<Action> actions, CommitCharacteristics commitCharacteristics, boolean addFileName, String filePath) {
    List<String> parents = commitCharacteristics.getParentCommitId();
    if (parents != null && !parents.isEmpty()) {
        try {
            RevCommit[] parentsRevCommits = RevCommitUtil.getParents(GitAccess.getInstance().getRepository(), commitCharacteristics.getCommitId());
            boolean addParentID = parents.size() > 1;
            for (RevCommit parentID : parentsRevCommits) {
                actions.add(createCompareWithPrevVersionAction(filePath, commitCharacteristics.getCommitId(), filePath, parentID, addParentID, addFileName));
            }
        } catch (IOException | NoRepositorySelected e2) {
            PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(UNABLE_TO_COMPARE + e2.getMessage());
            LOGGER.error(e2.getMessage(), e2);
        }
    }
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)28 IOException (java.io.IOException)15 File (java.io.File)10 URL (java.net.URL)8 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 Repository (org.eclipse.jgit.lib.Repository)6 FileStatus (com.oxygenxml.git.service.entities.FileStatus)4 MalformedURLException (java.net.MalformedURLException)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 RepoNotInitializedException (com.oxygenxml.git.service.RepoNotInitializedException)3 ActionEvent (java.awt.event.ActionEvent)3 AbstractAction (javax.swing.AbstractAction)3 BranchInfo (com.oxygenxml.git.service.BranchInfo)2 GitChangeType (com.oxygenxml.git.service.entities.GitChangeType)2 Translator (com.oxygenxml.git.translator.Translator)2 CheckoutCommitAction (com.oxygenxml.git.view.history.actions.CheckoutCommitAction)2 CreateBranchFromCommitAction (com.oxygenxml.git.view.history.actions.CreateBranchFromCommitAction)2 CreateTagAction (com.oxygenxml.git.view.history.actions.CreateTagAction)2 ResetBranchToCommitAction (com.oxygenxml.git.view.history.actions.ResetBranchToCommitAction)2 RevertCommitAction (com.oxygenxml.git.view.history.actions.RevertCommitAction)2