001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 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.editor.target;
011:
012: import org.eclipse.jface.dialogs.IDialogConstants;
013: import org.eclipse.jface.dialogs.MessageDialog;
014: import org.eclipse.jface.viewers.ITreeContentProvider;
015: import org.eclipse.jface.viewers.LabelProvider;
016: import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin;
017: import org.eclipse.pde.internal.ui.PDEPlugin;
018: import org.eclipse.pde.internal.ui.PDEPluginImages;
019: import org.eclipse.pde.internal.ui.PDEUIMessages;
020: import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
021: import org.eclipse.pde.internal.ui.parts.TreeMessageDialog;
022: import org.eclipse.swt.graphics.Image;
023: import org.eclipse.swt.widgets.Shell;
024:
025: public class TargetErrorDialog extends TreeMessageDialog {
026:
027: private static LabelProvider fLabelProvider;
028:
029: private static class TreeNode {
030: Object[] fChildren;
031: boolean fFeature;
032:
033: protected TreeNode(Object[] children, boolean feature) {
034: fChildren = children;
035: fFeature = feature;
036: }
037:
038: protected Object[] getChildren() {
039: return fChildren;
040: }
041:
042: protected boolean isFeatureBased() {
043: return fFeature;
044: }
045:
046: public String toString() {
047: return fFeature ? PDEUIMessages.TargetPluginsTab_features
048: : PDEUIMessages.TargetPluginsTab_plugins;
049: }
050: }
051:
052: protected static class ErrorDialogContentProvider extends
053: DefaultContentProvider implements ITreeContentProvider {
054: TreeNode fPlugins, fFeatures;
055:
056: ErrorDialogContentProvider(TreeNode features, TreeNode plugins) {
057: fFeatures = features;
058: fPlugins = plugins;
059: }
060:
061: public Object[] getChildren(Object parentElement) {
062: if (parentElement instanceof TreeNode)
063: return ((TreeNode) parentElement).getChildren();
064: return null;
065: }
066:
067: public Object getParent(Object element) {
068: return null;
069: }
070:
071: public boolean hasChildren(Object element) {
072: return element instanceof TreeNode;
073: }
074:
075: public Object[] getElements(Object inputElement) {
076: if (fFeatures != null && fPlugins != null)
077: return new Object[] { fFeatures, fPlugins };
078: else if (fFeatures != null)
079: return new Object[] { fFeatures };
080: else
081: return new Object[] { fPlugins };
082: }
083: }
084:
085: private TargetErrorDialog(Shell parentShell, String dialogTitle,
086: Image dialogTitleImage, String dialogMessage,
087: int dialogImageType, String[] dialogButtonLabels,
088: int defaultIndex) {
089: super (parentShell, dialogTitle, dialogTitleImage,
090: dialogMessage, dialogImageType, dialogButtonLabels,
091: defaultIndex);
092: }
093:
094: public static void showDialog(Shell parentShell, Object[] features,
095: Object[] plugins) {
096: TreeMessageDialog dialog = new TargetErrorDialog(parentShell,
097: PDEUIMessages.TargetErrorDialog_title, null,
098: PDEUIMessages.TargetErrorDialog_description,
099: MessageDialog.WARNING,
100: new String[] { IDialogConstants.OK_LABEL }, 0);
101: TreeNode featureNode = (features.length > 0) ? new TreeNode(
102: features, true) : null;
103: TreeNode pluginNode = (plugins.length > 0) ? new TreeNode(
104: plugins, false) : null;
105: dialog.setContentProvider(new ErrorDialogContentProvider(
106: featureNode, pluginNode));
107: dialog.setLabelProvider(getLabelProvider());
108: dialog.setInput(new Object());
109: dialog.open();
110: }
111:
112: protected static LabelProvider getLabelProvider() {
113: if (fLabelProvider == null) {
114: fLabelProvider = new LabelProvider() {
115:
116: public Image getImage(Object obj) {
117: if (obj instanceof TreeNode) {
118: if (((TreeNode) obj).isFeatureBased())
119: return PDEPlugin
120: .getDefault()
121: .getLabelProvider()
122: .get(
123: PDEPluginImages.DESC_FEATURE_OBJ,
124: 0);
125: return PDEPlugin
126: .getDefault()
127: .getLabelProvider()
128: .get(PDEPluginImages.DESC_PLUGIN_OBJ, 0);
129: }
130: if (obj instanceof IFeaturePlugin) {
131: IFeaturePlugin plugin = (IFeaturePlugin) obj;
132: if (plugin.isFragment())
133: return PDEPlugin
134: .getDefault()
135: .getLabelProvider()
136: .get(
137: PDEPluginImages.DESC_FRAGMENT_OBJ,
138: 0);
139: return PDEPlugin
140: .getDefault()
141: .getLabelProvider()
142: .get(PDEPluginImages.DESC_PLUGIN_OBJ, 0);
143: }
144: return PDEPlugin.getDefault().getLabelProvider()
145: .getImage(obj);
146: }
147:
148: public String getText(Object obj) {
149: return PDEPlugin.getDefault().getLabelProvider()
150: .getText(obj);
151: }
152: };
153: }
154: return fLabelProvider;
155: }
156:
157: }
|