1 | package de.uka.ipd.sdq.cip.runtime.runconfig.tabs; |
2 | |
3 | import org.eclipse.core.resources.IProject; |
4 | import org.eclipse.core.resources.IResource; |
5 | import org.eclipse.core.runtime.IAdaptable; |
6 | import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; |
7 | import org.eclipse.jface.viewers.ISelection; |
8 | import org.eclipse.jface.viewers.IStructuredSelection; |
9 | import org.eclipse.ui.IWorkbench; |
10 | import org.eclipse.ui.IWorkbenchPage; |
11 | import org.eclipse.ui.IWorkbenchWindow; |
12 | import org.eclipse.ui.PlatformUI; |
13 | |
14 | public abstract class AbstractCipLaunchConfigurationTab extends |
15 | AbstractLaunchConfigurationTab { |
16 | |
17 | protected IResource getSelectedResource() { |
18 | IWorkbench iworkbench = PlatformUI.getWorkbench(); |
19 | if (iworkbench == null) return null; |
20 | IWorkbenchWindow iworkbenchwindow = iworkbench.getActiveWorkbenchWindow(); |
21 | if (iworkbenchwindow == null) return null; |
22 | IWorkbenchPage iworkbenchpage = iworkbenchwindow.getActivePage(); |
23 | if (iworkbenchpage == null) return null; |
24 | //the current selection in the entire page |
25 | ISelection selection = iworkbenchpage.getSelection(); |
26 | if (!(selection instanceof IStructuredSelection)) |
27 | return null; |
28 | IStructuredSelection ss = (IStructuredSelection) selection; |
29 | Object element = ss.getFirstElement(); |
30 | if (element instanceof IResource) |
31 | return (IResource) element; |
32 | if (!(element instanceof IAdaptable)) |
33 | return null; |
34 | IAdaptable adaptable = (IAdaptable)element; |
35 | Object adapter = adaptable.getAdapter(IResource.class); |
36 | return (IResource) adapter; |
37 | } |
38 | |
39 | protected IProject getSelectedProject() { |
40 | IResource resource = getSelectedResource(); |
41 | if(resource == null) return null; |
42 | return resource.getProject(); |
43 | } |
44 | |
45 | protected IResource[] getFeatureConfig() { |
46 | return null; |
47 | } |
48 | } |