use of org.csstudio.apputil.time.StartEndTimeParser in project org.csstudio.display.builder by kasemir.
the class StartEndTimeAction method run.
/**
* Change start/end time
* @param model Model to change
* @param operations_manager Undo/Redo operations manager
* @param start_time Desired start time specification
* @param end_time .. end time
* @throws Exception on error in start/end time
*/
public static void run(final Model model, final UndoableActionManager operations_manager, final String start_time, final String end_time) throws Exception {
// Parsing somewhat redundant, but gives exception 'right away' for better error display
final StartEndTimeParser parser = new StartEndTimeParser(start_time, end_time);
new ChangeTimerangeCommand(model, operations_manager, parser.isEndNow(), start_time, end_time);
}
use of org.csstudio.apputil.time.StartEndTimeParser in project org.csstudio.display.builder by kasemir.
the class Model method setTimerange.
/**
* Set absolute or relative time range.
* <p>In 'scroll' mode, this determines the displayed time range.
* Otherwise, it determines the absolute start and end times
* @param start_spec Start and ..
* @param end_spec end time specification of the range to display
* @throws Exception on error in the time specifications
*/
public void setTimerange(final String start_spec, final String end_spec) throws Exception {
final StartEndTimeParser times = new StartEndTimeParser(Objects.requireNonNull(start_spec), Objects.requireNonNull(end_spec));
final Instant start_time = times.getStart().toInstant();
final Instant end_time = times.getEnd().toInstant();
final Duration new_span = Duration.between(start_time, end_time);
if (!(new_span.isZero() || new_span.isNegative())) {
synchronized (this) {
if (this.start_spec.equals(start_spec) && this.end_spec.equals(end_spec))
return;
this.start_spec = start_spec;
this.end_spec = end_spec;
this.end_time = end_time;
time_span = new_span;
scroll_enabled = times.isEndNow();
}
// Notify listeners
for (ModelListener listener : listeners) listener.changedTimerange();
}
}
use of org.csstudio.apputil.time.StartEndTimeParser in project org.csstudio.display.builder by kasemir.
the class ExportView method startExportJob.
/**
* Start export job with parameters from GUI
*/
private void startExportJob() {
if (model == null)
return;
// Determine start/end time
final Instant start_time, end_time;
if (use_plot_times.getSelection()) {
start_time = model.getStartTime();
end_time = model.getEndTime();
} else {
try {
final StartEndTimeParser times = new StartEndTimeParser(start.getText(), end.getText());
start_time = times.getStart().toInstant();
end_time = times.getEnd().toInstant();
} catch (final Exception ex) {
handleExportError(ex);
return;
}
}
// Determine source: Plot, archive, ...
final Source source;
int optimize_parameter = -1;
if (source_raw.getSelection())
source = Source.RAW_ARCHIVE;
else if (source_opt.getSelection()) {
source = Source.OPTIMIZED_ARCHIVE;
try {
optimize_parameter = Integer.parseInt(optimize.getText());
} catch (Exception ex) {
MessageDialog.openError(optimize.getShell(), Messages.Error, Messages.ExportOptimizeCountError);
return;
}
} else if (source_lin.getSelection()) {
source = Source.LINEAR_INTERPOLATION;
try {
optimize_parameter = (int) (SecondsParser.parseSeconds(linear.getText()) + 0.5);
if (optimize_parameter < 1)
optimize_parameter = 1;
} catch (Exception ex) {
MessageDialog.openError(linear.getShell(), Messages.Error, Messages.ExportLinearIntervalError);
return;
}
} else
source = Source.PLOT;
// Get remaining export parameters
final String filename = this.filename.getText().trim();
if (filename.equalsIgnoreCase(Messages.ExportDefaultFilename)) {
MessageDialog.openConfirm(optimize.getShell(), Messages.Error, Messages.ExportEnterFilenameError);
this.filename.setFocus();
return;
}
if (new File(filename).exists()) {
if (!MessageDialog.openConfirm(optimize.getShell(), Messages.ExportFileExists, NLS.bind(Messages.ExportFileExistsFmt, filename)))
return;
}
// Construct appropriate export job
final Job export;
if (type_matlab.getSelection()) {
if (// $NON-NLS-1$
filename.endsWith(".m"))
export = new MatlabScriptExportJob(model, start_time, end_time, source, optimize_parameter, filename, this);
else if (// $NON-NLS-1$
filename.endsWith(".mat"))
export = new MatlabFileExportJob(model, start_time, end_time, source, optimize_parameter, filename, this);
else {
MessageDialog.openError(type_matlab.getShell(), Messages.Error, Messages.ExportMatlabFilenameError);
return;
}
} else {
// Spreadsheet file export
final Style style;
if (format_decimal.getSelection())
style = Style.Decimal;
else if (format_expo.getSelection())
style = Style.Exponential;
else
style = Style.Default;
final int precision;
if (style == Style.Default)
// Not used
precision = 0;
else {
try {
precision = Integer.parseInt(format_digits.getText().trim());
} catch (Exception ex) {
MessageDialog.openError(optimize.getShell(), Messages.Error, Messages.ExportDigitsError);
return;
}
}
final ValueFormatter formatter;
if (sev_stat.getSelection())
formatter = new ValueWithInfoFormatter(style, precision);
else
formatter = new ValueFormatter(style, precision);
formatter.useMinMaxColumn(minMaxAllowed() && min_max_col.getSelection());
if (tabular.getSelection())
export = new SpreadsheetExportJob(model, start_time, end_time, source, optimize_parameter, formatter, filename, this);
else
export = new PlainExportJob(model, start_time, end_time, source, optimize_parameter, formatter, filename, this);
}
export.schedule();
}
Aggregations