use of org.eclipse.jgit.events.ConfigChangedEvent 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));
}
use of org.eclipse.jgit.events.ConfigChangedEvent 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;
}
use of org.eclipse.jgit.events.ConfigChangedEvent 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;
}
use of org.eclipse.jgit.events.ConfigChangedEvent 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;
}
Aggregations