1 11 package org.eclipse.pde.internal.ui.wizards.exports; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.runtime.IAdaptable; 18 import org.eclipse.jdt.core.IJavaProject; 19 import org.eclipse.jface.viewers.IStructuredContentProvider; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.jface.viewers.TableViewer; 22 import org.eclipse.jface.window.Window; 23 import org.eclipse.pde.core.IModel; 24 import org.eclipse.pde.internal.core.PDECore; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 28 import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart; 29 import org.eclipse.pde.internal.ui.wizards.ListUtil; 30 import org.eclipse.swt.SWT; 31 import org.eclipse.swt.layout.GridData; 32 import org.eclipse.swt.layout.GridLayout; 33 import org.eclipse.swt.widgets.Button; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.ui.IWorkingSet; 36 import org.eclipse.ui.IWorkingSetManager; 37 import org.eclipse.ui.PlatformUI; 38 import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog; 39 40 public abstract class ExportWizardPageWithTable extends BaseExportWizardPage { 41 42 protected ExportPart fExportPart; 43 private IStructuredSelection fSelection; 44 45 class ExportListProvider extends DefaultContentProvider implements 46 IStructuredContentProvider { 47 public Object [] getElements(Object parent) { 48 return getListElements(); 49 } 50 } 51 52 class ExportPart extends WizardCheckboxTablePart { 53 public ExportPart(String label, String [] buttonLabels) { 54 super(label, buttonLabels); 55 } 56 57 public void updateCounter(int count) { 58 super.updateCounter(count); 59 pageChanged(); 60 } 61 62 protected void buttonSelected(Button button, int index) { 63 switch (index) { 64 case 0: 65 handleSelectAll(true); 66 break; 67 case 1: 68 handleSelectAll(false); 69 break; 70 case 3: 71 handleWorkingSets(); 72 } 73 } 74 } 75 76 public ExportWizardPageWithTable(IStructuredSelection selection, String name, String choiceLabel) { 77 super(name); 78 fSelection = selection; 79 fExportPart = 80 new ExportPart( 81 choiceLabel, 82 new String [] { 83 PDEUIMessages.WizardCheckboxTablePart_selectAll, 84 PDEUIMessages.WizardCheckboxTablePart_deselectAll, 85 null, 86 PDEUIMessages.ExportWizard_workingSet }); setDescription(PDEUIMessages.ExportWizard_Plugin_description); } 89 90 protected void createTopSection(Composite parent) { 91 Composite composite = new Composite(parent, SWT.NONE); 92 GridLayout layout = new GridLayout(); 93 layout.numColumns = 3; 94 layout.marginHeight = 0; 95 layout.marginWidth = 0; 96 composite.setLayout(layout); 97 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 98 99 fExportPart.createControl(composite); 100 GridData gd = (GridData) fExportPart.getControl().getLayoutData(); 101 gd.heightHint = 125; 102 gd.widthHint = 150; 103 gd.horizontalSpan = 2; 104 105 TableViewer viewer = fExportPart.getTableViewer(); 106 viewer.setContentProvider(new ExportListProvider()); 107 viewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); 108 viewer.setSorter(ListUtil.PLUGIN_SORTER); 109 fExportPart.getTableViewer().setInput(PDECore.getDefault().getWorkspaceModelManager()); 110 } 111 112 protected void initializeTopSection() { 113 Object [] elems = fSelection.toArray(); 114 ArrayList checked = new ArrayList (elems.length); 115 116 for (int i = 0; i < elems.length; i++) { 117 Object elem = elems[i]; 118 IProject project = null; 119 120 if (elem instanceof IFile) { 121 IFile file = (IFile) elem; 122 project = file.getProject(); 123 } else if (elem instanceof IProject) { 124 project = (IProject) elem; 125 } else if (elem instanceof IJavaProject) { 126 project = ((IJavaProject) elem).getProject(); 127 } 128 if (project != null) { 129 IModel model = findModelFor(project); 130 if (model != null && !checked.contains(model)) { 131 checked.add(model); 132 } 133 } 134 } 135 fExportPart.setSelection(checked.toArray()); 136 if (checked.size() > 0) 137 fExportPart.getTableViewer().reveal(checked.get(0)); 138 } 139 140 private void handleWorkingSets() { 141 IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); 142 IWorkingSetSelectionDialog dialog = manager.createWorkingSetSelectionDialog(getShell(), true); 143 if (dialog.open() == Window.OK) { 144 ArrayList models = new ArrayList (); 145 IWorkingSet[] workingSets = dialog.getSelection(); 146 for (int i = 0; i < workingSets.length; i++) { 147 IAdaptable[] elements = workingSets[i].getElements(); 148 for (int j = 0; j < elements.length; j++) { 149 IModel model = findModelFor(elements[j]); 150 if (isValidModel(model)) { 151 models.add(model); 152 } 153 } 154 } 155 fExportPart.setSelection(models.toArray()); 156 } 157 } 158 159 protected abstract boolean isValidModel(IModel model); 160 161 protected abstract IModel findModelFor(IAdaptable object); 162 163 public Object [] getSelectedItems() { 164 return fExportPart.getSelection(); 165 } 166 167 protected void validateTopSection() { 168 setMessage(fExportPart.getSelectionCount() > 0 169 ? null 170 : PDEUIMessages.ExportWizard_status_noselection); } 172 173 public abstract Object [] getListElements(); 174 175 protected void pageChanged() { 176 super.pageChanged(); 177 String message = fExportPart.getSelectionCount() > 0 178 ? null 179 : PDEUIMessages.ExportWizard_status_noselection; if (message == null) { 181 message = validateBottomSections(); 182 } 183 setMessage(message); 184 setPageComplete(message == null); 185 } 186 187 } 188 | Popular Tags |