use of org.eclipse.linuxtools.vagrant.core.IVagrantVM in project linuxtools by eclipse.
the class PackageVMCommandHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
final IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
List<IVagrantVM> vms = CommandUtils.getSelectedContainers(selection);
IVagrantVM vm = vms.iterator().next();
PackageVMWizard wizard = new PackageVMWizard();
boolean finished = CommandUtils.openWizard(wizard, HandlerUtil.getActiveShell(event));
if (finished) {
performPackageVM(vm, wizard.getBoxName(), Paths.get(wizard.getBoxFolder()));
}
return null;
}
use of org.eclipse.linuxtools.vagrant.core.IVagrantVM in project linuxtools by eclipse.
the class VagrantToolBarContributionItem method fill.
@Override
public void fill(Menu menu, int index) {
// Ignore it, get the parent IMenuManager and create the structure
if (getParent() instanceof IMenuManager) {
IMenuManager mm = (IMenuManager) getParent();
IContributionItem v = mm.find(getId());
// Menu manager contributions get aggregated so remove them first
mm.removeAll();
// dynamic menu contribution ensures fill() gets called
mm.add(v);
for (IVagrantVM vm : vms) {
EnumVMStatus containerStatus = EnumVMStatus.fromStatusMessage(vm.state());
ImageDescriptor img = (containerStatus == EnumVMStatus.RUNNING) ? SWTImagesFactory.DESC_CONTAINER_STARTED : SWTImagesFactory.DESC_CONTAINER_STOPPED;
IMenuManager vmM = new MenuManager(vm.name(), img, null);
for (IAction act : getApplicableActions(vm)) {
vmM.add(act);
}
mm.add(vmM);
}
}
}
use of org.eclipse.linuxtools.vagrant.core.IVagrantVM in project linuxtools by eclipse.
the class VagrantVMView method createTableViewer.
private void createTableViewer(final Composite container) {
search = new Text(container, SWT.SEARCH | SWT.ICON_SEARCH);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(search);
search.addModifyListener(onSearch());
Composite tableArea = new Composite(container, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(tableArea);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableArea);
final TableColumnLayout tableLayout = new TableColumnLayout();
tableArea.setLayout(tableLayout);
this.viewer = new TableViewer(tableArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
this.viewer.setContentProvider(new VagrantVMContentProvider());
final Table table = viewer.getTable();
GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(table);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(table);
table.setLinesVisible(true);
table.setHeaderVisible(true);
// 'Name' column
// $NON-NLS-1$
final TableViewerColumn nameColumn = createColumn(DVMessages.getString("NAME"));
setLayout(nameColumn, tableLayout, 150);
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IVagrantVM) {
return ((IVagrantVM) element).name();
}
return super.getText(element);
}
@Override
public Image getImage(Object element) {
if (element instanceof IVagrantVM) {
final IVagrantVM container = (IVagrantVM) element;
final String state = container.state();
if (EnumVMStatus.RUNNING.equals(EnumVMStatus.fromStatusMessage(state))) {
return SWTImagesFactory.DESC_CONTAINER_STARTED.createImage();
} else {
return SWTImagesFactory.DESC_CONTAINER_STOPPED.createImage();
}
}
return super.getImage(element);
}
});
// 'Provider' column
// $NON-NLS-1$
final TableViewerColumn imageColumn = createColumn(DVMessages.getString("PROVIDER"));
setLayout(imageColumn, tableLayout, 150);
imageColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IVagrantVM) {
return ((IVagrantVM) element).provider();
}
return super.getText(element);
}
});
// 'State' column
// $NON-NLS-1$
final TableViewerColumn creationDateColumn = createColumn(DVMessages.getString("STATE"));
setLayout(creationDateColumn, tableLayout, 150);
creationDateColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IVagrantVM) {
return ((IVagrantVM) element).state();
}
return super.getText(element);
}
});
// 'State Description' column
// $NON-NLS-1$
final TableViewerColumn commandColumn = createColumn(DVMessages.getString("STATE_DESC"));
setLayout(commandColumn, tableLayout, 150);
commandColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IVagrantVM) {
return ((IVagrantVM) element).state_desc();
}
return super.getText(element);
}
});
// comparator
final VagrantVMComparator comparator = new VagrantVMComparator(this.viewer);
viewer.setComparator(comparator);
// apply search filter
this.viewer.addFilter(getContainersFilter());
setConnection(VagrantService.getInstance());
connection.addVMListener(this);
// get the current selection in the tableviewer
getSite().setSelectionProvider(viewer);
}
use of org.eclipse.linuxtools.vagrant.core.IVagrantVM in project linuxtools by eclipse.
the class VagrantConnection method removeKeysFromInnactiveVMs.
/**
* If a key stored in preferences comes from a non-running VM
* or came from a Vagrant VM (tracked) but is not longer
* associated with one, then it is safe to remove it.
*/
private void removeKeysFromInnactiveVMs() {
// org.eclipse.jsch.internal.core.IConstants.KEY_PRIVATEKEY
// $NON-NLS-1$
String newKeys = "";
// $NON-NLS-1$
String keys = InstanceScope.INSTANCE.getNode(JSCH_ID).get(KEY, "");
if (keys.isEmpty()) {
// $NON-NLS-1$
keys = DefaultScope.INSTANCE.getNode(JSCH_ID).get(KEY, "");
}
boolean vmFound = false;
for (String key : keys.split(",")) {
// $NON-NLS-1$
for (IVagrantVM vm : vms) {
if (key.equals(vm.identityFile())) {
vmFound = true;
if (!EnumVMStatus.RUNNING.equals(EnumVMStatus.fromStatusMessage(vm.state()))) {
newKeys = removeFromKeys(keys, key);
removeFromTrackedKeys(key);
break;
}
}
}
if (!vmFound && isTrackedKey(key)) {
newKeys = removeFromKeys(keys, key);
removeFromTrackedKeys(key);
}
}
if (!newKeys.isEmpty() && !newKeys.equals(keys)) {
InstanceScope.INSTANCE.getNode(JSCH_ID).put(KEY, newKeys);
}
}
use of org.eclipse.linuxtools.vagrant.core.IVagrantVM in project linuxtools by eclipse.
the class BaseVMCommandHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
final IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
final List<IVagrantVM> selectedContainers = CommandUtils.getSelectedContainers(selection);
final Job job = new Job(getJobName(selectedContainers)) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
if (confirmed(selectedContainers)) {
monitor.beginTask(getJobName(selectedContainers), selectedContainers.size());
for (final IVagrantVM container : selectedContainers) {
monitor.setTaskName(getTaskName(container));
executeInJob(container, monitor);
monitor.worked(1);
}
}
monitor.done();
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return null;
}
Aggregations