|
Added
Link Here
|
| 1 |
package org.eclipse.pde.internal.ui.shared.target; |
| 2 |
|
| 3 |
import com.ibm.icu.text.MessageFormat; |
| 4 |
import java.net.URI; |
| 5 |
import java.util.*; |
| 6 |
import java.util.List; |
| 7 |
import org.eclipse.core.runtime.*; |
| 8 |
import org.eclipse.core.runtime.jobs.*; |
| 9 |
import org.eclipse.jface.viewers.*; |
| 10 |
import org.eclipse.pde.internal.core.target.provisional.*; |
| 11 |
import org.eclipse.pde.internal.ui.SWTFactory; |
| 12 |
import org.eclipse.swt.SWT; |
| 13 |
import org.eclipse.swt.events.SelectionAdapter; |
| 14 |
import org.eclipse.swt.events.SelectionEvent; |
| 15 |
import org.eclipse.swt.layout.GridData; |
| 16 |
import org.eclipse.swt.widgets.*; |
| 17 |
import org.eclipse.ui.dialogs.FilteredTree; |
| 18 |
import org.eclipse.ui.dialogs.PatternFilter; |
| 19 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
| 20 |
import org.eclipse.ui.progress.UIJob; |
| 21 |
|
| 22 |
public class TargetContentsGroup extends FilteredTree { |
| 23 |
|
| 24 |
private CheckboxTreeViewer fTree; |
| 25 |
private Button fSelectButton; |
| 26 |
private Button fDeselectButton; |
| 27 |
private Button fSelectAllButton; |
| 28 |
private Button fDeselectAllButton; |
| 29 |
// private Button fSelectRequiredButton; |
| 30 |
private Label fShowLabel; |
| 31 |
private Button fShowSourceButton; |
| 32 |
private Button fShowPluginsButton; |
| 33 |
private Label fCountLabel; |
| 34 |
private Label fGroupLabel; |
| 35 |
private Combo fGroupCombo; |
| 36 |
|
| 37 |
private ViewerFilter fSourceFilter; |
| 38 |
private ViewerFilter fPluginFilter; |
| 39 |
|
| 40 |
private List fAllBundles; |
| 41 |
private Set fAllChecked; |
| 42 |
private Map fContainerBundles; |
| 43 |
private Map fContainerChecked; |
| 44 |
private Map fFileBundles; |
| 45 |
private Map fFileChecked; |
| 46 |
|
| 47 |
private ITargetDefinition fTargetDefinition; |
| 48 |
|
| 49 |
private int fGrouping; |
| 50 |
private static final int GROUP_BY_NONE = 0; |
| 51 |
private static final int GROUP_BY_FILE_LOC = 1; |
| 52 |
private static final int GROUP_BY_CONTAINER = 2; |
| 53 |
private ListenerList fChangeListeners = new ListenerList(); |
| 54 |
|
| 55 |
public static TargetContentsGroup createInForm(Composite parent, FormToolkit toolkit) { |
| 56 |
// TODO Should we be using the tooklit to create the controls? |
| 57 |
TargetContentsGroup control = new TargetContentsGroup(parent); |
| 58 |
return control; |
| 59 |
} |
| 60 |
|
| 61 |
public static TargetContentsGroup createInDialog(Composite parent) { |
| 62 |
TargetContentsGroup control = new TargetContentsGroup(parent); |
| 63 |
return control; |
| 64 |
} |
| 65 |
|
| 66 |
private TargetContentsGroup(Composite parent) { |
| 67 |
super(parent, SWT.BORDER | SWT.MULTI, new PatternFilter(), true); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Adds a listener to the set of listeners that will be notified when the bundle containers |
| 72 |
* are modified. This method has no effect if the listener has already been added. |
| 73 |
* |
| 74 |
* @param listener target changed listener to add |
| 75 |
*/ |
| 76 |
public void addTargetChangedListener(ITargetChangedListener listener) { |
| 77 |
fChangeListeners.add(listener); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Informs the target content listeners that check state has changed |
| 82 |
*/ |
| 83 |
public void contentChanged() { |
| 84 |
// TODO Save the included bundles |
| 85 |
Object[] listeners = fChangeListeners.getListeners(); |
| 86 |
for (int i = 0; i < listeners.length; i++) { |
| 87 |
((ITargetChangedListener) listeners[i]).contentsChanged(fTargetDefinition, false); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/* (non-Javadoc) |
| 92 |
* @see org.eclipse.ui.dialogs.FilteredTree#createTreeControl(org.eclipse.swt.widgets.Composite, int) |
| 93 |
*/ |
| 94 |
protected Control createTreeControl(Composite parent, int style) { |
| 95 |
fGrouping = GROUP_BY_NONE; |
| 96 |
Composite treeComp = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_BOTH, 0, 0); |
| 97 |
super.createTreeControl(treeComp, style); |
| 98 |
((GridData) fTree.getControl().getLayoutData()).heightHint = 300; |
| 99 |
createButtons(treeComp); |
| 100 |
createOptions(treeComp); |
| 101 |
|
| 102 |
updateButtons(); |
| 103 |
initializeFilters(); |
| 104 |
return treeComp; |
| 105 |
} |
| 106 |
|
| 107 |
/* (non-Javadoc) |
| 108 |
* @see org.eclipse.ui.dialogs.FilteredTree#doCreateTreeViewer(org.eclipse.swt.widgets.Composite, int) |
| 109 |
*/ |
| 110 |
protected TreeViewer doCreateTreeViewer(Composite parent, int style) { |
| 111 |
fTree = new CheckboxTreeViewer(parent, style) { |
| 112 |
public void refresh(boolean updateLabels) { |
| 113 |
super.refresh(updateLabels); |
| 114 |
if (updateLabels) { |
| 115 |
// We want to update the labels and buttons as users change the filtering |
| 116 |
updateButtons(); |
| 117 |
} |
| 118 |
} |
| 119 |
}; |
| 120 |
fTree.setContentProvider(new TreeContentProvider()); |
| 121 |
fTree.setLabelProvider(new BundleContainerLabelProvider()); |
| 122 |
fTree.addDoubleClickListener(new IDoubleClickListener() { |
| 123 |
public void doubleClick(DoubleClickEvent event) { |
| 124 |
IStructuredSelection selection = (IStructuredSelection) event.getSelection(); |
| 125 |
Object first = selection.getFirstElement(); |
| 126 |
handleCheck(new Object[] {selection.getFirstElement()}, !fTree.getChecked(first)); |
| 127 |
} |
| 128 |
}); |
| 129 |
fTree.addCheckStateListener(new ICheckStateListener() { |
| 130 |
public void checkStateChanged(CheckStateChangedEvent event) { |
| 131 |
handleCheck(new Object[] {event.getElement()}, fTree.getChecked(event.getElement())); |
| 132 |
} |
| 133 |
}); |
| 134 |
fTree.addSelectionChangedListener(new ISelectionChangedListener() { |
| 135 |
public void selectionChanged(SelectionChangedEvent event) { |
| 136 |
updateButtons(); |
| 137 |
} |
| 138 |
}); |
| 139 |
fTree.setSorter(new ViewerSorter() { |
| 140 |
public int compare(Viewer viewer, Object e1, Object e2) { |
| 141 |
if (e1 instanceof IResolvedBundle && e2 instanceof IResolvedBundle) { |
| 142 |
IStatus status1 = ((IResolvedBundle) e1).getStatus(); |
| 143 |
IStatus status2 = ((IResolvedBundle) e2).getStatus(); |
| 144 |
if (!status1.isOK() && status2.isOK()) { |
| 145 |
return -1; |
| 146 |
} |
| 147 |
if (status1.isOK() && !status2.isOK()) { |
| 148 |
return 1; |
| 149 |
} |
| 150 |
} |
| 151 |
return super.compare(viewer, e1, e2); |
| 152 |
} |
| 153 |
|
| 154 |
}); |
| 155 |
return fTree; |
| 156 |
} |
| 157 |
|
| 158 |
private void createButtons(Composite parent) { |
| 159 |
Composite buttonComp = SWTFactory.createComposite(parent, 1, 1, GridData.FILL_VERTICAL, 0, 0); |
| 160 |
|
| 161 |
fSelectButton = SWTFactory.createPushButton(buttonComp, Messages.IncludedBundlesTree_0, null); |
| 162 |
fSelectButton.addSelectionListener(new SelectionAdapter() { |
| 163 |
public void widgetSelected(SelectionEvent e) { |
| 164 |
if (!fTree.getSelection().isEmpty()) { |
| 165 |
Object[] selected = ((IStructuredSelection) fTree.getSelection()).toArray(); |
| 166 |
handleCheck(selected, true); |
| 167 |
} |
| 168 |
} |
| 169 |
}); |
| 170 |
fDeselectButton = SWTFactory.createPushButton(buttonComp, Messages.IncludedBundlesTree_1, null); |
| 171 |
fDeselectButton.addSelectionListener(new SelectionAdapter() { |
| 172 |
public void widgetSelected(SelectionEvent e) { |
| 173 |
if (!fTree.getSelection().isEmpty()) { |
| 174 |
Object[] selected = ((IStructuredSelection) fTree.getSelection()).toArray(); |
| 175 |
handleCheck(selected, false); |
| 176 |
} |
| 177 |
} |
| 178 |
}); |
| 179 |
|
| 180 |
createEmptySpace(buttonComp); |
| 181 |
|
| 182 |
fSelectAllButton = SWTFactory.createPushButton(buttonComp, Messages.IncludedBundlesTree_2, null); |
| 183 |
fSelectAllButton.addSelectionListener(new SelectionAdapter() { |
| 184 |
public void widgetSelected(SelectionEvent e) { |
| 185 |
// TODO |
| 186 |
// Object[] elements = ((ITreeContentProvider) fTree.getContentProvider()).getElements(fTree.getInput()); |
| 187 |
// fTree.setGrayedElements(new Object[0]); |
| 188 |
// for (int i = 0; i < elements.length; i++) { |
| 189 |
// fTree.setSubtreeChecked(elements[i], true); |
| 190 |
// } |
| 191 |
// updateParentCheckState(elements); |
| 192 |
// contentChanged(); |
| 193 |
// updateButtons(); |
| 194 |
} |
| 195 |
}); |
| 196 |
fDeselectAllButton = SWTFactory.createPushButton(buttonComp, Messages.IncludedBundlesTree_3, null); |
| 197 |
fDeselectAllButton.addSelectionListener(new SelectionAdapter() { |
| 198 |
public void widgetSelected(SelectionEvent e) { |
| 199 |
// TODO |
| 200 |
// Object[] elements = ((ITreeContentProvider) fTree.getContentProvider()).getElements(fTree.getInput()); |
| 201 |
// fTree.setGrayedElements(new Object[0]); |
| 202 |
// for (int i = 0; i < elements.length; i++) { |
| 203 |
// fTree.setSubtreeChecked(elements[i], false); |
| 204 |
// } |
| 205 |
// updateParentCheckState(elements); |
| 206 |
// contentChanged(); |
| 207 |
// updateButtons(); |
| 208 |
} |
| 209 |
}); |
| 210 |
|
| 211 |
createEmptySpace(buttonComp); |
| 212 |
|
| 213 |
// TODO Support selecting required. |
| 214 |
// fSelectRequiredButton = SWTFactory.createPushButton(buttonComp, Messages.IncludedBundlesTree_4, null); |
| 215 |
// fSelectRequiredButton.addSelectionListener(new SelectionAdapter() { |
| 216 |
// public void widgetSelected(SelectionEvent e) { |
| 217 |
// updateButtons(); |
| 218 |
// } |
| 219 |
// }); |
| 220 |
|
| 221 |
Composite filterComp = SWTFactory.createComposite(buttonComp, 1, 1, SWT.NONE, 0, 0); |
| 222 |
filterComp.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true, true)); |
| 223 |
|
| 224 |
fShowLabel = SWTFactory.createLabel(filterComp, Messages.BundleContainerTable_9, 1); |
| 225 |
|
| 226 |
fShowPluginsButton = SWTFactory.createCheckButton(filterComp, Messages.BundleContainerTable_14, null, true, 1); |
| 227 |
fShowPluginsButton.addSelectionListener(new SelectionAdapter() { |
| 228 |
public void widgetSelected(SelectionEvent e) { |
| 229 |
if (!fShowPluginsButton.getSelection()) { |
| 230 |
fTree.addFilter(fPluginFilter); |
| 231 |
} else { |
| 232 |
fTree.removeFilter(fPluginFilter); |
| 233 |
} |
| 234 |
updateButtons(); |
| 235 |
} |
| 236 |
}); |
| 237 |
fShowPluginsButton.setSelection(true); |
| 238 |
GridData gd = new GridData(); |
| 239 |
gd.horizontalIndent = 10; |
| 240 |
fShowPluginsButton.setLayoutData(gd); |
| 241 |
|
| 242 |
fShowSourceButton = SWTFactory.createCheckButton(filterComp, Messages.BundleContainerTable_15, null, true, 1); |
| 243 |
fShowSourceButton.addSelectionListener(new SelectionAdapter() { |
| 244 |
public void widgetSelected(SelectionEvent e) { |
| 245 |
if (!fShowSourceButton.getSelection()) { |
| 246 |
fTree.addFilter(fSourceFilter); |
| 247 |
} else { |
| 248 |
fTree.removeFilter(fSourceFilter); |
| 249 |
} |
| 250 |
updateButtons(); |
| 251 |
} |
| 252 |
}); |
| 253 |
fShowSourceButton.setSelection(true); |
| 254 |
gd = new GridData(); |
| 255 |
gd.horizontalIndent = 10; |
| 256 |
fShowSourceButton.setLayoutData(gd); |
| 257 |
} |
| 258 |
|
| 259 |
private void createOptions(Composite parent) { |
| 260 |
Composite comp = SWTFactory.createComposite(parent, 2, 2, GridData.FILL_HORIZONTAL, 0, 0); |
| 261 |
|
| 262 |
fGroupLabel = SWTFactory.createLabel(comp, "Group by:", 1); |
| 263 |
fGroupCombo = SWTFactory.createCombo(comp, SWT.READ_ONLY, 1, new String[] {"None", "File Path", "Plug-in Container"}); |
| 264 |
fGroupCombo.addSelectionListener(new SelectionAdapter() { |
| 265 |
public void widgetSelected(SelectionEvent e) { |
| 266 |
handleGroupChange(); |
| 267 |
} |
| 268 |
}); |
| 269 |
|
| 270 |
fCountLabel = SWTFactory.createLabel(comp, "", 2); //$NON-NLS-1$ |
| 271 |
} |
| 272 |
|
| 273 |
private void initializeFilters() { |
| 274 |
fSourceFilter = new ViewerFilter() { |
| 275 |
public boolean select(Viewer viewer, Object parentElement, Object element) { |
| 276 |
if (element instanceof IResolvedBundle) { |
| 277 |
if (((IResolvedBundle) element).isSourceBundle()) { |
| 278 |
return false; |
| 279 |
} |
| 280 |
} |
| 281 |
return true; |
| 282 |
} |
| 283 |
}; |
| 284 |
fPluginFilter = new ViewerFilter() { |
| 285 |
public boolean select(Viewer viewer, Object parentElement, Object element) { |
| 286 |
if (element instanceof IResolvedBundle) { |
| 287 |
if (!((IResolvedBundle) element).isSourceBundle()) { |
| 288 |
return false; |
| 289 |
} |
| 290 |
} |
| 291 |
return true; |
| 292 |
} |
| 293 |
}; |
| 294 |
} |
| 295 |
|
| 296 |
private Label createEmptySpace(Composite parent) { |
| 297 |
Label label = new Label(parent, SWT.NONE); |
| 298 |
GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); |
| 299 |
gd.widthHint = gd.heightHint = 5; |
| 300 |
label.setLayoutData(gd); |
| 301 |
return label; |
| 302 |
} |
| 303 |
|
| 304 |
private IPath getParentPath(IResolvedBundle bundle) { |
| 305 |
URI location = bundle.getBundleInfo().getLocation(); |
| 306 |
if (location == null) { |
| 307 |
return new Path("Unknown"); |
| 308 |
} |
| 309 |
IPath path = new Path(URIUtil.toUnencodedString(location)); |
| 310 |
path = path.removeLastSegments(1); |
| 311 |
return path; |
| 312 |
} |
| 313 |
|
| 314 |
private void handleCheck(Object[] changedElements, boolean checkState) { |
| 315 |
if (changedElements.length > 0) { |
| 316 |
if (changedElements[0] instanceof IResolvedBundle) { |
| 317 |
Set parentsToUpdate = new HashSet(); |
| 318 |
for (int i = 0; i < changedElements.length; i++) { |
| 319 |
Object parent = ((IResolvedBundle) changedElements[i]).getParentContainer(); |
| 320 |
if (fGrouping == GROUP_BY_CONTAINER) { |
| 321 |
parentsToUpdate.add(parent); |
| 322 |
} |
| 323 |
Set containerChecked = ((Set) fContainerChecked.get(parent)); |
| 324 |
|
| 325 |
parent = getParentPath((IResolvedBundle) changedElements[i]); |
| 326 |
if (fGrouping == GROUP_BY_FILE_LOC) { |
| 327 |
parentsToUpdate.add(parent); |
| 328 |
} |
| 329 |
Set fileChecked = ((Set) fContainerChecked.get(parent)); |
| 330 |
|
| 331 |
if (checkState) { |
| 332 |
fAllChecked.add(changedElements[i]); |
| 333 |
containerChecked.add(changedElements[i]); |
| 334 |
fileChecked.add(changedElements[i]); |
| 335 |
} else { |
| 336 |
fAllChecked.remove(changedElements[i]); |
| 337 |
containerChecked.remove(changedElements[i]); |
| 338 |
fileChecked.remove(changedElements[i]); |
| 339 |
} |
| 340 |
fTree.setChecked(changedElements, checkState); |
| 341 |
} |
| 342 |
for (Iterator iterator = parentsToUpdate.iterator(); iterator.hasNext();) { |
| 343 |
Object parent = iterator.next(); |
| 344 |
if (getChecked(parent).size() == 0) { |
| 345 |
fTree.setGrayChecked(parent, false); |
| 346 |
} else if (getChecked(parent).size() == getBundleChildren(parent).size()) { |
| 347 |
fTree.setGrayed(parent, false); |
| 348 |
fTree.setChecked(parent, true); |
| 349 |
} else { |
| 350 |
fTree.setGrayChecked(parent, true); |
| 351 |
} |
| 352 |
} |
| 353 |
} else { |
| 354 |
for (int i = 0; i < changedElements.length; i++) { |
| 355 |
fTree.setGrayed(changedElements[i], false); |
| 356 |
fTree.setChecked(changedElements[i], checkState); |
| 357 |
fTree.setSubtreeChecked(changedElements[i], checkState); |
| 358 |
|
| 359 |
fgetChecked(changedElements[i]). |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
/** |
| 366 |
* Update the check state of parent elements when there is grouping. The list of changed elements must be |
| 367 |
* all IResolvedBundles. |
| 368 |
* |
| 369 |
* @param changedElements array of IResolvedBundles that have changed |
| 370 |
*/ |
| 371 |
private void updateParentCheckState(Object[] changedElements) { |
| 372 |
if (fGrouping != GROUP_BY_NONE && changedElements.length > 0) { |
| 373 |
Set changedParents = new HashSet(); |
| 374 |
if (changedElements[0] instanceof IResolvedBundle) { |
| 375 |
if (fGrouping == GROUP_BY_FILE_LOC) { |
| 376 |
for (int i = 0; i < changedElements.length; i++) { |
| 377 |
changedParents.add(getParentPath((IResolvedBundle) changedElements[i])); |
| 378 |
} |
| 379 |
} else if (fGrouping == GROUP_BY_CONTAINER) { |
| 380 |
for (int i = 0; i < changedElements.length; i++) { |
| 381 |
changedParents.add(((IResolvedBundle) changedElements[i]).getParentContainer()); |
| 382 |
} |
| 383 |
} |
| 384 |
} else { |
| 385 |
changedParents.addAll(Arrays.asList(changedElements)); |
| 386 |
} |
| 387 |
if (fGrouping == GROUP_BY_FILE_LOC) { |
| 388 |
for (Iterator iterator = changedParents.iterator(); iterator.hasNext();) { |
| 389 |
IPath currentParent = (IPath) iterator.next(); |
| 390 |
List children = (List) getFileLocationMap().get(currentParent); |
| 391 |
updateGrayChecked(currentParent, children); |
| 392 |
} |
| 393 |
} else if (fGrouping == GROUP_BY_CONTAINER) { |
| 394 |
for (Iterator iterator = changedParents.iterator(); iterator.hasNext();) { |
| 395 |
IBundleContainer currentParent = (IBundleContainer) iterator.next(); |
| 396 |
List children = Arrays.asList(currentParent.getAllBundles()); |
| 397 |
// TODO Get plug-in errors (missing bundles) |
| 398 |
updateGrayChecked(currentParent, children); |
| 399 |
} |
| 400 |
} |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
/** |
| 405 |
* Updates the children of the changed parent elements. Also removed the gray state |
| 406 |
* of the parent. |
| 407 |
* |
| 408 |
* @param changedElements list of changed parents |
| 409 |
* @param state whether the parents are being checked or unchecked |
| 410 |
*/ |
| 411 |
private void updateChildrenCheckState(Object[] changedElements, boolean state) { |
| 412 |
for (int i = 0; i < changedElements.length; i++) { |
| 413 |
fTree.setSubtreeChecked(changedElements[i], state); |
| 414 |
fTree.setGrayed(changedElements[i], false); |
| 415 |
fTree.setChecked(changedElements[i], state); |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
private void updateGrayChecked(Object parent, List children) { |
| 420 |
boolean allChecked = true; |
| 421 |
boolean noneChecked = true; |
| 422 |
for (Iterator iterator2 = children.iterator(); iterator2.hasNext();) { |
| 423 |
boolean checked = fTree.getChecked(iterator2.next()); |
| 424 |
if (checked) { |
| 425 |
noneChecked = false; |
| 426 |
} else { |
| 427 |
allChecked = false; |
| 428 |
} |
| 429 |
if (!noneChecked && !allChecked) { |
| 430 |
break; |
| 431 |
} |
| 432 |
} |
| 433 |
if (!noneChecked && !allChecked) { |
| 434 |
fTree.setGrayChecked(parent, true); |
| 435 |
} else if (allChecked) { |
| 436 |
fTree.setChecked(parent, true); |
| 437 |
fTree.setGrayed(parent, false); |
| 438 |
} else { |
| 439 |
fTree.setChecked(parent, false); |
| 440 |
fTree.setGrayed(parent, false); |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
private void handleGroupChange() { |
| 445 |
// TODO |
| 446 |
fGrouping = fGroupCombo.getSelectionIndex(); |
| 447 |
Object[] checked = fTree.getCheckedElements(); |
| 448 |
fTree.getControl().setRedraw(false); |
| 449 |
fTree.refresh(false); |
| 450 |
fTree.setCheckedElements(checked); |
| 451 |
if (fGrouping == GROUP_BY_CONTAINER) { |
| 452 |
updateParentCheckState(fTargetDefinition.getBundleContainers()); |
| 453 |
} else if (fGrouping == GROUP_BY_FILE_LOC) { |
| 454 |
updateParentCheckState(getFileLocationMap().keySet().toArray()); |
| 455 |
} |
| 456 |
fTree.getControl().setRedraw(true); |
| 457 |
updateButtons(); |
| 458 |
} |
| 459 |
|
| 460 |
private void updateButtons() { |
| 461 |
if (fTargetDefinition != null && !fTree.getSelection().isEmpty()) { |
| 462 |
Object[] selection = ((IStructuredSelection) fTree.getSelection()).toArray(); |
| 463 |
boolean hasResolveBundle = false; |
| 464 |
boolean hasParent = false; |
| 465 |
boolean allSelected = true; |
| 466 |
boolean noneSelected = true; |
| 467 |
for (int i = 0; i < selection.length; i++) { |
| 468 |
if (!hasResolveBundle || !hasParent) { |
| 469 |
if (selection[i] instanceof IResolvedBundle) { |
| 470 |
hasResolveBundle = true; |
| 471 |
} else { |
| 472 |
hasParent = true; |
| 473 |
} |
| 474 |
} |
| 475 |
boolean checked = fTree.getChecked(selection[i]); |
| 476 |
if (checked) { |
| 477 |
noneSelected = false; |
| 478 |
} else { |
| 479 |
allSelected = false; |
| 480 |
} |
| 481 |
} |
| 482 |
// Selection is available is not everything is already selected and not both a parent and child item are selected |
| 483 |
fSelectButton.setEnabled(!allSelected && !(hasResolveBundle && hasParent)); |
| 484 |
fDeselectButton.setEnabled(!noneSelected && !(hasResolveBundle && hasParent)); |
| 485 |
// fSelectRequiredButton.setEnabled(true); |
| 486 |
} else { |
| 487 |
fSelectButton.setEnabled(false); |
| 488 |
fDeselectButton.setEnabled(false); |
| 489 |
// fSelectRequiredButton.setEnabled(false); |
| 490 |
} |
| 491 |
|
| 492 |
// TODO how to handle filtered case |
| 493 |
if (fGrouping == GROUP_BY_FILE_LOC) { |
| 494 |
boolean allChecked = true; |
| 495 |
boolean noneChecked = true; |
| 496 |
if (fTree.getGrayedElements().length > 0) { |
| 497 |
allChecked = false; |
| 498 |
noneChecked = false; |
| 499 |
} else { |
| 500 |
for (Iterator iterator = getFileLocationMap().keySet().iterator(); iterator.hasNext();) { |
| 501 |
boolean checked = fTree.getChecked(iterator.next()); |
| 502 |
if (checked) { |
| 503 |
noneChecked = false; |
| 504 |
} else { |
| 505 |
allChecked = false; |
| 506 |
} |
| 507 |
if (!noneChecked && !allChecked) { |
| 508 |
break; |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
fSelectAllButton.setEnabled(fTargetDefinition != null && !allChecked); |
| 513 |
fDeselectAllButton.setEnabled(fTargetDefinition != null && !noneChecked); |
| 514 |
} else { |
| 515 |
int checked = fTree.getCheckedElements().length; |
| 516 |
fSelectAllButton.setEnabled(fTargetDefinition != null && checked != fTree.getTree().getItemCount()); |
| 517 |
fDeselectAllButton.setEnabled(fTargetDefinition != null && checked != 0); |
| 518 |
} |
| 519 |
|
| 520 |
if (fTargetDefinition != null) { |
| 521 |
fCountLabel.setText(MessageFormat.format("{0} of {1} selected", new String[] {Integer.toString(fAllChecked.size()), Integer.toString(fAllBundles.size())})); |
| 522 |
} else { |
| 523 |
fCountLabel.setText(""); //$NON-NLS-1$ |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
/** |
| 528 |
* Set the container to display in the tree or <code>null</code> to disable the tree |
| 529 |
* @param input bundle container or <code>null</code> |
| 530 |
*/ |
| 531 |
public void setInput(ITargetDefinition input) { |
| 532 |
fTargetDefinition = input; |
| 533 |
|
| 534 |
if (input == null || !input.isResolved()) { |
| 535 |
fTree.setInput("Resolving..."); |
| 536 |
setEnabled(false); |
| 537 |
return; |
| 538 |
} |
| 539 |
|
| 540 |
IResolvedBundle[] allResolvedBundles = input.getAllBundles(); |
| 541 |
if (allResolvedBundles == null || allResolvedBundles.length == 0) { |
| 542 |
fTree.setInput("< no plug-ins found in the target >"); |
| 543 |
setEnabled(false); |
| 544 |
return; |
| 545 |
} |
| 546 |
|
| 547 |
fTree.setInput("Initializing..."); |
| 548 |
setEnabled(false); |
| 549 |
Job initJob = new InitalizeJob(); |
| 550 |
initJob.addJobChangeListener(new JobChangeAdapter() { |
| 551 |
public void done(IJobChangeEvent event) { |
| 552 |
Job refreshJob = new UIJob("Refreshing Tree") { |
| 553 |
public IStatus runInUIThread(IProgressMonitor monitor) { |
| 554 |
fTree.setInput(fTargetDefinition); |
| 555 |
// For now we always start with no grouping |
| 556 |
fTree.setCheckedElements(getChecked(null).toArray()); |
| 557 |
setEnabled(true); |
| 558 |
return Status.OK_STATUS; |
| 559 |
} |
| 560 |
}; |
| 561 |
refreshJob.setSystem(true); |
| 562 |
refreshJob.schedule(); |
| 563 |
} |
| 564 |
}); |
| 565 |
initJob.schedule(); |
| 566 |
} |
| 567 |
|
| 568 |
private class InitalizeJob extends Job { |
| 569 |
|
| 570 |
public InitalizeJob() { |
| 571 |
super("Initializing Tree"); |
| 572 |
setSystem(true); |
| 573 |
} |
| 574 |
|
| 575 |
protected IStatus run(IProgressMonitor monitor) { |
| 576 |
fAllBundles = new ArrayList(); |
| 577 |
fAllChecked = new HashSet(); |
| 578 |
fContainerBundles = new HashMap(); |
| 579 |
fContainerChecked = new HashMap(); |
| 580 |
IBundleContainer[] containers = fTargetDefinition.getBundleContainers(); |
| 581 |
// Iterate through each container, adding bundles to the map and list |
| 582 |
for (int i = 0; i < containers.length; i++) { |
| 583 |
List containerBundles = Arrays.asList(containers[i].getAllBundles()); |
| 584 |
fAllBundles.addAll(containerBundles); |
| 585 |
fContainerBundles.put(containers[i], containerBundles); |
| 586 |
|
| 587 |
// Determine which of the bundles are checked (included) |
| 588 |
if (containers[i].getIncludedBundles() == null) { |
| 589 |
// Everything is included |
| 590 |
Set checked = new HashSet(); |
| 591 |
checked.addAll(containerBundles); |
| 592 |
fContainerChecked.put(containers[i], checked); |
| 593 |
fAllChecked.addAll(checked); |
| 594 |
} else { |
| 595 |
// Mark the included bundles as checked |
| 596 |
List includedBundles = Arrays.asList(containers[i].getBundles()); |
| 597 |
// If an included bundle has errors it must be explicitly added to the bundle list as getAllBundles does not return it. |
| 598 |
for (Iterator iterator = includedBundles.iterator(); iterator.hasNext();) { |
| 599 |
IResolvedBundle currentIncluded = (IResolvedBundle) iterator.next(); |
| 600 |
if (!currentIncluded.getStatus().isOK()) { |
| 601 |
((List) fContainerBundles.get(containers[i])).add(currentIncluded); |
| 602 |
fAllBundles.add(currentIncluded); |
| 603 |
} |
| 604 |
} |
| 605 |
Set checked = new HashSet(); |
| 606 |
checked.addAll(includedBundles); |
| 607 |
fContainerChecked.put(containers[i], checked); |
| 608 |
fAllChecked.addAll(checked); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
// Map the bundles into their file locations |
| 613 |
fFileBundles = new HashMap(); |
| 614 |
fFileChecked = new HashMap(); |
| 615 |
Set allChecked = new HashSet(); |
| 616 |
allChecked.addAll(fAllChecked); |
| 617 |
for (Iterator iterator = fAllBundles.iterator(); iterator.hasNext();) { |
| 618 |
IResolvedBundle currentBundle = (IResolvedBundle) iterator.next(); |
| 619 |
IPath parentPath = getParentPath(currentBundle); |
| 620 |
List bundles = (List) fFileBundles.get(parentPath); |
| 621 |
if (bundles == null) { |
| 622 |
bundles = new ArrayList(); |
| 623 |
bundles.add(currentBundle); |
| 624 |
fFileBundles.put(parentPath, bundles); |
| 625 |
} else { |
| 626 |
bundles.add(currentBundle); |
| 627 |
} |
| 628 |
// Determine whether the current bundle is checked |
| 629 |
if (allChecked.contains(currentBundle)) { |
| 630 |
Set checked = (Set) fFileChecked.get(parentPath); |
| 631 |
if (checked == null) { |
| 632 |
checked = new HashSet(); |
| 633 |
checked.add(currentBundle); |
| 634 |
fFileChecked.put(parentPath, checked); |
| 635 |
} else { |
| 636 |
checked.add(currentBundle); |
| 637 |
} |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
return Status.OK_STATUS; |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
private Set getChecked(Object parent) { |
| 646 |
Set result = null; |
| 647 |
if (parent == null) { |
| 648 |
result = fAllChecked; |
| 649 |
} else if (fGrouping == GROUP_BY_CONTAINER) { |
| 650 |
result = (Set) fContainerChecked.get(parent); |
| 651 |
} else if (fGrouping == GROUP_BY_FILE_LOC) { |
| 652 |
result = (Set) fFileChecked.get(parent); |
| 653 |
} |
| 654 |
if (result == null) { |
| 655 |
return new HashSet(0); |
| 656 |
} |
| 657 |
return result; |
| 658 |
} |
| 659 |
|
| 660 |
private List getBundleChildren(Object parent) { |
| 661 |
List result = null; |
| 662 |
if (parent == null) { |
| 663 |
result = fAllBundles; |
| 664 |
} else if (fGrouping == GROUP_BY_CONTAINER) { |
| 665 |
result = (List) fContainerBundles.get(parent); |
| 666 |
} else if (fGrouping == GROUP_BY_FILE_LOC) { |
| 667 |
result = (List) fFileBundles.get(parent); |
| 668 |
} |
| 669 |
if (result == null) { |
| 670 |
return new ArrayList(0); |
| 671 |
} |
| 672 |
return result; |
| 673 |
} |
| 674 |
|
| 675 |
/* (non-Javadoc) |
| 676 |
* @see org.eclipse.swt.widgets.Control#setEnabled(boolean) |
| 677 |
*/ |
| 678 |
public void setEnabled(boolean enabled) { |
| 679 |
super.setEnabled(enabled); |
| 680 |
if (enabled) { |
| 681 |
updateButtons(); |
| 682 |
} else { |
| 683 |
fSelectButton.setEnabled(false); |
| 684 |
fSelectAllButton.setEnabled(false); |
| 685 |
fDeselectButton.setEnabled(false); |
| 686 |
fDeselectAllButton.setEnabled(false); |
| 687 |
// fSelectRequiredButton.setEnabled(false); |
| 688 |
fCountLabel.setText(""); //$NON-NLS-1$ |
| 689 |
} |
| 690 |
fShowLabel.setEnabled(enabled); |
| 691 |
fShowPluginsButton.setEnabled(enabled); |
| 692 |
fShowSourceButton.setEnabled(enabled); |
| 693 |
fGroupLabel.setEnabled(enabled); |
| 694 |
fGroupCombo.setEnabled(enabled); |
| 695 |
super.setEnabled(enabled); |
| 696 |
} |
| 697 |
|
| 698 |
public void saveIncludedBundleState() { |
| 699 |
// TODO Simplify with bundle containers |
| 700 |
// IBundleContainer[] containers = fTargetDefinition.getBundleContainers(); |
| 701 |
// for (int i = 0; i < containers.length; i++) { |
| 702 |
// IResolvedBundle[] allBundles = containers[i].getAllBundles(); |
| 703 |
// List included = new ArrayList(allBundles.length); |
| 704 |
// for (int j = 0; j < allBundles.length; j++) { |
| 705 |
// if (fTree.getChecked(allBundles[j])) { |
| 706 |
// included.add(new BundleInfo(allBundles[j].getBundleInfo().getSymbolicName(), null, null, BundleInfo.NO_LEVEL, false)); |
| 707 |
// } |
| 708 |
// } |
| 709 |
// if (included.size() == allBundles.length) { |
| 710 |
// containers[i].setIncludedBundles(null); |
| 711 |
// } else { |
| 712 |
// containers[i].setIncludedBundles((BundleInfo[]) included.toArray(new BundleInfo[included.size()])); |
| 713 |
// } |
| 714 |
// } |
| 715 |
// TODO Handle plug-in errors (missing bundles) |
| 716 |
} |
| 717 |
|
| 718 |
class TreeContentProvider implements ITreeContentProvider { |
| 719 |
public Object[] getChildren(Object parentElement) { |
| 720 |
return getBundleChildren(parentElement).toArray(); |
| 721 |
} |
| 722 |
|
| 723 |
public Object getParent(Object element) { |
| 724 |
// if (fGrouping == GROUP_BY_CONTAINER && element instanceof IResolvedBundle) { |
| 725 |
// return ((IResolvedBundle) element).getParentContainer(); |
| 726 |
// } else if (fGrouping == GROUP_BY_FILE_LOC && element instanceof IResolvedBundle) { |
| 727 |
// return getParentPath((IResolvedBundle) element); |
| 728 |
// } |
| 729 |
return null; |
| 730 |
} |
| 731 |
|
| 732 |
public boolean hasChildren(Object element) { |
| 733 |
if (fGrouping == GROUP_BY_NONE || element instanceof IResolvedBundle) { |
| 734 |
return false; |
| 735 |
} |
| 736 |
if (element instanceof IBundleContainer || element instanceof IPath) { |
| 737 |
return getBundleChildren(element).size() > 0; |
| 738 |
} |
| 739 |
return false; |
| 740 |
} |
| 741 |
|
| 742 |
public Object[] getElements(Object inputElement) { |
| 743 |
if (inputElement instanceof ITargetDefinition) { |
| 744 |
if (fGrouping == GROUP_BY_NONE) { |
| 745 |
return fAllBundles.toArray(); |
| 746 |
} else if (fGrouping == GROUP_BY_CONTAINER) { |
| 747 |
return fContainerBundles.keySet().toArray(); |
| 748 |
} else { |
| 749 |
return fFileBundles.keySet().toArray(); |
| 750 |
} |
| 751 |
} |
| 752 |
return new Object[] {inputElement}; |
| 753 |
} |
| 754 |
|
| 755 |
public void dispose() { |
| 756 |
} |
| 757 |
|
| 758 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
} |