KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > LaunchConfigurationTabGroupWrapper


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.launchConfigurations;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Arrays JavaDoc;
15 import java.util.List JavaDoc;
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 /**
29  * This class is used to wrap a contributed <code>ILaunchConfigurationTabGroup</code> with any contributed tabs
30  * for that group (from a <code>launchConfigurationTabs</code> extension point).
31  *
32  * @since 3.3
33  */

34 public class LaunchConfigurationTabGroupWrapper implements ILaunchConfigurationTabGroup {
35     
36     private ILaunchConfigurationTabGroup fGroup = null;
37     private String JavaDoc fGroupId = null;
38     /**
39      * listing of tab extensions that we have to create
40      */

41     private List JavaDoc fTabs = null;
42     private String JavaDoc fMode = null;
43     private ILaunchConfiguration fConfig = null;
44     
45     /**
46      * Constructor
47      * @param group the existing group to wrapper
48      * @param groupId the string id of the associated tab group
49      * @param config the launch configuration this tab group is opened on
50      */

51     public LaunchConfigurationTabGroupWrapper(ILaunchConfigurationTabGroup group, String JavaDoc groupId, ILaunchConfiguration config) {
52         fGroup = group;
53         fGroupId = groupId;
54         fConfig = config;
55     }
56     
57     /**
58      * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#createTabs(org.eclipse.debug.ui.ILaunchConfigurationDialog, java.lang.String)
59      */

60     public void createTabs(ILaunchConfigurationDialog dialog, String JavaDoc mode) {
61         if(fGroup != null) {
62             fGroup.createTabs(dialog, mode);
63             fMode = mode;
64         }
65     }
66
67     /**
68      * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#dispose()
69      */

70     public void dispose() {
71         fGroup.dispose();
72         if(fTabs != null) {
73             List JavaDoc 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     /**
86      * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#getTabs()
87      */

88     public ILaunchConfigurationTab[] getTabs() {
89         if(fTabs == null) {
90             try {
91                 fTabs = new ArrayList JavaDoc();
92             //add the tab groups' tabs first (defaults)
93
fTabs.addAll(Arrays.asList(fGroup.getTabs()));
94             //last, add the extensions (if any)
95
LaunchConfigurationTabExtension[] ext = LaunchConfigurationPresentationManager.getDefault().getTabExtensions(fGroupId, fConfig, fMode);
96                 //copy contributed into correct position or end if no id or id is not found
97
String JavaDoc 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     /**
120      * Returns the index of the tab matching the specified id
121      * @param id the id of the tab to find the index for
122      * @return the index of the tab specified by the id or -1 if not found
123      */

124     private int indexofTab(String JavaDoc id) {
125         if(id != null) {
126             Object JavaDoc 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     /**
140      * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
141      */

142     public void initializeFrom(ILaunchConfiguration configuration) {
143         fGroup.initializeFrom(configuration);
144         if(fTabs != null) {
145             List JavaDoc 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     /**
157      * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#launched(org.eclipse.debug.core.ILaunch)
158      */

159     public void launched(ILaunch launch) {
160         if(fGroup != null) {
161             fGroup.launched(launch);
162         }
163     }
164
165     /**
166      * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
167      */

168     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
169         fGroup.performApply(configuration);
170         if(fTabs != null) {
171             List JavaDoc 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     /**
183      * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
184      */

185     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
186         fGroup.setDefaults(configuration);
187         if(fTabs != null) {
188             List JavaDoc 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