use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class StagingPanel method treatEditorSavedEvent.
/**
* Treat editor saved event.
*
* @param editorLocation Editor URL.
*/
private void treatEditorSavedEvent(final URL editorLocation) {
File locateFile = null;
if ("file".equals(editorLocation.getProtocol())) {
locateFile = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().locateFile(editorLocation);
if (locateFile != null) {
String fileInWorkPath = locateFile.toString();
fileInWorkPath = FileUtil.rewriteSeparator(fileInWorkPath);
try {
String selectedRepositoryPath = GitAccess.getInstance().getWorkingCopy().getAbsolutePath();
selectedRepositoryPath = FileUtil.rewriteSeparator(selectedRepositoryPath);
if (fileInWorkPath.startsWith(selectedRepositoryPath)) {
if (gitActionsManager != null) {
gitActionsManager.refreshActionsStates();
}
updateToolbarsButtonsStates();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Notify " + fileInWorkPath);
LOGGER.debug("WC " + selectedRepositoryPath);
}
Collection<String> affectedFiles = Collections.singletonList(fileInWorkPath.substring(selectedRepositoryPath.length() + 1));
FileGitEventInfo changeEvent = new FileGitEventInfo(GitOperation.UNSTAGE, affectedFiles);
SwingUtilities.invokeLater(() -> unstagedChangesPanel.fileStatesChanged(changeEvent));
}
} 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 ToolbarPanel method updateButtonsStates.
/**
* Updates the presented information, like the Pull-behind, Pushes-ahead
* and branch status.
*/
public void updateButtonsStates() {
this.pullsBehind = GIT_ACCESS.getPullsBehind();
try {
this.pushesAhead = GIT_ACCESS.getPushesAhead();
} catch (RepoNotInitializedException e) {
this.pushesAhead = -1;
LOGGER.debug(e.getMessage(), e);
}
Repository repo = null;
try {
repo = GIT_ACCESS.getRepository();
} catch (NoRepositorySelected e) {
LOGGER.debug(e.getMessage(), e);
}
final Collection<RevCommit> stashes = GIT_ACCESS.listStashes();
if (stashes != null) {
noOfStashes = stashes.size();
}
final boolean isPullMenuEnabled = isPullButtonEnabled();
final boolean isStashButtonEnabled = isStashButtonEnabled();
SwingUtilities.invokeLater(() -> {
/* for @pushButton, @historyButton, @showBranchesButton --->
* it is necessary to refresh, even if it has a single action,
* because there are other code sequences that directly change their state by calling the setEnabled(false) method
*/
pushButton.setEnabled(gitActionsManager.getPushAction().isEnabled());
pullMenuButton.setEnabled(isPullMenuEnabled);
stashButton.setEnabled(isStashButtonEnabled);
historyButton.setEnabled(gitActionsManager.getShowHistoryAction().isEnabled());
showBranchesButton.setEnabled(gitActionsManager.getShowBranchesAction().isEnabled());
pullMenuButton.repaint();
pushButton.repaint();
stashButton.repaint();
});
BranchInfo branchInfo = GIT_ACCESS.getBranchInfo();
String currentBranchName = branchInfo.getBranchName();
if (branchInfo.isDetached()) {
SwingUtilities.invokeLater(() -> {
pushButton.setToolTipText(TRANSLATOR.getTranslation(Tags.PUSH_BUTTON_TOOLTIP));
pullMenuButton.setToolTipText(TRANSLATOR.getTranslation(Tags.PULL_BUTTON_TOOLTIP));
});
String tooltipText = TRANSLATOR.getTranslation(Tags.TOOLBAR_PANEL_INFORMATION_STATUS_DETACHED_HEAD) + " " + currentBranchName;
if (repo != null && repo.getRepositoryState() == RepositoryState.REBASING_MERGE) {
tooltipText += "<br>" + TRANSLATOR.getTranslation(Tags.REBASE_IN_PROGRESS) + ".";
}
tooltipText = TextFormatUtil.toHTML(tooltipText);
} else {
if (currentBranchName != null && !currentBranchName.isEmpty()) {
String upstreamBranchFromConfig = GIT_ACCESS.getUpstreamBranchShortNameFromConfig(currentBranchName);
boolean isAnUpstreamBranchDefinedInConfig = upstreamBranchFromConfig != null;
String upstreamShortestName = isAnUpstreamBranchDefinedInConfig ? upstreamBranchFromConfig.substring(upstreamBranchFromConfig.lastIndexOf('/') + 1) : null;
Ref remoteBranchRefForUpstreamFromConfig = isAnUpstreamBranchDefinedInConfig ? RepoUtil.getRemoteBranch(upstreamShortestName) : null;
boolean existsRemoteBranchForUpstreamDefinedInConfig = remoteBranchRefForUpstreamFromConfig != null;
String commitsBehindMessage = "";
String commitsAheadMessage = "";
if (isAnUpstreamBranchDefinedInConfig && existsRemoteBranchForUpstreamDefinedInConfig) {
if (pullsBehind == 0) {
commitsBehindMessage = TRANSLATOR.getTranslation(Tags.TOOLBAR_PANEL_INFORMATION_STATUS_UP_TO_DATE);
} else if (pullsBehind == 1) {
commitsBehindMessage = TRANSLATOR.getTranslation(Tags.ONE_COMMIT_BEHIND);
} else {
commitsBehindMessage = MessageFormat.format(TRANSLATOR.getTranslation(Tags.COMMITS_BEHIND), pullsBehind);
}
if (pushesAhead == 0) {
commitsAheadMessage = TRANSLATOR.getTranslation(Tags.NOTHING_TO_PUSH);
} else if (pushesAhead == 1) {
commitsAheadMessage = TRANSLATOR.getTranslation(Tags.ONE_COMMIT_AHEAD);
} else {
commitsAheadMessage = MessageFormat.format(TRANSLATOR.getTranslation(Tags.COMMITS_AHEAD), pushesAhead);
}
}
// ===================== Push button tooltip =====================
String pushButtonTooltipFinal = updatePushToolTip(isAnUpstreamBranchDefinedInConfig, existsRemoteBranchForUpstreamDefinedInConfig, upstreamBranchFromConfig, commitsAheadMessage, currentBranchName, repo);
SwingUtilities.invokeLater(() -> pushButton.setToolTipText(pushButtonTooltipFinal));
// ===================== Pull button tooltip =====================
String pullButtonTooltipFinal = updatePullToolTip(isAnUpstreamBranchDefinedInConfig, existsRemoteBranchForUpstreamDefinedInConfig, upstreamBranchFromConfig, commitsBehindMessage, remoteBranchRefForUpstreamFromConfig, repo);
SwingUtilities.invokeLater(() -> pullMenuButton.setToolTipText(pullButtonTooltipFinal));
}
}
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class TagsDialog method createTableComponentMenu.
/**
* Create the popup menu for the tagsTable
*
* @return a JPopUpMenu for the tags table
*/
private JPopupMenu createTableComponentMenu() {
JPopupMenu contextualActions = new JPopupMenu();
JMenuItem menuItemDetails = new JMenuItem(TRANSLATOR.getTranslation(Tags.TAGS_DIALOG_POPUP_MENU_DETAILS));
menuItemDetails.addActionListener(e -> {
try {
int selectedRow = tagsTable.getSelectedRow();
TagsTableModel model = (TagsTableModel) tagsTable.getModel();
GitTag tag = model.getItemAt(selectedRow);
TagDetailsDialog dialog = new TagDetailsDialog(tag);
dialog.setVisible(true);
} catch (NoRepositorySelected | IOException ex) {
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(ex.getMessage(), ex);
}
});
contextualActions.add(menuItemDetails);
contextualActions.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
SwingUtilities.invokeLater(() -> {
int rowAtPoint = tagsTable.rowAtPoint(SwingUtilities.convertPoint(contextualActions, new Point(0, 0), tagsTable));
if (rowAtPoint > -1) {
tagsTable.setRowSelectionInterval(rowAtPoint, rowAtPoint);
}
});
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
/*//Not necessary to be implemented*/
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
/*//Not necessary to be implemented*/
}
});
return contextualActions;
}
use of com.oxygenxml.git.service.NoRepositorySelected 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);
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class CreateTagAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
CreateTagDialog dialog = new CreateTagDialog();
String tagTitle = dialog.getTagTitle();
String tagMessage = dialog.getTagMessage();
if (dialog.getResult() == OKCancelDialog.RESULT_OK) {
GitOperationScheduler.getInstance().schedule(() -> {
try {
GitAccess.getInstance().tagCommit(tagTitle, tagMessage, commitId);
if (dialog.shouldPushNewTag()) {
GitAccess.getInstance().pushTag(tagTitle);
}
} catch (GitAPIException | RevisionSyntaxException | NoRepositorySelected | IOException ex) {
LOGGER.debug(ex.getMessage(), ex);
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(ex.getMessage(), ex);
}
});
}
}
Aggregations