use of org.csstudio.display.builder.model.widgets.WebBrowserWidget in project org.csstudio.display.builder by kasemir.
the class WidgetTransfer method installWidgetsFromURL.
private static void installWidgetsFromURL(final DragEvent event, final List<Widget> widgets, final List<Runnable> updates) {
final String choice;
final Dragboard db = event.getDragboard();
String url = db.getUrl();
// Fix URL, which on linux can contain the file name twice:
// "http://some/path/to/file.xyz\nfile.xyz"
int sep = url.indexOf('\n');
if (sep > 0) {
url = url.substring(0, sep);
}
// Check URL's extension
sep = url.lastIndexOf('.');
final String ext = sep > 0 ? url.substring(1 + sep).toUpperCase() : null;
if (EMBEDDED_FILE_EXTENSIONS.contains(ext)) {
choice = EmbeddedDisplayWidget.WIDGET_DESCRIPTOR.getName();
} else if (IMAGE_FILE_EXTENSIONS.contains(ext)) {
choice = PictureWidget.WIDGET_DESCRIPTOR.getName();
} else {
// Prompt user
final List<String> choices = Arrays.asList(LabelWidget.WIDGET_DESCRIPTOR.getName(), EmbeddedDisplayWidget.WIDGET_DESCRIPTOR.getName(), PictureWidget.WIDGET_DESCRIPTOR.getName(), WebBrowserWidget.WIDGET_DESCRIPTOR.getName());
final ChoiceDialog<String> dialog = new ChoiceDialog<>(choices.get(3), choices);
// Position dialog
dialog.setX(event.getScreenX());
dialog.setY(event.getScreenY());
dialog.setTitle(Messages.WT_FromURL_dialog_title);
dialog.setHeaderText(NLS.bind(Messages.WT_FromURL_dialog_headerFMT, reduceString(url)));
dialog.setContentText(Messages.WT_FromURL_dialog_content);
final Optional<String> result = dialog.showAndWait();
if (result.isPresent()) {
choice = result.get();
} else {
return;
}
}
if (LabelWidget.WIDGET_DESCRIPTOR.getName().equals(choice)) {
logger.log(Level.FINE, "Creating LabelWidget for {0}", url);
final LabelWidget widget = (LabelWidget) LabelWidget.WIDGET_DESCRIPTOR.createWidget();
widget.propText().setValue(url);
widgets.add(widget);
} else if (WebBrowserWidget.WIDGET_DESCRIPTOR.getName().equals(choice)) {
logger.log(Level.FINE, "Creating WebBrowserWidget for {0}", url);
final WebBrowserWidget widget = (WebBrowserWidget) WebBrowserWidget.WIDGET_DESCRIPTOR.createWidget();
widget.propWidgetURL().setValue(url);
widgets.add(widget);
} else if (PictureWidget.WIDGET_DESCRIPTOR.getName().equals(choice)) {
logger.log(Level.FINE, "Creating PictureWidget for {0}", url);
final PictureWidget widget = (PictureWidget) PictureWidget.WIDGET_DESCRIPTOR.createWidget();
widget.propFile().setValue(url);
widgets.add(widget);
updates.add(() -> updatePictureWidgetSize(widget));
} else if (EmbeddedDisplayWidget.WIDGET_DESCRIPTOR.getName().equals(choice)) {
logger.log(Level.FINE, "Creating EmbeddedDisplayWidget for {0}", url);
EmbeddedDisplayWidget widget = (EmbeddedDisplayWidget) EmbeddedDisplayWidget.WIDGET_DESCRIPTOR.createWidget();
widget.propFile().setValue(url);
widgets.add(widget);
updates.add(() -> updateEmbeddedDisplayWidget(widget));
}
}
Aggregations