KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > target > TargetErrorDialog


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.editor.target;
12
13 import org.eclipse.jface.dialogs.IDialogConstants;
14 import org.eclipse.jface.dialogs.MessageDialog;
15 import org.eclipse.jface.viewers.ITreeContentProvider;
16 import org.eclipse.jface.viewers.LabelProvider;
17 import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin;
18 import org.eclipse.pde.internal.ui.PDEPlugin;
19 import org.eclipse.pde.internal.ui.PDEPluginImages;
20 import org.eclipse.pde.internal.ui.PDEUIMessages;
21 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
22 import org.eclipse.pde.internal.ui.parts.TreeMessageDialog;
23 import org.eclipse.swt.graphics.Image;
24 import org.eclipse.swt.widgets.Shell;
25
26 public class TargetErrorDialog extends TreeMessageDialog {
27     
28     private static LabelProvider fLabelProvider;
29     
30     private static class TreeNode {
31         Object JavaDoc[] fChildren;
32         boolean fFeature;
33         protected TreeNode (Object JavaDoc[] children, boolean feature) {
34             fChildren = children;
35             fFeature = feature;
36         }
37         protected Object JavaDoc[] getChildren() { return fChildren; }
38         protected boolean isFeatureBased() { return fFeature; }
39         public String JavaDoc toString() {
40             return fFeature ? PDEUIMessages.TargetPluginsTab_features : PDEUIMessages.TargetPluginsTab_plugins;
41         }
42     }
43     
44     protected static class ErrorDialogContentProvider extends DefaultContentProvider implements ITreeContentProvider{
45         TreeNode fPlugins, fFeatures;
46         ErrorDialogContentProvider(TreeNode features, TreeNode plugins) {
47             fFeatures = features;
48             fPlugins = plugins;
49         }
50         public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
51             if (parentElement instanceof TreeNode)
52                 return ((TreeNode)parentElement).getChildren();
53             return null;
54         }
55         public Object JavaDoc getParent(Object JavaDoc element) {
56             return null;
57         }
58         public boolean hasChildren(Object JavaDoc element) {
59             return element instanceof TreeNode;
60         }
61         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
62             if (fFeatures != null && fPlugins != null) return new Object JavaDoc[] {fFeatures, fPlugins};
63             else if (fFeatures != null) return new Object JavaDoc[] {fFeatures};
64             else return new Object JavaDoc[] {fPlugins};
65         }
66     }
67
68     private TargetErrorDialog(Shell parentShell, String JavaDoc dialogTitle, Image dialogTitleImage, String JavaDoc dialogMessage, int dialogImageType, String JavaDoc[] dialogButtonLabels, int defaultIndex) {
69         super(parentShell, dialogTitle, dialogTitleImage, dialogMessage,
70                 dialogImageType, dialogButtonLabels, defaultIndex);
71     }
72     
73     public static void showDialog(Shell parentShell, Object JavaDoc[] features, Object JavaDoc[] plugins) {
74         TreeMessageDialog dialog = new TargetErrorDialog(parentShell, PDEUIMessages.TargetErrorDialog_title, null, PDEUIMessages.TargetErrorDialog_description,
75                 MessageDialog.WARNING, new String JavaDoc[] { IDialogConstants.OK_LABEL }, 0);
76         TreeNode featureNode = (features.length > 0) ? new TreeNode(features, true) : null;
77         TreeNode pluginNode = (plugins.length > 0) ? new TreeNode(plugins, false) : null;
78         dialog.setContentProvider(new ErrorDialogContentProvider(featureNode, pluginNode));
79         dialog.setLabelProvider(getLabelProvider());
80         dialog.setInput(new Object JavaDoc());
81         dialog.open();
82     }
83     
84     protected static LabelProvider getLabelProvider() {
85         if (fLabelProvider == null) {
86             fLabelProvider = new LabelProvider() {
87                 
88                 public Image getImage(Object JavaDoc obj) {
89                     if (obj instanceof TreeNode) {
90                         if (((TreeNode)obj).isFeatureBased())
91                             return PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_FEATURE_OBJ, 0);
92                         return PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_PLUGIN_OBJ, 0);
93                     } if (obj instanceof IFeaturePlugin) {
94                         IFeaturePlugin plugin = (IFeaturePlugin) obj;
95                         if (plugin.isFragment())
96                             return PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_FRAGMENT_OBJ, 0);
97                         return PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_PLUGIN_OBJ, 0);
98                     }
99                     return PDEPlugin.getDefault().getLabelProvider().getImage(obj);
100                 }
101
102                 public String JavaDoc getText(Object JavaDoc obj) {
103                     return PDEPlugin.getDefault().getLabelProvider().getText(obj);
104                 }
105             };
106         }
107         return fLabelProvider;
108     }
109
110 }
111
Popular Tags