KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > dependencies > UnusedImportsDialog


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.pde.internal.ui.search.dependencies;
12
13 import org.eclipse.jface.dialogs.IDialogConstants;
14 import org.eclipse.jface.dialogs.TrayDialog;
15 import org.eclipse.jface.viewers.CheckboxTableViewer;
16 import org.eclipse.jface.viewers.Viewer;
17 import org.eclipse.pde.core.plugin.IPluginModelBase;
18 import org.eclipse.pde.internal.core.text.bundle.ImportPackageObject;
19 import org.eclipse.pde.internal.ui.PDEPlugin;
20 import org.eclipse.pde.internal.ui.PDEUIMessages;
21 import org.eclipse.pde.internal.ui.elements.DefaultTableProvider;
22 import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart;
23 import org.eclipse.pde.internal.ui.wizards.ListUtil.PluginComparator;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.Shell;
30
31 public class UnusedImportsDialog extends TrayDialog {
32     private IPluginModelBase model;
33     private Object JavaDoc[] unused;
34     private WizardCheckboxTablePart checkboxTablePart;
35     private CheckboxTableViewer choiceViewer;
36     
37     static class Comparator extends PluginComparator {
38
39         public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
40             if (e1.getClass() == e2.getClass())
41                 return super.compare(viewer, e1, e2);
42             else if (e1 instanceof ImportPackageObject)
43                 return 1;
44             else
45                 return -1;
46         }
47     }
48     
49     class ContentProvider extends DefaultTableProvider {
50         public Object JavaDoc[] getElements(Object JavaDoc parent) {
51             return unused;
52         }
53     }
54
55     public UnusedImportsDialog(
56         Shell parentShell,
57         IPluginModelBase model,
58         Object JavaDoc[] unused) {
59         super(parentShell);
60         this.model = model;
61         this.unused = unused;
62         checkboxTablePart =
63             new WizardCheckboxTablePart(
64                 PDEUIMessages.UnusedDependencies_remove);
65     }
66
67     protected void createButtonsForButtonBar(Composite parent) {
68         createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
69         createButton(
70             parent,
71             IDialogConstants.CANCEL_ID,
72             IDialogConstants.CANCEL_LABEL,
73             false);
74     }
75
76     protected Control createDialogArea(Composite parent) {
77         Composite container = new Composite(parent, SWT.NULL);
78         GridLayout layout = new GridLayout();
79         layout.numColumns = 2;
80         layout.marginWidth = layout.marginHeight = 9;
81         container.setLayout(layout);
82         GridData gd = new GridData(GridData.FILL_BOTH);
83         container.setLayoutData(gd);
84
85         checkboxTablePart.createControl(container);
86         choiceViewer = checkboxTablePart.getTableViewer();
87         choiceViewer.setContentProvider(new ContentProvider());
88         choiceViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
89         choiceViewer.setComparator(new Comparator());
90
91         gd = (GridData) checkboxTablePart.getControl().getLayoutData();
92         gd.widthHint = 250;
93         gd.heightHint = 275;
94
95         choiceViewer.setInput(PDEPlugin.getDefault());
96         checkboxTablePart.setSelection(unused);
97         return container;
98     }
99
100     protected void okPressed() {
101         GatherUnusedDependenciesOperation.removeDependencies(model, choiceViewer.getCheckedElements());
102         super.okPressed();
103     }
104
105 }
106
Popular Tags