KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.pde.internal.ui.search;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.viewers.CheckboxTableViewer;
17 import org.eclipse.pde.core.plugin.IPluginImport;
18 import org.eclipse.pde.core.plugin.IPluginModelBase;
19 import org.eclipse.pde.internal.ui.PDEPlugin;
20 import org.eclipse.pde.internal.ui.elements.DefaultTableProvider;
21 import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart;
22 import org.eclipse.pde.internal.ui.wizards.ListUtil;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Shell;
29
30 public class UnusedImportsDialog extends Dialog {
31     private IPluginModelBase model;
32     private IPluginImport[] unused;
33     private WizardCheckboxTablePart checkboxTablePart;
34     private CheckboxTableViewer choiceViewer;
35     
36     class ContentProvider extends DefaultTableProvider {
37         public Object JavaDoc[] getElements(Object JavaDoc parent) {
38             return unused;
39         }
40     }
41
42     public UnusedImportsDialog(
43         Shell parentShell,
44         IPluginModelBase model,
45         IPluginImport[] unused) {
46         super(parentShell);
47         this.model = model;
48         this.unused = unused;
49         checkboxTablePart =
50             new WizardCheckboxTablePart(
51                 PDEPlugin.getResourceString("UnusedDependencies.remove")); //$NON-NLS-1$
52
}
53
54     protected void createButtonsForButtonBar(Composite parent) {
55         createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
56         createButton(
57             parent,
58             IDialogConstants.CANCEL_ID,
59             IDialogConstants.CANCEL_LABEL,
60             false);
61     }
62
63     protected Control createDialogArea(Composite parent) {
64         Composite container = new Composite(parent, SWT.NULL);
65         GridLayout layout = new GridLayout();
66         layout.numColumns = 2;
67         layout.marginWidth = layout.marginHeight = 9;
68         container.setLayout(layout);
69         GridData gd = new GridData(GridData.FILL_BOTH);
70         container.setLayoutData(gd);
71
72         checkboxTablePart.createControl(container);
73         choiceViewer = checkboxTablePart.getTableViewer();
74         choiceViewer.setContentProvider(new ContentProvider());
75         choiceViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
76         choiceViewer.setSorter(ListUtil.PLUGIN_SORTER);
77
78         gd = (GridData) checkboxTablePart.getControl().getLayoutData();
79         gd.widthHint = 250;
80         gd.heightHint = 275;
81
82         choiceViewer.setInput(PDEPlugin.getDefault());
83         checkboxTablePart.setSelection(unused);
84         return container;
85     }
86
87     protected void okPressed() {
88         try {
89             Object JavaDoc[] elements = choiceViewer.getCheckedElements();
90             for (int i = 0; i < elements.length; i++) {
91                 model.getPluginBase().remove((IPluginImport) elements[i]);
92             }
93             super.okPressed();
94         } catch (CoreException e) {
95         }
96     }
97
98 }
99
Popular Tags