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

CSSTUDIO-1660 replaced TimeRangeDialog with popover implementation in DataBrowser #2239

Merged
merged 3 commits into from
May 10, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
******************************************************************************/
package org.csstudio.trends.databrowser3.ui;

import javafx.scene.Node;
import javafx.scene.layout.Region;
import org.csstudio.trends.databrowser3.model.Model;
import org.csstudio.trends.databrowser3.ui.properties.ChangeTimerangeCommand;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.dialog.PopOver;
import org.phoebus.ui.time.TimeRelativeIntervalPane;
import org.phoebus.ui.undo.UndoableActionManager;
import org.phoebus.util.time.TimeInterval;
import org.phoebus.util.time.TimeRelativeInterval;

import javafx.scene.Node;
import java.util.function.BiConsumer;

/** Helper for handling start/end time changes
* @author Kay Kasemir
Expand All @@ -28,18 +31,26 @@ public class ChangeTimerangeAction
*/
public static void run(final Model model, final Node node, final UndoableActionManager undo)
{
final TimeRangeDialog dlg = new TimeRangeDialog(model.getTimerange());
DialogHelper.positionDialog(dlg, node, -300, -200);
dlg.showAndWait().ifPresent(range ->
{
// If anything is absolute, make both ends absolute

BiConsumer<TimeRelativeIntervalPane, PopOver> closeCallback = (timePane, popOver) -> {
popOver.hide();
};

BiConsumer<TimeRelativeIntervalPane, PopOver> applyCallback = (timePane, popOver) -> {
TimeRelativeInterval range = timePane.getInterval();
if (range.isStartAbsolute() || range.isEndAbsolute())
{
final TimeInterval abs = range.toAbsoluteInterval();
new ChangeTimerangeCommand(model, undo, TimeRelativeInterval.of(abs.getStart(), abs.getEnd()));
}
else
else {
new ChangeTimerangeCommand(model, undo, range);
});
}
popOver.hide();
};

final TimeRangePopover popover = TimeRangePopover.withDefaultTimePane(model, closeCallback, applyCallback);

popover.show((Region) node);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.csstudio.trends.databrowser3.ui;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import org.csstudio.trends.databrowser3.model.Model;
import org.phoebus.ui.dialog.PopOver;
import org.phoebus.ui.time.TemporalAmountPane;
import org.phoebus.ui.time.TimeRelativeIntervalPane;

import java.util.function.BiConsumer;
import java.util.logging.Logger;
import java.util.logging.Level;

public class TimeRangePopover extends PopOver {

private static final Logger log = Logger.getLogger(TimeRangePopover.class.getName());

public static TimeRangePopover withDefaultTimePane(final Model model, BiConsumer<TimeRelativeIntervalPane, PopOver> cancelCallback, BiConsumer<TimeRelativeIntervalPane, PopOver> applyCallback) {
return new TimeRangePopover(new TimeRelativeIntervalPane(TemporalAmountPane.Type.ONLY_NOW), model, cancelCallback, applyCallback);
}

public TimeRangePopover(final TimeRelativeIntervalPane timePane, final Model model, BiConsumer<TimeRelativeIntervalPane, PopOver> cancelCallback, BiConsumer<TimeRelativeIntervalPane, PopOver> applyCallback) {
// Initialize the PopOver with the timepane as the content
super(timePane);

// Set the interval for the TimePane
timePane.setInterval(model.getTimerange());

// Add Apply and Close buttons to the TimePane
Button cancelButton = new Button();
cancelButton.setText("Close");
Button applyButton = new Button();
applyButton.setText("Apply");

HBox buttonBar = new HBox();
buttonBar.setSpacing(10);
buttonBar.setAlignment(Pos.CENTER_RIGHT);
buttonBar.setPadding(new Insets(5));
buttonBar.getChildren().add(cancelButton);
buttonBar.getChildren().add(applyButton);
timePane.add(buttonBar, 0, 5, 4, 1);

cancelButton.setOnAction(actionEvent -> {
try {
cancelCallback.accept(timePane, this);
} catch (Exception e) {
log.log(Level.WARNING, "Could not execute cancel action on TimeRangePopover", e);
}
});
applyButton.setOnAction(actionEvent -> {
try {
applyCallback.accept(timePane, this);
} catch (Exception e) {
log.log(Level.WARNING, "Could not execute apply action on TimeRangePopover", e);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import java.text.MessageFormat;
import java.time.Instant;
import java.time.temporal.TemporalAmount;
import java.util.function.BiConsumer;

import javafx.beans.property.SimpleBooleanProperty;
import javafx.scene.layout.*;
import org.csstudio.trends.databrowser3.Activator;
import org.csstudio.trends.databrowser3.Messages;
import org.csstudio.trends.databrowser3.export.ExportJob;
Expand All @@ -24,13 +26,15 @@
import org.csstudio.trends.databrowser3.export.ValueFormatter;
import org.csstudio.trends.databrowser3.export.ValueWithInfoFormatter;
import org.csstudio.trends.databrowser3.model.Model;
import org.csstudio.trends.databrowser3.ui.TimeRangeDialog;
import org.csstudio.trends.databrowser3.ui.TimeRangePopover;
import org.phoebus.archive.vtype.Style;
import org.phoebus.framework.jobs.JobManager;
import org.phoebus.framework.persistence.Memento;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
import org.phoebus.ui.dialog.PopOver;
import org.phoebus.ui.dialog.SaveAsDialog;
import org.phoebus.ui.time.TimeRelativeIntervalPane;
import org.phoebus.util.time.SecondsParser;
import org.phoebus.util.time.TimeInterval;
import org.phoebus.util.time.TimeParser;
Expand All @@ -50,10 +54,6 @@
import javafx.scene.control.TitledPane;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

/** Panel for exporting data into files
* @author Kay Kasemir
Expand Down Expand Up @@ -117,16 +117,19 @@ public ExportView(final Model model)
GridPane.setHgrow(end, Priority.ALWAYS);
grid.add(end, 1, 1);

BiConsumer<TimeRelativeIntervalPane, PopOver> closeCallback = (timePane, popOver) -> {
popOver.hide();
};
BiConsumer<TimeRelativeIntervalPane, PopOver> applyCallback = (timePane, popOver) -> {
final String[] range = Model.getTimerangeText(timePane.getInterval());
start.setText(range[0]);
end.setText(range[1]);
popOver.hide();
};
final TimeRangePopover popover = TimeRangePopover.withDefaultTimePane(model, closeCallback, applyCallback);
sel_times.setOnAction(event ->
{
final TimeRangeDialog dlg = new TimeRangeDialog(model.getTimerange());
DialogHelper.positionDialog(dlg, this, -200, -200);
dlg.showAndWait().ifPresent(interval ->
{
final String[] range = Model.getTimerangeText(interval);
start.setText(range[0]);
end.setText(range[1]);
});
popover.show((Region) event.getSource());
});

use_plot_times.setTooltip(new Tooltip(Messages.ExportPlotStartEndTT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void changedTimeAxisConfig()

final Button times = new Button(Messages.StartEndDialogBtn, Activator.getIcon("time_range"));
times.setTooltip(times_tt);
times.setOnAction(event -> ChangeTimerangeAction.run(model, layout, undo));
times.setOnAction(event -> ChangeTimerangeAction.run(model, times, undo));
layout.add(times, 4, 0);

layout.add(new Label(Messages.GridLbl), 0, 1);
Expand Down