Lines 13-18
Link Here
|
13 |
import java.util.*; |
13 |
import java.util.*; |
14 |
import org.eclipse.core.runtime.*; |
14 |
import org.eclipse.core.runtime.*; |
15 |
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; |
15 |
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; |
|
|
16 |
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; |
16 |
import org.eclipse.jface.viewers.*; |
17 |
import org.eclipse.jface.viewers.*; |
17 |
import org.eclipse.jface.window.Window; |
18 |
import org.eclipse.jface.window.Window; |
18 |
import org.eclipse.jface.wizard.WizardDialog; |
19 |
import org.eclipse.jface.wizard.WizardDialog; |
Lines 311-337
Link Here
|
311 |
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); |
312 |
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); |
312 |
IBundleContainer[] containers = fTarget.getBundleContainers(); |
313 |
IBundleContainer[] containers = fTarget.getBundleContainers(); |
313 |
if (!selection.isEmpty() && containers != null && containers.length > 0) { |
314 |
if (!selection.isEmpty() && containers != null && containers.length > 0) { |
314 |
Set newContainers = new HashSet(); |
315 |
|
315 |
newContainers.addAll(Arrays.asList(fTarget.getBundleContainers())); |
316 |
// Check if we are removing containers or IUs |
316 |
Iterator iterator = selection.iterator(); |
317 |
Iterator iterator = selection.iterator(); |
317 |
boolean removedSite = false; |
318 |
boolean removingIUs = true; |
318 |
while (iterator.hasNext()) { |
319 |
while (iterator.hasNext()) { |
319 |
Object currentSelection = iterator.next(); |
320 |
if (!(iterator.next() instanceof IInstallableUnit)) { |
320 |
if (currentSelection instanceof IBundleContainer) { |
321 |
removingIUs = false; |
321 |
if (currentSelection instanceof IUBundleContainer) { |
322 |
break; |
322 |
removedSite = true; |
|
|
323 |
} |
324 |
newContainers.remove(currentSelection); |
325 |
} |
323 |
} |
326 |
} |
324 |
} |
327 |
if (newContainers.size() > 0) { |
325 |
|
328 |
fTarget.setBundleContainers((IBundleContainer[]) newContainers.toArray(new IBundleContainer[newContainers.size()])); |
326 |
boolean forceResolve = false; |
|
|
327 |
|
328 |
if (removingIUs) { |
329 |
// forceResolve = true; |
330 |
// Map newContainers |
331 |
// iterator = selection.iterator(); |
332 |
// while (iterator.hasNext()) { |
333 |
// IInstallableUnit toRemove = (IInstallableUnit) iterator.next(); |
334 |
// IUBundleContainer container = (IUBundleContainer) ((ITreeContentProvider) fTreeViewer.getContentProvider()).getParent(toRemove); |
335 |
// if (container != null) { |
336 |
// try { |
337 |
// // TODO Can we use API instead of internal to get the profile? |
338 |
// IInstallableUnit[] units = container.getInstallableUnits(null); |
339 |
// List unitList = new ArrayList(units.length); |
340 |
// for (int i = 0; i < units.length; i++) { |
341 |
// if (!toRemove.equals(units[i])) { |
342 |
// unitList.add(units[i]); |
343 |
// } |
344 |
// } |
345 |
// container.setInstallableUnits((IInstallableUnit[]) unitList.toArray(new IInstallableUnit[units.length])); |
346 |
// } catch (CoreException e) { |
347 |
// PDEPlugin.log(e); |
348 |
// } |
349 |
// } |
350 |
// } |
351 |
|
329 |
} else { |
352 |
} else { |
330 |
fTarget.setBundleContainers(null); |
353 |
Set newContainers = new HashSet(); |
|
|
354 |
newContainers.addAll(Arrays.asList(fTarget.getBundleContainers())); |
355 |
iterator = selection.iterator(); |
356 |
while (iterator.hasNext()) { |
357 |
Object currentSelection = iterator.next(); |
358 |
if (currentSelection instanceof IBundleContainer) { |
359 |
if (currentSelection instanceof IUBundleContainer) { |
360 |
forceResolve = true; |
361 |
} |
362 |
newContainers.remove(currentSelection); |
363 |
} |
364 |
} |
365 |
if (newContainers.size() > 0) { |
366 |
fTarget.setBundleContainers((IBundleContainer[]) newContainers.toArray(new IBundleContainer[newContainers.size()])); |
367 |
} else { |
368 |
fTarget.setBundleContainers(null); |
369 |
} |
331 |
} |
370 |
} |
332 |
|
371 |
|
333 |
// If we remove a site container, the content change update must force a re-resolve bug 275458 / bug 275401 |
372 |
// If we remove a site container, the content change update must force a re-resolve bug 275458 / bug 275401 |
334 |
contentsChanged(removedSite); |
373 |
contentsChanged(forceResolve); |
335 |
fTreeViewer.refresh(false); |
374 |
fTreeViewer.refresh(false); |
336 |
updateButtons(); |
375 |
updateButtons(); |
337 |
} |
376 |
} |
Lines 340-355
Link Here
|
340 |
private void updateButtons() { |
379 |
private void updateButtons() { |
341 |
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); |
380 |
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); |
342 |
fEditButton.setEnabled(!selection.isEmpty() && selection.getFirstElement() instanceof IBundleContainer); |
381 |
fEditButton.setEnabled(!selection.isEmpty() && selection.getFirstElement() instanceof IBundleContainer); |
343 |
// If any container is selected, allow the remove (the remove ignores non-container entries) |
382 |
// If any container is selected, or only installable units, allow the remove (the remove ignores non-container entries) |
344 |
boolean removeAllowed = false; |
383 |
boolean removeContainers = false; |
|
|
384 |
boolean removeUnits = true; |
345 |
Iterator iter = selection.iterator(); |
385 |
Iterator iter = selection.iterator(); |
346 |
while (iter.hasNext()) { |
386 |
while (iter.hasNext()) { |
347 |
if (iter.next() instanceof IBundleContainer) { |
387 |
Object next = iter.next(); |
348 |
removeAllowed = true; |
388 |
if (next instanceof IBundleContainer) { |
|
|
389 |
removeContainers = true; |
390 |
// If one or more containers are selected just remove the containers ignoring everything else |
349 |
break; |
391 |
break; |
350 |
} |
392 |
} |
|
|
393 |
if (!(next instanceof IInstallableUnit)) { |
394 |
// Only allow removal of IUs if only IUs are selected |
395 |
removeUnits = false; |
396 |
} |
351 |
} |
397 |
} |
352 |
fRemoveButton.setEnabled(removeAllowed); |
398 |
fRemoveButton.setEnabled(removeContainers || removeUnits); |
353 |
} |
399 |
} |
354 |
|
400 |
|
355 |
/** |
401 |
/** |
Lines 368-373
Link Here
|
368 |
*/ |
414 |
*/ |
369 |
class BundleContainerContentProvider implements ITreeContentProvider { |
415 |
class BundleContainerContentProvider implements ITreeContentProvider { |
370 |
|
416 |
|
|
|
417 |
/** |
418 |
* Maps installable units to their parent container |
419 |
* TODO Could cause problems if multiple site containers have the same IUs |
420 |
*/ |
421 |
private Map iuParents = new HashMap(); |
422 |
|
371 |
public Object[] getChildren(Object parentElement) { |
423 |
public Object[] getChildren(Object parentElement) { |
372 |
if (parentElement instanceof ITargetDefinition) { |
424 |
if (parentElement instanceof ITargetDefinition) { |
373 |
IBundleContainer[] containers = ((ITargetDefinition) parentElement).getBundleContainers(); |
425 |
IBundleContainer[] containers = ((ITargetDefinition) parentElement).getBundleContainers(); |
Lines 388-397
Link Here
|
388 |
} |
440 |
} |
389 |
} else if (parentElement instanceof IUBundleContainer) { |
441 |
} else if (parentElement instanceof IUBundleContainer) { |
390 |
// Show the IUs as children |
442 |
// Show the IUs as children |
391 |
// TODO See if we can get the profile using API |
443 |
// TODO See if we can get the profile using API instead of internal |
392 |
try { |
444 |
try { |
393 |
IProfile profile = ((TargetDefinition) fTarget).getProfile(); |
445 |
IProfile profile = ((TargetDefinition) fTarget).getProfile(); |
394 |
return ((IUBundleContainer) parentElement).getInstallableUnits(profile); |
446 |
IInstallableUnit[] units = ((IUBundleContainer) parentElement).getInstallableUnits(profile); |
|
|
447 |
// Store the unit parents so we can support removal |
448 |
for (int i = 0; i < units.length; i++) { |
449 |
iuParents.put(units[i], parentElement); |
450 |
} |
451 |
return units; |
395 |
} catch (CoreException e) { |
452 |
} catch (CoreException e) { |
396 |
return new Object[] {e.getStatus()}; |
453 |
return new Object[] {e.getStatus()}; |
397 |
} |
454 |
} |
Lines 402-407
Link Here
|
402 |
} |
459 |
} |
403 |
|
460 |
|
404 |
public Object getParent(Object element) { |
461 |
public Object getParent(Object element) { |
|
|
462 |
if (element instanceof IInstallableUnit) { |
463 |
return iuParents.get(element); |
464 |
} |
405 |
return null; |
465 |
return null; |
406 |
} |
466 |
} |
407 |
|
467 |
|