1 11 package org.eclipse.update.internal.ui.wizards; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.jface.dialogs.*; 16 import org.eclipse.jface.viewers.*; 17 import org.eclipse.swt.*; 18 import org.eclipse.swt.graphics.*; 19 import org.eclipse.swt.layout.*; 20 import org.eclipse.swt.widgets.*; 21 import org.eclipse.update.internal.operations.*; 22 import org.eclipse.update.internal.ui.*; 23 import org.eclipse.update.internal.ui.parts.*; 24 25 28 public class DuplicateConflictsDialog extends MessageDialog { 29 30 private TreeViewer treeViewer; 31 private ArrayList conflicts; 32 33 class ConflictContentProvider 34 extends DefaultContentProvider 35 implements ITreeContentProvider, IStructuredContentProvider { 36 public Object [] getElements(Object input) { 37 return getChildren(input); 38 } 39 public Object getParent(Object child) { 40 return null; 41 } 42 public boolean hasChildren(Object parent) { 43 if (parent instanceof ArrayList ) 44 return true; 45 return false; 46 } 47 public Object [] getChildren(Object parent) { 48 if (parent instanceof ArrayList ) 49 return ((ArrayList ) parent).toArray(); 50 return new Object [0]; 51 } 52 } 53 54 class ConflictLabelProvider extends LabelProvider { 55 public String getText(Object obj) { 56 if (obj instanceof ArrayList ) { 57 ArrayList list = (ArrayList ) obj; 58 for (int i = 0; i < list.size(); i++) { 59 DuplicateConflictsValidator.IdEntry entry = 60 (DuplicateConflictsValidator.IdEntry) (list).get(i); 61 if (entry.isInstallCandidate()) 62 return entry.getFeature().getLabel(); 63 } 64 } 65 return super.getText(obj); 66 } 67 public Image getImage(Object obj) { 68 int flags = 0; 69 if (obj instanceof ArrayList ) 70 flags = UpdateLabelProvider.F_WARNING; 71 if (obj instanceof DuplicateConflictsValidator.IdEntry 72 || obj instanceof ArrayList ) 73 return UpdateUI.getDefault().getLabelProvider().get( 74 UpdateUIImages.DESC_FEATURE_OBJ, 75 flags); 76 return null; 77 } 78 } 79 80 public DuplicateConflictsDialog(Shell shell, ArrayList conflicts) { 81 super( 82 shell, 83 UpdateUIMessages.DuplicateConflictsDialog_title, 84 null, 85 UpdateUIMessages.DuplicateConflictsDialog_message, 86 WARNING, 87 new String [] { 88 IDialogConstants.YES_LABEL, 89 IDialogConstants.NO_LABEL }, 90 0); 91 this.conflicts = conflicts; 92 UpdateUI.getDefault().getLabelProvider().connect(this); 93 } 94 95 public boolean close() { 96 UpdateUI.getDefault().getLabelProvider().disconnect(this); 97 return super.close(); 98 } 99 100 protected Control createCustomArea(Composite parent) { 101 Composite client = new Composite(parent, SWT.NULL); 102 client.setLayoutData(new GridData(GridData.FILL_BOTH)); 103 GridLayout layout = new GridLayout(); 104 client.setLayout(layout); 105 106 Label label = new Label(client, SWT.NULL); 107 label.setText(UpdateUIMessages.DuplicateConflictsDialog_treeLabel); 108 109 treeViewer = new TreeViewer(client, SWT.SINGLE | SWT.BORDER); 110 GridData gd = new GridData(GridData.FILL_BOTH); 111 gd.heightHint = 200; 112 gd.widthHint = 300; 113 treeViewer.getTree().setLayoutData(gd); 114 treeViewer.setContentProvider(new ConflictContentProvider()); 115 treeViewer.setLabelProvider(new ConflictLabelProvider()); 116 treeViewer.setAutoExpandLevel(10); 117 treeViewer.setSorter(new ViewerSorter() { 118 }); 119 treeViewer.setInput(conflicts); 120 return client; 121 } 122 123 } 124 | Popular Tags |