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