Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect changes of dialog font #13

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions org.eclipse.eclemma.doc/pages/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ <h2>Trunk Build (not yet released)</h2>
4.3 (Eclipse Bug 507907).</li>
<li>Session import and export is now consistently named and has been moved to
category <i>Run/Debug</i> (Eclipse Bug 507696).</li>
<li>All pages and dialogs now respect changes of dialog font
(Eclipse Bug 507694).</li>
<li>Automated UI tests with SWTBot.</li>
<li>End of support for Eclipse versions older than 3.8.</li>
<li>Upgrade to JaCoCo 0.7.7.</li>
Expand Down
4 changes: 3 additions & 1 deletion org.eclipse.eclemma.ui.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ Bundle-Version: 3.0.0.qualifier
Bundle-Vendor: Mountainminds GmbH & Co. KG
Fragment-Host: org.eclipse.eclemma.ui;bundle-version="[3.0.0,4.0.0)"
Require-Bundle: org.junit;bundle-version="4.0.0",
org.eclipse.swtbot.eclipse.finder;bundle-version="2.5.0"
org.eclipse.swtbot.eclipse.finder;bundle-version="2.5.0",
org.apache.log4j,
org.eclipse.jdt.debug.ui
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 Mountainminds GmbH & Co. KG and Contributors
* 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:
* Evgeny Mandrikov - initial API and implementation
*
******************************************************************************/
package org.eclipse.eclemma.ui;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.eclemma.core.ICoverageSession;
import org.eclipse.eclemma.core.launching.ICoverageLaunch;
import org.eclipse.eclemma.internal.ui.dialogs.MergeSessionsDialog;
import org.eclipse.eclemma.internal.ui.handlers.DumpExecutionDataHandler;
import org.eclipse.eclemma.internal.ui.handlers.SelectActiveSessionHandler;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class FontChangeTest {

private static final SWTWorkbenchBot bot = new SWTWorkbenchBot();

private FontData expected;

@BeforeClass
public static void closeWelcomeView() {
try {
bot.viewByTitle("Welcome").close();
} catch (WidgetNotFoundException e) {
// ignore
}
}

@Before
public void changeFont() {
ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.ui.workbench");
expected = new FontData(store.getString(JFaceResources.DIALOG_FONT));
expected.setHeight(expected.getHeight() + 1);
store.setValue(JFaceResources.DIALOG_FONT, expected.toString());
}

@After
public void resetWorkbench() {
bot.resetWorkbench();
}

/**
* Test for {@link org.eclipse.eclemma.internal.ui.dialogs.CoveragePreferencePage}.
*/
@Test
public void preferencePage() {
// This does not work on Mac
// bot.menu("Window").menu("Preferences").click();
// Launch preferences programmatically instead
UIThreadRunnable.asyncExec(new VoidResult() {
public void run() {
ActionFactory.PREFERENCES.create(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run();
}
});

bot.shell("Preferences").activate();
bot.tree().getTreeItem("Java").expand().getNode("Code Coverage").select();

assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.coverage_preferences_context")));
}

/**
* Test for {@link org.eclipse.eclemma.internal.ui.wizards.SessionImportPage1} and {@link org.eclipse.eclemma.internal.ui.wizards.SessionImportPage2}.
*/
@Test
public void importWizard() {
bot.menu("File").menu("Import...").click();
bot.shell("Import").activate();

SWTBotTreeItem treeItem = bot.tree().getTreeItem("Run/Debug").expand();
treeItem.getNode("Coverage Session").select();
bot.button("Next >").click();

assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.session_import_context")));

bot.radio("Agent address:").click();
bot.button("Next >").click();

assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.session_import_context")));
}

/**
* Test for {@link org.eclipse.eclemma.internal.ui.wizards.SessionExportPage1}.
*/
@Test
public void exportWizard() {
bot.menu("File").menu("Export...").click();
bot.shell("Export").activate();

SWTBotTreeItem treeItem = bot.tree().getTreeItem("Run/Debug").expand();
treeItem.getNode("Coverage Session").select();
bot.button("Next >").click();

assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.session_export_context")));
}

/**
* Test for {@link org.eclipse.eclemma.internal.ui.dialogs.CoveragePropertyPage}.
*/
@Test
public void propertyPage() throws CoreException {
createProject();

bot.viewByTitle("Project Explorer").bot().tree().select("prj").contextMenu().menu("Properties", false, 0).click();
bot.shell("Properties for prj").activate();
bot.tree().select("Coverage");

assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.coverage_properties_context")));
}

/**
* Test for {@link org.eclipse.eclemma.ui.launching.CoverageTab}.
*/
@Test
public void launchingTab() throws CoreException {
createProject();

bot.viewByTitle("Project Explorer").bot().tree().select("prj").contextMenu("Coverage As").menu("Coverage Configurations...").click();
bot.shell("Coverage Configurations").activate();
bot.tree().getTreeItem("Java Application").contextMenu("New").click();
bot.cTabItem("Coverage").activate();

assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.coverage_launch_tab_context")));
}

private static void createProject() throws CoreException {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("prj");
if (project.exists()) {
project.delete(true, null);
}
project.create(null);
project.open(null);
IProjectDescription description = project.getDescription();
description.setNatureIds(new String[] { JavaCore.NATURE_ID });
project.setDescription(description, null);
}

/**
* Test for {@link org.eclipse.eclemma.internal.ui.dialogs.MergeSessionsDialog}.
*/
@Test
public void mergeSessionsDialog() {
UIThreadRunnable.asyncExec(new VoidResult() {
public void run() {
new MergeSessionsDialog(bot.activeShell().widget, new ArrayList<ICoverageSession>(), "").open();
}
});

UIThreadRunnable.syncExec(new VoidResult() {
public void run() {
assertFont(expected, bot.shellWithId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.merge_sessions_context").widget.getChildren()[0]);
}
});
}

/**
* Test for {@link org.eclipse.eclemma.internal.ui.handlers.SelectActiveSessionHandler}.
*/
@Test
public void selectActiveSessionDialog() throws ExecutionException {
UIThreadRunnable.asyncExec(new VoidResult() {
public void run() {
try {
new SelectActiveSessionHandler().execute(new ExecutionEvent());
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
});

assertFont(expected, bot.shellWithId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.select_active_session_context").widget);
}

/**
* Test for {@link org.eclipse.eclemma.internal.ui.handlers.DumpExecutionDataHandler#openDialog(ExecutionEvent, java.util.List)}.
*/
@Test
public void selectLaunchDialog() {
UIThreadRunnable.asyncExec(new VoidResult() {
public void run() {
DumpExecutionDataHandler.openDialog(new ExecutionEvent(), new ArrayList<ICoverageLaunch>());
}
});

assertFont(expected, bot.shellWithId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.dump_execution_data").widget);
}

private static void assertFont(final FontData expected, final Widget parentWidget) {
UIThreadRunnable.syncExec(new VoidResult() {
public void run() {
for (Control widget : bot.widgets(CoreMatchers.any(Control.class), parentWidget)) {
FontData actual = widget.getFont().getFontData()[0];
assertEquals(widget + " font", expected, actual);
}
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.eclemma.internal.ui.EclEmmaUIPlugin;
import org.eclipse.eclemma.internal.ui.UIMessages;
import org.eclipse.eclemma.internal.ui.UIPreferences;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.preference.BooleanFieldEditor;
Expand Down Expand Up @@ -63,6 +64,7 @@ protected Control createContents(final Composite parent) {
createLink(result, UIMessages.CoveragePreferencesAnnotationsLink_label,
ANNOTATIONS_PAGE);

Dialog.applyDialogFont(result);
initialize();
checkState();
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.OwnerDrawLabelProvider;
Expand Down Expand Up @@ -77,6 +78,7 @@ protected Control createContents(Composite parent) {
gd.horizontalSpan = 2;
table.setLayoutData(gd);

Dialog.applyDialogFont(parent);
return parent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
return null;
}

private ICoverageLaunch openDialog(ExecutionEvent event,
public static ICoverageLaunch openDialog(ExecutionEvent event,
List<ICoverageLaunch> launches) {
final ListDialog dialog = new ListDialog(HandlerUtil.getActiveShell(event)) {
protected void configureShell(Shell shell) {
super.configureShell(shell);
Dialog.applyDialogFont(shell);
ContextHelp.setHelp(shell, ContextHelp.DUMP_EXECUTION_DATA);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
final ListDialog dialog = new ListDialog(HandlerUtil.getActiveShell(event)) {
protected void configureShell(Shell shell) {
super.configureShell(shell);
Dialog.applyDialogFont(shell);
ContextHelp.setHelp(shell, ContextHelp.SELECT_ACTIVE_SESSION);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void createControl(Composite parent) {
group.setText(UIMessages.ExportSessionPage1DestinationGroup_label);
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
createExportOptionsGroup(group);
Dialog.applyDialogFont(parent);
setControl(parent);
ContextHelp.setHelp(parent, ContextHelp.SESSION_EXPORT);
restoreWidgetValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.layout.GridDataFactory;
Expand Down Expand Up @@ -108,6 +109,7 @@ public void createControl(Composite parent) {
ContextHelp.setHelp(parent, ContextHelp.SESSION_IMPORT);
restoreWidgetValues();
updateStatus();
Dialog.applyDialogFont(parent);
}

private void createFileBlock(Composite parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
Expand Down Expand Up @@ -71,6 +72,7 @@ public void createControl(Composite parent) {
createScopeBlock(parent);
createButtonsBlock(parent);
setControl(parent);
Dialog.applyDialogFont(parent);
ContextHelp.setHelp(parent, ContextHelp.SESSION_IMPORT);
restoreWidgetValues();
update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -54,6 +55,7 @@ public void createControl(Composite parent) {
parent.setLayout(layout);
setControl(parent);
createAnalysisScope(parent);
Dialog.applyDialogFont(parent);
}

private void createAnalysisScope(Composite parent) {
Expand Down