Search in sources :

Example 1 with ChannelInfo

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

the class OpenDataBrowserPopup method execute.

/**
 * {@inheritDoc}
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // Get selection first because the ApplicationContext might change.
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        // This works for double-clicks.
        selection = HandlerUtil.getCurrentSelection(event);
    }
    // Create new editor
    final DataBrowserEditor editor = DataBrowserEditor.createInstance();
    if (editor == null)
        return null;
    // Add received items
    final Model model = editor.getModel();
    try {
        if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() instanceof ChannelInfo) {
            // Received items are from search dialog
            final Object[] channels = ((IStructuredSelection) selection).toArray();
            for (Object channel : channels) {
                final ChannelInfo info = (ChannelInfo) channel;
                add(model, info.getProcessVariable(), info.getArchiveDataSource());
            }
        } else {
            // Add received PVs with default archive data sources
            final List<TimestampedPV> timestampedPVs = Arrays.asList(AdapterUtil.convert(selection, TimestampedPV.class));
            if (!timestampedPVs.isEmpty()) {
                // Add received items, tracking their start..end time
                long start_ms = Long.MAX_VALUE, end_ms = 0;
                for (TimestampedPV timestampedPV : timestampedPVs) {
                    final long time = timestampedPV.getTime();
                    if (time < start_ms)
                        start_ms = time;
                    if (time > end_ms)
                        end_ms = time;
                    final PVItem item = new PVItem(timestampedPV.getName().trim(), period);
                    item.setAxis(model.addAxis());
                    item.useDefaultArchiveDataSources();
                    model.addItem(item);
                }
                final Instant start = Instant.ofEpochMilli(start_ms).minus(Duration.ofMinutes(30));
                final Instant end = Instant.ofEpochMilli(end_ms).plus(Duration.ofMinutes(30));
                model.enableScrolling(false);
                model.setTimerange(start, end);
            } else {
                final ProcessVariable[] pvs = AdapterUtil.convert(selection, ProcessVariable.class);
                for (ProcessVariable pv : pvs) add(model, pv, null);
            }
        }
    } catch (Exception ex) {
        MessageDialog.openError(editor.getSite().getShell(), Messages.Error, NLS.bind(Messages.ErrorFmt, ex.getMessage()));
    }
    return null;
}
Also used : ProcessVariable(org.csstudio.csdata.ProcessVariable) Instant(java.time.Instant) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) TimestampedPV(org.csstudio.csdata.TimestampedPV) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) ISelection(org.eclipse.jface.viewers.ISelection) Model(org.csstudio.trends.databrowser3.model.Model) PVItem(org.csstudio.trends.databrowser3.model.PVItem) DataBrowserEditor(org.csstudio.trends.databrowser3.editor.DataBrowserEditor)

Example 2 with ChannelInfo

use of org.csstudio.trends.databrowser3.model.ChannelInfo 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 3 with ChannelInfo

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

the class SearchView method configureActions.

/**
 * React to selections, button presses, ...
 */
private void configureActions() {
    // Start a channel search
    search.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            searchForChannels();
        }
    });
    // Channel Table: Allow dragging of PVs with archive
    final Table table = channel_table.getTable();
    new ControlSystemDragSource(table) {

        @Override
        public Object getSelection() {
            final IStructuredSelection selection = (IStructuredSelection) channel_table.getSelection();
            // To allow transfer of array, the data must be
            // of the actual array type, not Object[]
            final Object[] objs = selection.toArray();
            final ChannelInfo[] channels = Arrays.copyOf(objs, objs.length, ChannelInfo[].class);
            return channels;
        }
    };
    // Double-clicks should have the same effect as context menu -> Data Browser
    getSite().setSelectionProvider(channel_table);
    channel_table.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            // casting is needed for RAP
            IHandlerService handlerService = getSite().getService(IHandlerService.class);
            try {
                handlerService.executeCommand("org.csstudio.trends.databrowser3.OpenDataBrowserPopup", null);
            } catch (CommandException ex) {
                // $NON-NLS-1$
                Activator.getLogger().log(Level.WARNING, "Failed to open data browser", ex);
            }
        }
    });
    // Add context menu for object contributions
    final MenuManager menu = new MenuManager();
    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    table.setMenu(menu.createContextMenu(table));
    getSite().registerContextMenu(menu, channel_table);
}
Also used : Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CommandException(org.eclipse.core.commands.common.CommandException) ControlSystemDragSource(org.csstudio.ui.util.dnd.ControlSystemDragSource) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuManager(org.eclipse.jface.action.MenuManager) Separator(org.eclipse.jface.action.Separator)

Example 4 with ChannelInfo

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

the class SearchView method displayChannelInfos.

/**
 * Update the <code>channel_table</code> with received channel list
 *  @param channels Channel infos to add/replace
 */
private void displayChannelInfos(final ChannelInfo[] channels) {
    final Table table = channel_table.getTable();
    if (table.isDisposed())
        return;
    table.getDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            if (result_replace.isDisposed())
                return;
            if (result_replace.getSelection())
                channel_table.setInput(channels);
            else {
                // Combine new channels with existing list
                final ChannelInfo[] old = (ChannelInfo[]) channel_table.getInput();
                final ArrayList<ChannelInfo> full = new ArrayList<ChannelInfo>();
                for (ChannelInfo channel : old) full.add(channel);
                // Add new channels but avoid duplicates
                for (ChannelInfo channel : channels) if (!full.contains(channel))
                    full.add(channel);
                channel_table.setInput(full.toArray(new ChannelInfo[full.size()]));
            }
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) ArrayList(java.util.ArrayList) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo)

Example 5 with ChannelInfo

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

the class SearchView method createSearchSash.

/**
 * Create the 'lower' sash for searching archives
 *  @param sashform
 */
private void createSearchSash(final SashForm sashform) {
    final Composite parent = new Composite(sashform, SWT.BORDER);
    final GridLayout layout = new GridLayout(3, false);
    parent.setLayout(layout);
    // Pattern:  ___pattern___ [x] [search]
    Label l = new Label(parent, 0);
    l.setText(Messages.SearchPattern);
    l.setLayoutData(new GridData());
    // On OS X, a 'search' box might look a little better:
    // pattern = new Text(parent, SWT.SEARCH | SWT.ICON_CANCEL);
    // ... except:
    // a) only takes effect on OS X
    // b) doesn't support drop-down for recent searches
    pattern = new Text(parent, SWT.BORDER);
    pattern.setToolTipText(Messages.SearchPatternTT);
    pattern.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    pattern.setEnabled(false);
    pattern.addListener(SWT.DefaultSelection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            searchForChannels();
        }
    });
    AutoCompleteWidget acw = new AutoCompleteWidget(pattern, AutoCompleteTypes.PV);
    search = new Button(parent, SWT.PUSH);
    search.setText(Messages.Search);
    search.setToolTipText(Messages.SearchTT);
    search.setLayoutData(new GridData());
    search.setEnabled(false);
    AutoCompleteUIHelper.handleSelectEvent(search, acw);
    // ( ) Add  (*) Replace   [ ] Reg.Exp.
    final Button result_append = new Button(parent, SWT.RADIO);
    result_append.setText(Messages.AppendSearchResults);
    result_append.setToolTipText(Messages.AppendSearchResultsTT);
    result_append.setLayoutData(new GridData());
    result_replace = new Button(parent, SWT.RADIO);
    result_replace.setText(Messages.ReplaceSearchResults);
    result_replace.setToolTipText(Messages.ReplaceSearchResultsTT);
    result_replace.setLayoutData(new GridData(SWT.LEFT, 0, true, false));
    result_replace.setSelection(true);
    regex = new Button(parent, SWT.CHECK);
    regex.setText(Messages.RegularExpression);
    regex.setToolTipText(Messages.RegularExpressionTT);
    regex.setLayoutData(new GridData());
    // Table for channel names, displaying array of ChannelInfo entries
    // TableColumnLayout requires table in its own composite
    final Composite table_parent = new Composite(parent, 0);
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    table_parent.setLayout(table_layout);
    table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    channel_table = new TableViewer(table_parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    channel_table.setContentProvider(new ArrayContentProvider());
    TableViewerColumn col = TableHelper.createColumn(table_layout, channel_table, Messages.PVName, 200, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ChannelInfo channel = (ChannelInfo) cell.getElement();
            cell.setText(channel.getProcessVariable().getName());
        }
    });
    new TableColumnSortHelper<ChannelInfo>(channel_table, col) {

        @Override
        public int compare(final ChannelInfo item1, final ChannelInfo item2) {
            return item1.getProcessVariable().getName().compareTo(item2.getProcessVariable().getName());
        }
    };
    col = TableHelper.createColumn(table_layout, channel_table, Messages.ArchiveName, 50, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ChannelInfo channel = (ChannelInfo) cell.getElement();
            cell.setText(channel.getArchiveDataSource().getName());
        }
    });
    new TableColumnSortHelper<ChannelInfo>(channel_table, col) {

        @Override
        public int compare(final ChannelInfo item1, final ChannelInfo item2) {
            return item1.getArchiveDataSource().getName().compareTo(item2.getArchiveDataSource().getName());
        }
    };
    final Table table = channel_table.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    // searchForChannels() relies on non-null content
    channel_table.setInput(new ChannelInfo[0]);
    // Restore settings from memento
    if (memento != null) {
        if (memento.getBoolean(TAG_REGEX) != null)
            regex.setSelection(memento.getBoolean(TAG_REGEX));
        if (memento.getBoolean(TAG_REPLACE) != null) {
            final boolean replace = memento.getBoolean(TAG_REPLACE);
            result_append.setSelection(!replace);
            result_replace.setSelection(replace);
        }
    }
}
Also used : MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Listener(org.eclipse.swt.widgets.Listener) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridLayout(org.eclipse.swt.layout.GridLayout) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) AutoCompleteWidget(org.csstudio.autocomplete.ui.AutoCompleteWidget) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableColumnSortHelper(org.csstudio.apputil.ui.swt.TableColumnSortHelper) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Aggregations

ChannelInfo (org.csstudio.trends.databrowser3.model.ChannelInfo)8 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)4 ArrayList (java.util.ArrayList)3 Table (org.eclipse.swt.widgets.Table)3 ProcessVariable (org.csstudio.csdata.ProcessVariable)2 CommandException (org.eclipse.core.commands.common.CommandException)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 PartInitException (org.eclipse.ui.PartInitException)2 Instant (java.time.Instant)1 List (java.util.List)1 TestProperties (org.csstudio.apputil.test.TestProperties)1 TableColumnSortHelper (org.csstudio.apputil.ui.swt.TableColumnSortHelper)1 ArchiveReader (org.csstudio.archive.reader.ArchiveReader)1 AutoCompleteWidget (org.csstudio.autocomplete.ui.AutoCompleteWidget)1 TimestampedPV (org.csstudio.csdata.TimestampedPV)1 SearchJob (org.csstudio.trends.databrowser3.archive.SearchJob)1 DataBrowserEditor (org.csstudio.trends.databrowser3.editor.DataBrowserEditor)1