Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 948972e3d0aa2f5327db8eef70b0f4bb898b36b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*******************************************************************************
 * Copyright (c) 2015, 2018 Red Hat.
 * 
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Red Hat - Initial Contribution
 *******************************************************************************/
package org.eclipse.linuxtools.internal.vagrant.ui.commands;

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.linuxtools.internal.vagrant.ui.views.DVMessages;
import org.eclipse.linuxtools.vagrant.core.IVagrantConnection;
import org.eclipse.linuxtools.vagrant.core.IVagrantVM;
import org.eclipse.linuxtools.vagrant.core.VagrantException;
import org.eclipse.linuxtools.vagrant.core.VagrantService;

public class StopVMCommandHandler extends BaseVMCommandHandler {

	private static final String CONTAINERS_STOP_MSG = "ContainersStop.msg"; //$NON-NLS-1$
	private static final String CONTAINER_STOP_MSG = "ContainerStop.msg"; //$NON-NLS-1$
	private static final String CONTAINER_STOP_ERROR_MSG = "ContainerStopError.msg"; //$NON-NLS-1$

	@Override
	void executeInJob(final IVagrantVM vm, IProgressMonitor monitor) {
		IVagrantConnection connection = VagrantService.getInstance();
		try {
			connection.haltVM(vm);
		} catch (VagrantException | InterruptedException e) {
			final String errorMessage = DVMessages.getFormattedString(CONTAINER_STOP_ERROR_MSG, vm.id());
			openError(errorMessage, e);
		} finally {
			connection.getVMs(true);
		}
	}

	@Override
	String getJobName(final List<IVagrantVM> selectedVMs) {
		return DVMessages.getString(CONTAINERS_STOP_MSG);
	}

	@Override
	String getTaskName(final IVagrantVM vm) {
		return DVMessages.getFormattedString(CONTAINER_STOP_MSG, vm.id());
	}
}

Back to the top