@Override public void onCommandsLoaded(CommandsLoadedEvent event) { if (appContext.getWorkspace().getStatus() == RUNNING) { getMachines().stream().map(MachineImpl::getName).forEach(this::restoreProcessesState); } }
/** Does an appropriate action depending on the current workspace's status. */ private void handleWorkspaceStatus() { WorkspaceImpl workspace = appContext.getWorkspace(); if (workspace.getStatus() == STOPPED) { workspaceServiceClient .getSettings() .then( settings -> { if (parseBoolean(settings.getOrDefault(CHE_WORKSPACE_AUTO_START, "true"))) { startWorkspace(); } }); } } }
String url = workspace.getLinks().get(LINK_REL_ENVIRONMENT_STATUS_CHANNEL); if (workspace.getStatus() == STOPPED || url == null) { return;
@Override public void update(ActionEvent e) { e.getPresentation() .setEnabledAndVisible(WorkspaceStatus.STOPPED == appContext.getWorkspace().getStatus()); }
@Inject public ProjectTypeRegistryImpl( AsyncRequestFactory asyncRequestFactory, DtoUnmarshallerFactory dtoUnmarshallerFactory, AppContext appContext, EventBus eventBus) { this.asyncRequestFactory = asyncRequestFactory; this.dtoUnmarshallerFactory = dtoUnmarshallerFactory; this.appContext = appContext; this.eventBus = eventBus; projectTypes = new HashMap<>(); eventBus.addHandler( BasicIDEInitializedEvent.TYPE, e -> { if (RUNNING == appContext.getWorkspace().getStatus()) { registerProjectTypes(); } }); eventBus.addHandler(WsAgentServerRunningEvent.TYPE, e -> registerProjectTypes()); eventBus.addHandler(WsAgentServerStoppedEvent.TYPE, e -> projectTypes.clear()); }
void subscribe() { eventBus.addHandler(WsAgentServerRunningEvent.TYPE, event -> initialize()); if (appContext.getWorkspace().getStatus() == RUNNING) { initialize(); } }
@Inject public ProgressorJsonRpcHandler( RequestHandlerConfigurator configurator, AppContext appContext, EventBus eventBus, RequestTransmitter requestTransmitter) { this.configurator = configurator; this.requestTransmitter = requestTransmitter; handleProgressesReports(); eventBus.addHandler(WorkspaceRunningEvent.TYPE, e -> subscribe()); if (appContext.getWorkspace().getStatus() == RUNNING) { subscribe(); } }
/** Updates list of the machines from application context. */ public void updateMachineList() { if (appContext.getWorkspace() == null) { return; } List<MachineImpl> machines = getMachines(); if (machines.isEmpty()) { return; } Optional<MachineImpl> wsAgentServerMachine = wsAgentServerUtil.getWsAgentServerMachine(); wsAgentServerMachine.ifPresent( machine -> { provideMachineNode(machine.getName(), true, false); machines.remove(machine); }); for (MachineImpl machine : machines) { provideMachineNode(machine.getName(), true, false); } if (WorkspaceStatus.RUNNING == appContext.getWorkspace().getStatus()) { ProcessTreeNode machineToSelect = machineNodes.entrySet().iterator().next().getValue(); view.selectNode(machineToSelect); notifyTreeNodeSelected(machineToSelect); } }
@Inject public ProjectTreeNotificationsSubscriber( EventBus eventBus, AppContext appContext, RequestTransmitter requestTransmitter, DtoFactory dtoFactory) { this.requestTransmitter = requestTransmitter; this.dtoFactory = dtoFactory; eventBus.addHandler(WsAgentServerRunningEvent.TYPE, event -> subscribe()); // in case ws-agent is already running eventBus.addHandler( BasicIDEInitializedEvent.TYPE, event -> { if (appContext.getWorkspace().getStatus() == RUNNING) { subscribe(); } }); }
@Inject public JavaExtension( FileTypeRegistry fileTypeRegistry, AppContext appContext, EventBus eventBus, CustomNotificationReceiver customNotificationReceiver, @Named("JavaFileType") FileType javaFile, @Named("JavaClassFileType") FileType classFile, @Named("JspFileType") FileType jspFile) { JavaResources.INSTANCE.css().ensureInjected(); fileTypeRegistry.registerFileType(javaFile); fileTypeRegistry.registerFileType(jspFile); fileTypeRegistry.registerFileType(classFile); eventBus.addHandler( WsAgentServerRunningEvent.TYPE, e -> { customNotificationReceiver.subscribe(); }); if (appContext.getWorkspace().getStatus() == RUNNING) { customNotificationReceiver.subscribe(); } }
@Inject StartWorkspaceNotification( WorkspaceStatusNotification wsStatusNotification, StartWorkspaceNotificationUiBinder uiBinder, Provider<CurrentWorkspaceManager> currentWorkspaceManagerProvider, EventBus eventBus, AppContext appContext, RestartingStateHolder restartingStateHolder, WindowClientBundle windowClientBundle) { this.wsStatusNotification = wsStatusNotification; this.uiBinder = uiBinder; this.currentWorkspaceManagerProvider = currentWorkspaceManagerProvider; this.restartingStateHolder = restartingStateHolder; this.windowClientBundle = windowClientBundle; eventBus.addHandler( BasicIDEInitializedEvent.TYPE, e -> { WorkspaceStatus status = appContext.getWorkspace().getStatus(); if (status == STOPPED) { show(); } }); eventBus.addHandler(WorkspaceStoppedEvent.TYPE, e -> show()); }
@Inject public ProcessesOutputRestorer( EventBus eventBus, AppContext appContext, ExecAgentCommandManager execAgentCommandManager) { this.eventBus = eventBus; this.execAgentCommandManager = execAgentCommandManager; eventBus.addHandler( ExecAgentServerRunningEvent.TYPE, event -> restoreLogs(event.getMachineName())); // in case workspace is already running eventBus.addHandler( BasicIDEInitializedEvent.TYPE, event -> { final WorkspaceImpl workspace = appContext.getWorkspace(); if (workspace.getStatus() == RUNNING) { final RuntimeImpl runtime = workspace.getRuntime(); if (runtime != null) { runtime.getMachines().values().forEach(m -> restoreLogs(m.getName())); } } }); }
@Override public void onIDEInitialized(BasicIDEInitializedEvent event) { if (appContext.getFactory() == null && partStack != null) { partStack.setActivePart(this); } if (appContext.getWorkspace().getStatus() == RUNNING) { selectDevMachine(); TerminalOptionsJso options = TerminalOptionsJso.create(); newTerminal(options, false); } }
@Inject public WsAgentJsonRpcInitializer( JsonRpcInitializer initializer, AppContext appContext, EventBus eventBus, AgentURLModifier agentURLModifier, WsAgentServerUtil wsAgentServerUtil) { this.appContext = appContext; this.initializer = initializer; this.agentURLModifier = agentURLModifier; this.wsAgentServerUtil = wsAgentServerUtil; eventBus.addHandler(WsAgentServerRunningEvent.TYPE, event -> initializeJsonRpcService()); eventBus.addHandler( WsAgentServerStoppedEvent.TYPE, event -> initializer.terminate(WS_AGENT_JSON_RPC_ENDPOINT_ID)); // in case ws-agent is already running eventBus.addHandler( BasicIDEInitializedEvent.TYPE, event -> { if (appContext.getWorkspace().getStatus() == RUNNING) { initializeJsonRpcService(); } }); }
@Override public void startTracking() { if (WorkspaceStatus.RUNNING == appContext.getWorkspace().getStatus()) { return; } showWorkspaceStatusPanel(); addMachines(); processesListView.setLoadMode(); processesListView.setLoadingMessage(localizationConstant.menuLoaderWaitingWorkspace()); processesListView.setLoadingProgress(0); }
@Override public Path getProjectsRoot() { // default root (backward compatible solution) Path projectsRoot = Path.valueOf("/projects"); if (workspace != null && workspace.getStatus().equals(WorkspaceStatus.RUNNING)) { String machineName = wsAgentServerUtilProvider.get().getWsAgentServerMachine().get().getName(); String activeEnv = workspace.getRuntime().getActiveEnv(); EnvironmentImpl environment = workspace.getConfig().getEnvironments().get(activeEnv); VolumeImpl vol = null; if (environment != null) { vol = environment.getMachines().get(machineName).getVolume("projects"); } // if voulme exists return its path, otherwise use backward compatible path (/projects) if (vol != null) { projectsRoot = Path.valueOf(vol.getPath()); } } Log.debug( AppContextImpl.class, "Project Root: " + projectsRoot + " workspace: " + workspace.getConfig().getName()); return projectsRoot; }
@Inject public EditorMultiPartStackPresenter( EventBus eventBus, EditorMultiPartStackView view, Provider<EditorPartStack> editorPartStackFactory, AppContext appContext) { this.view = view; this.editorPartStackFactory = editorPartStackFactory; this.partStackPresenters = new LinkedList<>(); eventBus.addHandler(ActivePartChangedEvent.TYPE, this); eventBus.addHandler(WorkspaceStoppingEvent.TYPE, event -> view.showPlaceholder(true)); eventBus.addHandler(WorkspaceStoppedEvent.TYPE, event -> view.showPlaceholder(true)); eventBus.addHandler(WorkspaceStartingEvent.TYPE, event -> view.showPlaceholder(true)); eventBus.addHandler(WorkspaceRunningEvent.TYPE, event -> view.showPlaceholder(false)); if (WorkspaceStatus.RUNNING != appContext.getWorkspace().getStatus()) { view.showPlaceholder(true); } }
@Override public void showPanel() { showWorkspaceStatusPanel(); addMachines(); showInstallers(); if (WorkspaceStatus.RUNNING == appContext.getWorkspace().getStatus()) { view.showWorkspaceStarted(); Map<String, MachineImpl> runtimeMachines = appContext.getWorkspace().getRuntime().getMachines(); for (String machineName : runtimeMachines.keySet()) { view.setMachineRunning(machineName); } String defaultEnvironmentName = appContext.getWorkspace().getConfig().getDefaultEnv(); EnvironmentImpl defaultEnvironment = appContext.getWorkspace().getConfig().getEnvironments().get(defaultEnvironmentName); if (defaultEnvironment == null) { return; } Map<String, MachineConfigImpl> environmentMachines = defaultEnvironment.getMachines(); for (final String machineName : environmentMachines.keySet()) { MachineConfigImpl machineConfig = environmentMachines.get(machineName); for (String installerId : machineConfig.getInstallers()) { view.setInstallerRunning(machineName, installerId); } } } }
public WorkspaceImpl(WorkspaceImpl workspace) { this( workspace.getId(), workspace.getNamespace(), workspace.getConfig(), workspace.getRuntime(), workspace.getAttributes(), workspace.isTemporary(), workspace.getStatus(), workspace.getLinks(), workspace.getRuntime() != null ? workspace.getRuntime().getMachineToken() : null); }
@Override protected Promise<Void> initAppContext() { return super.initAppContext() .thenPromise( aVoid -> getFactory() .then( (Function<FactoryDto, Void>) factory -> { ((AppContextImpl) appContext).setFactory(factory); return null; }) .catchError( (Operation<PromiseError>) err -> { throw new OperationException( "Unable to load Factory: " + err.getMessage(), err.getCause()); }) .then( arg -> { if (RUNNING != appContext.getWorkspace().getStatus()) { throw new OperationException( "Can't load Factory. Workspace is not running."); } })); }