Skip to content

Commit

Permalink
Adds capability to display warnings in LaunchBar Launch Config Dialog
Browse files Browse the repository at this point in the history
Add SWTBot to test that the Launch Configuration, when opened via the
Launch Bar, displays a warning in the message area.

The Launch Bar Launch Configuration is, confusingly, handled by 2
different classes depending on whether a new configuration is being
created (NewLaunchConfigEditPage) or edited
(LaunchBarLaunchConfigDialog).

When using NewLaunchConfigEditPage, the existing
LaunchConfigurationTabGroupViewer.getWarningMessage() mechanism is used.
This was added to eclipse-platform in Bug 386673 (commit 231ef13).

When using LaunchBarLaunchConfigDialog (when editing), the new
getWarningMessage() mechanism, copied from the existing, is used.

In both classes above, logic was added to update the message when a tab
change occurs.
  • Loading branch information
betamaxbandit committed Aug 6, 2024
1 parent 9e1be51 commit c2a7e7a
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 4 deletions.
11 changes: 10 additions & 1 deletion launchbar/org.eclipse.launchbar.ui.tests/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
after="org.eclipse.debug.ui.prototypeTab">
</placement>
</tab>
<!-- Test for Launch Bar Launch Configuration Warnings -->
<tab
class="org.eclipse.launchbar.ui.tests.internal.WarningLaunchConfigTab"
group="org.eclipse.pde.ui.launcher.WorkbenchLauncherTabGroup"
id="org.eclipse.launchbar.ui.tests.internal.WarningLaunchConfigTab"
name="Warning Tab">
<placement
after="my.custom.tab">
</placement>
</tab>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2021 QNX Software Systems and others.
* Copyright (c) 2017, 2024 Renesas Electronics Europe and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -11,9 +11,11 @@
package org.eclipse.launchbar.ui.tests.internal;

import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
Expand All @@ -24,6 +26,7 @@
import org.eclipse.launchbar.ui.tests.SWTBotConfigSelector;
import org.eclipse.launchbar.ui.tests.SWTBotConfigSelector.EditConfigDialog;
import org.eclipse.launchbar.ui.tests.SWTBotConfigSelector.NewConfigDialog;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
Expand Down Expand Up @@ -139,4 +142,102 @@ public String getFailureMessage() {
}
});
}

/**
* Tests that when a new Launch Configuration is created, using the Launch Bar, it displays a
* warning icon/message in the message area.
* @see {@link WarningLaunchConfigTab}
* @see {@code org.eclipse.launchbar.ui.tests/plugin.xml}
*/
@Test
@Timeout(value = 2, unit = TimeUnit.MINUTES)
public void createNewLaunchConfigWithWarning() throws Exception {
// Test message. Needs to be effectively final.
AtomicReference<String> warningMessage = new AtomicReference<>();

// Create config with launchbar
bot.waitUntil(new ICondition() {
@Override
public void init(SWTBot bot) {
/*
* Use the Launch Bar new Launch Config and create an Eclipse Application Launch Config.
* This will include a WarningLaunchConfigTab tab which has a warning set in it.
*/
NewConfigDialog dialog = new SWTBotConfigSelector(bot).newConfigDialog();
dialog.setMode("Debug").setType("Eclipse Application").next();

// Select the warning tab, which sets the Launch Config message area to contain a warning.
dialog.bot().cTabItem(WarningLaunchConfigTab.TAB_NAME).activate();

// Get the Launch Config message area and stash the warning message for testing later
int indexOfErrorLabel = dialog.bot().widgets(widgetOfType(Text.class)).size() - 1;
warningMessage.set(dialog.bot().text(indexOfErrorLabel).getText());

dialog.finish();
}

@Override
public boolean test() throws Exception {
// The expected value has a space prefixed to account for an added space for the warning icon.
return warningMessage.get() != null
&& warningMessage.get().equals(" " + WarningLaunchConfigTab.WARNING_MESSAGE);
}

@Override
public String getFailureMessage() {
return String.format("Incorrect warning message; expected=%s, actual=%s",
WarningLaunchConfigTab.WARNING_MESSAGE, warningMessage.get());
}
});
}

/**
* Tests that when editing an existing Launch Configuration, using the Launch Bar, it displays a
* warning icon/message in the message area.
* @see {@link WarningLaunchConfigTab}
* @see {@code org.eclipse.launchbar.ui.tests/plugin.xml}
*/
@Test
@Timeout(value = 2, unit = TimeUnit.MINUTES)
public void editExistingLaunchConfigWithWarning() throws Exception {
// Test message. Needs to be effectively final.
AtomicReference<String> warningMessage = new AtomicReference<>();

// Create a launch config to edit (well to view)
ILaunchConfigurationType type = DebugPlugin.getDefault().getLaunchManager()
.getLaunchConfigurationType("org.eclipse.pde.ui.RuntimeWorkbench");
ILaunchConfigurationWorkingCopy wc = type.newInstance(null, "Test Config 2");
wc.doSave();

// Edit config with launchbar
bot.waitUntil(new ICondition() {
@Override
public void init(SWTBot bot) {
// Open the launch config created above using the launch bar
EditConfigDialog dialog = new SWTBotConfigSelector(bot).editConfigDialog();

// Select the warning tab, which sets the Launch Config message area to contain a warning.
dialog.selectTab(WarningLaunchConfigTab.TAB_NAME);

// Get the Launch Config message area and stash the warning message for testing later
int indexOfErrorLabel = dialog.bot().widgets(widgetOfType(Text.class)).size() - 1;
warningMessage.set(dialog.bot().text(indexOfErrorLabel).getText());

dialog.ok();
}

@Override
public boolean test() throws Exception {
// The expected value has a space prefixed to account for an added space for the warning icon.
return warningMessage.get() != null
&& warningMessage.get().equals(" " + WarningLaunchConfigTab.WARNING_MESSAGE);
}

@Override
public String getFailureMessage() {
return String.format("Incorrect warning message; expected=%s, actual=%s",
WarningLaunchConfigTab.WARNING_MESSAGE, warningMessage.get());
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2024 Renesas Electronics Europe and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.launchbar.ui.tests.internal;

import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

/**
* Creates a tab to test that the Launch Configuration, when opened via the Launch Bar,
* displays a warning in the message area.
* @see {@link CreateLaunchConfigTests}
*/
public class WarningLaunchConfigTab extends AbstractLaunchConfigurationTab {
public static final String WARNING_MESSAGE = "This is a warning";
public static final String TAB_NAME = "Warning Tab";

@Override
public void createControl(Composite parent) {
parent.setLayout(new RowLayout());
Label label = new Label(parent, SWT.NONE);
label.setText("The Launch Configuration message area should show a warning message!");
setControl(label);
}

@Override
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
}

@Override
public void initializeFrom(ILaunchConfiguration configuration) {
}

@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
}

@Override
public String getName() {
return TAB_NAME;
}

@Override
public String getId() {
return "org.eclipse.launchbar.ui.tests.internal.WarningLaunchConfigTab";
}

@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
setWarningMessage(WARNING_MESSAGE);
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2021 QNX Software Systems and others.
* Copyright (c) 2016, 2021, 2024 Renesas Electronics Europe and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -19,6 +19,7 @@
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPresentationManager;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.ILaunchConfigurationTab2;
import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
Expand Down Expand Up @@ -163,6 +164,7 @@ public void widgetSelected(SelectionEvent e) {
newTab.activated(workingCopy);

selItem.getControl().setFocus();
updateMessage();
}
});

Expand Down Expand Up @@ -386,6 +388,29 @@ private String getTabsErrorMessage() {
return null;
}

/**
* Returns the current warning message or <code>null</code> if none.
* @return Returns an appropriate warning message for display to user. The message returned will be:
* The warning message defined by the visible tab or <code>null</code> if no message is defined.
* Copied from LaunchConfigurationTabGroupViewer#getWarningMessage().
*/
private String getWarningMessage() {
if (initing) {
return null;
}
String message = null;

ILaunchConfigurationTab tab = getActiveTab();
if (tab instanceof ILaunchConfigurationTab2 confTab) {
String tabMessage = confTab.getWarningMessage();
if (tabMessage != null) {
message = tabMessage;
}
}

return message;
}

private String getTabsMessage() {
ILaunchConfigurationTab activeTab = getActiveTab();
if (activeTab != null) {
Expand Down Expand Up @@ -451,6 +476,12 @@ public void updateMessage() {
return;
}

message = getWarningMessage();
if (message != null) {
setMessage(message, IMessageProvider.WARNING);
return;
}

message = getTabsMessage();
setMessage(message);
okButton.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* Copyright (c) 2014, 2024 Renesas Electronics Europe and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -207,6 +207,12 @@ public LaunchConfigurationTabGroupViewerExt(Composite parent, ILaunchConfigurati
public ILaunchConfigurationWorkingCopy getWorkingCopy() {
return super.getWorkingCopy();
}

@Override
protected void handleTabSelected() {
super.handleTabSelected();
setMessage(getWarningMessage(), WARNING);
}
}

public LaunchGroupExtension getLaunchGroup() {
Expand Down

0 comments on commit c2a7e7a

Please sign in to comment.