001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.search.dependencies;
011:
012: import org.eclipse.jface.dialogs.IDialogConstants;
013: import org.eclipse.jface.dialogs.TrayDialog;
014: import org.eclipse.jface.viewers.CheckboxTableViewer;
015: import org.eclipse.jface.viewers.Viewer;
016: import org.eclipse.pde.core.plugin.IPluginModelBase;
017: import org.eclipse.pde.internal.core.text.bundle.ImportPackageObject;
018: import org.eclipse.pde.internal.ui.PDEPlugin;
019: import org.eclipse.pde.internal.ui.PDEUIMessages;
020: import org.eclipse.pde.internal.ui.elements.DefaultTableProvider;
021: import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart;
022: import org.eclipse.pde.internal.ui.wizards.ListUtil.PluginComparator;
023: import org.eclipse.swt.SWT;
024: import org.eclipse.swt.layout.GridData;
025: import org.eclipse.swt.layout.GridLayout;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Control;
028: import org.eclipse.swt.widgets.Shell;
029:
030: public class UnusedImportsDialog extends TrayDialog {
031: private IPluginModelBase model;
032: private Object[] unused;
033: private WizardCheckboxTablePart checkboxTablePart;
034: private CheckboxTableViewer choiceViewer;
035:
036: static class Comparator extends PluginComparator {
037:
038: public int compare(Viewer viewer, Object e1, Object e2) {
039: if (e1.getClass() == e2.getClass())
040: return super .compare(viewer, e1, e2);
041: else if (e1 instanceof ImportPackageObject)
042: return 1;
043: else
044: return -1;
045: }
046: }
047:
048: class ContentProvider extends DefaultTableProvider {
049: public Object[] getElements(Object parent) {
050: return unused;
051: }
052: }
053:
054: public UnusedImportsDialog(Shell parentShell,
055: IPluginModelBase model, Object[] unused) {
056: super (parentShell);
057: this .model = model;
058: this .unused = unused;
059: checkboxTablePart = new WizardCheckboxTablePart(
060: PDEUIMessages.UnusedDependencies_remove);
061: }
062:
063: protected void createButtonsForButtonBar(Composite parent) {
064: createButton(parent, IDialogConstants.OK_ID,
065: IDialogConstants.OK_LABEL, true);
066: createButton(parent, IDialogConstants.CANCEL_ID,
067: IDialogConstants.CANCEL_LABEL, false);
068: }
069:
070: protected Control createDialogArea(Composite parent) {
071: Composite container = new Composite(parent, SWT.NULL);
072: GridLayout layout = new GridLayout();
073: layout.numColumns = 2;
074: layout.marginWidth = layout.marginHeight = 9;
075: container.setLayout(layout);
076: GridData gd = new GridData(GridData.FILL_BOTH);
077: container.setLayoutData(gd);
078:
079: checkboxTablePart.createControl(container);
080: choiceViewer = checkboxTablePart.getTableViewer();
081: choiceViewer.setContentProvider(new ContentProvider());
082: choiceViewer.setLabelProvider(PDEPlugin.getDefault()
083: .getLabelProvider());
084: choiceViewer.setComparator(new Comparator());
085:
086: gd = (GridData) checkboxTablePart.getControl().getLayoutData();
087: gd.widthHint = 250;
088: gd.heightHint = 275;
089:
090: choiceViewer.setInput(PDEPlugin.getDefault());
091: checkboxTablePart.setSelection(unused);
092: return container;
093: }
094:
095: protected void okPressed() {
096: GatherUnusedDependenciesOperation.removeDependencies(model,
097: choiceViewer.getCheckedElements());
098: super.okPressed();
099: }
100:
101: }
|