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;
}
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);
}
}
}
};
}
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();
}
Aggregations