use of com.oxygenxml.git.view.event.GitOperation in project oxygen-git-client-addon by oxygenxml.
the class OxygenGitPluginExtension method customizeGitStagingView.
/**
* Customize the Git Staging view.
*
* @param viewInfo View information.
*/
private void customizeGitStagingView(final ViewInfo viewInfo, final GitActionsManager gitActionsManager) {
boolean shouldRecreateStagingPanel = stagingPanel == null;
if (shouldRecreateStagingPanel) {
stagingPanel = new StagingPanel(gitRefreshSupport, gitController, OxygenGitPluginExtension.this, gitActionsManager);
gitRefreshSupport.setStagingPanel(stagingPanel);
}
viewInfo.setComponent(stagingPanel);
GitOperationUtil.installMouseBusyCursor(gitController, stagingPanel);
gitController.addGitListener(new GitEventAdapter() {
@Override
public void operationAboutToStart(GitEventInfo info) {
// not needed
}
@Override
public void operationSuccessfullyEnded(GitEventInfo info) {
final GitOperation operation = info.getGitOperation();
if (operation == GitOperation.CHECKOUT || operation == GitOperation.CONTINUE_REBASE || operation == GitOperation.RESET_TO_COMMIT || operation == GitOperation.OPEN_WORKING_COPY || operation == GitOperation.MERGE || operation == GitOperation.COMMIT || operation == GitOperation.REVERT_COMMIT || operation == GitOperation.STASH_CREATE || operation == GitOperation.STASH_DROP || operation == GitOperation.STASH_APPLY || operation == GitOperation.UPDATE_CONFIG_FILE || operation == GitOperation.STASH_POP || operation == GitOperation.CHECKOUT_FILE || operation == GitOperation.CHECKOUT_COMMIT || operation == GitOperation.CREATE_TAG || operation == GitOperation.DELETE_TAG || operation == GitOperation.DISCARD) {
gitRefreshSupport.call();
if (operation == GitOperation.CHECKOUT || operation == GitOperation.MERGE) {
try {
FileUtil.refreshProjectView();
} catch (NoRepositorySelected e) {
LOGGER.debug(e.getMessage(), e);
}
} else if (operation == GitOperation.OPEN_WORKING_COPY && GitAccess.getInstance().getBranchInfo().isDetached()) {
treatDetachedHead((WorkingCopyGitEventInfo) info);
}
}
}
@Override
public void operationFailed(GitEventInfo info, Throwable t) {
final GitOperation operation = info.getGitOperation();
if (operation == GitOperation.CONTINUE_REBASE || operation == GitOperation.RESET_TO_COMMIT) {
gitRefreshSupport.call();
}
}
});
gitRefreshSupport.call();
viewInfo.setIcon(Icons.getIcon(Icons.GIT_ICON));
viewInfo.setTitle(translator.getTranslation(Tags.GIT_STAGING));
}
use of com.oxygenxml.git.view.event.GitOperation in project oxygen-git-client-addon by oxygenxml.
the class StatusCacheTest method testGitEvent.
/**
* <p><b>Description:</b> A git event resets the cache.</p>
* <p><b>Bug ID:</b> EXM-49363</p>
*
* @author alex_jitianu
*
* @throws Exception If it fails.
*/
public void testGitEvent() throws Exception {
OxygenGitPluginExtension extension = new OxygenGitPluginExtension();
PluginWorkspace pluginWorkspace = PluginWorkspaceProvider.getPluginWorkspace();
JFrame mockFrame = new JFrame();
Mockito.when(pluginWorkspace.getParentFrame()).thenReturn(mockFrame);
// These operations do not affect a status.
List<GitOperation> exceptions = Arrays.asList(GitOperation.DELETE_BRANCH, GitOperation.PUSH);
extension.applicationStarted((StandalonePluginWorkspace) pluginWorkspace);
Arrays.stream(GitOperation.values()).forEach(op -> {
GitStatus status = GitAccess.getInstance().getStatus();
GitEventAdapter listener = new GitEventAdapter() {
@Override
public void operationSuccessfullyEnded(GitEventInfo info) {
// When a normal listener receives a git event, if it requests the status it
// should receive a newly computed status, not the stale one from cache.
assertStatus(exceptions, op, status);
}
};
GitListeners.getInstance().addGitListener(listener);
GitListeners.getInstance().fireOperationSuccessfullyEnded(new GitEventInfo(op));
GitListeners.getInstance().removeGitListener(listener);
assertStatus(exceptions, op, status);
});
}
Aggregations