1 11 package org.eclipse.pde.ui.internal.samples; 12 13 import org.eclipse.core.runtime.IConfigurationElement; 14 import org.eclipse.jface.viewers.IStructuredContentProvider; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.jface.viewers.LabelProvider; 17 import org.eclipse.jface.wizard.WizardPage; 18 import org.eclipse.pde.internal.ui.IHelpContextIds; 19 import org.eclipse.pde.internal.ui.PDEPlugin; 20 import org.eclipse.pde.internal.ui.PDEPluginImages; 21 import org.eclipse.pde.internal.ui.PDEUIMessages; 22 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 23 import org.eclipse.pde.internal.ui.parts.TablePart; 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.graphics.Image; 26 import org.eclipse.swt.layout.GridData; 27 import org.eclipse.swt.layout.GridLayout; 28 import org.eclipse.swt.widgets.Button; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.swt.widgets.Text; 31 import org.eclipse.ui.PlatformUI; 32 33 public class SelectionPage extends WizardPage { 34 private TablePart part; 35 private Text desc; 36 private SampleWizard wizard; 37 38 class SelectionPart extends TablePart { 39 public SelectionPart() { 40 super(new String [] { "More Info" }); } 42 protected void buttonSelected(Button button, int index) { 43 if (index == 0) 44 doMoreInfo(); 45 } 46 47 protected void selectionChanged(IStructuredSelection selection) { 48 updateSelection(selection); 49 } 50 protected void handleDoubleClick(IStructuredSelection selection) { 51 } 52 } 53 54 class SampleProvider extends DefaultContentProvider implements IStructuredContentProvider { 55 public Object [] getElements(Object input) { 56 return wizard.getSamples(); 57 } 58 } 59 60 class SampleLabelProvider extends LabelProvider { 61 private Image image; 62 public SampleLabelProvider() { 63 image = PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_NEWEXP_TOOL); 64 } 65 public String getText(Object obj) { 66 IConfigurationElement sample = (IConfigurationElement)obj; 67 return sample.getAttribute("name"); } 69 public Image getImage(Object obj) { 70 return image; 71 } 72 } 73 76 public SelectionPage(SampleWizard wizard) { 77 super("selection"); this.wizard = wizard; 79 setTitle(PDEUIMessages.SelectionPage_title); setDescription(PDEUIMessages.SelectionPage_desc); part = new SelectionPart(); 82 } 83 84 public void createControl(Composite parent) { 85 Composite container = new Composite(parent, SWT.NULL); 86 GridLayout layout = new GridLayout(); 87 container.setLayout(layout); 88 layout.numColumns = 2; 89 part.setMinimumSize(300, 300); 90 part.createControl(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, 2, null); 91 part.getTableViewer().setContentProvider(new SampleProvider()); 92 part.getTableViewer().setLabelProvider(new SampleLabelProvider()); 93 desc = new Text(container, SWT.MULTI|SWT.BORDER|SWT.WRAP|SWT.V_SCROLL); 94 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 95 gd.heightHint = 64; 96 desc.setLayoutData(gd); 97 part.getTableViewer().setInput(this); 98 updateSelection(null); 99 setControl(container); 100 101 PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.SELECTION); 102 } 103 private void doMoreInfo() { 104 if (wizard.getSelection()!=null) { 105 IConfigurationElement desc[] = wizard.getSelection().getChildren("description"); String helpHref = desc[0].getAttribute("helpHref"); PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpHref); 108 } 109 } 110 private void updateSelection(IStructuredSelection selection) { 111 if (selection==null) { 112 desc.setText(""); part.setButtonEnabled(0, false); 114 setPageComplete(false); 115 } 116 else { 117 IConfigurationElement sample = (IConfigurationElement)selection.getFirstElement(); 118 String text = ""; String helpHref=null; 120 IConfigurationElement [] sampleDesc = sample.getChildren("description"); if (sampleDesc.length==1) { 122 text = sampleDesc[0].getValue(); 123 helpHref = sampleDesc[0].getAttribute("helpHref"); } 125 desc.setText(text); 126 part.setButtonEnabled(0, helpHref!=null); 127 wizard.setSelection(sample); 128 setPageComplete(true); 129 } 130 } 131 } 132 | Popular Tags |