1 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 [] fChildren; 32 boolean fFeature; 33 protected TreeNode (Object [] children, boolean feature) { 34 fChildren = children; 35 fFeature = feature; 36 } 37 protected Object [] getChildren() { return fChildren; } 38 protected boolean isFeatureBased() { return fFeature; } 39 public String 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 [] getChildren(Object parentElement) { 51 if (parentElement instanceof TreeNode) 52 return ((TreeNode)parentElement).getChildren(); 53 return null; 54 } 55 public Object getParent(Object element) { 56 return null; 57 } 58 public boolean hasChildren(Object element) { 59 return element instanceof TreeNode; 60 } 61 public Object [] getElements(Object inputElement) { 62 if (fFeatures != null && fPlugins != null) return new Object [] {fFeatures, fPlugins}; 63 else if (fFeatures != null) return new Object [] {fFeatures}; 64 else return new Object [] {fPlugins}; 65 } 66 } 67 68 private TargetErrorDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String [] dialogButtonLabels, int defaultIndex) { 69 super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, 70 dialogImageType, dialogButtonLabels, defaultIndex); 71 } 72 73 public static void showDialog(Shell parentShell, Object [] features, Object [] plugins) { 74 TreeMessageDialog dialog = new TargetErrorDialog(parentShell, PDEUIMessages.TargetErrorDialog_title, null, PDEUIMessages.TargetErrorDialog_description, 75 MessageDialog.WARNING, new String [] { 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 ()); 81 dialog.open(); 82 } 83 84 protected static LabelProvider getLabelProvider() { 85 if (fLabelProvider == null) { 86 fLabelProvider = new LabelProvider() { 87 88 public Image getImage(Object 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 getText(Object obj) { 103 return PDEPlugin.getDefault().getLabelProvider().getText(obj); 104 } 105 }; 106 } 107 return fLabelProvider; 108 } 109 110 } 111 | Popular Tags |