Search in sources :

Example 1 with IVagrantVM

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;
}
Also used : IVagrantVM(org.eclipse.linuxtools.vagrant.core.IVagrantVM) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PackageVMWizard(org.eclipse.linuxtools.internal.vagrant.ui.wizards.PackageVMWizard)

Example 2 with IVagrantVM

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);
        }
    }
}
Also used : IAction(org.eclipse.jface.action.IAction) IContributionItem(org.eclipse.jface.action.IContributionItem) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IVagrantVM(org.eclipse.linuxtools.vagrant.core.IVagrantVM) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IMenuManager(org.eclipse.jface.action.IMenuManager) EnumVMStatus(org.eclipse.linuxtools.vagrant.core.EnumVMStatus)

Example 3 with IVagrantVM

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);
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Text(org.eclipse.swt.widgets.Text) IVagrantVM(org.eclipse.linuxtools.vagrant.core.IVagrantVM) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 4 with IVagrantVM

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);
    }
}
Also used : IVagrantVM(org.eclipse.linuxtools.vagrant.core.IVagrantVM)

Example 5 with IVagrantVM

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IVagrantVM(org.eclipse.linuxtools.vagrant.core.IVagrantVM) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

IVagrantVM (org.eclipse.linuxtools.vagrant.core.IVagrantVM)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 IAction (org.eclipse.jface.action.IAction)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 PackageVMWizard (org.eclipse.linuxtools.internal.vagrant.ui.wizards.PackageVMWizard)1 EnumVMStatus (org.eclipse.linuxtools.vagrant.core.EnumVMStatus)1 Image (org.eclipse.swt.graphics.Image)1 Composite (org.eclipse.swt.widgets.Composite)1 Table (org.eclipse.swt.widgets.Table)1 Text (org.eclipse.swt.widgets.Text)1