Search in sources :

Example 1 with ArchiveDataSource

use of org.csstudio.trends.databrowser3.model.ArchiveDataSource in project org.csstudio.display.builder by kasemir.

the class PlotDemo method createGUI.

// final private PlotListener listener = new PlotListener()
// {
// @Override
// public void scrollRequested(final boolean enable_scrolling)
// {
// System.out.println("Scroll enabled: " + enable_scrolling);
// scroll = enable_scrolling;
// }
// 
// @Override
// public void timeConfigRequested()
// {
// System.out.println("Time Config requested");
// }
// 
// @Override
// public void timeAxisChanged(final long start_ms, final long end_ms)
// {
// start_time = TimestampHelper.fromMillisecs(start_ms);
// end_time = TimestampHelper.fromMillisecs(end_ms);
// System.out.println("Time axis: " + start_time + " ... " + end_time);
// }
// 
// @Override
// public void valueAxisChanged(final int index, final double lower, final double upper)
// {
// System.out.println("Value axis " + index + ": " + lower + " ... " + upper);
// }
// 
// @Override
// public void droppedName(final String name)
// {
// System.out.println("Name dropped: " + name);
// }
// 
// @Override
// public void droppedPVName(final ProcessVariable name, final ArchiveDataSource archive)
// {
// System.out.println("PV Name dropped: " + name);
// }
// 
// @Override
// public void droppedFilename(final String file_name)
// {
// System.out.println("File Name dropped: " + file_name);
// }
// 
// @Override
// public void xyGraphConfigChanged(XYGraph newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void removeAnnotationChanged(Annotation oldValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void addAnnotationChanged(Annotation newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void backgroundColorChanged(Color newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void timeAxisForegroundColorChanged(Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisForegroundColorChanged(int index, Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisTitleChanged(int index, String oldTitle,
// String newTitle) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisAutoScaleChanged(int index, boolean oldAutoScale,
// boolean newAutoScale) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceNameChanged(int index, String oldName, String newName) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceYAxisChanged(int index, AxisConfig oldConfig,
// AxisConfig config) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceTypeChanged(int index, TraceType old,
// TraceType newTraceType) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceColorChanged(int index, Color old, Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisLogScaleChanged(int index, boolean old,
// boolean logScale) {
// // TODO Auto-generated method stub
// 
// }
// };
private void createGUI(final Composite parent) {
    final GridLayout layout = new GridLayout(1, false);
    parent.setLayout(layout);
    ModelBasedPlot plot;
    try {
        plot = new ModelBasedPlot(true);
    } catch (Exception e1) {
        e1.printStackTrace();
        return;
    }
    final FXCanvas canvas = new FXCanvas(parent, SWT.NONE);
    canvas.setScene(new Scene(plot.getPlot()));
    canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    // [Done] button to end demo
    final Button ok = new Button(parent, SWT.PUSH);
    ok.setText("Done");
    ok.setLayoutData(new GridData(SWT.RIGHT, 0, true, false));
    ok.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            run = false;
        }
    });
    // plot.addListener(listener);
    // Create demo samples
    final List<PlotSample> values = new ArrayList<PlotSample>();
    for (int i = 1; i < 10; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
    values.add(new PlotSample("Test", TestHelper.makeError(15, "Disconnected")));
    // Single value. Line should continue until the following 'disconnect'.
    values.add(new PlotSample("Test", TestHelper.makeValue(17)));
    values.add(new PlotSample("Test", TestHelper.makeError(18, "Disconnected")));
    for (int i = 20; i < 30; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
    final PlotSampleArray samples = new PlotSampleArray();
    samples.set(values);
    // Add item with demo samples
    final ModelItem item = new ModelItem("Demo") {

        @Override
        public PlotSamples getSamples() {
            return samples;
        }

        @Override
        public void write(final PrintWriter writer) {
        // NOP
        }
    };
    // TODO: Fix or remove
    // item.setColor(new RGB(0, 0, 255));
    plot.addTrace(item);
// start_time = VTypeHelper.getTimestamp(samples.getSample(0).getValue());
// end_time = VTypeHelper.getTimestamp(samples.getSample(samples.getSize()-1).getValue());
// plot.setTimeRange(start_time, end_time);
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) Scene(javafx.scene.Scene) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) PlotSampleArray(org.csstudio.trends.databrowser3.model.PlotSampleArray) FXCanvas(javafx.embed.swt.FXCanvas) PrintWriter(java.io.PrintWriter)

Example 2 with ArchiveDataSource

use of org.csstudio.trends.databrowser3.model.ArchiveDataSource in project org.csstudio.display.builder by kasemir.

the class OpenDataBrowserPopup method add.

/**
 * Add item
 *  @param model Model to which to add the item
 *  @param pv PV to add
 *  @param archive Archive to use or <code>null</code>
 *  @throws Exception on error
 */
private void add(final Model model, final ProcessVariable pv, final ArchiveDataSource archive) throws Exception {
    final PVItem item = new PVItem(pv.getName(), period);
    if (archive == null)
        item.useDefaultArchiveDataSources();
    else
        item.addArchiveDataSource(archive);
    // Add item to new axis
    item.setAxis(model.addAxis());
    model.addItem(item);
}
Also used : PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 3 with ArchiveDataSource

use of org.csstudio.trends.databrowser3.model.ArchiveDataSource in project org.csstudio.display.builder by kasemir.

the class SearchJobTest method testSearchJob.

@Test(timeout = 20000)
public void testSearchJob() throws Exception {
    final TestProperties settings = new TestProperties();
    String url = settings.getString("archive_rdb_url");
    if (url == null) {
        System.out.println("Skipped");
        return;
    }
    // final ArchiveReader reader =
    // ArchiveRepository.getInstance().getArchiveReader(url);
    final ArchiveDataSource[] archives = new ArchiveDataSource[] { new ArchiveDataSource(url, 1, "") };
    new SearchJob(archives, "DTL_LLRF:FCM1:*", true) {

        @Override
        protected void receivedChannelInfos(final ChannelInfo[] channels) {
            System.out.println("Found these channels:");
            for (final ChannelInfo channel : channels) System.out.println(channel.getArchiveDataSource().getName() + " - " + channel.getProcessVariable().getName());
            info = "Found " + channels.length + " channels";
            done.countDown();
        }

        @Override
        protected void archiveServerError(final String url, final Exception ex) {
            info = NLS.bind(Messages.ArchiveServerErrorFmt, url, ex.getMessage());
            done.countDown();
        }
    }.schedule();
    // Wait for success or error
    done.await();
    System.out.println(info);
    assertThat(info, notNullValue());
    assertTrue(info.startsWith("Found"));
}
Also used : TestProperties(org.csstudio.apputil.test.TestProperties) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) Test(org.junit.Test)

Example 4 with ArchiveDataSource

use of org.csstudio.trends.databrowser3.model.ArchiveDataSource in project org.csstudio.display.builder by kasemir.

the class ArchiveListGUI method connectToArchiveServer.

/**
 * Connect to archive data server.
 *  <p>
 *  On success, set <code>server</code>, update <code>archive_table</code>
 *  @param url Server URL
 */
private void connectToArchiveServer(final String url) {
    new ConnectJob(url) {

        @Override
        protected void archiveServerConnected(final String server_info, final ArchiveInfo[] infos) {
            ArchiveListGUI.this.server_info = server_info;
            if (urls.isDisposed())
                return;
            urls.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (info.isDisposed())
                        return;
                    ArchiveListGUI.this.url = url;
                    final List<ArchiveDataSource> archives = new ArrayList<>();
                    for (ArchiveInfo info : infos) archives.add(new ArchiveDataSource(url, info.getKey(), info.getName(), info.getDescription()));
                    archive_table.setInput(archives);
                    // Select all default archive data sources for this URL
                    final List<ArchiveDataSource> selected = new ArrayList<>();
                    for (ArchiveDataSource dataSource : default_archives) if (dataSource.getUrl().equals(url) && archives.contains(dataSource))
                        selected.add(dataSource);
                    archive_table.setSelection(new StructuredSelection(selected));
                    // Enable operations on server resp. archives
                    info.setEnabled(true);
                    handleArchiveUpdate();
                }
            });
        }

        @Override
        protected void archiveServerError(final String url, final Exception ex) {
            // Called from non-UI thread
            if (info.isDisposed())
                return;
            info.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (info.isDisposed())
                        return;
                    info.setEnabled(false);
                    handleServerError(url, ex);
                }
            });
        }
    }.schedule();
}
Also used : ArchiveInfo(org.csstudio.archive.reader.ArchiveInfo) ConnectJob(org.csstudio.trends.databrowser3.archive.ConnectJob) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource)

Example 5 with ArchiveDataSource

use of org.csstudio.trends.databrowser3.model.ArchiveDataSource in project org.csstudio.display.builder by kasemir.

the class AddModelItemCommand method forPV.

/**
 * Create PV via undo-able AddModelItemCommand,
 *  displaying errors in dialog
 *  @param shell Shell used for error dialogs
 *  @param operations_manager OperationsManager where command will be reg'ed
 *  @param model Model were PV is to be added
 *  @param pv_name Name of new PV
 *  @param period scan period
 *  @param axis Axis
 *  @param archive Archive data source
 *  @return AddModelItemCommand or <code>null</code> on error
 */
public static Optional<AddModelItemCommand> forPV(final Shell shell, final UndoableActionManager operations_manager, final Model model, final String pv_name, final double period, final AxisConfig axis, final ArchiveDataSource archive) {
    // Create item
    final PVItem item;
    try {
        item = new PVItem(pv_name, period);
        if (archive != null)
            item.addArchiveDataSource(archive);
        else
            item.useDefaultArchiveDataSources();
        axis.setVisible(true);
        item.setAxis(axis);
    } catch (Exception ex) {
        MessageDialog.openError(shell, Messages.Error, NLS.bind(Messages.AddItemErrorFmt, pv_name, ex.getMessage()));
        return Optional.empty();
    }
    // Add to model via undo-able command
    return Optional.of(new AddModelItemCommand(shell, operations_manager, model, item));
}
Also used : PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Aggregations

ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)17 PVItem (org.csstudio.trends.databrowser3.model.PVItem)8 ArrayList (java.util.ArrayList)6 ChannelInfo (org.csstudio.trends.databrowser3.model.ChannelInfo)4 TestProperties (org.csstudio.apputil.test.TestProperties)3 Test (org.junit.Test)3 ArchiveReader (org.csstudio.archive.reader.ArchiveReader)2 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)2 FormulaItem (org.csstudio.trends.databrowser3.model.FormulaItem)2 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)2 AddAxisCommand (org.csstudio.trends.databrowser3.propsheet.AddAxisCommand)2 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2 ViewerCell (org.eclipse.jface.viewers.ViewerCell)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 PartInitException (org.eclipse.ui.PartInitException)2 PrintWriter (java.io.PrintWriter)1