KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > plugin > LoopDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.plugin;
12
13 import org.eclipse.jface.dialogs.IDialogConstants;
14 import org.eclipse.jface.dialogs.TrayDialog;
15 import org.eclipse.jface.viewers.ITreeContentProvider;
16 import org.eclipse.jface.viewers.LabelProvider;
17 import org.eclipse.jface.viewers.TreeViewer;
18 import org.eclipse.pde.internal.core.builders.DependencyLoop;
19 import org.eclipse.pde.internal.ui.PDELabelProvider;
20 import org.eclipse.pde.internal.ui.PDEPlugin;
21 import org.eclipse.pde.internal.ui.PDEPluginImages;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
24 import org.eclipse.swt.graphics.Image;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.swt.widgets.Tree;
31
32 public class LoopDialog extends TrayDialog {
33     private DependencyLoop[] fLoops;
34     private TreeViewer fLoopViewer;
35     private Image fLoopImage;
36     
37     class ContentProvider extends DefaultContentProvider implements ITreeContentProvider {
38
39         /* (non-Javadoc)
40          * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
41          */

42         public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
43             if (parentElement instanceof DependencyLoop)
44                 return ((DependencyLoop)parentElement).getMembers();
45             return new Object JavaDoc[0];
46         }
47
48         /* (non-Javadoc)
49          * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
50          */

51         public Object JavaDoc getParent(Object JavaDoc element) {
52             return null;
53         }
54
55         /* (non-Javadoc)
56          * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
57          */

58         public boolean hasChildren(Object JavaDoc element) {
59             return element instanceof DependencyLoop;
60         }
61
62         /* (non-Javadoc)
63          * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
64          */

65         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
66             return fLoops;
67         }
68         
69     }
70     
71     class LoopLabelProvider extends LabelProvider {
72         /* (non-Javadoc)
73          * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
74          */

75         public Image getImage(Object JavaDoc element) {
76             if (element instanceof DependencyLoop)
77                 return fLoopImage;
78             return PDEPlugin.getDefault().getLabelProvider().getImage(element);
79         }
80         /* (non-Javadoc)
81          * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
82          */

83         public String JavaDoc getText(Object JavaDoc element) {
84             return PDEPlugin.getDefault().getLabelProvider().getText(element);
85         }
86     }
87     
88     
89     public LoopDialog(
90         Shell parentShell, DependencyLoop[] loops) {
91         super(parentShell);
92         fLoops = loops;
93         PDELabelProvider provider = PDEPlugin.getDefault().getLabelProvider();
94         fLoopImage = provider.get(PDEPluginImages.DESC_LOOP_OBJ);
95     }
96     
97     protected void createButtonsForButtonBar(Composite parent) {
98         createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
99     }
100
101     protected Control createDialogArea(Composite parent) {
102         Composite container = (Composite) super.createDialogArea(parent);
103         GridLayout layout = new GridLayout();
104         layout.numColumns = 2;
105         layout.marginWidth = layout.marginHeight = 9;
106         container.setLayout(layout);
107         GridData gd = new GridData(GridData.FILL_BOTH);
108         gd.widthHint = 300;
109         gd.heightHint = 300;
110         container.setLayoutData(gd);
111
112         fLoopViewer = new TreeViewer(container);
113         fLoopViewer.setContentProvider(new ContentProvider());
114         fLoopViewer.setLabelProvider(new LoopLabelProvider());
115         Tree tree = fLoopViewer.getTree();
116         gd = new GridData(GridData.FILL_BOTH);
117         tree.setLayoutData(gd);
118         fLoopViewer.setInput(PDEPlugin.getDefault());
119         fLoopViewer.expandAll();
120         getShell().setText(PDEUIMessages.LoopDialog_title);
121         return container;
122     }
123 }
124
Popular Tags