1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.debug.core.ILaunch; 19 import org.eclipse.debug.core.ILaunchConfiguration; 20 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 21 import org.eclipse.debug.internal.ui.DebugUIPlugin; 22 import org.eclipse.debug.internal.ui.LaunchConfigurationTabExtension; 23 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; 24 import org.eclipse.debug.ui.ILaunchConfigurationDialog; 25 import org.eclipse.debug.ui.ILaunchConfigurationTab; 26 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup; 27 28 34 public class LaunchConfigurationTabGroupWrapper implements ILaunchConfigurationTabGroup { 35 36 private ILaunchConfigurationTabGroup fGroup = null; 37 private String fGroupId = null; 38 41 private List fTabs = null; 42 private String fMode = null; 43 private ILaunchConfiguration fConfig = null; 44 45 51 public LaunchConfigurationTabGroupWrapper(ILaunchConfigurationTabGroup group, String groupId, ILaunchConfiguration config) { 52 fGroup = group; 53 fGroupId = groupId; 54 fConfig = config; 55 } 56 57 60 public void createTabs(ILaunchConfigurationDialog dialog, String mode) { 61 if(fGroup != null) { 62 fGroup.createTabs(dialog, mode); 63 fMode = mode; 64 } 65 } 66 67 70 public void dispose() { 71 fGroup.dispose(); 72 if(fTabs != null) { 73 List tabs = Arrays.asList(fGroup.getTabs()); 74 ILaunchConfigurationTab tab = null; 75 for(int i = 0; i < fTabs.size(); i++) { 76 tab = (ILaunchConfigurationTab)fTabs.get(i); 77 if(!tabs.contains(tab)) { 78 tab.dispose(); 79 } 80 } 81 } 82 fTabs.clear(); 83 } 84 85 88 public ILaunchConfigurationTab[] getTabs() { 89 if(fTabs == null) { 90 try { 91 fTabs = new ArrayList (); 92 fTabs.addAll(Arrays.asList(fGroup.getTabs())); 94 LaunchConfigurationTabExtension[] ext = LaunchConfigurationPresentationManager.getDefault().getTabExtensions(fGroupId, fConfig, fMode); 96 String id = null; 98 for(int i = 0; i < ext.length; i++) { 99 id = ext[i].getRelativeTabId(); 100 if(id != null) { 101 int idx = indexofTab(id); 102 if(idx > -1) { 103 fTabs.add(idx+1, ext[i].getTab()); 104 } 105 else { 106 fTabs.add(ext[i].getTab()); 107 } 108 } 109 else { 110 fTabs.add(ext[i].getTab()); 111 } 112 } 113 } 114 catch (CoreException ce) {DebugUIPlugin.log(ce);} 115 } 116 return (ILaunchConfigurationTab[]) fTabs.toArray(new ILaunchConfigurationTab[fTabs.size()]); 117 } 118 119 124 private int indexofTab(String id) { 125 if(id != null) { 126 Object o = null; 127 for(int i = 0; i < fTabs.size(); i++) { 128 o = fTabs.get(i); 129 if(o instanceof AbstractLaunchConfigurationTab) { 130 if(id.equals(((AbstractLaunchConfigurationTab)o).getId())) { 131 return i; 132 } 133 } 134 } 135 } 136 return -1; 137 } 138 139 142 public void initializeFrom(ILaunchConfiguration configuration) { 143 fGroup.initializeFrom(configuration); 144 if(fTabs != null) { 145 List tabs = Arrays.asList(fGroup.getTabs()); 146 ILaunchConfigurationTab tab = null; 147 for(int i = 0; i < fTabs.size(); i++) { 148 tab = (ILaunchConfigurationTab)fTabs.get(i); 149 if(!tabs.contains(tab)) { 150 tab.initializeFrom(configuration); 151 } 152 } 153 } 154 } 155 156 159 public void launched(ILaunch launch) { 160 if(fGroup != null) { 161 fGroup.launched(launch); 162 } 163 } 164 165 168 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 169 fGroup.performApply(configuration); 170 if(fTabs != null) { 171 List tabs = Arrays.asList(fGroup.getTabs()); 172 ILaunchConfigurationTab tab = null; 173 for(int i = 0; i < fTabs.size(); i++) { 174 tab = (ILaunchConfigurationTab)fTabs.get(i); 175 if(!tabs.contains(tab)) { 176 tab.performApply(configuration); 177 } 178 } 179 } 180 } 181 182 185 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { 186 fGroup.setDefaults(configuration); 187 if(fTabs != null) { 188 List tabs = Arrays.asList(fGroup.getTabs()); 189 ILaunchConfigurationTab tab = null; 190 for(int i = 0; i < fTabs.size(); i++) { 191 tab = (ILaunchConfigurationTab)fTabs.get(i); 192 if(!tabs.contains(tab)) { 193 tab.setDefaults(configuration); 194 } 195 } 196 } 197 } 198 199 } 200 | Popular Tags |