|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 11-17
Link Here
|
| 11 |
package org.eclipse.releng.tools; |
11 |
package org.eclipse.releng.tools; |
| 12 |
|
12 |
|
| 13 |
import java.util.*; |
13 |
import java.util.*; |
| 14 |
|
|
|
| 15 |
import org.eclipse.core.resources.IProject; |
14 |
import org.eclipse.core.resources.IProject; |
| 16 |
import org.eclipse.core.resources.ResourcesPlugin; |
15 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 17 |
import org.eclipse.jface.dialogs.IDialogSettings; |
16 |
import org.eclipse.jface.dialogs.IDialogSettings; |
|
Lines 30-36
Link Here
|
| 30 |
import org.eclipse.ui.model.WorkbenchContentProvider; |
29 |
import org.eclipse.ui.model.WorkbenchContentProvider; |
| 31 |
import org.eclipse.ui.model.WorkbenchLabelProvider; |
30 |
import org.eclipse.ui.model.WorkbenchLabelProvider; |
| 32 |
|
31 |
|
| 33 |
|
|
|
| 34 |
/** |
32 |
/** |
| 35 |
* This class extends <code>WizardPage<code> class and use a <code>CheckboxTreeViewer<code> to |
33 |
* This class extends <code>WizardPage<code> class and use a <code>CheckboxTreeViewer<code> to |
| 36 |
* display selectable items. |
34 |
* display selectable items. |
|
Lines 39-77
Link Here
|
| 39 |
private CheckboxTreeViewer viewer; |
37 |
private CheckboxTreeViewer viewer; |
| 40 |
private IDialogSettings settings; |
38 |
private IDialogSettings settings; |
| 41 |
private Button compareButton; |
39 |
private Button compareButton; |
| 42 |
private boolean compareButtonChecked; |
40 |
private boolean compareButtonChecked; |
| 43 |
private String SELECTED_ITEMS_KEY = Messages.getString("ProjectSelectionPage.0"); //$NON-NLS-1$ |
41 |
private String SELECTED_ITEMS_KEY = Messages.getString("ProjectSelectionPage.0"); //$NON-NLS-1$ |
| 44 |
private String COMPARE_BUTTON_KEY = Messages.getString("ProjectSelectionPage.1"); //$NON-NLS-1$ |
42 |
private String COMPARE_BUTTON_KEY = Messages.getString("ProjectSelectionPage.1"); //$NON-NLS-1$ |
| 45 |
private MapProject mapProject; |
43 |
private MapProject mapProject; |
| 46 |
|
44 |
|
| 47 |
private class MapFileLabelProvider extends LabelProvider { |
45 |
private class MapFileLabelProvider extends LabelProvider { |
| 48 |
WorkbenchLabelProvider provider = new WorkbenchLabelProvider(); |
46 |
WorkbenchLabelProvider provider = new WorkbenchLabelProvider(); |
|
|
47 |
|
| 49 |
public String getText(Object element) { |
48 |
public String getText(Object element) { |
| 50 |
if (element instanceof MapFile) { |
49 |
if (element instanceof MapFile) { |
| 51 |
return ((MapFile)element).getName(); |
50 |
return ((MapFile) element).getName(); |
| 52 |
} |
51 |
} |
| 53 |
return provider.getText(element); |
52 |
return provider.getText(element); |
| 54 |
} |
53 |
} |
|
|
54 |
|
| 55 |
public Image getImage(Object element) { |
55 |
public Image getImage(Object element) { |
| 56 |
if (element instanceof MapFile) { |
56 |
if (element instanceof MapFile) { |
| 57 |
return provider.getImage(((MapFile)element).getFile()); |
57 |
return provider.getImage(((MapFile) element).getFile()); |
| 58 |
} |
58 |
} |
| 59 |
return provider.getImage(element); |
59 |
return provider.getImage(element); |
| 60 |
} |
60 |
} |
|
|
61 |
|
| 61 |
public void dispose() { |
62 |
public void dispose() { |
| 62 |
provider.dispose(); |
63 |
provider.dispose(); |
| 63 |
super.dispose(); |
64 |
super.dispose(); |
| 64 |
} |
65 |
} |
| 65 |
} |
66 |
} |
| 66 |
|
67 |
|
| 67 |
public ProjectSelectionPage(String pageName, |
68 |
public ProjectSelectionPage(String pageName, String title, IDialogSettings settings, ImageDescriptor image) { |
| 68 |
String title, |
|
|
| 69 |
IDialogSettings settings, |
| 70 |
ImageDescriptor image) { |
| 71 |
super(pageName, title, image); |
69 |
super(pageName, title, image); |
| 72 |
this.settings = settings; |
70 |
this.settings = settings; |
| 73 |
} |
71 |
} |
| 74 |
|
72 |
|
| 75 |
/* |
73 |
/* |
| 76 |
* (non-Javadoc) |
74 |
* (non-Javadoc) |
| 77 |
* |
75 |
* |
|
Lines 79-110
Link Here
|
| 79 |
*/ |
77 |
*/ |
| 80 |
public void createControl(Composite parent) { |
78 |
public void createControl(Composite parent) { |
| 81 |
Font font = parent.getFont(); |
79 |
Font font = parent.getFont(); |
| 82 |
|
80 |
|
| 83 |
Composite topContainer = new Composite(parent, SWT.NONE); |
81 |
Composite topContainer = new Composite(parent, SWT.NONE); |
| 84 |
topContainer.setLayout(new GridLayout()); |
82 |
topContainer.setLayout(new GridLayout()); |
| 85 |
topContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); |
83 |
topContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 86 |
|
84 |
|
| 87 |
Label label = new Label(topContainer, SWT.HORIZONTAL); |
85 |
Label label = new Label(topContainer, SWT.HORIZONTAL); |
| 88 |
label.setFont(font); |
86 |
label.setFont(font); |
| 89 |
label.setText(Messages.getString("ProjectSelectionPage.2")); //$NON-NLS-1$ |
87 |
label.setText(Messages.getString("ProjectSelectionPage.2")); //$NON-NLS-1$ |
| 90 |
|
88 |
|
| 91 |
viewer = new ContainerCheckedTreeViewer(topContainer, SWT.SINGLE | SWT.H_SCROLL |
89 |
viewer = new ContainerCheckedTreeViewer(topContainer, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); |
| 92 |
| SWT.V_SCROLL | SWT.BORDER); |
90 |
GridData gd = new GridData(GridData.FILL_BOTH); |
| 93 |
GridData gd= new GridData(GridData.FILL_BOTH); |
91 |
gd.heightHint = viewer.getTree().getItemHeight() * 15; |
| 94 |
gd.heightHint= viewer.getTree().getItemHeight() * 15; |
|
|
| 95 |
viewer.getTree().setLayoutData(gd); |
92 |
viewer.getTree().setLayoutData(gd); |
| 96 |
viewer.getTree().setFont(font); |
93 |
viewer.getTree().setFont(font); |
| 97 |
viewer.setLabelProvider(new MapFileLabelProvider()); |
94 |
viewer.setLabelProvider(new MapFileLabelProvider()); |
| 98 |
viewer.setContentProvider(getContentProvider()); |
95 |
viewer.setContentProvider(getContentProvider()); |
| 99 |
viewer.setInput(mapProject); |
96 |
viewer.setInput(mapProject); |
| 100 |
viewer.expandAll(); |
97 |
viewer.expandAll(); |
| 101 |
viewer.addCheckStateListener(new ICheckStateListener(){ |
98 |
viewer.addCheckStateListener(new ICheckStateListener() { |
| 102 |
public void checkStateChanged(CheckStateChangedEvent event) { |
99 |
public void checkStateChanged(CheckStateChangedEvent event) { |
| 103 |
updatePageComplete(); |
100 |
updatePageComplete(); |
| 104 |
} |
101 |
} |
| 105 |
}); |
102 |
}); |
| 106 |
|
103 |
|
| 107 |
compareButton = new Button(topContainer,SWT.CHECK); |
104 |
compareButton = new Button(topContainer, SWT.CHECK); |
| 108 |
compareButton.setText(Messages.getString("ProjectSelectionPage.3")); //$NON-NLS-1$ |
105 |
compareButton.setText(Messages.getString("ProjectSelectionPage.3")); //$NON-NLS-1$ |
| 109 |
compareButton.setFont(font); |
106 |
compareButton.setFont(font); |
| 110 |
compareButton.addSelectionListener(new SelectionAdapter() { |
107 |
compareButton.addSelectionListener(new SelectionAdapter() { |
|
Lines 112-139
Link Here
|
| 112 |
compareButtonChecked = compareButton.getSelection(); |
109 |
compareButtonChecked = compareButton.getSelection(); |
| 113 |
} |
110 |
} |
| 114 |
}); |
111 |
}); |
| 115 |
|
112 |
|
| 116 |
initialize(); |
113 |
initialize(); |
| 117 |
setControl(topContainer); |
114 |
setControl(topContainer); |
| 118 |
} |
115 |
} |
|
|
116 |
|
| 119 |
/** |
117 |
/** |
| 120 |
* Returns the content provider for the viewer |
118 |
* Returns the content provider for the viewer |
| 121 |
*/ |
119 |
*/ |
| 122 |
private IContentProvider getContentProvider() { |
120 |
private IContentProvider getContentProvider() { |
| 123 |
return new WorkbenchContentProvider() { |
121 |
return new WorkbenchContentProvider() { |
| 124 |
public Object[] getChildren(Object parentElement) { |
122 |
public Object[] getChildren(Object parentElement) { |
|
|
123 |
|
| 125 |
if (parentElement instanceof MapProject) { |
124 |
if (parentElement instanceof MapProject) { |
| 126 |
return mapProject.getValidMapFiles(); |
125 |
MapFile[] files = mapProject.getValidMapFiles(); |
| 127 |
} |
126 |
if (files == null) |
| 128 |
if (parentElement instanceof MapFile) { |
127 |
return null; |
| 129 |
return ((MapFile)parentElement).getAccessibleProjects(); |
128 |
Set list = new TreeSet(new Comparator() { |
|
|
129 |
public int compare(Object o1, Object o2) { |
| 130 |
String m1 = ((MapFile) o1).getName().toLowerCase(); |
| 131 |
String m2 = ((MapFile) o2).getName().toLowerCase(); |
| 132 |
return m1.compareTo(m2); |
| 133 |
} |
| 134 |
}); |
| 135 |
list.addAll(Arrays.asList(files)); |
| 136 |
return list.toArray(); |
| 137 |
} else if (parentElement instanceof MapFile) { |
| 138 |
IProject[] projects = ((MapFile) parentElement).getAccessibleProjects(); |
| 139 |
if (projects == null) |
| 140 |
return null; |
| 141 |
Set list = new TreeSet(new Comparator() { |
| 142 |
public int compare(Object o1, Object o2) { |
| 143 |
String p1 = ((IProject) o1).getName().toLowerCase(); |
| 144 |
String p2 = ((IProject) o2).getName().toLowerCase(); |
| 145 |
return p1.compareTo(p2); |
| 146 |
} |
| 147 |
}); |
| 148 |
list.addAll(Arrays.asList(projects)); |
| 149 |
return list.toArray(); |
| 130 |
} |
150 |
} |
| 131 |
return null; |
151 |
return null; |
| 132 |
} |
152 |
} |
| 133 |
|
153 |
|
| 134 |
public boolean hasChildren(Object element) { |
154 |
public boolean hasChildren(Object element) { |
| 135 |
if (element instanceof MapFile) { |
155 |
if (element instanceof MapFile) { |
| 136 |
return ((MapFile)element).getAccessibleProjects().length > 0; |
156 |
return ((MapFile) element).getAccessibleProjects().length > 0; |
| 137 |
} |
157 |
} |
| 138 |
return false; |
158 |
return false; |
| 139 |
} |
159 |
} |
|
Lines 143-214
Link Here
|
| 143 |
/** |
163 |
/** |
| 144 |
* Returns all the checked items if they are IProject |
164 |
* Returns all the checked items if they are IProject |
| 145 |
*/ |
165 |
*/ |
| 146 |
public IProject[] getCheckedProjects(){ |
166 |
public IProject[] getCheckedProjects() { |
| 147 |
ArrayList projectsToRelease = new ArrayList(); |
167 |
ArrayList projectsToRelease = new ArrayList(); |
| 148 |
Object[] obj = viewer.getCheckedElements(); |
168 |
Object[] obj = viewer.getCheckedElements(); |
| 149 |
if (obj == null)return null; |
169 |
if (obj == null) |
| 150 |
for(int i = 0; i < obj.length; i++){ |
170 |
return null; |
|
|
171 |
for (int i = 0; i < obj.length; i++) { |
| 151 |
if (obj[i] instanceof IProject) |
172 |
if (obj[i] instanceof IProject) |
| 152 |
projectsToRelease.add(obj[i]); |
173 |
projectsToRelease.add(obj[i]); |
| 153 |
} |
174 |
} |
| 154 |
return (IProject[])projectsToRelease.toArray(new IProject[projectsToRelease.size()]); |
175 |
return (IProject[]) projectsToRelease.toArray(new IProject[projectsToRelease.size()]); |
| 155 |
} |
176 |
} |
| 156 |
|
177 |
|
| 157 |
private void readProjectSettings(){ |
178 |
private void readProjectSettings() { |
| 158 |
if( settings == null) return; |
179 |
if (settings == null) |
| 159 |
if(settings.getArray(SELECTED_ITEMS_KEY) != null){ |
180 |
return; |
|
|
181 |
if (settings.getArray(SELECTED_ITEMS_KEY) != null) { |
| 160 |
ArrayList nameList = new ArrayList(Arrays.asList(settings.getArray(SELECTED_ITEMS_KEY))); |
182 |
ArrayList nameList = new ArrayList(Arrays.asList(settings.getArray(SELECTED_ITEMS_KEY))); |
| 161 |
if(nameList != null){ |
183 |
if (nameList != null) { |
| 162 |
Iterator iter = nameList.iterator(); |
184 |
Iterator iter = nameList.iterator(); |
| 163 |
while(iter.hasNext()){ |
185 |
while (iter.hasNext()) { |
| 164 |
String name = (String)iter.next(); |
186 |
String name = (String) iter.next(); |
| 165 |
IProject project = getProjectWithName(name); |
187 |
IProject project = getProjectWithName(name); |
| 166 |
if(project != null){ |
188 |
if (project != null) { |
| 167 |
viewer.setChecked(project,true); |
189 |
viewer.setChecked(project, true); |
| 168 |
} |
190 |
} |
| 169 |
} |
191 |
} |
| 170 |
} |
192 |
} |
| 171 |
} |
193 |
} |
| 172 |
} |
194 |
} |
| 173 |
|
195 |
|
| 174 |
private void initCompareEnablement(){ |
196 |
private void initCompareEnablement() { |
| 175 |
if( settings == null || settings.get(COMPARE_BUTTON_KEY) == null) { |
197 |
if (settings == null || settings.get(COMPARE_BUTTON_KEY) == null) { |
| 176 |
compareButton.setSelection( true); |
198 |
compareButton.setSelection(true); |
| 177 |
compareButtonChecked = true; |
199 |
compareButtonChecked = true; |
| 178 |
return; |
200 |
return; |
| 179 |
}else{ |
201 |
} else { |
| 180 |
boolean b = settings.getBoolean(COMPARE_BUTTON_KEY); |
202 |
boolean b = settings.getBoolean(COMPARE_BUTTON_KEY); |
| 181 |
compareButton.setSelection(b); |
203 |
compareButton.setSelection(b); |
| 182 |
compareButtonChecked = b; |
204 |
compareButtonChecked = b; |
| 183 |
} |
205 |
} |
| 184 |
} |
206 |
} |
| 185 |
|
207 |
|
| 186 |
/** |
208 |
/** |
| 187 |
* Save the checked items and the checkbox options to dialog settings |
209 |
* Save the checked items and the checkbox options to dialog settings |
| 188 |
*/ |
210 |
*/ |
| 189 |
public void saveSettings(){ |
211 |
public void saveSettings() { |
| 190 |
Object[] obj = viewer.getCheckedElements(); |
212 |
Object[] obj = viewer.getCheckedElements(); |
| 191 |
ArrayList names = new ArrayList(); |
213 |
ArrayList names = new ArrayList(); |
| 192 |
for (int i = 0; i < obj.length; i++){ |
214 |
for (int i = 0; i < obj.length; i++) { |
| 193 |
if(obj[i] instanceof IProject){ |
215 |
if (obj[i] instanceof IProject) { |
| 194 |
names.add(((IProject)obj[i]).getName()); |
216 |
names.add(((IProject) obj[i]).getName()); |
| 195 |
} |
217 |
} |
| 196 |
} |
218 |
} |
| 197 |
settings.put(SELECTED_ITEMS_KEY, (String[])names.toArray(new String[names.size()])); |
219 |
settings.put(SELECTED_ITEMS_KEY, (String[]) names.toArray(new String[names.size()])); |
| 198 |
settings.put(COMPARE_BUTTON_KEY, compareButtonChecked); |
220 |
settings.put(COMPARE_BUTTON_KEY, compareButtonChecked); |
| 199 |
} |
221 |
} |
| 200 |
|
222 |
|
| 201 |
private void initialize(){ |
223 |
private void initialize() { |
| 202 |
initCheckedProjects(); |
224 |
initCheckedProjects(); |
| 203 |
initCompareEnablement(); |
225 |
initCompareEnablement(); |
| 204 |
updatePageComplete(); |
226 |
updatePageComplete(); |
| 205 |
} |
227 |
} |
| 206 |
|
228 |
|
| 207 |
private void initCheckedProjects(){ |
229 |
private void initCheckedProjects() { |
| 208 |
IProject[] p = ((ReleaseWizard)getWizard()).getPreSelectedProjects( ); |
230 |
IProject[] p = ((ReleaseWizard) getWizard()).getPreSelectedProjects(); |
| 209 |
if(p != null){ |
231 |
if (p != null) { |
| 210 |
viewer.setCheckedElements(p); |
232 |
viewer.setCheckedElements(p); |
| 211 |
}else{ |
233 |
} else { |
| 212 |
readProjectSettings(); |
234 |
readProjectSettings(); |
| 213 |
} |
235 |
} |
| 214 |
} |
236 |
} |
|
Lines 216-263
Link Here
|
| 216 |
/** |
238 |
/** |
| 217 |
* Called by <code>readSettings()<code> to return the project associated with the given name |
239 |
* Called by <code>readSettings()<code> to return the project associated with the given name |
| 218 |
*/ |
240 |
*/ |
| 219 |
private IProject getProjectWithName(String name){ |
241 |
private IProject getProjectWithName(String name) { |
| 220 |
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); |
242 |
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); |
| 221 |
if(project.exists() && project.isAccessible()) |
243 |
if (project.exists() && project.isAccessible()) |
| 222 |
return project; |
244 |
return project; |
| 223 |
return null; |
245 |
return null; |
| 224 |
} |
246 |
} |
| 225 |
|
247 |
|
| 226 |
public boolean isCompareButtonChecked(){ |
248 |
public boolean isCompareButtonChecked() { |
| 227 |
return compareButtonChecked; |
249 |
return compareButtonChecked; |
| 228 |
} |
250 |
} |
| 229 |
|
251 |
|
| 230 |
/** |
252 |
/** |
| 231 |
*This page will not complete until at least one project is checked |
253 |
*This page will not complete until at least one project is checked |
| 232 |
*/ |
254 |
*/ |
| 233 |
private void updatePageComplete(){ |
255 |
private void updatePageComplete() { |
| 234 |
Object[] obj = viewer.getCheckedElements(); |
256 |
Object[] obj = viewer.getCheckedElements(); |
| 235 |
if(obj.length > 0){ |
257 |
if (obj.length > 0) { |
| 236 |
for(int i = 0; i < obj.length; i++){ |
258 |
for (int i = 0; i < obj.length; i++) { |
| 237 |
//Exclude the situation that an empty shown map file is selected |
259 |
//Exclude the situation that an empty shown map file is selected |
| 238 |
if(obj[i] instanceof IProject){ |
260 |
if (obj[i] instanceof IProject) { |
| 239 |
setPageComplete(true); |
261 |
setPageComplete(true); |
| 240 |
break; |
262 |
break; |
| 241 |
} |
263 |
} |
| 242 |
} |
264 |
} |
| 243 |
} |
265 |
} else { |
| 244 |
else{ |
|
|
| 245 |
setPageComplete(false); |
266 |
setPageComplete(false); |
| 246 |
} |
267 |
} |
| 247 |
} |
268 |
} |
| 248 |
|
269 |
|
| 249 |
private CheckboxTreeViewer getViewer(){ |
270 |
private CheckboxTreeViewer getViewer() { |
| 250 |
return viewer; |
271 |
return viewer; |
| 251 |
} |
272 |
} |
| 252 |
|
273 |
|
| 253 |
public void setSelection(IProject[] projects) { |
274 |
public void setSelection(IProject[] projects) { |
| 254 |
if(projects != null && projects.length > 0){ |
275 |
if (projects != null && projects.length > 0) { |
| 255 |
getViewer().setCheckedElements(projects); |
276 |
getViewer().setCheckedElements(projects); |
| 256 |
} |
277 |
} |
| 257 |
} |
278 |
} |
| 258 |
public void updateMapProject(MapProject m){ |
279 |
|
|
|
280 |
public void updateMapProject(MapProject m) { |
| 259 |
mapProject = m; |
281 |
mapProject = m; |
| 260 |
if(viewer != null){ |
282 |
if (viewer != null) { |
| 261 |
viewer.setInput(mapProject); |
283 |
viewer.setInput(mapProject); |
| 262 |
} |
284 |
} |
| 263 |
} |
285 |
} |