use of com.oxygenxml.git.service.GitEventAdapter 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.service.GitEventAdapter in project oxygen-git-client-addon by oxygenxml.
the class GitOperationUtil method installMouseBusyCursor.
/**
* Install a mouse listener to change mouse cursor when an operation is too long.
*
* @param gitController The git controller.
* @param component The component to install the listener.
*/
public static void installMouseBusyCursor(final GitController gitController, JComponent component) {
final AtomicBoolean operationProgress = new AtomicBoolean(false);
final Timer cursorTimer = new Timer(1000, e -> SwingUtilities.invokeLater(() -> {
if (operationProgress.compareAndSet(true, true) && component != null) {
// Operation process still running. Present a hint.
component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
}));
gitController.addGitListener(new GitEventAdapter() {
@Override
public void operationAboutToStart(GitEventInfo info) {
stopTimer(operationProgress, cursorTimer);
operationProgress.getAndSet(true);
cursorTimer.start();
}
@Override
public void operationSuccessfullyEnded(GitEventInfo info) {
stopTimer(operationProgress, cursorTimer);
SwingUtilities.invokeLater(() -> component.setCursor(Cursor.getDefaultCursor()));
}
@Override
public void operationFailed(GitEventInfo info, Throwable t) {
stopTimer(operationProgress, cursorTimer);
SwingUtilities.invokeLater(() -> component.setCursor(Cursor.getDefaultCursor()));
}
});
}
Aggregations