use of org.cytoscape.app.event.AppsFinishedStartingEvent in project cytoscape-impl by cytoscape.
the class CyActivator method start.
@Override
public void start(BundleContext bc) {
final CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
CommandTunableInterceptorImpl interceptor = new CommandTunableInterceptorImpl();
StringTunableHandlerFactory<FileTunableHandler> fileTHF = new SimpleStringTunableHandlerFactory<>(FileTunableHandler.class, File.class);
StringTunableHandlerFactory<IntTunableHandler> intTHF = new SimpleStringTunableHandlerFactory<>(IntTunableHandler.class, Integer.class, int.class);
StringTunableHandlerFactory<DoubleTunableHandler> doubleTHF = new SimpleStringTunableHandlerFactory<>(DoubleTunableHandler.class, Double.class, double.class);
StringTunableHandlerFactory<FloatTunableHandler> floatTHF = new SimpleStringTunableHandlerFactory<>(FloatTunableHandler.class, Float.class, float.class);
StringTunableHandlerFactory<LongTunableHandler> longTHF = new SimpleStringTunableHandlerFactory<>(LongTunableHandler.class, Long.class, long.class);
StringTunableHandlerFactory<BooleanTunableHandler> booleanTHF = new SimpleStringTunableHandlerFactory<>(BooleanTunableHandler.class, Boolean.class, boolean.class);
StringTunableHandlerFactory<StringTunableHandlerImpl> stringTHF = new SimpleStringTunableHandlerFactory<>(StringTunableHandlerImpl.class, String.class);
StringTunableHandlerFactory<BoundedIntTunableHandler> boundedIntTHF = new SimpleStringTunableHandlerFactory<>(BoundedIntTunableHandler.class, BoundedInteger.class);
StringTunableHandlerFactory<BoundedDoubleTunableHandler> boundedDoubleTHF = new SimpleStringTunableHandlerFactory<>(BoundedDoubleTunableHandler.class, BoundedDouble.class);
StringTunableHandlerFactory<BoundedFloatTunableHandler> boundedFloatTHF = new SimpleStringTunableHandlerFactory<>(BoundedFloatTunableHandler.class, BoundedFloat.class);
StringTunableHandlerFactory<BoundedLongTunableHandler> boundedLongTHF = new SimpleStringTunableHandlerFactory<>(BoundedLongTunableHandler.class, BoundedLong.class);
StringTunableHandlerFactory<URLTunableHandler> urlTHF = new SimpleStringTunableHandlerFactory<>(URLTunableHandler.class, URL.class);
StringTunableHandlerFactory<ListSingleTunableHandler> listSingleTHF = new SimpleStringTunableHandlerFactory<>(ListSingleTunableHandler.class, ListSingleSelection.class);
StringTunableHandlerFactory<ListMultipleTunableHandler> listMultipleTHF = new SimpleStringTunableHandlerFactory<>(ListMultipleTunableHandler.class, ListMultipleSelection.class);
registerService(bc, fileTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, intTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, doubleTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, floatTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, longTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, booleanTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, stringTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, boundedIntTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, boundedDoubleTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, boundedFloatTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, boundedLongTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, urlTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, listSingleTHF, StringTunableHandlerFactory.class, new Properties());
registerService(bc, listMultipleTHF, StringTunableHandlerFactory.class, new Properties());
StringToModel stm = new StringToModelImpl(serviceRegistrar);
registerService(bc, stm, StringToModel.class, new Properties());
CyIdentifiableStringTunableHandlerFactory<CyNetworkTunableHandler> networkTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, CyNetworkTunableHandler.class, CyNetwork.class);
registerService(bc, networkTHF, StringTunableHandlerFactory.class, new Properties());
CyIdentifiableStringTunableHandlerFactory<CyNetworkViewTunableHandler> networkViewTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, CyNetworkViewTunableHandler.class, CyNetworkView.class);
registerService(bc, networkViewTHF, StringTunableHandlerFactory.class, new Properties());
CyIdentifiableStringTunableHandlerFactory<CyTableTunableHandler> tableTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, CyTableTunableHandler.class, CyTable.class);
registerService(bc, tableTHF, StringTunableHandlerFactory.class, new Properties());
CyIdentifiableStringTunableHandlerFactory<NodeListTunableHandler> nodeListTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, NodeListTunableHandler.class, NodeList.class);
registerService(bc, nodeListTHF, StringTunableHandlerFactory.class, new Properties());
CyIdentifiableStringTunableHandlerFactory<EdgeListTunableHandler> edgeListTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, EdgeListTunableHandler.class, EdgeList.class);
registerService(bc, edgeListTHF, StringTunableHandlerFactory.class, new Properties());
CyIdentifiableStringTunableHandlerFactory<RowListTunableHandler> rowListTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, RowListTunableHandler.class, RowList.class);
registerService(bc, rowListTHF, StringTunableHandlerFactory.class, new Properties());
BasicArgHandlerFactory argHandlerFactory = new BasicArgHandlerFactory();
registerService(bc, argHandlerFactory, ArgHandlerFactory.class, new Properties());
ArgRecorder argRec = new ArgRecorder();
registerServiceListener(bc, argRec::addTunableHandlerFactory, argRec::removeTunableHandlerFactory, ArgHandlerFactory.class);
AvailableCommandsImpl availableCommandsImpl = new AvailableCommandsImpl(argRec, serviceRegistrar);
registerService(bc, availableCommandsImpl, AvailableCommands.class, new Properties());
registerServiceListener(bc, availableCommandsImpl::addTaskFactory, availableCommandsImpl::removeTaskFactory, TaskFactory.class);
registerServiceListener(bc, availableCommandsImpl::addNetworkTaskFactory, availableCommandsImpl::removeNetworkTaskFactory, NetworkTaskFactory.class);
registerServiceListener(bc, availableCommandsImpl::addNetworkViewTaskFactory, availableCommandsImpl::removeNetworkViewTaskFactory, NetworkViewTaskFactory.class);
registerServiceListener(bc, availableCommandsImpl::addNetworkViewCollectionTaskFactory, availableCommandsImpl::removeNetworkViewCollectionTaskFactory, NetworkViewCollectionTaskFactory.class);
registerServiceListener(bc, availableCommandsImpl::addTableTaskFactory, availableCommandsImpl::removeTableTaskFactory, TableTaskFactory.class);
CommandExecutorImpl commandExecutor = new CommandExecutorImpl(interceptor, availableCommandsImpl, serviceRegistrar);
CommandExecutorTaskFactoryImpl commandExecutorTaskFactory = new CommandExecutorTaskFactoryImpl(commandExecutor, serviceRegistrar);
Properties commandExecutorTaskFactoryProps = new Properties();
commandExecutorTaskFactoryProps.setProperty(ID, "commandExecutorTaskFactory");
registerService(bc, commandExecutorTaskFactory, TaskFactory.class, commandExecutorTaskFactoryProps);
registerService(bc, commandExecutorTaskFactory, CommandExecutorTaskFactory.class, commandExecutorTaskFactoryProps);
registerServiceListener(bc, commandExecutor::addTaskFactory, commandExecutor::removeTaskFactory, TaskFactory.class);
registerServiceListener(bc, commandExecutor::addNetworkTaskFactory, commandExecutor::removeNetworkTaskFactory, NetworkTaskFactory.class);
registerServiceListener(bc, commandExecutor::addNetworkViewTaskFactory, commandExecutor::removeNetworkViewTaskFactory, NetworkViewTaskFactory.class);
registerServiceListener(bc, commandExecutor::addNetworkViewCollectionTaskFactory, commandExecutor::removeNetworkViewCollectionTaskFactory, NetworkViewCollectionTaskFactory.class);
registerServiceListener(bc, commandExecutor::addTableTaskFactory, commandExecutor::removeTableTaskFactory, TableTaskFactory.class);
registerServiceListener(bc, interceptor::addTunableHandlerFactory, interceptor::removeTunableHandlerFactory, StringTunableHandlerFactory.class);
{
Properties props = new Properties();
props.setProperty(COMMAND, "sleep");
props.setProperty(COMMAND_NAMESPACE, "command");
props.setProperty(COMMAND_DESCRIPTION, "Stop command processing for a specified time");
props.setProperty(COMMAND_LONG_DESCRIPTION, "The **sleep** command will pause processing for a period of time as specified by *duration* seconds.");
registerService(bc, new SleepCommandTaskFactory(), TaskFactory.class, props);
}
{
Properties props = new Properties();
props.setProperty(COMMAND, "echo");
props.setProperty(COMMAND_NAMESPACE, "command");
props.setProperty(COMMAND_DESCRIPTION, "Returns the value of the 'message' argument.");
props.setProperty(COMMAND_LONG_DESCRIPTION, "Returns the value of the **message** argument.");
props.setProperty(COMMAND_SUPPORTS_JSON, "true");
props.setProperty(COMMAND_EXAMPLE_JSON, "");
registerService(bc, new EchoCommandTaskFactory(), TaskFactory.class, props);
}
{
Properties props = new Properties();
props.setProperty(COMMAND, "quit");
props.setProperty(COMMAND_NAMESPACE, "command");
props.setProperty(COMMAND_DESCRIPTION, "Exit Cytoscape");
props.setProperty(COMMAND_LONG_DESCRIPTION, "This command causes Cytoscape to exit. It is typically used at the end of a script file");
registerService(bc, new QuitTaskFactory(serviceRegistrar), TaskFactory.class, props);
}
{
Properties props = new Properties();
props.setProperty(PREFERRED_MENU, "Tools");
props.setProperty(TITLE, "Execute Command File...");
props.setProperty(COMMAND, "run");
props.setProperty(COMMAND_NAMESPACE, "command");
props.setProperty(COMMAND_DESCRIPTION, "Run a series of commands from a file");
props.setProperty(IN_MENU_BAR, "true");
props.setProperty(COMMAND_LONG_DESCRIPTION, "The **run** command will execute a command script from the " + "file pointed to by the ``file`` argument, which " + "should contain Cytoscape commands, one per line. " + "Arguments to the " + "script are provided by the *args* argument");
registerService(bc, new RunCommandsTaskFactory(commandExecutorTaskFactory), TaskFactory.class, props);
}
// Get any command line arguments. The "-S" and "-R" are ours
AppsFinishedStartingListener scriptRunner = new AppsFinishedStartingListener() {
public void handleEvent(AppsFinishedStartingEvent event) {
@SuppressWarnings("unchecked") CyProperty<Properties> commandLineProps = getService(bc, CyProperty.class, "(cyPropertyName=commandline.props)");
String scriptFile = commandLineProps.getProperties().getProperty("scriptFile");
if (scriptFile != null) {
TaskIterator tasks = commandExecutorTaskFactory.createTaskIterator(new File(scriptFile), null);
SynchronousTaskManager<?> taskManager = serviceRegistrar.getService(SynchronousTaskManager.class);
taskManager.execute(tasks);
}
}
};
registerService(bc, scriptRunner, AppsFinishedStartingListener.class, new Properties());
}
use of org.cytoscape.app.event.AppsFinishedStartingEvent in project cytoscape-impl by cytoscape.
the class AppManager method initializeApps.
void initializeApps() {
// Move apps from install-on-restart directory to install directory
Set<App> installOnRestartApps = obtainAppsFromDirectory(new File(getInstallOnRestartAppsPath()), false);
for (App app : installOnRestartApps) {
try {
app.moveAppFile(this, new File(getInstalledAppsPath()));
userLogger.info("Moved app '" + app.getAppName() + "' that was marked for install on restart to the 'installed' directory.");
} catch (IOException e) {
userLogger.error("Cannot move app '" + app.getAppName() + "' that was marked for install on restart to the 'installed' directory:", e);
}
}
// Remove the install-on-restart directory after apps were moved
try {
FileUtils.deleteDirectory(new File(getInstallOnRestartAppsPath()));
} catch (IOException e) {
userLogger.warn("Could not delete the directory of apps to install on restart:", e);
}
setupAlterationMonitor();
// Obtain previously disabled, installed apps
Set<App> disabledApps = obtainAppsFromDirectory(new File(getDisabledAppsPath()), false);
for (App app : disabledApps) {
try {
boolean appRegistered = false;
for (App regApp : apps) {
if (regApp.heuristicEquals(app)) {
userLogger.warn("Disabled app '" + app.getAppName() + "' in file '" + app.getAppFile().getAbsolutePath() + "' is equal to an already registered app '" + regApp.getAppName() + "' in file '" + (regApp.getAppFile() == null ? "N/A" : regApp.getAppFile().getAbsolutePath()) + "'");
appRegistered = true;
}
}
if (!appRegistered) {
apps.add(app);
app.setStatus(AppStatus.DISABLED);
} else {
// Delete the copy
userLogger.info("Trying to delete the disabled copy of app '" + app.getAppName() + "' in file '" + app.getAppFile().getAbsolutePath() + "' because another copy exists.");
FileUtils.deleteQuietly(app.getAppFile());
app.setAppFile(null);
}
} catch (Throwable e) {
userLogger.error("Error validating status of the disabled app '" + app.getAppName() + "'.", e);
}
}
Set<App> uninstalledApps = obtainAppsFromDirectory(new File(getUninstalledAppsPath()), false);
for (App app : uninstalledApps) {
try {
boolean appRegistered = false;
for (App regApp : apps) {
if (regApp.heuristicEquals(app)) {
userLogger.warn("Uninstalled app '" + app.getAppName() + "' in file '" + app.getAppFile().getAbsolutePath() + "' is equal to an already registered app '" + regApp.getAppName() + "' in file '" + (regApp.getAppFile() == null ? "N/A" : regApp.getAppFile().getAbsolutePath()) + "'");
appRegistered = true;
}
}
if (!appRegistered) {
apps.add(app);
app.setStatus(AppStatus.UNINSTALLED);
} else {
// Delete the copy
userLogger.info("Trying to delete the uninstalled copy of app '" + app.getAppName() + "' in file '" + app.getAppFile().getAbsolutePath() + "' because another copy exists.");
FileUtils.deleteQuietly(app.getAppFile());
app.setAppFile(null);
}
} catch (Throwable e) {
userLogger.error("Error validating status of the uninstalled app '" + app.getAppName() + "'.", e);
}
}
Set<App> installedApps = obtainAppsFromDirectory(getBundledAppsPath(), true);
installedApps.addAll(obtainAppsFromDirectory(new File(getInstalledAppsPath()), false));
Map<String, App> appsToStart = new HashMap<String, App>();
for (App app : installedApps) {
boolean appRegistered = false;
for (App regApp : apps) {
if (regApp.heuristicEquals(app)) {
userLogger.warn("Installed app '" + app.getAppName() + "' in file '" + app.getAppFile().getAbsolutePath() + "' is equal to an already registered app '" + regApp.getAppName() + "' in file '" + (regApp.getAppFile() == null ? "N/A" : regApp.getAppFile().getAbsolutePath()) + "'");
appRegistered = true;
}
}
if (!appRegistered) {
apps.add(app);
String appName = app.getAppName().toLowerCase();
App currentVersion = appsToStart.get(appName);
if (app.isCompatible(version)) {
if (currentVersion == null) {
appsToStart.put(appName, app);
} else if (compareApps(currentVersion, app) > 0) {
userLogger.warn("Installed app '" + app.getAppName() + "' version " + app.getVersion() + " will override an older version (" + currentVersion.getVersion() + ") that was registered previously.");
appsToStart.put(appName, app);
} else {
userLogger.warn("Installed app '" + app.getAppName() + "' version " + app.getVersion() + " will not be started, because a newer version (" + currentVersion.getVersion() + ") was already registered.");
}
} else {
userLogger.error("Installed app '" + app.getAppName() + "' is not compatible with the running version of Cytoscape (" + version.getVersion() + ").");
}
} else {
// Delete the copy
userLogger.info("Trying to delete the installed copy of app '" + app.getAppName() + "' in file '" + app.getAppFile().getAbsolutePath() + "' because another copy exists.");
FileUtils.deleteQuietly(app.getAppFile());
app.setAppFile(null);
}
}
Set<App> coreAppsToStart = new HashSet<App>();
App coreAppsMetaApp = appsToStart.get("core apps");
if (coreAppsMetaApp != null && coreAppsMetaApp.getDependencies() != null) {
for (App.Dependency dep : coreAppsMetaApp.getDependencies()) {
String appName = dep.getName().toLowerCase();
App app = appsToStart.get(appName);
if (app != null) {
coreAppsToStart.add(app);
}
}
coreAppsToStart.add(coreAppsMetaApp);
}
if (!startApps(coreAppsToStart))
userLogger.warn("One or more core apps failed to load or start");
eventHelper.fireEvent(new CyStartEvent(this));
Set<App> otherAppsToStart = new HashSet<App>(appsToStart.values());
otherAppsToStart.removeAll(coreAppsToStart);
if (!startApps(otherAppsToStart))
userLogger.warn("One or more apps failed to load or start");
eventHelper.fireEvent(new AppsFinishedStartingEvent(this));
}
Aggregations