Search in sources :

Example 6 with ISelectionService

use of org.eclipse.ui.ISelectionService in project azure-tools-for-java by Microsoft.

the class AzureDockerHostDeployHandler method onExecute.

@Override
public Object onExecute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    ISelectionService selectionService = window.getSelectionService();
    ISelection selection = selectionService.getSelection();
    Shell shell = window.getShell();
    IProject project = null;
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof IResource) {
            project = ((IResource) element).getProject();
        }
    }
    if (project == null) {
        project = AzureDockerUIResources.getCurrentSelectedProject();
        if (project == null) {
            return null;
        }
    }
    try {
        AzureDockerUIResources.publish2DockerHostContainer(PluginUtil.getParentShell(), project, null);
    //			AzureDockerUIResources.createArtifact(shell, project);
    //			
    //			AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
    //
    //			// not signed in
    //			if (azureAuthManager == null) {
    //				System.out.println("ERROR! Not signed in!");
    //				return null;
    //			}
    //
    //			AzureDockerHostsManager dockerManager = AzureDockerHostsManager
    //					.getAzureDockerHostsManager(azureAuthManager);
    //
    //			if (!dockerManager.isInitialized()) {
    //				AzureDockerUIResources.updateAzureResourcesWithProgressDialog(shell, project);
    //				if (AzureDockerUIResources.CANCELED) {
    //					return null;
    //				}
    //				dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(null);
    //			}
    //
    //			if (dockerManager.getSubscriptionsMap().isEmpty()) {
    //				PluginUtil.displayErrorDialog(shell, "Create Docker Host", "Must select an Azure subscription first");
    //				return null;
    //			}
    //			
    //			DockerHost dockerHost = (dockerManager.getDockerPreferredSettings() != null) ? dockerManager.getDockerHostForURL(dockerManager.getDockerPreferredSettings().dockerApiName) : null;
    //			AzureDockerImageInstance dockerImageDescription = dockerManager.getDefaultDockerImageDescription(project.getName(), dockerHost);
    //			AzureSelectDockerWizard selectDockerWizard = new AzureSelectDockerWizard(project, dockerManager, dockerImageDescription);
    //			WizardDialog selectDockerHostDialog = new WizardDialog(shell, selectDockerWizard);
    //
    //			if (dockerHost != null) {
    //				selectDockerWizard.selectDefaultDockerHost(dockerHost, true);
    //			}
    //
    //			if (selectDockerHostDialog.open() == Window.OK) {
    //
    //			}
    } catch (Exception e) {
        log.log(Level.SEVERE, "execute: " + e.getMessage(), e);
        e.printStackTrace();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 7 with ISelectionService

use of org.eclipse.ui.ISelectionService in project azure-tools-for-java by Microsoft.

the class AILibraryUtil method getSelectedProject.

/**
	 * This method returns currently selected project in workspace.
	 * 
	 * @return IProject
	 */
public static IProject getSelectedProject() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    ISelectionService service = window.getSelectionService();
    ISelection selection = service.getSelection();
    Object element = null;
    IResource resource;
    IProject selProject = null;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSel = (IStructuredSelection) selection;
        element = structuredSel.getFirstElement();
    }
    if (element instanceof IProject) {
        resource = (IResource) element;
        selProject = resource.getProject();
    } else if (element instanceof IJavaProject) {
        IJavaProject proj = ((IJavaElement) element).getJavaProject();
        selProject = proj.getProject();
    }
    return selProject;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IJavaProject(org.eclipse.jdt.core.IJavaProject) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 8 with ISelectionService

use of org.eclipse.ui.ISelectionService in project azure-tools-for-java by Microsoft.

the class ClasspathContainerPage method getSelectedProject.

/**
     * This method returns currently selected project in workspace.
     * @return IProject
     */
private IProject getSelectedProject() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    ISelectionService service = window.getSelectionService();
    ISelection selection = service.getSelection();
    Object element = null;
    IResource resource;
    IProject selProject = null;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSel = (IStructuredSelection) selection;
        element = structuredSel.getFirstElement();
    }
    if (element instanceof IProject) {
        resource = (IResource) element;
        selProject = resource.getProject();
    } else if (element instanceof IJavaProject) {
        IJavaProject proj = ((IJavaElement) element).getJavaProject();
        selProject = proj.getProject();
    }
    return selProject;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IJavaProject(org.eclipse.jdt.core.IJavaProject) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 9 with ISelectionService

use of org.eclipse.ui.ISelectionService in project knime-core by knime.

the class EditMetaInfoAction method getSelection.

private Object getSelection() {
    ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    IStructuredSelection selection = (IStructuredSelection) service.getSelection();
    if (selection == null) {
        return null;
    }
    return selection.getFirstElement();
}
Also used : ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 ISelectionService (org.eclipse.ui.ISelectionService)9 IResource (org.eclipse.core.resources.IResource)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IProject (org.eclipse.core.resources.IProject)7 IJavaProject (org.eclipse.jdt.core.IJavaProject)6 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)6 IWorkbench (org.eclipse.ui.IWorkbench)5 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 PackageFragmentRoot (org.eclipse.jdt.internal.core.PackageFragmentRoot)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1