001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 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.launcher;
011:
012: import java.util.Map;
013:
014: import org.eclipse.jface.dialogs.Dialog;
015: import org.eclipse.jface.dialogs.IDialogConstants;
016: import org.eclipse.jface.dialogs.TrayDialog;
017: import org.eclipse.jface.viewers.ITreeContentProvider;
018: import org.eclipse.jface.viewers.TreeViewer;
019: import org.eclipse.jface.viewers.ViewerComparator;
020: import org.eclipse.osgi.service.resolver.BundleDescription;
021: import org.eclipse.pde.internal.ui.PDEPlugin;
022: import org.eclipse.pde.internal.ui.PDEUIMessages;
023: import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
024: import org.eclipse.swt.SWT;
025: import org.eclipse.swt.layout.GridData;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Control;
028: import org.eclipse.swt.widgets.Label;
029: import org.eclipse.swt.widgets.Shell;
030:
031: public class PluginStatusDialog extends TrayDialog {
032:
033: class ContentProvider extends DefaultContentProvider implements
034: ITreeContentProvider {
035:
036: public Object[] getChildren(Object parentElement) {
037: return (Object[]) fInput.get(parentElement);
038: }
039:
040: public Object getParent(Object element) {
041: return null;
042: }
043:
044: public boolean hasChildren(Object element) {
045: return fInput.containsKey(element)
046: && element instanceof BundleDescription;
047: }
048:
049: public Object[] getElements(Object inputElement) {
050: return ((Map) inputElement).keySet().toArray();
051: }
052:
053: }
054:
055: private boolean fShowCancelButton;
056: private Map fInput;
057: private TreeViewer treeViewer;
058:
059: public PluginStatusDialog(Shell parentShell, int style) {
060: super (parentShell);
061: setShellStyle(style);
062: PDEPlugin.getDefault().getLabelProvider().connect(this );
063: }
064:
065: public PluginStatusDialog(Shell parentShell) {
066: super (parentShell);
067: setShellStyle(getShellStyle() | SWT.RESIZE);
068: PDEPlugin.getDefault().getLabelProvider().connect(this );
069: }
070:
071: public void showCancelButton(boolean showCancel) {
072: fShowCancelButton = showCancel;
073: }
074:
075: public void setInput(Map input) {
076: fInput = input;
077: }
078:
079: /* (non-Javadoc)
080: * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
081: */
082: protected void createButtonsForButtonBar(Composite parent) {
083: createButton(parent, IDialogConstants.OK_ID,
084: IDialogConstants.OK_LABEL, true);
085: if (fShowCancelButton)
086: createButton(parent, IDialogConstants.CANCEL_ID,
087: IDialogConstants.CANCEL_LABEL, true);
088: }
089:
090: protected Control createDialogArea(Composite parent) {
091: Composite container = (Composite) super
092: .createDialogArea(parent);
093: GridData gd = new GridData(GridData.FILL_BOTH);
094: gd.widthHint = 400;
095: gd.heightHint = 300;
096: container.setLayoutData(gd);
097:
098: Label label = new Label(container, SWT.NONE);
099: label.setText(PDEUIMessages.PluginStatusDialog_label);
100:
101: treeViewer = new TreeViewer(container);
102: treeViewer.setContentProvider(new ContentProvider());
103: treeViewer.setLabelProvider(PDEPlugin.getDefault()
104: .getLabelProvider());
105: treeViewer.setComparator(new ViewerComparator());
106: treeViewer.setInput(fInput);
107: treeViewer.getControl().setLayoutData(
108: new GridData(GridData.FILL_BOTH));
109:
110: getShell().setText(
111: PDEUIMessages.PluginStatusDialog_pluginValidation);
112: Dialog.applyDialogFont(container);
113: return container;
114: }
115:
116: public boolean close() {
117: PDEPlugin.getDefault().getLabelProvider().disconnect(this );
118: return super .close();
119: }
120:
121: public void refresh(Map input) {
122: fInput = input;
123: treeViewer.setInput(input);
124: treeViewer.refresh();
125: }
126:
127: }
|