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