1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 import org.eclipse.core.resources.ResourcesPlugin; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.ILaunchConfiguration; 20 import org.eclipse.debug.core.ILaunchConfigurationType; 21 import org.eclipse.debug.core.ILaunchManager; 22 import org.eclipse.debug.internal.ui.DebugUIPlugin; 23 import org.eclipse.jface.viewers.ITreeContentProvider; 24 import org.eclipse.jface.viewers.Viewer; 25 import org.eclipse.swt.widgets.Shell; 26 import org.eclipse.ui.activities.WorkbenchActivityHelper; 27 28 33 public class LaunchConfigurationTreeContentProvider implements ITreeContentProvider { 34 35 38 private static final Object [] EMPTY_ARRAY = new Object [0]; 39 40 45 private String fMode; 46 47 50 private Shell fShell; 51 52 57 public LaunchConfigurationTreeContentProvider(String mode, Shell shell) { 58 setMode(mode); 59 setShell(shell); 60 } 61 62 74 public Object [] getChildren(Object parentElement) { 75 if (parentElement instanceof ILaunchConfiguration) { 76 return EMPTY_ARRAY; 77 } else if (parentElement instanceof ILaunchConfigurationType) { 78 try { 79 ILaunchConfigurationType type = (ILaunchConfigurationType)parentElement; 80 return getLaunchManager().getLaunchConfigurations(type); 81 } catch (CoreException e) { 82 DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Error_19, LaunchConfigurationsMessages.LaunchConfigurationDialog_An_exception_occurred_while_retrieving_launch_configurations_20, e); } 84 } else { 85 return getLaunchManager().getLaunchConfigurationTypes(); 86 } 87 return EMPTY_ARRAY; 88 } 89 90 93 public Object getParent(Object element) { 94 if (element instanceof ILaunchConfiguration) { 95 if (!((ILaunchConfiguration)element).exists()) { 96 return null; 97 } 98 try { 99 return ((ILaunchConfiguration)element).getType(); 100 } catch (CoreException e) { 101 DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Error_19, LaunchConfigurationsMessages.LaunchConfigurationDialog_An_exception_occurred_while_retrieving_launch_configurations_20, e); } 103 } else if (element instanceof ILaunchConfigurationType) { 104 return ResourcesPlugin.getWorkspace().getRoot(); 105 } 106 return null; 107 } 108 109 112 public boolean hasChildren(Object element) { 113 if (element instanceof ILaunchConfiguration) { 114 return false; 115 } 116 return getChildren(element).length > 0; 117 } 118 119 125 public Object [] getElements(Object inputElement) { 126 ILaunchConfigurationType[] allTypes = getLaunchManager().getLaunchConfigurationTypes(); 127 return filterTypes(allTypes).toArray(); 128 } 129 130 138 private List filterTypes(ILaunchConfigurationType[] allTypes) { 139 List filteredTypes= new ArrayList (); 140 String mode = getMode(); 141 LaunchConfigurationTypeContribution contribution; 142 for (int i = 0; i < allTypes.length; i++) { 143 ILaunchConfigurationType type = allTypes[i]; 144 contribution= new LaunchConfigurationTypeContribution(type); 145 if (isVisible(type, mode) && !WorkbenchActivityHelper.filterItem(contribution)) { 146 filteredTypes.add(type); 147 } 148 } 149 return filteredTypes; 150 } 151 152 155 public void dispose() { 156 } 157 158 161 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 162 } 163 164 168 private boolean isVisible(ILaunchConfigurationType configType, String mode) { 169 if (!configType.isPublic()) { 170 return false; 171 } 172 if (mode == null) { 173 return true; 174 } 175 return configType.supportsMode(mode); 176 } 177 178 181 private ILaunchManager getLaunchManager() { 182 return DebugPlugin.getDefault().getLaunchManager(); 183 } 184 185 188 private void setMode(String mode) { 189 fMode = mode; 190 } 191 192 195 private String getMode() { 196 return fMode; 197 } 198 199 202 private void setShell(Shell shell) { 203 fShell = shell; 204 } 205 206 209 private Shell getShell() { 210 return fShell; 211 } 212 } 213 | Popular Tags |