1 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 42 public Object [] getChildren(Object parentElement) { 43 if (parentElement instanceof DependencyLoop) 44 return ((DependencyLoop)parentElement).getMembers(); 45 return new Object [0]; 46 } 47 48 51 public Object getParent(Object element) { 52 return null; 53 } 54 55 58 public boolean hasChildren(Object element) { 59 return element instanceof DependencyLoop; 60 } 61 62 65 public Object [] getElements(Object inputElement) { 66 return fLoops; 67 } 68 69 } 70 71 class LoopLabelProvider extends LabelProvider { 72 75 public Image getImage(Object element) { 76 if (element instanceof DependencyLoop) 77 return fLoopImage; 78 return PDEPlugin.getDefault().getLabelProvider().getImage(element); 79 } 80 83 public String getText(Object 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 |