Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*******************************************************************************
* Copyright (c) 2023, 2026 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.designer.rcp;

import org.eclipse.wb.tests.gef.UiContext;

import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellCloses;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.PlatformUI;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.osgi.framework.Version;

import java.util.Arrays;

/**
* Abstract base class for all tests that create Java files using the
* {@code New Wizard}.
*/
public abstract class AbstractWizardTest extends RcpModelTest {
private static Version ECLIPSE_VERSION = Platform.getBundle("org.eclipse.ui.workbench").getVersion();
private static Version VERSION = new Version(3, 135, 0);
// https://github.com/eclipse-platform/eclipse.platform/issues/1749
private static String WIZARD_NAME = ECLIPSE_VERSION.compareTo(VERSION) > 0 ? "New" : "Select a wizard";
private SWTWorkbenchBot workbench;
private SWTBotView projectExplorer;
private IFile editorFile;
protected SWTBot editor;

@Override
@BeforeEach
public void setUp() throws Exception {
super.setUp();
workbench = new SWTWorkbenchBot();
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView("org.eclipse.ui.navigator.ProjectExplorer");
IViewReference projectExplorerView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.findViewReference("org.eclipse.ui.navigator.ProjectExplorer");
projectExplorer = new SWTBotView(projectExplorerView, workbench);
}

@Override
@AfterEach
public void tearDown() throws Exception {
projectExplorer.close();
if (editorFile != null) {
forceDeleteResource(editorFile);
}
super.tearDown();
}

protected final void testTemplateViaProjectExplorer(String... fullPath) throws Exception {
new UiContext().executeAndCheck(() -> {
projectExplorer.bot().tree().getTreeItem("TestProject").contextMenu().menu("New", "Other...").click();
}, bot -> createTemplate(bot, fullPath));
}

protected final void testTemplateViaMenu(String... fullPath) throws Exception {
new UiContext().executeAndCheck(() -> {
workbench.shell().menu().menu("File").menu("New", "Other...").click();
}, bot -> createTemplate(bot, fullPath));
}

private void createTemplate(SWTBot activeShell, String... fullPath) throws CoreException {
assertTrue(fullPath.length > 1, "path requires at least one argument (template name)");
String[] path = Arrays.copyOf(fullPath, fullPath.length - 1);
String name = fullPath[fullPath.length - 1];
String fileName = name.replace(' ', '_').replaceAll("\\(|\\)", "");

SWTBotShell shell = activeShell.shell(WIZARD_NAME);
SWTBot bot = shell.bot();
bot.tree().expandNode(path).getNode(name).select();
bot.button("Next >").click();
bot.text(1).setText("test");
bot.text(2).setText(fileName);
bot.button("Finish").click();
// Wait for file creation
bot.waitUntil(shellCloses(shell));
// Open design page
SWTBotEditor activeEditor = new SWTWorkbenchBot().activeEditor();
editorFile = activeEditor.getReference().getEditorInput().getAdapter(IFile.class);
editor = activeEditor.bot();
editor.cTabItem("Design").activate();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2025 Google, Inc. and others.
* Copyright (c) 2011, 2026 Google, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -15,6 +15,7 @@
import org.eclipse.wb.tests.designer.swing.laf.LookAndFeelTest;
import org.eclipse.wb.tests.designer.swing.model.ModelTests;
import org.eclipse.wb.tests.designer.swing.swingx.SwingXTests;
import org.eclipse.wb.tests.designer.swing.wizard.WizardTests;

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
Expand All @@ -29,6 +30,7 @@
CustomizeTest.class,
ModelTests.class,
SwingXTests.class,
WizardTests.class
// WaitForMemoryProfilerTest.class,
})
public class SwingTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
* Copyright (c) 2023, 2026 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -10,11 +10,9 @@
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.swtbot.designer.swing.wizard;
package org.eclipse.wb.tests.designer.swing.wizard;

import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;

import org.junit.jupiter.api.Test;

Expand All @@ -37,7 +35,7 @@ public void testCreateNewJDialog() throws Exception {

@Test
public void testCreateNewJApplet() throws Exception {
testTemplateViaProjectExplorer("WindowBuilder", "Swing Designer", "JApplet");
testTemplateViaProjectExplorer("WindowBuilder", "Swing Designer", "(Deprecated) JApplet");
}

@Test
Expand All @@ -52,13 +50,13 @@ public void testCreateNewApplicationWindow() throws Exception {

@Test
public void testCreateWithJavaModules() throws Exception {
bot.setFileContent("module-info.java", """
setFileContentSrc("module-info.java", """
module test {
}""");
//
testTemplateViaProjectExplorer("WindowBuilder", "Swing Designer", "JFrame");
// We can't use code blocks as they don't consider carriage-returns
assertArrayEquals(bot.getFileContent("module-info.java").split(System.lineSeparator()),
assertArrayEquals(getFileContentSrc("module-info.java").split(System.lineSeparator()),
new String[] {
"module test {",
" requires java.desktop;",
Expand All @@ -83,7 +81,7 @@ public void testCreateNewJDialogNoSelection() throws Exception {

@Test
public void testCreateNewJAppletNoSelection() throws Exception {
testTemplateViaMenu("WindowBuilder", "Swing Designer", "JApplet");
testTemplateViaMenu("WindowBuilder", "Swing Designer", "(Deprecated) JApplet");
}

@Test
Expand All @@ -98,13 +96,13 @@ public void testCreateNewApplicationWindowNoSelection() throws Exception {

@Test
public void testCreateWithJavaModulesNoSelection() throws Exception {
bot.setFileContent("module-info.java", """
setFileContentSrc("module-info.java", """
module test {
}""");
//
testTemplateViaMenu("WindowBuilder", "Swing Designer", "JFrame");
// We can't use code blocks as they don't consider carriage-returns
assertArrayEquals(bot.getFileContent("module-info.java").split(System.lineSeparator()),
assertArrayEquals(getFileContentSrc("module-info.java").split(System.lineSeparator()),
new String[] {
"module test {",
" requires java.desktop;",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Patrick Ziegler and others.
* Copyright (c) 2024, 2026 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -10,9 +10,7 @@
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.swtbot.designer.swing;

import org.eclipse.wb.tests.swtbot.designer.swing.wizard.SwingNewWizardTest;
package org.eclipse.wb.tests.designer.swing.wizard;

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
Expand All @@ -22,6 +20,6 @@
*/
@Suite
@SelectClasses(SwingNewWizardTest.class)
public class SwingTests {
public class WizardTests {

}
11 changes: 10 additions & 1 deletion org.eclipse.wb.tests/src/org/eclipse/wb/tests/gef/UiContext.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2025 Google, Inc. and others.
* Copyright (c) 2011, 2026 Google, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -69,6 +69,15 @@ public void executeAndCheck(final FailableRunnable<Exception> uiRunnable,
Shell activeShell = UIThreadRunnable.syncExec(m_display::getActiveShell);
checkRunnable.accept(new SWTBot(activeShell));
} catch (Throwable e) {
// For debugging: Show all active shells
UIThreadRunnable.syncExec(() -> {
System.err.println("Active Shell:");
System.err.println(Display.getCurrent().getActiveShell());
System.err.println("Shells:");
for (Shell shell : Display.getCurrent().getShells()) {
System.err.println(shell);
}
});
e.printStackTrace();
checkException[0] = e;
} finally {
Expand Down
Loading