Search in sources :

Example 1 with ConfigChangedListener

use of org.eclipse.jgit.events.ConfigChangedListener 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 2 with ConfigChangedListener

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

the class RepositoryPropertyPage method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite displayArea = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(displayArea);
    GridDataFactory.fillDefaults().applyTo(displayArea);
    final Repository repo = AdapterUtils.adapt(getElement(), Repository.class);
    if (repo == null)
        return displayArea;
    StoredConfig config = repo.getConfig();
    if (config instanceof FileBasedConfig) {
        File configFile = ((FileBasedConfig) config).getFile();
        config = new FileBasedConfig(configFile, repo.getFS());
        config.addChangeListener(new ConfigChangedListener() {

            @Override
            public void onConfigChanged(ConfigChangedEvent event) {
                repo.fireEvent(new ConfigChangedEvent());
            }
        });
    }
    editor = new ConfigurationEditorComponent(displayArea, config, true) {

        @Override
        protected void setErrorMessage(String message) {
            RepositoryPropertyPage.this.setErrorMessage(message);
        }
    };
    editor.createContents();
    return displayArea;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) ConfigChangedListener(org.eclipse.jgit.events.ConfigChangedListener) Repository(org.eclipse.jgit.lib.Repository) Composite(org.eclipse.swt.widgets.Composite) ConfigurationEditorComponent(org.eclipse.egit.ui.internal.preferences.ConfigurationEditorComponent) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) File(java.io.File) ConfigChangedEvent(org.eclipse.jgit.events.ConfigChangedEvent)

Example 3 with ConfigChangedListener

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

the class GlobalConfigurationPreferencePage method createConfigurationEditor.

private ConfigurationEditorComponent createConfigurationEditor(final Repository repository) {
    StoredConfig repositoryConfig;
    if (repository.getConfig() instanceof FileBasedConfig) {
        File configFile = ((FileBasedConfig) repository.getConfig()).getFile();
        repositoryConfig = new FileBasedConfig(configFile, repository.getFS());
        repositoryConfig.addChangeListener(new ConfigChangedListener() {

            @Override
            public void onConfigChanged(ConfigChangedEvent event) {
                repository.getListenerList().dispatch(new ConfigChangedEvent());
            }
        });
    } else {
        repositoryConfig = repository.getConfig();
    }
    ConfigurationEditorComponent editorComponent = new ConfigurationEditorComponent(repoConfigComposite, repositoryConfig, true) {

        @Override
        protected void setErrorMessage(String message) {
            GlobalConfigurationPreferencePage.this.setErrorMessage(message);
        }

        @Override
        protected void setDirty(boolean dirty) {
            if (dirty)
                dirtyRepositories.add(repository);
            else
                dirtyRepositories.remove(repository);
            updateApplyButton();
        }
    };
    editorComponent.createContents();
    return editorComponent;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) ConfigChangedListener(org.eclipse.jgit.events.ConfigChangedListener) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) File(java.io.File) ConfigChangedEvent(org.eclipse.jgit.events.ConfigChangedEvent)

Example 4 with ConfigChangedListener

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

the class RepositoryPropertySourceProvider method getPropertySource.

@Override
public IPropertySource getPropertySource(Object object) {
    if (object == lastObject)
        return lastRepositorySource;
    if (!(object instanceof RepositoryTreeNode))
        return null;
    registerDisposal();
    removeListener();
    RepositoryTreeNode node = (RepositoryTreeNode) object;
    listenerHandle = node.getRepository().getListenerList().addConfigChangedListener(new ConfigChangedListener() {

        @Override
        public void onConfigChanged(ConfigChangedEvent event) {
            // force a refresh of the page
            lastObject = null;
            myPage.getSite().getShell().getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    myPage.setPropertySourceProvider(RepositoryPropertySourceProvider.this);
                }
            });
        }
    });
    if (node.getType() == RepositoryTreeNodeType.REPO) {
        lastObject = object;
        checkChangeType(SourceType.REPOSITORY);
        lastRepositorySource = new RepositoryPropertySource((Repository) node.getObject(), myPage);
        return lastRepositorySource;
    } else if (node.getType() == RepositoryTreeNodeType.REMOTE) {
        lastObject = object;
        checkChangeType(SourceType.REMOTE);
        lastRepositorySource = new RepositoryRemotePropertySource(node.getRepository().getConfig(), (String) node.getObject(), myPage);
        return lastRepositorySource;
    } else if (node.getType() == RepositoryTreeNodeType.FETCH || node.getType() == RepositoryTreeNodeType.PUSH)
        return getPropertySource(node.getParent());
    else if (node.getType() == RepositoryTreeNodeType.REF) {
        lastObject = object;
        Ref ref = (Ref) node.getObject();
        if (ref.getName().startsWith(Constants.R_HEADS) || ref.getName().startsWith(Constants.R_REMOTES)) {
            checkChangeType(SourceType.BRANCH);
            Repository repository = AdapterUtils.adapt(node, Repository.class);
            lastRepositorySource = new BranchPropertySource(repository, ref.getName(), myPage);
            return lastRepositorySource;
        }
        return null;
    } else
        return null;
}
Also used : ConfigChangedListener(org.eclipse.jgit.events.ConfigChangedListener) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) ConfigChangedEvent(org.eclipse.jgit.events.ConfigChangedEvent)

Aggregations

ConfigChangedEvent (org.eclipse.jgit.events.ConfigChangedEvent)4 ConfigChangedListener (org.eclipse.jgit.events.ConfigChangedListener)4 Repository (org.eclipse.jgit.lib.Repository)3 File (java.io.File)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2 FileBasedConfig (org.eclipse.jgit.storage.file.FileBasedConfig)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ConfigurationEditorComponent (org.eclipse.egit.ui.internal.preferences.ConfigurationEditorComponent)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 Git (org.eclipse.jgit.api.Git)1 ListenerHandle (org.eclipse.jgit.events.ListenerHandle)1 BranchRebaseMode (org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode)1 Ref (org.eclipse.jgit.lib.Ref)1 Composite (org.eclipse.swt.widgets.Composite)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