use of javafx.scene.control.ChoiceDialog 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 javafx.scene.control.ChoiceDialog in project org.csstudio.display.builder by kasemir.
the class WidgetTransfer method installWidgetsFromString.
private static void installWidgetsFromString(final DragEvent event, final String text, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets) {
// Consider each word a separate PV
final String[] words = text.split("[ \n]+");
final boolean multiple = words.length > 1;
final List<WidgetDescriptor> descriptors = getPVWidgetDescriptors();
final List<String> choices = new ArrayList<>(descriptors.size() + (multiple ? 1 : 0));
final String format = multiple ? Messages.WT_FromString_multipleFMT : Messages.WT_FromString_singleFMT;
// Always offer a single LabelWidget for the complete text
final String defaultChoice = NLS.bind(Messages.WT_FromString_singleFMT, LabelWidget.WIDGET_DESCRIPTOR.getName());
choices.add(defaultChoice);
// When multiple words were dropped, offer multiple label widgets
if (multiple) {
choices.add(NLS.bind(Messages.WT_FromString_multipleFMT, LabelWidget.WIDGET_DESCRIPTOR.getName()));
}
choices.addAll(descriptors.stream().map(d -> NLS.bind(format, d.getName())).collect(Collectors.toList()));
Collections.sort(choices);
final ChoiceDialog<String> dialog = new ChoiceDialog<>(defaultChoice, choices);
dialog.setX(event.getScreenX() - 100);
dialog.setY(event.getScreenY() - 200);
dialog.setTitle(Messages.WT_FromString_dialog_title);
dialog.setHeaderText(NLS.bind(Messages.WT_FromString_dialog_headerFMT, reduceStrings(words)));
dialog.setContentText(Messages.WT_FromString_dialog_content);
final Optional<String> result = dialog.showAndWait();
if (!result.isPresent()) {
return;
}
final String choice = result.get();
if (defaultChoice.equals(choice)) {
logger.log(Level.FINE, "Dropped text: created LabelWidget [{0}].", text);
// Not a valid XML. Instantiate a Label object.
final LabelWidget widget = (LabelWidget) LabelWidget.WIDGET_DESCRIPTOR.createWidget();
widget.propText().setValue(text);
widgets.add(widget);
} else {
// Parse selection back into widget descriptor
final MessageFormat msgf = new MessageFormat(format);
final String descriptorName;
try {
descriptorName = msgf.parse(choice)[0].toString();
} catch (Exception ex) {
logger.log(Level.SEVERE, "Cannot parse selected widget type " + choice, ex);
return;
}
WidgetDescriptor descriptor = null;
if (LabelWidget.WIDGET_DESCRIPTOR.getName().equals(descriptorName)) {
descriptor = LabelWidget.WIDGET_DESCRIPTOR;
} else {
descriptor = descriptors.stream().filter(d -> descriptorName.equals(d.getName())).findFirst().orElse(null);
}
if (descriptor == null) {
logger.log(Level.SEVERE, "Cannot obtain widget for " + descriptorName);
return;
}
for (String word : words) {
final Widget widget = descriptor.createWidget();
logger.log(Level.FINE, "Dropped text: created {0} [{1}].", new Object[] { widget.getClass().getSimpleName(), word });
if (widget instanceof PVWidget) {
((PVWidget) widget).propPVName().setValue(word);
} else if (widget instanceof LabelWidget) {
((LabelWidget) widget).propText().setValue(word);
} else {
logger.log(Level.WARNING, "Unexpected widget type [{0}].", widget.getClass().getSimpleName());
}
final int index = widgets.size();
if (index > 0) {
// Place widgets below each other
final Widget previous = widgets.get(index - 1);
int x = previous.propX().getValue();
int y = previous.propY().getValue() + previous.propHeight().getValue();
// Align (if enabled)
final Point2D pos = selection_tracker.gridConstrain(x, y);
widget.propX().setValue((int) pos.getX());
widget.propY().setValue((int) pos.getY());
}
widgets.add(widget);
}
}
}
use of javafx.scene.control.ChoiceDialog in project dwoss by gg-net.
the class ResolveRepaymentAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
Ui.exec(() -> {
Contractors contractors = Ui.progress().call(() -> Dl.local().lookup(CachedMandators.class).loadContractors());
Ui.exec(() -> {
Ui.build().dialog().eval(() -> {
ChoiceDialog<TradeName> dialog = new ChoiceDialog<>(contractors.all().iterator().next(), contractors.all());
dialog.setTitle("Gutschriften");
dialog.setHeaderText(RESOLVE_REPAYMENT.toName());
dialog.setContentText("Lieferant auswählen:");
return dialog;
}).opt().ifPresent(c -> Ui.build().fxml().show(() -> c, ResolveRepaymentController.class));
});
});
}
use of javafx.scene.control.ChoiceDialog in project NMEAParser by tvesalainen.
the class GaugePane method onMousePressed.
private void onMousePressed(MouseEvent e) {
List<I18nString> list = new ArrayList<>();
for (String p : propertyStore.getDisplayProperties()) {
list.add(I18n.getI18nString(p));
}
list.sort(null);
ChoiceDialog<I18nString> dia = new ChoiceDialog<>(list.get(0), list);
ResourceBundle rb = I18n.get();
dia.setTitle(rb.getString("addPropertyTitle"));
dia.setContentText(rb.getString("addPropertyContent"));
dia.setHeaderText(rb.getString("addPropertyHeader"));
dia.showAndWait().ifPresent(response -> bind2(response.getKey()));
}
use of javafx.scene.control.ChoiceDialog in project org.csstudio.display.builder by kasemir.
the class JFXRepresentation method showSelectionDialog.
@Override
public String showSelectionDialog(final Widget widget, final String title, final List<String> options) {
final Node node = JFXBaseRepresentation.getJFXNode(widget);
final CompletableFuture<String> done = new CompletableFuture<>();
execute(() -> {
final ChoiceDialog<String> dialog = new ChoiceDialog<>(null, options);
DialogHelper.positionDialog(dialog, node, -100, -50);
dialog.setHeaderText(title);
final Optional<String> result = dialog.showAndWait();
done.complete(result.orElse(null));
});
try {
return done.get();
} catch (Exception ex) {
logger.log(Level.WARNING, "Selection dialog ('" + title + ", ..') failed", ex);
}
return null;
}
Aggregations