Search in sources :

Example 1 with GitOperation

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));
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) GitOperation(com.oxygenxml.git.view.event.GitOperation) GitEventAdapter(com.oxygenxml.git.service.GitEventAdapter) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel)

Example 2 with GitOperation

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);
    });
}
Also used : PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) GitOperation(com.oxygenxml.git.view.event.GitOperation) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) JFrame(javax.swing.JFrame) OxygenGitPluginExtension(com.oxygenxml.git.OxygenGitPluginExtension)

Aggregations

GitEventInfo (com.oxygenxml.git.view.event.GitEventInfo)2 GitOperation (com.oxygenxml.git.view.event.GitOperation)2 OxygenGitPluginExtension (com.oxygenxml.git.OxygenGitPluginExtension)1 GitEventAdapter (com.oxygenxml.git.service.GitEventAdapter)1 NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 WorkingCopyGitEventInfo (com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)1 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)1 JFrame (javax.swing.JFrame)1 PluginWorkspace (ro.sync.exml.workspace.api.PluginWorkspace)1 StandalonePluginWorkspace (ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)1