Search in sources :

Example 1 with EmbeddedDisplayWidget

use of org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget 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)

Example 2 with EmbeddedDisplayWidget

use of org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget in project org.csstudio.display.builder by kasemir.

the class Widget method getTopDisplayModel.

/**
 * Locate top display model.
 *
 *  <p>For embedded displays, <code>getDisplayModel</code>
 *  only provides the embedded model.
 *  This method traverses up via the {@link EmbeddedDisplayWidget}
 *  to the top-level display model.
 *
 *  @return Top-level {@link DisplayModel} for widget
 *  @throws Exception if widget is not part of a model
 */
public final DisplayModel getTopDisplayModel() throws Exception {
    DisplayModel model = getDisplayModel();
    while (true) {
        final Widget embedder = model.getUserData(DisplayModel.USER_DATA_EMBEDDING_WIDGET);
        if (embedder == null)
            return model;
        model = embedder.getTopDisplayModel();
    }
}
Also used : EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)

Example 3 with EmbeddedDisplayWidget

use of org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget in project org.csstudio.display.builder by kasemir.

the class DisplayEditorPart method createContextMenu.

private Menu createContextMenu(final Control parent) {
    final MenuManager mm = new MenuManager();
    final Action execute = new ExecuteDisplayAction(this);
    final MenuManager morph = new MorphWidgetMenuSupport(editor).getMenuManager();
    final ImageDescriptor icon = AbstractUIPlugin.imageDescriptorFromPlugin(ModelPlugin.ID, "icons/display.png");
    final Action perspective = new OpenPerspectiveAction(icon, Messages.OpenEditorPerspective, EditorPerspective.ID);
    final Action reload = new ReloadDisplayAction(this);
    mm.setRemoveAllWhenShown(true);
    mm.addMenuListener(manager -> {
        manager.add(execute);
        final List<Widget> selection = editor.getWidgetSelectionHandler().getSelection();
        if (!selection.isEmpty()) {
            if (selection.size() >= 1)
                manager.add(new CreateGroupAction(editor, selection));
            if (selection.size() == 1 && selection.get(0) instanceof GroupWidget)
                manager.add(new RemoveGroupAction(editor, (GroupWidget) selection.get(0)));
            if (selection.size() == 1 && selection.get(0) instanceof EmbeddedDisplayWidget)
                manager.add(new EditEmbeddedDisplayAction((EmbeddedDisplayWidget) selection.get(0)));
            manager.add(morph);
        }
        manager.add(reload);
        final DisplayModel model = editor.getModel();
        if (model != null && !model.isClassModel()) {
            manager.add(new ReloadClassesAction(this));
            if (selection.isEmpty())
                manager.add(new SetDisplaySize(editor));
        }
        manager.add(perspective);
    });
    return mm.createContextMenu(parent);
}
Also used : OpenPerspectiveAction(org.csstudio.ui.util.perspective.OpenPerspectiveAction) IAction(org.eclipse.jface.action.IAction) RedoAction(org.csstudio.display.builder.editor.rcp.actions.RedoAction) CutDeleteAction(org.csstudio.display.builder.editor.rcp.actions.CutDeleteAction) PasteAction(org.csstudio.display.builder.editor.rcp.actions.PasteAction) OpenPerspectiveAction(org.csstudio.ui.util.perspective.OpenPerspectiveAction) ReloadDisplayAction(org.csstudio.display.builder.editor.rcp.actions.ReloadDisplayAction) RemoveGroupAction(org.csstudio.display.builder.editor.rcp.actions.RemoveGroupAction) ExecuteDisplayAction(org.csstudio.display.builder.editor.rcp.actions.ExecuteDisplayAction) CreateGroupAction(org.csstudio.display.builder.editor.rcp.actions.CreateGroupAction) SelectAllAction(org.csstudio.display.builder.editor.rcp.actions.SelectAllAction) CopyAction(org.csstudio.display.builder.editor.rcp.actions.CopyAction) Action(org.eclipse.jface.action.Action) ReloadClassesAction(org.csstudio.display.builder.editor.rcp.actions.ReloadClassesAction) UndoAction(org.csstudio.display.builder.editor.rcp.actions.UndoAction) CreateGroupAction(org.csstudio.display.builder.editor.rcp.actions.CreateGroupAction) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) Widget(org.csstudio.display.builder.model.Widget) ReloadClassesAction(org.csstudio.display.builder.editor.rcp.actions.ReloadClassesAction) ReloadDisplayAction(org.csstudio.display.builder.editor.rcp.actions.ReloadDisplayAction) ExecuteDisplayAction(org.csstudio.display.builder.editor.rcp.actions.ExecuteDisplayAction) DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) MenuManager(org.eclipse.jface.action.MenuManager) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) RemoveGroupAction(org.csstudio.display.builder.editor.rcp.actions.RemoveGroupAction) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget)

Example 4 with EmbeddedDisplayWidget

use of org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget in project org.csstudio.display.builder by kasemir.

the class WidgetTransfer method installEmbeddedDisplayWidgetFromFile.

/**
 * @param display_file Display file for which to create an
 *            {@link EmbeddedDisplayWidget}.
 * @param selection_tracker Used to get the grid steps from its model to be
 *            used
 *            in offsetting multiple widgets.
 * @param widgets The container of the created widgets.
 * @param updates Updates to perform on widgets
 */
private static void installEmbeddedDisplayWidgetFromFile(final String display_file, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets, final List<Runnable> updates) {
    logger.log(Level.FINE, "Creating EmbeddedDisplayWidget for {0}", display_file);
    final DisplayModel model = selection_tracker.getModel();
    final EmbeddedDisplayWidget widget = (EmbeddedDisplayWidget) EmbeddedDisplayWidget.WIDGET_DESCRIPTOR.createWidget();
    widget.propFile().setValue(display_file);
    // Offset multiple widgets by grid size
    final int index = widgets.size();
    widget.propX().setValue(model.propGridStepX().getValue() * index);
    widget.propY().setValue(model.propGridStepY().getValue() * index);
    widgets.add(widget);
    updates.add(() -> updateEmbeddedDisplayWidget(widget));
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)

Example 5 with EmbeddedDisplayWidget

use of org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget in project org.csstudio.display.builder by kasemir.

the class OpenDisplayInEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final RuntimeViewPart view = RuntimeViewPart.getActiveDisplay();
    if (view != null) {
        try {
            final Widget widget = view.getActiveWidget();
            final DisplayModel model = widget.getDisplayModel();
            final String path;
            // Options:
            if (widget instanceof EmbeddedDisplayWidget) {
                // c) Widget is an embedded widget.
                // -> User probably wanted to edit the _body_ of that embedded widget
                final EmbeddedDisplayWidget embedded = (EmbeddedDisplayWidget) widget;
                path = ModelResourceUtil.resolveResource(model, embedded.propFile().getValue());
            } else {
                // b) Widget is one of the widgets in the body of an embedded widget:
                // -> Get the body display, _not_ the top-level display
                // a) Widget is in the top-level display, or the display itself:
                // -> Use that that
                path = model.getUserData(DisplayModel.USER_DATA_INPUT_FILE);
            }
            try {
                open(path);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Cannot open in editor: " + path, ex);
            }
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Cannot open display in editor", ex);
        }
    }
    return null;
}
Also used : RuntimeViewPart(org.csstudio.display.builder.rcp.RuntimeViewPart) DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) Widget(org.csstudio.display.builder.model.Widget) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

EmbeddedDisplayWidget (org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)5 DisplayModel (org.csstudio.display.builder.model.DisplayModel)3 Widget (org.csstudio.display.builder.model.Widget)2 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 CopyAction (org.csstudio.display.builder.editor.rcp.actions.CopyAction)1 CreateGroupAction (org.csstudio.display.builder.editor.rcp.actions.CreateGroupAction)1 CutDeleteAction (org.csstudio.display.builder.editor.rcp.actions.CutDeleteAction)1 ExecuteDisplayAction (org.csstudio.display.builder.editor.rcp.actions.ExecuteDisplayAction)1 PasteAction (org.csstudio.display.builder.editor.rcp.actions.PasteAction)1 RedoAction (org.csstudio.display.builder.editor.rcp.actions.RedoAction)1 ReloadClassesAction (org.csstudio.display.builder.editor.rcp.actions.ReloadClassesAction)1 ReloadDisplayAction (org.csstudio.display.builder.editor.rcp.actions.ReloadDisplayAction)1 RemoveGroupAction (org.csstudio.display.builder.editor.rcp.actions.RemoveGroupAction)1 SelectAllAction (org.csstudio.display.builder.editor.rcp.actions.SelectAllAction)1 UndoAction (org.csstudio.display.builder.editor.rcp.actions.UndoAction)1 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)1