1 11 package org.eclipse.pde.internal.ui.wizards.imports; 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.resources.IResource; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.Path; 20 import org.eclipse.jdt.core.IJavaProject; 21 import org.eclipse.jface.dialogs.Dialog; 22 import org.eclipse.jface.viewers.CheckboxTableViewer; 23 import org.eclipse.jface.viewers.IStructuredContentProvider; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.jface.viewers.StructuredViewer; 26 import org.eclipse.osgi.util.NLS; 27 import org.eclipse.pde.core.build.IBuildEntry; 28 import org.eclipse.pde.core.build.IBuildModel; 29 import org.eclipse.pde.core.plugin.IPluginModelBase; 30 import org.eclipse.pde.core.plugin.PluginRegistry; 31 import org.eclipse.pde.internal.core.WorkspaceModelManager; 32 import org.eclipse.pde.internal.core.build.WorkspaceBuildModel; 33 import org.eclipse.pde.internal.ui.IHelpContextIds; 34 import org.eclipse.pde.internal.ui.PDEPlugin; 35 import org.eclipse.pde.internal.ui.PDEUIMessages; 36 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 37 import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart; 38 import org.eclipse.pde.internal.ui.wizards.ListUtil; 39 import org.eclipse.swt.SWT; 40 import org.eclipse.swt.events.SelectionAdapter; 41 import org.eclipse.swt.events.SelectionEvent; 42 import org.eclipse.swt.layout.GridData; 43 import org.eclipse.swt.layout.GridLayout; 44 import org.eclipse.swt.widgets.Button; 45 import org.eclipse.swt.widgets.Composite; 46 import org.eclipse.swt.widgets.Label; 47 import org.eclipse.ui.PlatformUI; 48 import org.eclipse.ui.forms.widgets.FormToolkit; 49 50 public class PluginImportWizardExpressPage extends BaseImportWizardSecondPage { 51 52 private TablePart tablePart; 53 private IStructuredSelection initialSelection; 54 private Label counterLabel; 55 56 class PluginContentProvider 57 extends DefaultContentProvider 58 implements IStructuredContentProvider { 59 public Object [] getElements(Object parent) { 60 IProject[] projects = PDEPlugin.getWorkspace().getRoot().getProjects(); 61 ArrayList result = new ArrayList (); 62 for (int i = 0; i < projects.length; i++) { 63 if (WorkspaceModelManager.isPluginProject(projects[i]) 64 && !WorkspaceModelManager.isBinaryProject(projects[i])) { 65 IPluginModelBase model = PluginRegistry.findModel(projects[i]); 66 if (model != null) 67 result.add(model); 68 } 69 } 70 return result.toArray(); 71 } 72 } 73 74 75 class TablePart extends WizardCheckboxTablePart { 76 public TablePart(String mainLabel, String [] buttonLabels) { 77 super(mainLabel, buttonLabels); 78 setSelectAllIndex(0); 79 setDeselectAllIndex(1); 80 } 81 public void updateCounter(int count) { 82 super.updateCounter(count); 83 } 84 public void buttonSelected(Button button, int index) { 85 if (index == 0 || index == 1) 86 super.buttonSelected(button, index); 87 } 88 protected StructuredViewer createStructuredViewer( 89 Composite parent, 90 int style, 91 FormToolkit toolkit) { 92 StructuredViewer viewer = 93 super.createStructuredViewer(parent, style, toolkit); 94 return viewer; 95 } 96 97 protected void elementChecked(Object element, boolean checked) { 98 super.elementChecked(element, checked); 99 pageChanged(); 100 } 101 102 protected void handleSelectAll(boolean select) { 103 super.handleSelectAll(select); 104 pageChanged(); 105 } 106 } 107 108 public PluginImportWizardExpressPage(String pageName, PluginImportWizardFirstPage page, IStructuredSelection selection) { 109 super(pageName, page); 110 this.initialSelection = selection; 111 setTitle(PDEUIMessages.ImportWizard_expressPage_title); 112 setMessage(PDEUIMessages.ImportWizard_expressPage_desc); 113 } 114 115 public void createControl(Composite parent) { 116 Composite container = new Composite(parent, SWT.NONE); 117 GridLayout layout = new GridLayout(); 118 layout.numColumns = 2; 119 layout.horizontalSpacing = 20; 120 layout.verticalSpacing = 10; 121 container.setLayout(layout); 122 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 123 124 createTablePart(container); 125 createImportPart(container); 126 127 createComputationsOption(container, 2); 128 129 fAddFragmentsButton.addSelectionListener(new SelectionAdapter() { 130 public void widgetSelected(SelectionEvent e) { 131 pageChanged(); 132 } 133 }); 134 135 initialize(); 136 setControl(container); 137 PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.PLUGIN_IMPORT_EXPRESS_PAGE); 138 Dialog.applyDialogFont(container); 139 } 140 141 private Composite createTablePart(Composite parent) { 142 Composite container = new Composite(parent, SWT.NONE); 143 GridLayout layout = new GridLayout(); 144 layout.numColumns = 2; 145 container.setLayout(layout); 146 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 147 148 tablePart = 149 new TablePart( 150 PDEUIMessages.ImportWizard_expressPage_nonBinary, 151 new String [] { 152 PDEUIMessages.WizardCheckboxTablePart_selectAll, 153 PDEUIMessages.WizardCheckboxTablePart_deselectAll}); 154 tablePart.createControl(container); 155 GridData gd = new GridData(GridData.FILL_BOTH); 156 gd.widthHint = 225; 157 gd.heightHint = 200; 158 tablePart.getControl().setLayoutData(gd); 159 160 CheckboxTableViewer viewer = tablePart.getTableViewer(); 161 viewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); 162 viewer.setContentProvider(new PluginContentProvider()); 163 viewer.setComparator(ListUtil.PLUGIN_COMPARATOR); 164 viewer.setInput(PDEPlugin.getWorkspace().getRoot()); 165 166 return container; 167 } 168 169 private void createImportPart(Composite parent) { 170 Composite container = new Composite(parent, SWT.NONE); 171 container.setLayout(new GridLayout()); 172 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 173 174 createImportList(container); 175 counterLabel = new Label(container, SWT.NONE); 176 counterLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 177 } 178 179 private void initialize() { 180 Object [] items = initialSelection.toArray(); 181 ArrayList list = new ArrayList (); 182 for (int i = 0; i < items.length; i++) { 183 Object item = items[i]; 184 if (item instanceof IJavaProject) { 185 item = ((IJavaProject)item).getProject(); 186 } 187 if (item instanceof IProject) { 188 IProject project = (IProject) item; 189 if (WorkspaceModelManager.isPluginProject(project) 190 && !WorkspaceModelManager.isBinaryProject(project)) { 191 IPluginModelBase model = PluginRegistry.findModel(project); 192 if (model != null) 193 list.add(model); 194 } 195 } 196 } 197 tablePart.setSelection(list.toArray()); 198 } 199 200 201 private void computeModelsToImport() { 202 fImportListViewer.getTable().removeAll(); 203 204 ArrayList result = new ArrayList (); 205 Object [] wModels = tablePart.getSelection(); 206 for (int i = 0; i < wModels.length; i++) { 207 IPluginModelBase model = (IPluginModelBase)wModels[i]; 208 addDependencies(model, result, fAddFragmentsButton.getSelection()); 209 addExtraPrerequisites(model, result); 210 } 211 212 if (wModels.length > 0) { 213 removeSharedModels(result); 214 } 215 216 fImportListViewer.add(result.toArray()); 217 } 218 219 private void removeSharedModels(ArrayList result) { 220 IPluginModelBase[] smodels = (IPluginModelBase[])result.toArray(new IPluginModelBase[result.size()]); 221 for (int i = 0; i < smodels.length; i++) { 222 String id = smodels[i].getPluginBase().getId(); 223 IPluginModelBase model = PluginRegistry.findModel(id); 224 if (model != null) { 225 IResource resource = model.getUnderlyingResource(); 226 if (resource != null) { 227 IProject project = resource.getProject(); 228 if (!WorkspaceModelManager.isUnsharedProject(project)) { 229 result.remove(smodels[i]); 230 } 231 } 232 } 233 } 234 } 235 236 private void addExtraPrerequisites(IPluginModelBase model, ArrayList result) { 237 try { 238 IBuildModel buildModel = model.getBuildModel(); 239 if (buildModel == null) { 240 IFile buildFile = model.getUnderlyingResource().getProject().getFile("build.properties"); if (buildFile.exists()) { 242 buildModel = new WorkspaceBuildModel(buildFile); 243 buildModel.load(); 244 } 245 } 246 if (buildModel == null) 247 return; 248 249 IBuildEntry entry = buildModel.getBuild().getEntry(IBuildEntry.JARS_EXTRA_CLASSPATH); 250 if (entry == null) 251 return; 252 253 String [] tokens = entry.getTokens(); 254 for (int i = 0; i < tokens.length; i++) { 255 Path path = new Path(tokens[i]); 256 if (path.segmentCount() >= 2 && path.segment(0).equals("..")) { for (int j = 0; j < fModels.length; j++) { 258 if (fModels[j].getPluginBase().getId().equals(path.segment(1)) 259 && !result.contains(fModels[j])) { 260 result.add(fModels[j]); 261 } 262 } 263 } 264 } 265 } catch (CoreException e) { 266 } 267 } 268 269 protected void refreshPage() { 270 pageChanged(); 271 } 272 273 protected void pageChanged() { 274 computeModelsToImport(); 275 updateCount(); 276 setPageComplete(fImportListViewer.getTable().getItemCount() > 0); 277 } 278 279 private void updateCount() { 280 counterLabel.setText( 281 NLS.bind(PDEUIMessages.ImportWizard_expressPage_total, new Integer (fImportListViewer.getTable().getItemCount()).toString())); 282 counterLabel.getParent().layout(); 283 } 284 285 286 } 287 | Popular Tags |