Skip to content

Commit

Permalink
#2213 update databrowser launcher to use TimeStampedProcessVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
shroffk committed Apr 12, 2022
1 parent c30cb92 commit fc7b936
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@
******************************************************************************/
package org.csstudio.trends.databrowser3;

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.csstudio.trends.databrowser3.model.ChannelInfo;
import org.csstudio.trends.databrowser3.model.PVItem;
import org.csstudio.trends.databrowser3.preferences.Preferences;
import org.phoebus.core.types.ProcessVariable;
import org.phoebus.core.types.TimeStampedProcessVariable;
import org.phoebus.framework.adapter.AdapterService;
import org.phoebus.framework.selection.Selection;
import org.phoebus.framework.workbench.ApplicationService;
import org.phoebus.ui.spi.ContextMenuEntry;

import javafx.scene.image.Image;
import org.phoebus.util.time.TimeRelativeInterval;

/** Entry for context menus that starts Data Browser for selected ProcessVariable
* @author Kay Kasemir
Expand Down Expand Up @@ -44,11 +52,14 @@ public Class<?> getSupportedType()
return supportedType;
}

private volatile Duration time_span = Preferences.time_span;

@Override
public void call(final Selection selection) throws Exception
{
final DataBrowserInstance instance = ApplicationService.createInstance(DataBrowserApp.NAME);
final List<ProcessVariable> pvs = selection.getSelections();
final List<Instant> pvInstances = new ArrayList<>();
for (ProcessVariable pv : pvs)
{
final PVItem item = new PVItem(pv.getName(), 0);
Expand All @@ -57,6 +68,22 @@ public void call(final Selection selection) throws Exception
else
item.useDefaultArchiveDataSources();
instance.getModel().addItem(item);
if (pv instanceof TimeStampedProcessVariable)
{
pvInstances.add(((TimeStampedProcessVariable) pv).getTime());
}
}
if (!pvInstances.isEmpty())
{
AtomicReference<Instant> start = new AtomicReference<>(Instant.MAX);
AtomicReference<Instant> end = new AtomicReference<>(Instant.MIN);
pvInstances.stream().sorted().forEach(inst -> {
start.set(inst.isBefore(start.get()) ? inst : start.get());
end.set(inst.isAfter(end.get()) ? inst : end.get());
});
instance.getModel().setTimerange(
TimeRelativeInterval.of(start.get().minus(time_span.dividedBy(2)),
end.get().plus(time_span.dividedBy(2))));
}
}
}

0 comments on commit fc7b936

Please sign in to comment.