Search in sources :

Example 6 with ChannelInfo

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

the class SearchJob method run.

/**
 * {@inheritDoc}
 */
@Override
protected IStatus run(final IProgressMonitor monitor) {
    final ArrayList<ChannelInfo> channels = new ArrayList<>();
    monitor.beginTask(Messages.Search, archives.length);
    for (ArchiveDataSource archive : archives) {
        try (final ArchiveReader reader = ArchiveRepository.getInstance().getArchiveReader(archive.getUrl())) {
            monitor.subTask(archive.getName());
            final String[] names;
            if (pattern_is_glob)
                names = reader.getNamesByPattern(archive.getKey(), pattern);
            else
                names = reader.getNamesByRegExp(archive.getKey(), pattern);
            for (String name : names) channels.add(new ChannelInfo(name, archive));
            monitor.worked(1);
        } catch (final Exception ex) {
            monitor.setCanceled(true);
            monitor.done();
            archiveServerError(archive.getUrl(), ex);
            return Status.CANCEL_STATUS;
        }
    }
    receivedChannelInfos((ChannelInfo[]) channels.toArray(new ChannelInfo[channels.size()]));
    monitor.done();
    return Status.OK_STATUS;
}
Also used : ArchiveReader(org.csstudio.archive.reader.ArchiveReader) ArrayList(java.util.ArrayList) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo)

Example 7 with ChannelInfo

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

the class DataBrowserEditor method hookDragAndDrop.

/**
 * Allow 'drop' of PV name, archive, ..
 *  @param canvas FXCanvas
 */
private void hookDragAndDrop(final Control canvas) {
    // CS-Studio uses the ControlSystemDragSource
    // and ControlSystemDropTarget to transfer its own
    // data types, using the SWT drag-and-drop API
    // plus some class loader hacking to de-serialize
    // types from other plugins.
    // 
    // The JavaFX plot is inside an FXCanvas.
    // The FXCanvas establishes an SWT DropTarget
    // to forward drops from SWT to the hosted JavaFX scene.
    // 
    // Issues:
    // The FXCanvas only reliably forwards standard transfers
    // (string, ..), and not custom data types.
    // SWT generally doesn't allow multiple drop targets.
    // 
    // Option 1)
    // Use the JavaFX drop API on the plot, and parse the received strings.
    // -> Don't want to parse possibly arbitrary strings.
    // 
    // Option 2)
    // Change the ControlSystemDropTarget to use
    // getSite().getService(IDragAndDropService.class).addMergedDropTarget(..)
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162192
    // This would allow 'adding' another DropTarget,
    // but requires changes to the ControlSystemDropTarget,
    // would only work in RCP, not plain SWT.
    // Who then receives the drop events would depend on the order
    // in which drop targets are added and which transfers they use.
    // 
    // Option 3)
    // Hack around the SWT limitation by fetching
    // the FXCanva's DropTarget via
    // control.getData(DND.DROP_TARGET_KEY);
    // and disposing it.
    // Checking the source code for the SWT DropTarget
    // on Windows, Mac and Linux for SWT 3.104,
    // this detaches the DropTarget and allows us
    // to add our own.
    final DropTarget old = (DropTarget) canvas.getData(DND.DROP_TARGET_KEY);
    if (old != null)
        old.dispose();
    if (canvas.getData(DND.DROP_TARGET_KEY) != null)
        throw new IllegalStateException("Cannot remove FXCanvas's DropTarget");
    // Allow dropped arrays
    new ControlSystemDropTarget(canvas, ChannelInfo[].class, ProcessVariable[].class, ArchiveDataSource[].class, File.class, String.class) {

        @Override
        public void handleDrop(final Object item) {
            final PlotListener lst = plot.getListener();
            if (lst == null)
                return;
            if (item instanceof ChannelInfo[]) {
                final ChannelInfo[] channels = (ChannelInfo[]) item;
                final int N = channels.length;
                final ProcessVariable[] pvs = new ProcessVariable[N];
                final ArchiveDataSource[] archives = new ArchiveDataSource[N];
                for (int i = 0; i < N; ++i) {
                    pvs[i] = channels[i].getProcessVariable();
                    archives[i] = channels[i].getArchiveDataSource();
                }
                lst.droppedPVNames(pvs, archives);
            } else if (item instanceof ProcessVariable[]) {
                final ProcessVariable[] pvs = (ProcessVariable[]) item;
                lst.droppedPVNames(pvs, null);
            } else if (item instanceof ArchiveDataSource[]) {
                final ArchiveDataSource[] archives = (ArchiveDataSource[]) item;
                lst.droppedPVNames(null, archives);
            } else if (item instanceof String) {
                final List<String> pvs = new ArrayList<>();
                // Allow passing in many names, assuming that white space separates them
                // $NON-NLS-1$
                final String[] names = ((String) item).split("[\\r\\n\\t ]+");
                for (String one_name : names) {
                    // Might also have received "[pv1, pv2, pv2]", turn that into "pv1", "pv2", "pv3"
                    String suggestion = one_name;
                    if (suggestion.startsWith("["))
                        suggestion = suggestion.substring(1);
                    if (suggestion.endsWith("]") && !suggestion.contains("["))
                        suggestion = suggestion.substring(0, suggestion.length() - 1);
                    if (suggestion.endsWith(","))
                        suggestion = suggestion.substring(0, suggestion.length() - 1);
                    pvs.add(suggestion);
                }
                if (pvs.size() > 0)
                    lst.droppedNames(pvs.toArray(new String[pvs.size()]));
            } else if (item instanceof String[]) {
                // File names arrive as String[]...
                final String[] files = (String[]) item;
                try {
                    for (String filename : files) lst.droppedFilename(filename);
                } catch (Exception ex) {
                    ExceptionDetailsErrorDialog.openError(canvas.getShell(), Messages.Error, ex);
                }
            }
        }
    };
}
Also used : PlotListener(org.csstudio.trends.databrowser3.ui.PlotListener) ProcessVariable(org.csstudio.csdata.ProcessVariable) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) ControlSystemDropTarget(org.csstudio.ui.util.dnd.ControlSystemDropTarget) PartInitException(org.eclipse.ui.PartInitException) List(java.util.List) ArrayList(java.util.ArrayList) ControlSystemDropTarget(org.csstudio.ui.util.dnd.ControlSystemDropTarget) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 8 with ChannelInfo

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

the class SearchView method searchForChannels.

/**
 * Search selected archives for channels, updating the
 *  <code>channel_table</code> with the result
 *  @see #channel_table
 */
private void searchForChannels() {
    final ArchiveDataSource[] archives = archive_gui.getSelectedArchives();
    if (archives == null)
        return;
    final String pattern_txt = pattern.getText().trim();
    // Warn when searching ALL channels
    if (pattern_txt.length() <= 0) {
        MessageDialog.openInformation(pattern.getShell(), Messages.Search, Messages.SearchPatternEmptyMessage);
        // Aborted, move focus to search pattern
        pattern.setFocus();
        return;
    }
    new SearchJob(archives, pattern_txt, !regex.getSelection()) {

        @Override
        protected void receivedChannelInfos(final ChannelInfo[] channels) {
            displayChannelInfos(channels);
        }

        @Override
        protected void archiveServerError(final String url, final Exception ex) {
            handleServerError(url, ex);
        }
    }.schedule();
}
Also used : ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) SearchJob(org.csstudio.trends.databrowser3.archive.SearchJob) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) PartInitException(org.eclipse.ui.PartInitException) CommandException(org.eclipse.core.commands.common.CommandException)

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