01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.search.dependencies;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.jface.dialogs.Dialog;
14: import org.eclipse.jface.dialogs.MessageDialog;
15: import org.eclipse.jface.viewers.IStructuredContentProvider;
16: import org.eclipse.jface.viewers.Viewer;
17: import org.eclipse.pde.core.plugin.IPluginModelBase;
18: import org.eclipse.pde.internal.ui.PDEPlugin;
19: import org.eclipse.pde.internal.ui.PDEUIMessages;
20: import org.eclipse.ui.dialogs.ListDialog;
21:
22: public class ShowResultsAction extends Action {
23:
24: private IPluginModelBase fModel;
25: Object[] fUnusedImports;
26: private boolean fReadOnly;
27:
28: public ShowResultsAction(IPluginModelBase model, Object[] unused,
29: boolean readOnly) {
30: fModel = model;
31: fUnusedImports = unused;
32: fReadOnly = readOnly;
33: }
34:
35: /* (non-Javadoc)
36: * @see org.eclipse.jface.action.Action#run()
37: */
38: public void run() {
39: if (fUnusedImports.length == 0) {
40: MessageDialog.openInformation(PDEPlugin
41: .getActiveWorkbenchShell(),
42: PDEUIMessages.UnusedDependencies_title,
43: PDEUIMessages.UnusedDependencies_notFound);
44: } else {
45: Dialog dialog;
46: if (fReadOnly) {
47: // Launched from Dependencies View, show information dialog
48: dialog = getUnusedDependeciesInfoDialog();
49: } else {
50: dialog = new UnusedImportsDialog(PDEPlugin
51: .getActiveWorkbenchShell(), fModel,
52: fUnusedImports);
53: dialog.create();
54: }
55: dialog.getShell().setText(
56: PDEUIMessages.UnusedDependencies_title);
57: dialog.open();
58: }
59: }
60:
61: /**
62: * @return Dialog
63: */
64: private Dialog getUnusedDependeciesInfoDialog() {
65: ListDialog dialog = new ListDialog(PDEPlugin
66: .getActiveWorkbenchShell());
67: dialog.setAddCancelButton(false);
68: dialog.setContentProvider(new IStructuredContentProvider() {
69: public Object[] getElements(Object inputElement) {
70: return fUnusedImports;
71: }
72:
73: public void dispose() {
74: }
75:
76: public void inputChanged(Viewer viewer, Object oldInput,
77: Object newInput) {
78: }
79: });
80: dialog.setLabelProvider(PDEPlugin.getDefault()
81: .getLabelProvider());
82: dialog.setInput(this );
83: dialog.create();
84: dialog.getTableViewer().setComparator(
85: new UnusedImportsDialog.Comparator());
86: return dialog;
87: }
88: }
|