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