use of org.phoebus.framework.spi.AppDescriptor in project phoebus by ControlSystemStudio.
the class PhoebusApplication method findApplication.
/**
* @param resource Resource
* @param prompt Prompt if there are multiple applications, or use first one?
* @return Application for opening resource, or <code>null</code> if none found
*/
private AppResourceDescriptor findApplication(final URI resource, final boolean prompt) {
// Does resource request a specific application?
final String app_name = ResourceParser.getAppName(resource);
if (app_name != null) {
final AppDescriptor app = ApplicationService.findApplication(app_name);
if (app == null) {
logger.log(Level.WARNING, "Unknown application '" + app_name + "'");
return null;
}
if (app instanceof AppResourceDescriptor)
return (AppResourceDescriptor) app;
else {
logger.log(Level.WARNING, "'" + app_name + "' application does not handle resources");
return null;
}
}
// Check all applications
final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
if (applications.isEmpty()) {
logger.log(Level.WARNING, "No application found for opening " + resource);
return null;
}
// Only one app?
if (applications.size() == 1)
return applications.get(0);
// Pick default application based on preference setting?
if (!prompt) {
for (AppResourceDescriptor app : applications) for (String part : Preferences.default_apps) if (app.getName().contains(part))
return app;
// , not just the first one, which may be undefined
logger.log(Level.WARNING, "No default application found for opening " + resource + ", using first one");
return applications.get(0);
}
// Prompt user which application to use for this resource
final List<String> options = applications.stream().map(app -> app.getDisplayName()).collect(Collectors.toList());
final Dialog<String> which = new ListPickerDialog(main_stage.getScene().getRoot(), options, default_application);
which.setTitle(Messages.OpenTitle);
which.setHeaderText(Messages.OpenHdr + resource);
which.setWidth(300);
which.setHeight(300);
final Optional<String> result = which.showAndWait();
if (!result.isPresent())
return null;
default_application = result.get();
return applications.get(options.indexOf(result.get()));
}
use of org.phoebus.framework.spi.AppDescriptor in project phoebus by ControlSystemStudio.
the class PhoebusApplication method startApplications.
/**
* Start all applications
*
* @param monitor
*/
private void startApplications(final JobMonitor monitor) {
final Collection<AppDescriptor> apps = ApplicationService.getApplications();
monitor.beginTask(Messages.MonitorTaskApps, apps.size());
for (AppDescriptor app : apps) {
monitor.updateTaskName(Messages.MonitorTaskStarting + app.getDisplayName());
try {
app.start();
} catch (Throwable ex) {
logger.log(Level.SEVERE, app.getDisplayName() + " startup failed", ex);
}
monitor.worked(1);
}
}
use of org.phoebus.framework.spi.AppDescriptor in project phoebus by ControlSystemStudio.
the class ApplicationLauncherService method findApplication.
/**
* Locate suitable application
*
* @param resource
* Resource {@link URI}
* @param prompt
* Prompt if there are multiple applications, or use first one?
* @param stage
* If prompt is enabled, a selection dialog will be launched
* positioned next to the provided stage. If <code>null</code> then the
* default or first application will be used
* @return Application for opening resource, or <code>null</code> if none
* found
*/
public static AppResourceDescriptor findApplication(final URI resource, final boolean prompt, final Stage stage) {
// Does resource request a specific application?
final String app_name = ResourceParser.getAppName(resource);
if (app_name != null) {
final AppDescriptor app = ApplicationService.findApplication(app_name);
if (app == null) {
logger.log(Level.WARNING, "Unknown application '" + app_name + "'");
return null;
}
if (app instanceof AppResourceDescriptor)
return (AppResourceDescriptor) app;
else {
logger.log(Level.WARNING, "'" + app_name + "' application does not handle resources");
return null;
}
}
// Check all applications
final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
if (applications.isEmpty()) {
logger.log(Level.INFO, "No application found for opening " + resource);
return null;
}
// Only one app?
if (applications.size() == 1)
return applications.get(0);
// Pick default application based on preference setting?
if (!prompt || stage == null) {
for (AppResourceDescriptor app : applications) for (String part : Preferences.default_apps) if (app.getName().contains(part))
return app;
// , not just the first one, which may be undefined
final AppResourceDescriptor first = applications.get(0);
logger.log(Level.WARNING, "No default application found for opening " + resource + ", using first one, \"" + first.getDisplayName() + "\"");
return first;
}
// Prompt user which application to use for this resource
final List<String> options = applications.stream().map(app -> app.getDisplayName()).collect(Collectors.toList());
final Dialog<String> which = new ListPickerDialog(stage.getScene().getRoot(), options, null);
which.setTitle(Messages.OpenTitle);
which.setHeaderText(Messages.OpenHdr + resource);
which.setWidth(300);
which.setHeight(300);
final Optional<String> result = which.showAndWait();
if (!result.isPresent())
return null;
return applications.get(options.indexOf(result.get()));
}
use of org.phoebus.framework.spi.AppDescriptor in project phoebus by ControlSystemStudio.
the class ApplicationLauncherService method launchApp.
/**
* Launch application
*
* @param appName name of the application to be launched
*/
public static void launchApp(final String appName) {
final AppDescriptor app = ApplicationService.findApplication(appName);
if (app == null) {
logger.log(Level.SEVERE, "Unknown application '" + appName + "'");
return;
}
app.create();
}
use of org.phoebus.framework.spi.AppDescriptor in project phoebus by ControlSystemStudio.
the class FileTreeCell method lookup_icon.
private void lookup_icon(final File file) {
final URI resource = ResourceParser.getURI(file);
final AppDescriptor app = ApplicationLauncherService.findApplication(resource, false, null);
if (app == null)
return;
final URL icon_url = app.getIconURL();
if (icon_url == null)
return;
final ImageView icon = ImageCache.getImageView(icon_url);
if (icon != null)
Platform.runLater(() -> setGraphic(icon));
}
Aggregations