Search in sources :

Example 6 with AppDescriptor

use of org.phoebus.framework.spi.AppDescriptor in project phoebus by ControlSystemStudio.

the class MementoHelper method restoreDockItem.

/**
 * Restore a DockItem and AppInstance from memento
 *
 *  <p>Create the {@link AppInstance} from the application name
 *  stored in memento.
 *  For resource-based application, check for saved resource (input),
 *  then allow application to restore details.
 *
 *  @param item_memento
 *  @param pane
 *  @return <code>true</code> if a tab was restored
 */
private static boolean restoreDockItem(final MementoTree item_memento, final DockPane pane) {
    final String app_id = item_memento.getString(DockItem.KEY_APPLICATION).orElse(null);
    if (app_id == null)
        return false;
    final AppDescriptor app = ApplicationService.findApplication(app_id);
    if (app == null) {
        logger.log(Level.WARNING, "No application found to restore " + app_id);
        return false;
    }
    // If dock item was restored within a SplitDock,
    // its Scene is only set on a later UI tick when the SplitPane is rendered.
    // Defer restoring the application so that DockPane.autoHideTabs can locate the tab header,
    // and for DockPane.setActiveDockPane(pane) to actually return the pane
    // that we're about to set via DockPane.setActiveDockPane(), which it won't do
    // for a pane without a Scene.
    pane.deferUntilInScene(scene -> restoreApplication(item_memento, pane, app));
    return true;
}
Also used : AppDescriptor(org.phoebus.framework.spi.AppDescriptor)

Example 7 with AppDescriptor

use of org.phoebus.framework.spi.AppDescriptor in project phoebus by ControlSystemStudio.

the class Launcher method main.

public static void main(final String[] original_args) throws Exception {
    LogManager.getLogManager().readConfiguration(Launcher.class.getResourceAsStream("/logging.properties"));
    final Logger logger = Logger.getLogger(Launcher.class.getName());
    // Can't change default charset, but warn if it's not UTF-8.
    // Config files for displays, data browser etc. explicitly use XMLUtil.ENCODING = "UTF-8".
    // EPICS database files, strings in Channel Access or PVAccess are expected to use UTF-8.
    // New Java API like java.nio.file.Files defaults to UTF-8,
    // but library code including JCA simply calls new String(byte[]).
    // The underlying Charset.defaultCharset() checks "file.encoding",
    // but this happens at an early stage of VM startup.
    // Calling System.setPropertu("file.encoding", "UTF-8") in main() is already too late,
    // must add -D"file.encoding=UTF-8" to java start up or JAVA_TOOL_OPTIONS.
    final Charset cs = Charset.defaultCharset();
    if (!"UTF-8".equalsIgnoreCase(cs.displayName())) {
        logger.severe("Default charset is " + cs.displayName() + " instead of UTF-8.");
        logger.severe("Add    -D\"file.encoding=UTF-8\"    to java command line or JAVA_TOOL_OPTIONS");
    }
    Locations.initialize();
    // Check for site-specific settings.ini bundled into distribution
    // before potentially adding command-line settings.
    final File site_settings = new File(Locations.install(), "settings.ini");
    if (site_settings.canRead()) {
        logger.log(Level.CONFIG, "Loading settings from " + site_settings);
        PropertyPreferenceLoader.load(new FileInputStream(site_settings));
    }
    // Handle arguments, potentially not even starting the UI
    final List<String> args = new ArrayList<>(List.of(original_args));
    final Iterator<String> iter = args.iterator();
    int port = -1;
    try {
        while (iter.hasNext()) {
            final String cmd = iter.next();
            if (cmd.startsWith("-h")) {
                help();
                return;
            }
            if (cmd.equals("-splash")) {
                iter.remove();
                Preferences.userNodeForPackage(org.phoebus.ui.Preferences.class).putBoolean(org.phoebus.ui.Preferences.SPLASH, true);
            } else if (cmd.equals("-nosplash")) {
                iter.remove();
                Preferences.userNodeForPackage(org.phoebus.ui.Preferences.class).putBoolean(org.phoebus.ui.Preferences.SPLASH, false);
            } else if (cmd.equals("-logging")) {
                if (!iter.hasNext())
                    throw new Exception("Missing -logging file name");
                iter.remove();
                final String filename = iter.next();
                iter.remove();
                LogManager.getLogManager().readConfiguration(new FileInputStream(filename));
            } else if (cmd.equals("-settings")) {
                if (!iter.hasNext())
                    throw new Exception("Missing -settings file name");
                iter.remove();
                final String filename = iter.next();
                iter.remove();
                logger.info("Loading settings from " + filename);
                if (filename.endsWith(".xml"))
                    Preferences.importPreferences(new FileInputStream(filename));
                else
                    PropertyPreferenceLoader.load(new FileInputStream(filename));
            } else if (cmd.equals("-export_settings")) {
                if (!iter.hasNext())
                    throw new Exception("Missing -export_settings file name");
                iter.remove();
                final String filename = iter.next();
                iter.remove();
                System.out.println("Exporting settings to " + filename);
                Preferences.userRoot().node("org/phoebus").exportSubtree(new FileOutputStream(filename));
                return;
            } else if (cmd.equals("-server")) {
                if (!iter.hasNext())
                    throw new Exception("Missing -server port");
                iter.remove();
                port = Integer.parseInt(iter.next());
                iter.remove();
            } else if (cmd.equals("-list")) {
                iter.remove();
                final Collection<AppDescriptor> apps = ApplicationService.getApplications();
                System.out.format("Name                 Description          File Extensions\n");
                for (AppDescriptor app : apps) {
                    if (app instanceof AppResourceDescriptor) {
                        final AppResourceDescriptor app_res = (AppResourceDescriptor) app;
                        System.out.format("%-20s %-20s %s\n", "'" + app.getName() + "'", app.getDisplayName(), app_res.supportedFileExtentions().stream().collect(Collectors.joining(", ")));
                    } else
                        System.out.format("%-20s %s\n", "'" + app.getName() + "'", app.getDisplayName());
                }
                return;
            } else if (cmd.equals("-main")) {
                iter.remove();
                if (!iter.hasNext())
                    throw new Exception("Missing -main name");
                final String main = iter.next();
                iter.remove();
                // Locate Main class and its main()
                final Class<?> main_class = Class.forName(main);
                final Method main_method = main_class.getDeclaredMethod("main", String[].class);
                // Collect remaining arguments
                final List<String> new_args = new ArrayList<>();
                iter.forEachRemaining(new_args::add);
                main_method.invoke(null, new Object[] { new_args.toArray(new String[new_args.size()]) });
                return;
            }
        }
    } catch (Exception ex) {
        help();
        System.out.println();
        ex.printStackTrace();
        return;
    }
    logger.info("Phoebus (PID " + ProcessHandle.current().pid() + ")");
    // instead of starting a new application
    if (port > 0) {
        final ApplicationServer server = ApplicationServer.create(port);
        if (!server.isServer()) {
            server.sendArguments(args);
            return;
        }
    }
    // Remaining args passed on
    Application.launch(PhoebusApplication.class, args.toArray(new String[args.size()]));
}
Also used : ArrayList(java.util.ArrayList) Logger(java.util.logging.Logger) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor) AppDescriptor(org.phoebus.framework.spi.AppDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) Preferences(java.util.prefs.Preferences) Charset(java.nio.charset.Charset) Method(java.lang.reflect.Method) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) ApplicationServer(org.phoebus.ui.application.ApplicationServer) File(java.io.File)

Aggregations

AppDescriptor (org.phoebus.framework.spi.AppDescriptor)7 File (java.io.File)3 URI (java.net.URI)3 List (java.util.List)3 Logger (java.util.logging.Logger)3 AppResourceDescriptor (org.phoebus.framework.spi.AppResourceDescriptor)3 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 Level (java.util.logging.Level)2 Collectors (java.util.stream.Collectors)2 Dialog (javafx.scene.control.Dialog)2 Stage (javafx.stage.Stage)2 ResourceParser (org.phoebus.framework.util.ResourceParser)2 ApplicationService (org.phoebus.framework.workbench.ApplicationService)2 Preferences (org.phoebus.ui.Preferences)2 ListPickerDialog (org.phoebus.ui.dialog.ListPickerDialog)2 FileOutputStream (java.io.FileOutputStream)1 WeakReference (java.lang.ref.WeakReference)1 Method (java.lang.reflect.Method)1