use of org.eclipse.linuxtools.vagrant.core.IVagrantBox in project linuxtools by eclipse.
the class CreateVmCommandHandler method performCreateVM.
private void performCreateVM(String vmName, String boxRef, String vmFile, Map<String, String> environment) {
final Job createVMJob = new Job(DVMessages.getFormattedString(CREATE_VM_MSG)) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask(DVMessages.getFormattedString(CRATE_VM_TITLE, vmName), IProgressMonitor.UNKNOWN);
IVagrantConnection connection = VagrantService.getInstance();
if (findVM(connection, vmName) != null) {
Display.getDefault().syncExec(() -> MessageDialog.openError(Display.getCurrent().getActiveShell(), // $NON-NLS-1$
WizardMessages.getString("CreateVmCommandHandler.VMExists.title"), // $NON-NLS-1$
WizardMessages.getString("CreateVmCommandHandler.VMExists.msg")));
return Status.CANCEL_STATUS;
}
IVagrantBox box = null;
File vagrantDir;
String boxName = boxRef;
if (vmFile == null) {
// The boxRef is a reference to an actual box file/url
boolean isValidURL = true;
try {
new URL(boxRef);
} catch (MalformedURLException e1) {
isValidURL = false;
}
if (Paths.get(boxRef).toFile().canRead() || isValidURL) {
try {
String boxPath = boxRef;
// Generate the box name from the file name (basename)
boxName = boxRef.substring(boxRef.lastIndexOf(File.separator) + 1).replace(".box", // $NON-NLS-1$ //$NON-NLS-2$
"");
connection.addBox(boxName, boxPath, isValidURL);
} catch (VagrantException e) {
} catch (InterruptedException e) {
}
}
// Init a new vagrant folder inside plugin metadata
vagrantDir = performInit(vmName, boxName, connection);
// box download job might not be complete so we wait
box = findBox(connection, boxName);
while (box == null && isValidURL) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
connection.getVMs(true);
box = findBox(connection, boxName);
if (monitor.isCanceled()) {
CommandUtils.delete(vagrantDir);
return Status.CANCEL_STATUS;
}
}
} else {
vagrantDir = Paths.get(vmFile).getParent().toFile();
}
EnvironmentsManager.getSingleton().setEnvironment(vagrantDir, environment);
String provider = (box == null ? null : box.getProvider());
connection.up(vagrantDir, provider);
connection.getVMs(true);
return Status.OK_STATUS;
}
};
createVMJob.setUser(true);
createVMJob.schedule();
}
use of org.eclipse.linuxtools.vagrant.core.IVagrantBox in project linuxtools by eclipse.
the class VagrantBoxView 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 VagrantBoxContentProvider());
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
final TableViewerColumn idColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
"NAME"));
setLayout(idColumn, tableLayout, 150);
idColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IVagrantBox) {
return ((IVagrantBox) element).getName();
}
return super.getText(element);
}
});
// 'PROVIDER' column
final TableViewerColumn tagsColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
"PROVIDER"));
setLayout(tagsColumn, tableLayout, 150);
tagsColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IVagrantBox) {
return ((IVagrantBox) element).getProvider();
}
return super.getText(element);
}
});
// 'VERSION' column
final TableViewerColumn creationDateColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
"VERSION"));
setLayout(creationDateColumn, tableLayout, 150);
creationDateColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IVagrantBox) {
return ((IVagrantBox) element).getVersion().toString();
}
return super.getText(element);
}
});
// comparator
final VagrantBoxComparator comparator = new VagrantBoxComparator(this.viewer);
viewer.setComparator(comparator);
// apply search filter
this.viewer.addFilter(getImagesFilter());
setConnection(VagrantService.getInstance());
connection.addBoxListener(this);
// get the current selection in the tableviewer
getSite().setSelectionProvider(viewer);
}
use of org.eclipse.linuxtools.vagrant.core.IVagrantBox in project linuxtools by eclipse.
the class VagrantConnection method getBoxes.
@Override
public List<IVagrantBox> getBoxes(boolean force) {
if (force || !isBoxesLoaded()) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] res = call(new String[] { "--machine-readable", "box", "list" });
List<IVagrantBox> images = new LinkedList<>();
// $NON-NLS-1$
String name = "";
// $NON-NLS-1$
String provider = "";
// $NON-NLS-1$
String version = "0";
for (int i = 0; i < res.length; i++) {
// $NON-NLS-1$
String[] items = res[i].split(",");
if (items[2].equals("box-name")) {
// $NON-NLS-1$
name = items[3];
} else if (items[2].equals("box-provider")) {
// $NON-NLS-1$
provider = items[3];
} else if (items[2].equals("box-version")) {
// $NON-NLS-1$
version = items[3];
images.add(new VagrantBox(name, provider, Version.parseVersion(version)));
// $NON-NLS-1$
name = "";
// $NON-NLS-1$
provider = "";
// $NON-NLS-1$
version = "0";
}
}
this.boxesLoaded = true;
synchronized (imageLock) {
this.boxes = images;
}
notifyBoxListeners(this.boxes);
}
return this.boxes;
}
use of org.eclipse.linuxtools.vagrant.core.IVagrantBox in project linuxtools by eclipse.
the class BaseBoxesCommandHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final List<IVagrantBox> selectedImages = CommandUtils.getSelectedImages(activePart);
final Job job = new Job(getJobName(selectedImages)) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
if (confirmed(selectedImages)) {
monitor.beginTask(getJobName(selectedImages), selectedImages.size());
for (final IVagrantBox image : selectedImages) {
monitor.setTaskName(getTaskName(image));
executeInJob(image, monitor);
monitor.worked(1);
}
}
monitor.done();
return Status.OK_STATUS;
}
};
job.setPriority(Job.LONG);
job.setUser(true);
job.schedule();
return null;
}
use of org.eclipse.linuxtools.vagrant.core.IVagrantBox in project linuxtools by eclipse.
the class CreateVmCommandHandler method execute.
@Override
public Object execute(final ExecutionEvent event) {
if (VagrantConnection.findVagrantPath() == null) {
Display.getDefault().syncExec(() -> MessageDialog.openError(Display.getCurrent().getActiveShell(), // $NON-NLS-1$
WizardMessages.getString("VagrantCommandNotFound.title"), // $NON-NLS-1$
WizardMessages.getString("VagrantCommandNotFound.msg")));
} else {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final List<IVagrantBox> selectedBoxes = CommandUtils.getSelectedImages(activePart);
if (selectedBoxes.size() <= 1) {
IVagrantBox selectedBox = selectedBoxes.isEmpty() ? null : selectedBoxes.get(0);
final CreateVMWizard wizard = new CreateVMWizard(selectedBox);
final boolean finished = CommandUtils.openWizard(wizard, HandlerUtil.getActiveShell(event));
if (finished) {
performCreateVM(wizard.getVMName(), wizard.getBoxReference(), wizard.getVMFile(), wizard.getVMEnvironment());
}
}
}
return null;
}
Aggregations