KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > launcher > PluginStatusDialog


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.launcher;
12
13 import java.util.Map JavaDoc;
14
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.jface.dialogs.TrayDialog;
18 import org.eclipse.jface.viewers.ITreeContentProvider;
19 import org.eclipse.jface.viewers.TreeViewer;
20 import org.eclipse.jface.viewers.ViewerComparator;
21 import org.eclipse.osgi.service.resolver.BundleDescription;
22 import org.eclipse.pde.internal.ui.PDEPlugin;
23 import org.eclipse.pde.internal.ui.PDEUIMessages;
24 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.Label;
30 import org.eclipse.swt.widgets.Shell;
31
32
33 public class PluginStatusDialog extends TrayDialog {
34     
35     class ContentProvider extends DefaultContentProvider implements ITreeContentProvider {
36
37         public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
38             return (Object JavaDoc[])fInput.get(parentElement);
39         }
40
41         public Object JavaDoc getParent(Object JavaDoc element) {
42             return null;
43         }
44
45         public boolean hasChildren(Object JavaDoc element) {
46             return fInput.containsKey(element) && element instanceof BundleDescription;
47         }
48
49         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
50             return ((Map JavaDoc)inputElement).keySet().toArray();
51         }
52         
53     }
54     
55     private boolean fShowCancelButton;
56     private Map JavaDoc fInput;
57     private TreeViewer treeViewer;
58
59     public PluginStatusDialog(Shell parentShell, int style) {
60         super(parentShell);
61         setShellStyle(style);
62         PDEPlugin.getDefault().getLabelProvider().connect(this);
63     }
64
65     public PluginStatusDialog(Shell parentShell) {
66         super(parentShell);
67         setShellStyle(getShellStyle()|SWT.RESIZE);
68         PDEPlugin.getDefault().getLabelProvider().connect(this);
69     }
70     
71     public void showCancelButton(boolean showCancel) {
72         fShowCancelButton = showCancel;
73     }
74     
75     public void setInput(Map JavaDoc input) {
76         fInput = input;
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
81      */

82     protected void createButtonsForButtonBar(Composite parent) {
83         createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
84         if (fShowCancelButton)
85             createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
86     }
87     
88     protected Control createDialogArea(Composite parent) {
89         Composite container = (Composite) super.createDialogArea(parent);
90         GridData gd = new GridData(GridData.FILL_BOTH);
91         gd.widthHint = 400;
92         gd.heightHint = 300;
93         container.setLayoutData(gd);
94
95         Label label = new Label(container, SWT.NONE);
96         label.setText(PDEUIMessages.PluginStatusDialog_label);
97
98         treeViewer = new TreeViewer(container);
99         treeViewer.setContentProvider(new ContentProvider());
100         treeViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
101         treeViewer.setComparator(new ViewerComparator());
102         treeViewer.setInput(fInput);
103         treeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
104         
105         getShell().setText(PDEUIMessages.PluginStatusDialog_pluginValidation);
106         Dialog.applyDialogFont(container);
107         return container;
108     }
109     
110     public boolean close() {
111         PDEPlugin.getDefault().getLabelProvider().disconnect(this);
112         return super.close();
113     }
114     
115     public void refresh(Map JavaDoc input) {
116         fInput = input;
117         treeViewer.setInput(input);
118         treeViewer.refresh();
119     }
120
121 }
122
Popular Tags