Search in sources :

Example 1 with ListenerHandle

use of org.eclipse.jgit.events.ListenerHandle in project egit by eclipse.

the class IndexDiffCacheEntry method dispose.

/**
 * Dispose cache entry by removing listeners. Pending update or reload jobs
 * are canceled.
 */
public void dispose() {
    for (ListenerHandle h : listenerHandles) {
        h.remove();
    }
    listenerHandles.clear();
    submodules.clear();
    if (resourceChangeListener != null) {
        ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
    }
    listeners.clear();
    if (reloadJob != null) {
        reloadJob.cancel();
        reloadJob = null;
    }
    if (updateJob != null) {
        updateJob.cleanupAndCancel();
        updateJob = null;
    }
    indexDiffData = null;
    lastIndex = null;
}
Also used : ListenerHandle(org.eclipse.jgit.events.ListenerHandle)

Example 2 with ListenerHandle

use of org.eclipse.jgit.events.ListenerHandle in project egit by eclipse.

the class GitRepositoriesViewBranchHandlingTest method testBranchConfiguration.

@Test
public void testBranchConfiguration() throws Exception {
    Repository repo = lookupRepository(clonedRepositoryFile);
    try (Git git = new Git(repo)) {
        git.branchCreate().setName("configTest").setStartPoint("refs/remotes/origin/master").setUpstreamMode(SetupUpstreamMode.TRACK).call();
    }
    BranchRebaseMode rebase = repo.getConfig().getEnum(BranchRebaseMode.values(), ConfigConstants.CONFIG_BRANCH_SECTION, "configTest", ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.NONE);
    assertEquals(BranchRebaseMode.NONE, rebase);
    SWTBotView view = getOrOpenView();
    SWTBotTreeItem localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
    TestUtil.expandAndWait(localItem).getNode("configTest").select();
    ContextMenuHelper.clickContextMenuSync(view.bot().tree(), myUtil.getPluginLocalizedValue("ShowIn"), "Properties");
    SWTBotView propsView = bot.viewById(IPageLayout.ID_PROP_SHEET);
    SWTBotTreeItem rootItem = propsView.bot().tree().getTreeItem(UIText.BranchPropertySource_UpstreamConfigurationCategory);
    SWTBotTreeItem rebaseItem = TestUtil.expandAndWait(rootItem).getNode(UIText.BranchPropertySource_RebaseDescriptor);
    assertEquals(UIText.BranchPropertySource_ValueNotSet, rebaseItem.cell(1));
    SWTBotTreeItem remoteItem = rootItem.getNode(UIText.BranchPropertySource_RemoteDescriptor);
    assertEquals("origin", remoteItem.cell(1));
    SWTBotTreeItem upstreamItem = rootItem.getNode(UIText.BranchPropertySource_UpstreamBranchDescriptor);
    assertEquals("refs/heads/master", upstreamItem.cell(1));
    view = getOrOpenView();
    localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
    TestUtil.expandAndWait(localItem).getNode("configTest").select();
    ContextMenuHelper.clickContextMenu(view.bot().tree(), myUtil.getPluginLocalizedValue("ConfigurBranchCommand.label"));
    SWTBotShell configureBranchDialog = bot.shell(UIText.BranchConfigurationDialog_BranchConfigurationTitle);
    assertEquals(MessageFormat.format(UIText.BranchConfigurationDialog_EditBranchConfigMessage, "configTest"), configureBranchDialog.bot().text().getText());
    assertEquals("refs/heads/master", configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchConfigurationDialog_UpstreamBranchLabel).getText());
    assertEquals("origin", configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchConfigurationDialog_RemoteLabel).getText());
    assertEquals(UIText.BranchRebaseMode_None, configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchRebaseModeCombo_RebaseModeLabel).getText());
    configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchRebaseModeCombo_RebaseModeLabel).setSelection(0);
    // add a listener to wait for the configuration changed event
    final AtomicBoolean changed = new AtomicBoolean();
    ConfigChangedListener listener = new ConfigChangedListener() {

        @Override
        public void onConfigChanged(ConfigChangedEvent event) {
            changed.set(true);
        }
    };
    ListenerHandle handle = repo.getConfig().addChangeListener(listener);
    // only now click ok
    configureBranchDialog.bot().button("OK").click();
    // cleanup behind ourselves
    handle.remove();
    if (!changed.get())
        fail("We should have received a config change event");
    // Repo view updates itself after config change.
    refreshAndWait();
    rebase = repo.getConfig().getEnum(BranchRebaseMode.values(), ConfigConstants.CONFIG_BRANCH_SECTION, "configTest", ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.NONE);
    assertEquals(BranchRebaseMode.REBASE, rebase);
    localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
    TestUtil.expandAndWait(localItem).getNode("configTest").select();
    ContextMenuHelper.clickContextMenu(view.bot().tree(), myUtil.getPluginLocalizedValue("ShowIn"), "Properties");
    propsView = bot.viewById(IPageLayout.ID_PROP_SHEET);
    rootItem = propsView.bot().tree().getTreeItem(UIText.BranchPropertySource_UpstreamConfigurationCategory);
    rebaseItem = TestUtil.expandAndWait(rootItem).getNode(UIText.BranchPropertySource_RebaseDescriptor);
    assertEquals("true", rebaseItem.cell(1));
}
Also used : BranchRebaseMode(org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConfigChangedListener(org.eclipse.jgit.events.ConfigChangedListener) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) ListenerHandle(org.eclipse.jgit.events.ListenerHandle) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) ConfigChangedEvent(org.eclipse.jgit.events.ConfigChangedEvent) Test(org.junit.Test)

Example 3 with ListenerHandle

use of org.eclipse.jgit.events.ListenerHandle in project egit by eclipse.

the class RepositoriesViewContentProvider method dispose.

@Override
public void dispose() {
    commandState.removeListener(this);
    for (ListenerHandle handle : refsChangedListeners.values()) handle.remove();
    refsChangedListeners.clear();
}
Also used : ListenerHandle(org.eclipse.jgit.events.ListenerHandle)

Aggregations

ListenerHandle (org.eclipse.jgit.events.ListenerHandle)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Git (org.eclipse.jgit.api.Git)1 ConfigChangedEvent (org.eclipse.jgit.events.ConfigChangedEvent)1 ConfigChangedListener (org.eclipse.jgit.events.ConfigChangedListener)1 BranchRebaseMode (org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode)1 Repository (org.eclipse.jgit.lib.Repository)1 SWTBotView (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)1 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)1 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)1 Test (org.junit.Test)1