1 11 package org.eclipse.pde.internal.ui.wizards.templates; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.jface.dialogs.Dialog; 16 import org.eclipse.jface.viewers.CheckboxTableViewer; 17 import org.eclipse.jface.viewers.ColumnWeightData; 18 import org.eclipse.jface.viewers.ISelectionChangedListener; 19 import org.eclipse.jface.viewers.IStructuredContentProvider; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.jface.viewers.ITableLabelProvider; 22 import org.eclipse.jface.viewers.LabelProvider; 23 import org.eclipse.jface.viewers.SelectionChangedEvent; 24 import org.eclipse.jface.viewers.StructuredViewer; 25 import org.eclipse.jface.viewers.TableLayout; 26 import org.eclipse.jface.wizard.IWizardPage; 27 import org.eclipse.jface.wizard.Wizard; 28 import org.eclipse.jface.wizard.WizardPage; 29 import org.eclipse.pde.internal.ui.IHelpContextIds; 30 import org.eclipse.pde.internal.ui.PDEPlugin; 31 import org.eclipse.pde.internal.ui.PDEPluginImages; 32 import org.eclipse.pde.internal.ui.PDEUIMessages; 33 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 34 import org.eclipse.pde.internal.ui.parts.FormBrowser; 35 import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart; 36 import org.eclipse.pde.ui.templates.ITemplateSection; 37 import org.eclipse.swt.SWT; 38 import org.eclipse.swt.graphics.Image; 39 import org.eclipse.swt.layout.GridData; 40 import org.eclipse.swt.layout.GridLayout; 41 import org.eclipse.swt.widgets.Composite; 42 import org.eclipse.swt.widgets.Control; 43 import org.eclipse.swt.widgets.Table; 44 import org.eclipse.swt.widgets.TableColumn; 45 import org.eclipse.ui.PlatformUI; 46 import org.eclipse.ui.forms.widgets.FormToolkit; 47 48 public class TemplateSelectionPage extends WizardPage { 49 private ITemplateSection[] fCandidates; 50 private ArrayList fVisiblePages; 51 private WizardCheckboxTablePart fTablePart; 52 private FormBrowser fDescriptionBrowser; 53 class TablePart extends WizardCheckboxTablePart { 54 public TablePart(String mainLabel) { 55 super(mainLabel); 56 } 57 protected StructuredViewer createStructuredViewer( 58 Composite parent, 59 int style, 60 FormToolkit toolkit) { 61 return super.createStructuredViewer( 62 parent, 63 style | SWT.FULL_SELECTION, 64 toolkit); 65 } 66 protected void updateCounter(int amount) { 67 super.updateCounter(amount); 68 if (getContainer() != null) 69 getContainer().updateButtons(); 70 } 71 } 72 73 class ListContentProvider 74 extends DefaultContentProvider 75 implements IStructuredContentProvider { 76 public Object [] getElements(Object parent) { 77 return fCandidates; 78 } 79 } 80 81 class ListLabelProvider extends LabelProvider implements ITableLabelProvider { 82 public String getColumnText(Object obj, int index) { 83 ITemplateSection section = (ITemplateSection) obj; 84 if (index == 0) 85 return section.getLabel(); 86 return section.getUsedExtensionPoint(); 87 } 88 public Image getColumnImage(Object obj, int index) { 89 if (index == 0) 90 return PDEPlugin.getDefault().getLabelProvider().get( 91 PDEPluginImages.DESC_EXTENSION_OBJ); 92 return PDEPlugin.getDefault().getLabelProvider().get( 93 PDEPluginImages.DESC_EXT_POINT_OBJ); 94 } 95 } 96 97 101 public TemplateSelectionPage(ITemplateSection[] candidates) { 102 super("templateSelection"); fCandidates = candidates; 104 setTitle(PDEUIMessages.TemplateSelectionPage_title); 105 setDescription(PDEUIMessages.TemplateSelectionPage_desc); 106 initializeTemplates(); 107 } 108 109 private void initializeTemplates(){ 110 fTablePart = new TablePart(PDEUIMessages.TemplateSelectionPage_table); 111 fDescriptionBrowser = new FormBrowser(SWT.BORDER | SWT.V_SCROLL); 112 fDescriptionBrowser.setText(""); PDEPlugin.getDefault().getLabelProvider().connect(this); 114 fVisiblePages = new ArrayList (); 115 } 116 117 public void dispose() { 118 super.dispose(); 119 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 120 } 121 122 125 public void createControl(Composite parent) { 126 Composite container = new Composite(parent, SWT.NULL); 127 GridLayout layout = new GridLayout(); 128 container.setLayout(layout); 129 layout.numColumns = 2; 130 fTablePart.createControl(container); 131 CheckboxTableViewer viewer = fTablePart.getTableViewer(); 132 viewer.setContentProvider(new ListContentProvider()); 133 viewer.setLabelProvider(new ListLabelProvider()); 134 initializeTable(viewer.getTable()); 135 136 viewer.addSelectionChangedListener(new ISelectionChangedListener() { 137 public void selectionChanged(SelectionChangedEvent event) { 138 IStructuredSelection sel = (IStructuredSelection) event.getSelection(); 139 handleSelectionChanged((ITemplateSection) sel.getFirstElement()); 140 } 141 }); 142 fDescriptionBrowser.createControl(container); 143 Control c = fDescriptionBrowser.getControl(); 144 GridData gd = 145 new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); 146 gd.heightHint = 100; 147 c.setLayoutData(gd); 149 viewer.setInput(PDEPlugin.getDefault()); 150 initializeWizardPages(); 152 fTablePart.selectAll(true); 153 setControl(container); 154 Dialog.applyDialogFont(container); 155 PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.TEMPLATE_SELECTION); 156 } 157 158 private void initializeWizardPages() { 159 for (int i = 0; i < fCandidates.length; i++) { 160 ITemplateSection section = fCandidates[i]; 161 if (section.getPagesAdded() == false) 162 section.addPages((Wizard) getWizard()); 163 } 164 } 165 166 public ITemplateSection[] getSelectedTemplates() { 167 Object [] elements = fTablePart.getTableViewer().getCheckedElements(); 168 ITemplateSection[] result = new ITemplateSection[elements.length]; 169 System.arraycopy(elements, 0, result, 0, elements.length); 170 return result; 171 } 172 173 private void initializeTable(Table table) { 174 table.setHeaderVisible(true); 175 TableColumn column = new TableColumn(table, SWT.NULL); 176 column.setText(PDEUIMessages.TemplateSelectionPage_column_name); 177 column.setResizable(true); 178 column = new TableColumn(table, SWT.NULL); 179 column.setText(PDEUIMessages.TemplateSelectionPage_column_point); 180 column.setResizable(true); 181 182 TableLayout layout = new TableLayout(); 183 layout.addColumnData(new ColumnWeightData(50)); 184 layout.addColumnData(new ColumnWeightData(50)); 185 table.setLayout(layout); 186 } 187 188 private void handleSelectionChanged(ITemplateSection section) { 189 String text = section != null ? section.getDescription() : ""; if (text.length() > 0) 191 text = "<p>" + text + "</p>"; fDescriptionBrowser.setText(text); 193 } 194 195 public boolean canFlipToNextPage() { 196 if (fTablePart.getSelectionCount() == 0) 197 return false; 198 return super.canFlipToNextPage(); 199 } 200 201 public IWizardPage getNextPage() { 202 ITemplateSection[] sections = getSelectedTemplates(); 203 fVisiblePages.clear(); 204 205 for (int i = 0; i < sections.length; i++) { 206 ITemplateSection section = sections[i]; 207 208 for (int j = 0; j < section.getPageCount(); j++) { 209 fVisiblePages.add(section.getPage(j)); 210 } 211 } 212 if (fVisiblePages.size() > 0) 213 return (IWizardPage) fVisiblePages.get(0); 214 215 return null; 216 } 217 218 public IWizardPage getNextVisiblePage(IWizardPage page) { 219 if (page == this) 220 return page.getNextPage(); 221 int index = fVisiblePages.indexOf(page); 222 if (index >= 0 && index < fVisiblePages.size() - 1) 223 return (IWizardPage) fVisiblePages.get(index + 1); 224 return null; 225 } 226 227 } 228 | Popular Tags |