Search in sources :

Example 1 with WebBrowserWidget

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));
    }
}
Also used : ChoiceDialog(javafx.scene.control.ChoiceDialog) Optional(java.util.Optional) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) PictureWidget(org.csstudio.display.builder.model.widgets.PictureWidget) List(java.util.List) ArrayList(java.util.ArrayList) WebBrowserWidget(org.csstudio.display.builder.model.widgets.WebBrowserWidget) Dragboard(javafx.scene.input.Dragboard)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 ChoiceDialog (javafx.scene.control.ChoiceDialog)1 Dragboard (javafx.scene.input.Dragboard)1 EmbeddedDisplayWidget (org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)1 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)1 PictureWidget (org.csstudio.display.builder.model.widgets.PictureWidget)1 WebBrowserWidget (org.csstudio.display.builder.model.widgets.WebBrowserWidget)1