001: /*******************************************************************************
002: * Copyright (c) 2000, 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.plugin;
011:
012: import org.eclipse.jface.dialogs.IDialogConstants;
013: import org.eclipse.jface.dialogs.TrayDialog;
014: import org.eclipse.jface.viewers.ITreeContentProvider;
015: import org.eclipse.jface.viewers.LabelProvider;
016: import org.eclipse.jface.viewers.TreeViewer;
017: import org.eclipse.pde.internal.core.builders.DependencyLoop;
018: import org.eclipse.pde.internal.ui.PDELabelProvider;
019: import org.eclipse.pde.internal.ui.PDEPlugin;
020: import org.eclipse.pde.internal.ui.PDEPluginImages;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
023: import org.eclipse.swt.graphics.Image;
024: import org.eclipse.swt.layout.GridData;
025: import org.eclipse.swt.layout.GridLayout;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Control;
028: import org.eclipse.swt.widgets.Shell;
029: import org.eclipse.swt.widgets.Tree;
030:
031: public class LoopDialog extends TrayDialog {
032: private DependencyLoop[] fLoops;
033: private TreeViewer fLoopViewer;
034: private Image fLoopImage;
035:
036: class ContentProvider extends DefaultContentProvider implements
037: ITreeContentProvider {
038:
039: /* (non-Javadoc)
040: * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
041: */
042: public Object[] getChildren(Object parentElement) {
043: if (parentElement instanceof DependencyLoop)
044: return ((DependencyLoop) parentElement).getMembers();
045: return new Object[0];
046: }
047:
048: /* (non-Javadoc)
049: * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
050: */
051: public Object getParent(Object element) {
052: return null;
053: }
054:
055: /* (non-Javadoc)
056: * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
057: */
058: public boolean hasChildren(Object element) {
059: return element instanceof DependencyLoop;
060: }
061:
062: /* (non-Javadoc)
063: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
064: */
065: public Object[] getElements(Object inputElement) {
066: return fLoops;
067: }
068:
069: }
070:
071: class LoopLabelProvider extends LabelProvider {
072: /* (non-Javadoc)
073: * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
074: */
075: public Image getImage(Object element) {
076: if (element instanceof DependencyLoop)
077: return fLoopImage;
078: return PDEPlugin.getDefault().getLabelProvider().getImage(
079: element);
080: }
081:
082: /* (non-Javadoc)
083: * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
084: */
085: public String getText(Object element) {
086: return PDEPlugin.getDefault().getLabelProvider().getText(
087: element);
088: }
089: }
090:
091: public LoopDialog(Shell parentShell, DependencyLoop[] loops) {
092: super (parentShell);
093: fLoops = loops;
094: PDELabelProvider provider = PDEPlugin.getDefault()
095: .getLabelProvider();
096: fLoopImage = provider.get(PDEPluginImages.DESC_LOOP_OBJ);
097: }
098:
099: protected void createButtonsForButtonBar(Composite parent) {
100: createButton(parent, IDialogConstants.OK_ID,
101: IDialogConstants.OK_LABEL, true);
102: }
103:
104: protected Control createDialogArea(Composite parent) {
105: Composite container = (Composite) super
106: .createDialogArea(parent);
107: GridLayout layout = new GridLayout();
108: layout.numColumns = 2;
109: layout.marginWidth = layout.marginHeight = 9;
110: container.setLayout(layout);
111: GridData gd = new GridData(GridData.FILL_BOTH);
112: gd.widthHint = 300;
113: gd.heightHint = 300;
114: container.setLayoutData(gd);
115:
116: fLoopViewer = new TreeViewer(container);
117: fLoopViewer.setContentProvider(new ContentProvider());
118: fLoopViewer.setLabelProvider(new LoopLabelProvider());
119: Tree tree = fLoopViewer.getTree();
120: gd = new GridData(GridData.FILL_BOTH);
121: tree.setLayoutData(gd);
122: fLoopViewer.setInput(PDEPlugin.getDefault());
123: fLoopViewer.expandAll();
124: getShell().setText(PDEUIMessages.LoopDialog_title);
125: return container;
126: }
127: }
|