KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > wizards > DuplicateConflictsDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.ui.wizards;
12
13 import java.util.ArrayList JavaDoc;
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 /**
26  *
27  */

28 public class DuplicateConflictsDialog extends MessageDialog {
29
30     private TreeViewer treeViewer;
31     private ArrayList JavaDoc conflicts;
32
33     class ConflictContentProvider
34         extends DefaultContentProvider
35         implements ITreeContentProvider, IStructuredContentProvider {
36         public Object JavaDoc[] getElements(Object JavaDoc input) {
37             return getChildren(input);
38         }
39         public Object JavaDoc getParent(Object JavaDoc child) {
40             return null;
41         }
42         public boolean hasChildren(Object JavaDoc parent) {
43             if (parent instanceof ArrayList JavaDoc)
44                 return true;
45             return false;
46         }
47         public Object JavaDoc[] getChildren(Object JavaDoc parent) {
48             if (parent instanceof ArrayList JavaDoc)
49                 return ((ArrayList JavaDoc) parent).toArray();
50             return new Object JavaDoc[0];
51         }
52     }
53
54     class ConflictLabelProvider extends LabelProvider {
55         public String JavaDoc getText(Object JavaDoc obj) {
56             if (obj instanceof ArrayList JavaDoc) {
57                 ArrayList JavaDoc list = (ArrayList JavaDoc) 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 JavaDoc obj) {
68             int flags = 0;
69             if (obj instanceof ArrayList JavaDoc)
70                 flags = UpdateLabelProvider.F_WARNING;
71             if (obj instanceof DuplicateConflictsValidator.IdEntry
72                 || obj instanceof ArrayList JavaDoc)
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 JavaDoc conflicts) {
81         super(
82             shell,
83             UpdateUIMessages.DuplicateConflictsDialog_title,
84             null,
85             UpdateUIMessages.DuplicateConflictsDialog_message,
86             WARNING,
87             new String JavaDoc[] {
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