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

Rework clock handling while debugging #1022

Merged
merged 2 commits into from
Feb 15, 2025
Merged
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: 1 addition & 1 deletion plugins/org.eclipse.fordiac.ide.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<view
id="org.eclipse.fordiac.ide.debug.ui.view.FBDebugView"
minimized="false"
ratio="0.75f"
ratio="0.6f"
relationship="bottom"
relative="org.eclipse.ui.navigator.ProjectExplorer">
</view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@

@SuppressWarnings("squid:S3008") // tell sonar the java naming convention does not make sense for this class
public final class Messages extends NLS {
private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$
private static final String BUNDLE_NAME = "org.eclipse.fordiac.ide.debug.ui.messages"; //$NON-NLS-1$
public static String DebugClockWidget_ClockIntervalTextLabel;
public static String DebugClockWidget_FixedClock;
public static String DebugClockWidget_IntervalClock;
public static String DebugClockWidget_InvalidInterval;
public static String DebugClockWidget_InvalidMonotonicClockValue;
public static String DebugClockWidget_InvalidRealtimeClockValue;
public static String DebugClockWidget_MonotonicClock;
public static String DebugClockWidget_MonotonicClockTextLabel;
public static String DebugClockWidget_RealtimeClock;
public static String DebugClockWidget_RealtimeClockTextLabel;
public static String DebugClockWidget_SystemClock;
public static String DebugClockWidget_Title;
public static String EvaluatorDebugFindAction_Text;
public static String EvaluatorDebugFindDialog_Title;
public static String EvaluatorVariableValueEditor_Exception;
Expand All @@ -31,18 +43,11 @@ public final class Messages extends NLS {
public static String MainLaunchConfigurationTab_ErrorUpdatingArguments;
public static String MainLaunchConfigurationTab_InvalidValueMessage;
public static String MainLaunchConfigurationTab_InvalidValueTitle;

public static String FBLaunchConfigurationTab_ClockInterval;
public static String FBLaunchConfigurationTab_DebugTime;
public static String FBLaunchConfigurationTab_ERROR_InvalidDebugTime;
public static String FBDebugViewClockWidget_Apply;
public static String FBDebugViewClockWidget_InvalidValues;
public static String FBLaunchConfigurationTab_Event;
public static String FBLaunchConfigurationTab_IncrementClockAfterEachEventBySpecifiedAmount;
public static String FBLaunchConfigurationTab_KeepDebuggerRunningWhenIdle;
public static String FBLaunchConfigurationTab_RepeatEvent;

public static String FBLaunchConfigurationTab_UseFixedClockWithSpecifiedTime;
public static String FBLaunchConfigurationTab_UseSystemClock;

static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.eclipse.core.resources.IFile;
Expand All @@ -29,6 +30,7 @@
import org.eclipse.fordiac.ide.debug.fb.FBLaunchConfigurationDelegate;
import org.eclipse.fordiac.ide.debug.ui.MainLaunchConfigurationTab;
import org.eclipse.fordiac.ide.debug.ui.Messages;
import org.eclipse.fordiac.ide.debug.ui.widgets.DebugClockWidget;
import org.eclipse.fordiac.ide.model.eval.variable.Variable;
import org.eclipse.fordiac.ide.model.libraryElement.AdapterDeclaration;
import org.eclipse.fordiac.ide.model.libraryElement.AdapterFB;
Expand All @@ -47,32 +49,32 @@
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class FBLaunchConfigurationTab extends MainLaunchConfigurationTab {

private ComboViewer eventCombo;
private Button repeatEventCheckbox;
private Button keepDebuggerRunningCheckbox;
private Button systemTimeRadio;
private Button incrementTimeRadio;
private Button manualTimeRadio;
private Text debugTimeText;
private final DebugClockWidget clockWidget = new DebugClockWidget(this::updateLaunchConfigurationDialog);

@Override
public void createControl(final Composite parent) {
super.createControl(parent);

final Composite eventComponent = createEventComponent((Composite) getControl());
final Composite comp = (Composite) getControl();

final Composite eventComponent = createEventComponent(comp);
GridDataFactory.fillDefaults().grab(true, false).applyTo(eventComponent);

final Composite argumentsComponent = createArgumentsComponent((Composite) getControl());
final Composite argumentsComponent = createArgumentsComponent(comp);
GridDataFactory.fillDefaults().grab(true, true).applyTo(argumentsComponent);

final Control clockComponent = clockWidget.createControl(comp);
GridDataFactory.fillDefaults().grab(true, false).applyTo(clockComponent);
}

@Override
Expand All @@ -90,9 +92,6 @@ protected Composite createOptionsComponent(final Composite parent) {
keepDebuggerRunningCheckbox.addSelectionListener(widgetSelectedAdapter(e -> updateLaunchConfigurationDialog()));
GridDataFactory.fillDefaults().applyTo(keepDebuggerRunningCheckbox);

final Composite debugTimeComponent = createDebugTimeComponent(comp);
GridDataFactory.fillDefaults().grab(true, false).applyTo(debugTimeComponent);

return group;
}

Expand All @@ -114,47 +113,6 @@ protected Composite createEventComponent(final Composite parent) {
return group;
}

protected Composite createDebugTimeComponent(final Composite parent) {
final Group group = new Group(parent, SWT.BORDER);
GridLayoutFactory.swtDefaults().applyTo(group);
group.setText(Messages.FBLaunchConfigurationTab_DebugTime);

final Composite radioComp = new Composite(group, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(1).applyTo(radioComp);
GridDataFactory.fillDefaults().grab(true, false).applyTo(radioComp);

systemTimeRadio = new Button(radioComp, SWT.RADIO);
systemTimeRadio.setText(Messages.FBLaunchConfigurationTab_UseSystemClock);
systemTimeRadio.addListener(SWT.Selection, e -> updateLaunchConfigurationDialog());
GridDataFactory.fillDefaults().applyTo(systemTimeRadio);

incrementTimeRadio = new Button(radioComp, SWT.RADIO);
incrementTimeRadio.setText(Messages.FBLaunchConfigurationTab_IncrementClockAfterEachEventBySpecifiedAmount);
incrementTimeRadio.addListener(SWT.Selection, e -> updateLaunchConfigurationDialog());
GridDataFactory.fillDefaults().applyTo(incrementTimeRadio);

manualTimeRadio = new Button(radioComp, SWT.RADIO);
manualTimeRadio.setText(Messages.FBLaunchConfigurationTab_UseFixedClockWithSpecifiedTime);
manualTimeRadio.addListener(SWT.Selection, e -> updateLaunchConfigurationDialog());
GridDataFactory.fillDefaults().applyTo(manualTimeRadio);

final Composite c = new Composite(group, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(3).applyTo(c);
GridDataFactory.fillDefaults().grab(true, false).applyTo(c);

final Label clockIntervalLabel = new Label(c, SWT.NONE);
clockIntervalLabel.setText(Messages.FBLaunchConfigurationTab_ClockInterval);
debugTimeText = new Text(c, SWT.BORDER);
debugTimeText.setText("0"); //$NON-NLS-1$
debugTimeText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
debugTimeText.addSegmentListener(e -> updateLaunchConfigurationDialog());
final Label debugTimeLabel = new Label(c, SWT.NONE);
debugTimeLabel.setText("ms"); //$NON-NLS-1$
debugTimeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

return group;
}

@Override
public void setDefaults(final ILaunchConfigurationWorkingCopy configuration) {
super.setDefaults(configuration);
Expand All @@ -163,6 +121,8 @@ public void setDefaults(final ILaunchConfigurationWorkingCopy configuration) {
configuration.removeAttribute(FBLaunchConfigurationAttributes.KEEP_RUNNING_WHEN_IDLE);
configuration.removeAttribute(FBLaunchConfigurationAttributes.CLOCK_MODE);
configuration.removeAttribute(FBLaunchConfigurationAttributes.CLOCK_INTERVAL);
configuration.removeAttribute(FBLaunchConfigurationAttributes.CLOCK_REALTIME_OFFSET);
configuration.removeAttribute(FBLaunchConfigurationAttributes.CLOCK_MONOTONIC_OFFSET);
}

@Override
Expand All @@ -179,10 +139,12 @@ public void initializeFrom(final ILaunchConfiguration configuration) {
repeatEventCheckbox.setSelection(FBLaunchConfigurationAttributes.isRepeatEvent(configuration));
keepDebuggerRunningCheckbox
.setSelection(FBLaunchConfigurationAttributes.isKeepRunningWhenIdle(configuration));
systemTimeRadio.setSelection(FBLaunchConfigurationAttributes.isSystem(configuration));
incrementTimeRadio.setSelection(FBLaunchConfigurationAttributes.isIncrement(configuration));
manualTimeRadio.setSelection(FBLaunchConfigurationAttributes.isManual(configuration));
debugTimeText.setText(FBLaunchConfigurationAttributes.getClockIntervalText(configuration));
clockWidget.setSelectedClockMode(FBLaunchConfigurationAttributes.getClockMode(configuration));
clockWidget.setClockIntervalText(FBLaunchConfigurationAttributes.getClockIntervalText(configuration));
clockWidget
.setRealtimeClockText(FBLaunchConfigurationAttributes.getClockRealtimeOffsetText(configuration));
clockWidget.setMonotonicClockText(
FBLaunchConfigurationAttributes.getClockMonotonicOffsetText(configuration));
} catch (final CoreException e) {
// ignore
}
Expand All @@ -202,21 +164,16 @@ public void performApply(final ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(FBLaunchConfigurationAttributes.KEEP_RUNNING_WHEN_IDLE,
keepDebuggerRunningCheckbox.getSelection());

if (systemTimeRadio.getSelection()) {
configuration.setAttribute(FBLaunchConfigurationAttributes.CLOCK_MODE, FBDebugClockMode.SYSTEM.toString());
}
if (incrementTimeRadio.getSelection()) {
configuration.setAttribute(FBLaunchConfigurationAttributes.CLOCK_MODE,
FBDebugClockMode.INCREMENT.toString());
final FBDebugClockMode clockMode = clockWidget.getSelectedClockMode();
configuration.setAttribute(FBLaunchConfigurationAttributes.CLOCK_MODE, clockMode.toString());
if (clockMode == FBDebugClockMode.INTERVAL) {
configuration.setAttribute(FBLaunchConfigurationAttributes.CLOCK_INTERVAL, clockWidget.getClockIntervalText());
}
if (manualTimeRadio.getSelection()) {
configuration.setAttribute(FBLaunchConfigurationAttributes.CLOCK_MODE, FBDebugClockMode.MANUAL.toString());
}
final String debugTime = debugTimeText.getText();
if (!debugTime.isBlank()) {
configuration.setAttribute(FBLaunchConfigurationAttributes.CLOCK_INTERVAL, debugTime);
} else {
configuration.setAttribute(FBLaunchConfigurationAttributes.CLOCK_INTERVAL, "0"); //$NON-NLS-1$
if (clockMode == FBDebugClockMode.INTERVAL || clockMode == FBDebugClockMode.FIXED) {
configuration.setAttribute(FBLaunchConfigurationAttributes.CLOCK_REALTIME_OFFSET,
clockWidget.getRealtimeClockText());
configuration.setAttribute(FBLaunchConfigurationAttributes.CLOCK_MONOTONIC_OFFSET,
clockWidget.getMonotonicClockText());
}
}

Expand Down Expand Up @@ -279,17 +236,9 @@ protected boolean filterTargetResource(final IResource resource) throws CoreExce

@Override
public boolean isValid(final ILaunchConfiguration launchConfig) {
setErrorMessage(null);
try {
final int debugTime = Integer.parseInt(debugTimeText.getText());
if (debugTime < 0) {
throw new NumberFormatException();
}
} catch (final NumberFormatException nfe) {
setErrorMessage(Messages.FBLaunchConfigurationTab_ERROR_InvalidDebugTime);
return false;
}
return true;
final Optional<String> clockValid = clockWidget.validate();
setErrorMessage(clockValid.orElse(null));
return clockValid.isEmpty();
}

@SuppressWarnings("static-method") // subclasses may override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
DebugClockWidget_ClockIntervalTextLabel=T\#
DebugClockWidget_FixedClock=Use fixed clock with specified value
DebugClockWidget_IntervalClock=Increment clock on each event by
DebugClockWidget_InvalidInterval=Invalid clock interval: {0}
DebugClockWidget_InvalidMonotonicClockValue=Invalid monotonic clock value: {0}
DebugClockWidget_InvalidRealtimeClockValue=Invalid real-time clock value: {0}
DebugClockWidget_MonotonicClock=Monotonic Clock:
DebugClockWidget_MonotonicClockTextLabel=T\#
DebugClockWidget_RealtimeClock=Real-time Clock:
DebugClockWidget_RealtimeClockTextLabel=DT\#
DebugClockWidget_SystemClock=Use system clock
DebugClockWidget_Title=Clock
EvaluatorDebugFindAction_Text=&Find...
EvaluatorDebugFindDialog_Title=Filter
EvaluatorVariableValueEditor_Exception=An exception occurred
Expand All @@ -12,13 +24,8 @@ MainLaunchConfigurationTab_ErrorInitializingArguments=Error initializing argumen
MainLaunchConfigurationTab_ErrorUpdatingArguments=Error updating arguments
MainLaunchConfigurationTab_InvalidValueMessage={0} is not a valid value for variable {1} with type {2}
MainLaunchConfigurationTab_InvalidValueTitle=Invalid Value

FBLaunchConfigurationTab_ClockInterval=Clock interval:
FBLaunchConfigurationTab_DebugTime=Debug Time
FBLaunchConfigurationTab_ERROR_InvalidDebugTime=Invalid value for clock interval given. Must be number greater or equal to 0.
FBDebugViewClockWidget_Apply=Apply
FBDebugViewClockWidget_InvalidValues=Invalid Values
FBLaunchConfigurationTab_Event=Event
FBLaunchConfigurationTab_IncrementClockAfterEachEventBySpecifiedAmount=Increment clock after each event by specified amount
FBLaunchConfigurationTab_KeepDebuggerRunningWhenIdle=Keep debugger running when idle
FBLaunchConfigurationTab_RepeatEvent=Repeat event
FBLaunchConfigurationTab_UseFixedClockWithSpecifiedTime=Use fixed clock with specified time
FBLaunchConfigurationTab_UseSystemClock=Use system clock
Loading
Loading