diff options
author | Mathias Kinzler | 2010-09-07 13:17:48 +0000 |
---|---|---|
committer | Matthias Sohn | 2010-09-07 13:17:48 +0000 |
commit | 752847e9b263abaa96929fb12d171e3d65e089bd (patch) | |
tree | dfc803c4b641c7fbbab13eee43e4be9130c48104 | |
parent | 1d50df98790106e3c20a8f4e1fb2f681a2043b98 (diff) | |
download | egit-752847e9b263abaa96929fb12d171e3d65e089bd.tar.gz egit-752847e9b263abaa96929fb12d171e3d65e089bd.tar.xz egit-752847e9b263abaa96929fb12d171e3d65e089bd.zip |
Supportability: Provide a Trace Configuration Preference Page
Since we have the infrastructure in place, we can now switch debug
tracing on and off in a running IDE. This can be very helpful in
situations where we can't debug.
Unfortunately, there is no generic UI to do this, so this adds a
dialog to show the existing trace locations for the EGit UI and
EGit Core plug-ins and allows to activate them.
The dialog cannot be started from a "normal" UI control, but only
using CTRL-3 and triggering a dedicated command "Configure Git
Debug Trace" in order to avoid pollution of the Preference UI.
Change-Id: I4681acf85de8d05be6290d88acde5d99453ce89d
Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
9 files changed, 774 insertions, 2 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllLocalTests.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllLocalTests.java index b420533ca3..8352f2845a 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllLocalTests.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllLocalTests.java @@ -11,6 +11,7 @@ package org.eclipse.egit.ui.test; import org.eclipse.egit.ui.prefpages.configuration.GlobalConfigurationPageTest; import org.eclipse.egit.ui.test.history.HistoryViewTest; import org.eclipse.egit.ui.test.team.actions.AllTeamActionTests; +import org.eclipse.egit.ui.test.trace.TraceConfigurationDialogTest; import org.eclipse.egit.ui.view.repositories.AllRepositoriesViewTests; import org.eclipse.egit.ui.wizards.clone.GitCloneWizardTest; import org.eclipse.egit.ui.wizards.share.SharingWizardTest; @@ -24,7 +25,8 @@ import org.junit.runners.Suite.SuiteClasses; GitCloneWizardTest.class, // SharingWizardTest.class, // AllTeamActionTests.class, // - HistoryViewTest.class }) + HistoryViewTest.class, // + TraceConfigurationDialogTest.class}) public class AllLocalTests { // empty class, don't need anything here } diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/trace/TraceConfigurationDialogTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/trace/TraceConfigurationDialogTest.java new file mode 100644 index 0000000000..3d4212468c --- /dev/null +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/trace/TraceConfigurationDialogTest.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * Copyright (c) 2010, SAP AG. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mathias Kinzler (SAP AG) - initial implementation + *******************************************************************************/ +package org.eclipse.egit.ui.test.trace; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.eclipse.egit.ui.Activator; +import org.eclipse.egit.ui.UIText; +import org.eclipse.egit.ui.common.EGitTestCase; +import org.eclipse.egit.ui.internal.dialogs.GitTraceConfigurationDialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(SWTBotJunit4ClassRunner.class) +public class TraceConfigurationDialogTest { + + private static final SWTWorkbenchBot bot = new SWTWorkbenchBot(); + + private SWTBotShell configurationDialog; + + @BeforeClass + public static void beforeClass() throws Exception { + EGitTestCase.closeWelcomePage(); + // make sure tracing is off globally + Activator.getDefault().getDebugOptions().setDebugEnabled(false); + } + + @AfterClass + public static void afterClass() throws Exception { + // make sure tracing is off globally + Activator.getDefault().getDebugOptions().setDebugEnabled(false); + } + + @Before + public void before() throws Exception { + getDialog(); + } + + @Test + public void testMainSwitch() throws Exception { + SWTBotCheckBox box = configurationDialog.bot().checkBox( + UIText.GitTraceConfigurationDialog_PlatformSwitchCheckbox); + SWTBotTree tree = findTree(); + assertFalse(box.isChecked()); + assertFalse(tree.isEnabled()); + box.click(); + assertTrue(box.isChecked()); + assertTrue(tree.isEnabled()); + + configurationDialog.close(); + getDialog(); + box = configurationDialog.bot().checkBox( + UIText.GitTraceConfigurationDialog_PlatformSwitchCheckbox); + + tree = findTree(); + assertFalse(box.isChecked()); + assertFalse(tree.isEnabled()); + box.click(); + assertTrue(box.isChecked()); + assertTrue(tree.isEnabled()); + + configurationDialog.bot().button(IDialogConstants.OK_LABEL).click(); + getDialog(); + box = configurationDialog.bot().checkBox( + UIText.GitTraceConfigurationDialog_PlatformSwitchCheckbox); + + tree = findTree(); + assertTrue(box.isChecked()); + assertTrue(tree.isEnabled()); + box.click(); + assertFalse(box.isChecked()); + assertFalse(tree.isEnabled()); + configurationDialog.bot().button(IDialogConstants.OK_LABEL).click(); + } + + @Test + public void testTreeNode() throws Exception { + SWTBotCheckBox box = configurationDialog.bot().checkBox( + UIText.GitTraceConfigurationDialog_PlatformSwitchCheckbox); + SWTBotTree tree = findTree(); + assertFalse(box.isChecked()); + assertFalse(tree.isEnabled()); + box.click(); + assertTrue(box.isChecked()); + assertTrue(tree.isEnabled()); + + SWTBotTreeItem item = tree.getAllItems()[0]; + assertFalse(item.isChecked()); + item.check(); + assertTrue(item.isChecked()); + + configurationDialog.close(); + getDialog(); + box = configurationDialog.bot().checkBox( + UIText.GitTraceConfigurationDialog_PlatformSwitchCheckbox); + + tree = findTree(); + assertFalse(box.isChecked()); + assertFalse(tree.isEnabled()); + box.click(); + assertTrue(box.isChecked()); + assertTrue(tree.isEnabled()); + + item = tree.getAllItems()[0]; + assertFalse(item.isChecked()); + item.check(); + assertTrue(item.isChecked()); + + configurationDialog.bot().button(IDialogConstants.OK_LABEL).click(); + getDialog(); + box = configurationDialog.bot().checkBox( + UIText.GitTraceConfigurationDialog_PlatformSwitchCheckbox); + + tree = findTree(); + assertTrue(box.isChecked()); + assertTrue(tree.isEnabled()); + + item = tree.getAllItems()[0]; + assertTrue(item.isChecked()); + + configurationDialog.bot().button( + UIText.GitTraceConfigurationDialog_DefaultButton).click(); + + assertFalse(item.isChecked()); + box.click(); + configurationDialog.bot().button(IDialogConstants.OK_LABEL).click(); + } + + private SWTBotTree findTree() { + return configurationDialog.bot().treeWithId("LocationTree"); + } + + private void getDialog() { + Display.getDefault().syncExec(new Runnable() { + public void run() { + if (configurationDialog != null) + configurationDialog.close(); + + GitTraceConfigurationDialog dlg = new GitTraceConfigurationDialog( + new Shell(Display.getDefault())); + dlg.setBlockOnOpen(false); + dlg.open(); + configurationDialog = bot.shell( + UIText.GitTraceConfigurationDialog_ShellTitle) + .activate(); + } + }); + } +} diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties index 3b6a87cc70..9a01c58227 100644 --- a/org.eclipse.egit.ui/plugin.properties +++ b/org.eclipse.egit.ui/plugin.properties @@ -185,4 +185,5 @@ RepoViewCreateRepositoryCommand.name = Create a Repository CreateRepositoryWizard.name = Git Repository HierarchyLayout.label = &Hierarchical Branch Layout ToggleLayoutCommand.name = Toggle Branch Representation -RepoViewHierarchicalBranchRepresenation.tooltip = Hierarchical Branch Layout
\ No newline at end of file +RepoViewHierarchicalBranchRepresenation.tooltip = Hierarchical Branch Layout +ConfigureTraceCommand.name = Configure Git Debug Trace
\ No newline at end of file diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml index 6fbbb52d8e..b7d444e0ce 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -497,6 +497,12 @@ id="org.eclipse.egit.ui.commandCategory" name="%Git"> </category> + <command + categoryId="org.eclipse.egit.ui.commandCategory" + defaultHandler="org.eclipse.egit.ui.internal.commands.ConfigureDebugTraceCommand" + id="org.eclipse.egit.ui.command.configureTrace" + name="%ConfigureTraceCommand.name"> + </command> </extension> <extension point="org.eclipse.ui.views"> diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/Activator.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/Activator.java index 80015dfc5b..95c8075c6b 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/Activator.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/Activator.java @@ -156,6 +156,7 @@ public class Activator extends AbstractUIPlugin implements DebugOptionsListener private RCS rcs; private RIRefresh refreshJob; private ListenerHandle refreshHandle; + private DebugOptions debugOptions; /** * Constructor for the egit ui plugin singleton @@ -182,9 +183,17 @@ public class Activator extends AbstractUIPlugin implements DebugOptionsListener public void optionsChanged(DebugOptions options) { // initialize the trace stuff + debugOptions = options; GitTraceLocation.initializeFromOptions(options, isDebugging()); } + /** + * @return the {@link DebugOptions} + */ + public DebugOptions getDebugOptions() { + return debugOptions; + } + private void setupRepoIndexRefresh() { refreshJob = new RIRefresh(); refreshHandle = Repository.getGlobalListenerList() diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java index e11ad77600..21c5631014 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java @@ -2447,6 +2447,36 @@ public class UIText extends NLS { public static String GitBranchSynchronizeWizardPage_deselectAll; /** */ + public static String GitTraceConfigurationDialog_ApplyButton; + + /** */ + public static String GitTraceConfigurationDialog_DefaultButton; + + /** */ + public static String GitTraceConfigurationDialog_DialogTitle; + + /** */ + public static String GitTraceConfigurationDialog_LocationHeader; + + /** */ + public static String GitTraceConfigurationDialog_MainSwitchNodeText; + + /** */ + public static String GitTraceConfigurationDialog_OpenInEditorButton; + + /** */ + public static String GitTraceConfigurationDialog_PlatformSwitchCheckbox; + + /** */ + public static String GitTraceConfigurationDialog_PlatformTraceDisabledMessage; + + /** */ + public static String GitTraceConfigurationDialog_ShellTitle; + + /** */ + public static String GitTraceConfigurationDialog_TraceFileLocationLabel; + + /** */ public static String LocalFileRevision_CurrentVersion; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ConfigureDebugTraceCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ConfigureDebugTraceCommand.java new file mode 100644 index 0000000000..7e39d462dd --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ConfigureDebugTraceCommand.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.egit.ui.internal.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.egit.ui.internal.dialogs.GitTraceConfigurationDialog; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Opens the "Configure Debug Trace" page + */ +public class ConfigureDebugTraceCommand extends AbstractHandler { + public Object execute(ExecutionEvent event) throws ExecutionException { + new GitTraceConfigurationDialog(HandlerUtil + .getActiveShellChecked(event)).open(); + return null; + } +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/GitTraceConfigurationDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/GitTraceConfigurationDialog.java new file mode 100644 index 0000000000..03793af5ac --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/GitTraceConfigurationDialog.java @@ -0,0 +1,518 @@ +/******************************************************************************* + * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.egit.ui.internal.dialogs; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.egit.ui.Activator; +import org.eclipse.egit.ui.UIText; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ICheckStateProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.osgi.service.debug.DebugOptions; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.ide.FileStoreEditorInput; +import org.eclipse.ui.ide.IDE; + +/** + * Preferences page for EGit UI Trace Configuration + * <p> + * Traces are enabled in a three-level way: first, there is a global switch, + * then there is one "main switch" per plug-in with the key "<plug-in id>/debug" + * which governs the overall tracing for a plug-in, and finally, there are any + * number of options which are used as "trace locations"; they are always + * prefixed with the plug-in id. + */ +public class GitTraceConfigurationDialog extends TitleAreaDialog { + private final static class PluginNode { + private final String plugin; + + PluginNode(String plugin) { + this.plugin = plugin; + } + + public String getPlugin() { + return plugin; + } + + @Override + public String toString() { + return NLS.bind( + UIText.GitTraceConfigurationDialog_MainSwitchNodeText, + plugin); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + plugin.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PluginNode other = (PluginNode) obj; + if (!plugin.equals(other.plugin)) + return false; + return true; + } + } + + private final static class OptionNode implements Comparable<OptionNode> { + private final PluginNode plugin; + + private final String option; + + private final String strippedOption; + + OptionNode(PluginNode parent, String option) { + this.plugin = parent; + this.option = option; + strippedOption = option.substring(option.indexOf('/')); + } + + public PluginNode getPlugin() { + return plugin; + } + + public String getOption() { + return this.option; + } + + @Override + public String toString() { + return this.strippedOption; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + option.hashCode(); + result = prime * result + plugin.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + OptionNode other = (OptionNode) obj; + if (!option.equals(other.option)) + return false; + if (!plugin.equals(other.plugin)) + return false; + return true; + } + + public int compareTo(OptionNode o) { + return option.compareTo(o.option); + } + } + + private final static class TraceTableContentProvider extends + ArrayContentProvider implements ITreeContentProvider { + private final Map<PluginNode, Properties> myOptionsMap; + + public TraceTableContentProvider(Map<PluginNode, Properties> optionsMap) { + this.myOptionsMap = optionsMap; + } + + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof PluginNode) { + PluginNode node = (PluginNode) parentElement; + List<OptionNode> result = new ArrayList<OptionNode>(); + for (Object key : myOptionsMap.get(node).keySet()) { + // hide the main switch + if (key.equals(node.getPlugin() + MAINSWITCH)) + continue; + result.add(new OptionNode(node, (String) key)); + } + Collections.sort(result); + return result.toArray(); + } + return null; + } + + public Object getParent(Object element) { + if (element instanceof OptionNode) + return ((OptionNode) element).getPlugin(); + return null; + } + + public boolean hasChildren(Object element) { + return element instanceof PluginNode; + } + } + + private static final String MAINSWITCH = "/debug"; //$NON-NLS-1$ + + private static final PluginNode[] PLUGIN_LIST = new PluginNode[] { + new PluginNode(Activator.getPluginId()), + new PluginNode(org.eclipse.egit.core.Activator.getPluginId()) }; + + private static final int APPLY_ID = 77; + + private static final int DEFAULT_ID = 88; + + private final Map<PluginNode, Properties> optionsMap = new HashMap<PluginNode, Properties>(); + + private boolean isDirty; + + private Button platformSwitch; + + private Text traceFileLocation; + + private CheckboxTreeViewer tv; + + /** + * @param shell + */ + public GitTraceConfigurationDialog(Shell shell) { + super(shell); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite main = new Composite(parent, SWT.NONE); + main.setLayout(new GridLayout(3, false)); + + platformSwitch = new Button(main, SWT.CHECK); + platformSwitch + .setText(UIText.GitTraceConfigurationDialog_PlatformSwitchCheckbox); + GridDataFactory.fillDefaults().span(3, 1).applyTo(platformSwitch); + platformSwitch.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateEnablement(); + } + }); + + tv = new CheckboxTreeViewer(main, SWT.BORDER); + tv.setContentProvider(new TraceTableContentProvider(optionsMap)); + + Tree tree = tv.getTree(); + GridDataFactory.fillDefaults().span(3, 1).grab(true, true) + .applyTo(tree); + + // enable testing with SWTBot + tree.setData("org.eclipse.swtbot.widget.key", "LocationTree"); //$NON-NLS-1$ //$NON-NLS-2$ + + TreeColumn c1 = new TreeColumn(tree, SWT.NONE); + c1.setWidth(400); + c1.setText(UIText.GitTraceConfigurationDialog_LocationHeader); + tree.setHeaderVisible(true); + + Label fileLabel = new Label(main, SWT.NONE); + fileLabel + .setText(UIText.GitTraceConfigurationDialog_TraceFileLocationLabel); + traceFileLocation = new Text(main, SWT.BORDER); + traceFileLocation.setEditable(false); + GridDataFactory.defaultsFor(traceFileLocation).grab(true, false) + .applyTo(traceFileLocation); + + Button openButton = new Button(main, SWT.PUSH); + openButton + .setText(UIText.GitTraceConfigurationDialog_OpenInEditorButton); + openButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + IFileStore store = EFS.getLocalFileSystem().getStore( + new Path(traceFileLocation.getText())); + try { + IDE.openEditor(PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage(), + new FileStoreEditorInput(store), + EditorsUI.DEFAULT_TEXT_EDITOR_ID); + + } catch (PartInitException ex) { + Activator.handleError(ex.getMessage(), ex, true); + } + } + }); + + initValues(); + + platformSwitch.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setDirty(true); + } + }); + + tv.addCheckStateListener(new ICheckStateListener() { + public void checkStateChanged(CheckStateChangedEvent event) { + setDirty(true); + } + }); + + Dialog.applyDialogFont(main); + return main; + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + super.createButtonsForButtonBar(parent); + createButton(parent, APPLY_ID, + UIText.GitTraceConfigurationDialog_ApplyButton, false); + createButton(parent, DEFAULT_ID, + UIText.GitTraceConfigurationDialog_DefaultButton, false); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(UIText.GitTraceConfigurationDialog_ShellTitle); + } + + @Override + public void create() { + super.create(); + updateApplyButton(); + setTitle(UIText.GitTraceConfigurationDialog_DialogTitle); + } + + private void initValues() { + DebugOptions options = getOptions(); + fillOptionsMapFromCurrent(options); + tv.setCheckStateProvider(new ICheckStateProvider() { + public boolean isGrayed(Object element) { + return false; + } + + public boolean isChecked(Object element) { + Object data = element; + Properties props; + String key; + if (data instanceof PluginNode) { + PluginNode node = (PluginNode) data; + props = optionsMap.get(node); + key = node.getPlugin() + MAINSWITCH; + } else if (data instanceof OptionNode) { + OptionNode node = (OptionNode) data; + props = optionsMap.get(node.getPlugin()); + key = node.getOption(); + } else { + return false; + } + boolean active = Boolean.valueOf(props.getProperty(key)) + .booleanValue(); + return active; + } + }); + + tv.setInput(PLUGIN_LIST); + tv.expandAll(); + + if (platformSwitch.getSelection() != options.isDebugEnabled()) { + platformSwitch.setSelection(options.isDebugEnabled()); + } + + traceFileLocation.setText(getOptions().getFile().getPath()); + updateEnablement(); + } + + private void updateApplyButton() { + if (getApplyButton() != null) + getApplyButton().setEnabled(isDirty); + if (getDefaultsButton() != null) + getDefaultsButton().setEnabled(platformSwitch.getSelection()); + } + + private Button getApplyButton() { + return getButton(APPLY_ID); + } + + private Button getDefaultsButton() { + return getButton(DEFAULT_ID); + } + + private void updateEnablement() { + setMessage(null); + if (!platformSwitch.getSelection()) + setMessage( + UIText.GitTraceConfigurationDialog_PlatformTraceDisabledMessage, + IMessageProvider.INFORMATION); + tv.getTree().setEnabled(platformSwitch.getSelection()); + updateApplyButton(); + } + + @Override + protected void buttonPressed(int buttonId) { + switch (buttonId) { + case IDialogConstants.OK_ID: + performOk(); + break; + case DEFAULT_ID: + fillOptionsMapFromOptions(); + tv.refresh(); + break; + case APPLY_ID: + performOk(); + break; + default: + break; + } + super.buttonPressed(buttonId); + } + + private void performOk() { + DebugOptions options = getOptions(); + if (isDirty) { + options.setDebugEnabled(platformSwitch.getSelection()); + if (platformSwitch.getSelection()) { + // if this is off, we won't be able to save anything + List<String> checkedKeys = new ArrayList<String>(); + for (Object checked : Arrays.asList(tv.getCheckedElements())) { + if (checked instanceof PluginNode) + checkedKeys.add(((PluginNode) checked).getPlugin() + + MAINSWITCH); + else if (checked instanceof OptionNode) + checkedKeys.add(((OptionNode) checked).getOption()); + } + + for (PluginNode plugin : optionsMap.keySet()) { + Properties props = optionsMap.get(plugin); + for (Object keyObject : props.keySet()) { + String key = (String) keyObject; + boolean isOn = options.getBooleanOption(key, false); + boolean shouldBeOn = checkedKeys.contains(key); + if (isOn != shouldBeOn) { + options + .setOption(key, Boolean + .toString(shouldBeOn)); + } + } + } + } + fillOptionsMapFromCurrent(options); + tv.refresh(); + setDirty(false); + } + } + + private void fillOptionsMapFromOptions() { + Map<String, String> oldValues = new HashMap<String, String>(); + for (Properties props : optionsMap.values()) + for (Object keyObject : props.keySet()) { + String key = (String) keyObject; + oldValues.put(key, props.getProperty(key)); + } + + optionsMap.clear(); + for (PluginNode plugin : PLUGIN_LIST) { + Properties props = new Properties(); + try { + InputStream is = Platform.getBundle(plugin.getPlugin()) + .getResource(".options").openStream(); //$NON-NLS-1$ + props.load(is); + } catch (IOException e) { + Activator.handleError(e.getMessage(), e, true); + } + optionsMap.put(plugin, props); + } + + Map<String, String> newValues = new HashMap<String, String>(); + for (Properties props : optionsMap.values()) + for (Object keyObject : props.keySet()) { + String key = (String) keyObject; + oldValues.put(key, props.getProperty(key)); + } + + boolean dirty = false; + if (oldValues.keySet().containsAll(newValues.keySet()) + && newValues.keySet().containsAll(oldValues.keySet())) { + for (String key : oldValues.keySet()) { + if (!oldValues.get(key).equals(newValues.get(key))) { + dirty = true; + break; + } + } + } else { + dirty = true; + } + if (dirty) + setDirty(true); + } + + private void fillOptionsMapFromCurrent(DebugOptions options) { + optionsMap.clear(); + for (PluginNode plugin : PLUGIN_LIST) { + Properties props = new Properties(); + try { + InputStream is = Platform.getBundle(plugin.getPlugin()) + .getResource(".options").openStream(); //$NON-NLS-1$ + props.load(is); + } catch (IOException e) { + Activator.handleError(e.getMessage(), e, true); + } + for (Object keyObject : props.keySet()) { + String key = (String) keyObject; + boolean isActive = options.getBooleanOption(key, false); + props.setProperty(key, Boolean.toString(isActive)); + } + optionsMap.put(plugin, props); + } + } + + private void setDirty(boolean dirty) { + isDirty = dirty; + updateApplyButton(); + } + + private DebugOptions getOptions() { + return Activator.getDefault().getDebugOptions(); + } +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 673f55c7d1..be349db0ef 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -862,6 +862,16 @@ GitBranchSynchronizeWizardPage_repositories=Repositories GitBranchSynchronizeWizardPage_branches=Branches GitBranchSynchronizeWizardPage_selectAll=Select All GitBranchSynchronizeWizardPage_deselectAll=Deselect All +GitTraceConfigurationDialog_ApplyButton=&Apply +GitTraceConfigurationDialog_DefaultButton=&Default +GitTraceConfigurationDialog_DialogTitle=Maintain the Git Trace Configuration +GitTraceConfigurationDialog_LocationHeader=Location +GitTraceConfigurationDialog_MainSwitchNodeText=Main switch for plug-in {0} +GitTraceConfigurationDialog_OpenInEditorButton=Open in &Editor +GitTraceConfigurationDialog_PlatformSwitchCheckbox=Enable &Platform Trace +GitTraceConfigurationDialog_PlatformTraceDisabledMessage=Platform Trace is currently disabled, please enable it in order to edit the trace configuration +GitTraceConfigurationDialog_ShellTitle=Git Trace Configuration +GitTraceConfigurationDialog_TraceFileLocationLabel=Trace File &Location: LocalFileRevision_CurrentVersion=*({0}) LocalFileRevision_currentVersionTag=<current version> NewRemoteWizard_CheckingUriTaskName=Checking URI {0} |