1 11 package org.eclipse.pde.internal.ui.wizards.imports; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.jface.dialogs.IDialogSettings; 16 import org.eclipse.jface.viewers.IStructuredContentProvider; 17 import org.eclipse.jface.viewers.TableViewer; 18 import org.eclipse.jface.wizard.WizardPage; 19 import org.eclipse.pde.core.IModelProviderEvent; 20 import org.eclipse.pde.core.IModelProviderListener; 21 import org.eclipse.pde.core.plugin.IFragment; 22 import org.eclipse.pde.core.plugin.IFragmentModel; 23 import org.eclipse.pde.core.plugin.IPlugin; 24 import org.eclipse.pde.core.plugin.IPluginImport; 25 import org.eclipse.pde.core.plugin.IPluginLibrary; 26 import org.eclipse.pde.core.plugin.IPluginModel; 27 import org.eclipse.pde.core.plugin.IPluginModelBase; 28 import org.eclipse.pde.internal.core.ClasspathUtilCore; 29 import org.eclipse.pde.internal.core.PDECore; 30 import org.eclipse.pde.internal.ui.PDEPlugin; 31 import org.eclipse.pde.internal.ui.PDEUIMessages; 32 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 33 import org.eclipse.pde.internal.ui.wizards.ListUtil; 34 import org.eclipse.swt.SWT; 35 import org.eclipse.swt.layout.GridData; 36 import org.eclipse.swt.layout.GridLayout; 37 import org.eclipse.swt.widgets.Button; 38 import org.eclipse.swt.widgets.Composite; 39 import org.eclipse.swt.widgets.Label; 40 import org.eclipse.swt.widgets.Table; 41 import org.eclipse.swt.widgets.TableItem; 42 43 public abstract class BaseImportWizardSecondPage extends WizardPage implements IModelProviderListener { 44 45 protected static final String SETTINGS_ADD_FRAGMENTS = "addFragments"; protected static final String SETTINGS_AUTOBUILD = "autobuild"; 48 protected PluginImportWizardFirstPage fPage1; 49 protected IPluginModelBase[] fModels = new IPluginModelBase[0]; 50 private String fLocation; 51 protected Button fAddFragmentsButton; 52 private Button fAutoBuildButton; 53 protected TableViewer fImportListViewer; 54 private boolean fRefreshNeeded = true; 55 56 class ContentProvider 57 extends DefaultContentProvider 58 implements IStructuredContentProvider { 59 public Object [] getElements(Object element) { 60 return new Object [0]; 61 } 62 } 63 64 public BaseImportWizardSecondPage(String pageName, PluginImportWizardFirstPage page) { 65 super(pageName); 66 fPage1 = page; 67 PDEPlugin.getDefault().getLabelProvider().connect(this); 68 PDECore.getDefault().getModelManager().getExternalModelManager().addModelProviderListener(this); 69 } 70 71 protected Composite createImportList(Composite parent) { 72 Composite container = new Composite(parent, SWT.NONE); 73 GridLayout layout = new GridLayout(); 74 layout.marginWidth = 0; 75 layout.marginHeight = 0; 76 container.setLayout(layout); 77 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 78 79 Label label = new Label(container, SWT.NONE); 80 label.setText(PDEUIMessages.ImportWizard_DetailedPage_importList); 81 82 Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); 83 GridData gd = new GridData(GridData.FILL_BOTH); 84 gd.widthHint = 225; 85 table.setLayoutData(gd); 86 87 fImportListViewer = new TableViewer(table); 88 fImportListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); 89 fImportListViewer.setContentProvider(new ContentProvider()); 90 fImportListViewer.setInput(PDECore.getDefault().getModelManager().getExternalModelManager()); 91 fImportListViewer.setComparator(ListUtil.PLUGIN_COMPARATOR); 92 return container; 93 } 94 95 protected Composite createComputationsOption(Composite parent, int span) { 96 Composite composite = new Composite(parent, SWT.NONE); 97 composite.setLayout(new GridLayout()); 98 GridData gd = new GridData(); 99 gd.horizontalSpan = span; 100 composite.setLayoutData(gd); 101 102 fAddFragmentsButton = new Button(composite, SWT.CHECK); 103 fAddFragmentsButton.setText(PDEUIMessages.ImportWizard_SecondPage_addFragments); 104 fAddFragmentsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 105 if (getDialogSettings().get(SETTINGS_ADD_FRAGMENTS) != null) 106 fAddFragmentsButton.setSelection(getDialogSettings().getBoolean(SETTINGS_ADD_FRAGMENTS)); 107 else 108 fAddFragmentsButton.setSelection(true); 109 110 if (!PDEPlugin.getWorkspace().isAutoBuilding()) { 111 fAutoBuildButton = new Button(composite, SWT.CHECK); 112 fAutoBuildButton.setText(PDEUIMessages.BaseImportWizardSecondPage_autobuild); 113 fAutoBuildButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 114 fAutoBuildButton.setSelection(getDialogSettings().getBoolean(SETTINGS_AUTOBUILD)); 115 } 116 return composite; 117 118 } 119 120 public void dispose() { 121 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 122 PDECore.getDefault().getModelManager().getExternalModelManager().removeModelProviderListener(this); 123 } 124 125 public void setVisible(boolean visible) { 126 super.setVisible(visible); 127 if (visible && isRefreshNeeded()) { 128 fModels = fPage1.getModels(); 129 refreshPage(); 130 } 131 } 132 133 protected abstract void refreshPage(); 134 135 protected boolean isRefreshNeeded() { 136 if (fRefreshNeeded) { 137 fRefreshNeeded = false; 138 fLocation = fPage1.getDropLocation(); 139 return true; 140 } 141 String currLocation = fPage1.getDropLocation(); 142 if (fLocation == null || !fLocation.equals(currLocation)) { 143 fLocation = fPage1.getDropLocation(); 144 return true; 145 } 146 return fPage1.isRefreshNeeded(); 147 } 148 149 private IPluginModelBase findModel(String id) { 150 for (int i = 0; i < fModels.length; i++) { 151 String modelId = fModels[i].getPluginBase().getId(); 152 if (modelId != null && modelId.equals(id)) 153 return fModels[i]; 154 } 155 return null; 156 } 157 158 private IFragmentModel[] findFragments(IPlugin plugin) { 159 ArrayList result = new ArrayList (); 160 for (int i = 0; i < fModels.length; i++) { 161 if (fModels[i] instanceof IFragmentModel) { 162 IFragment fragment = ((IFragmentModel) fModels[i]).getFragment(); 163 if (plugin.getId().equalsIgnoreCase(fragment.getPluginId())) { 164 result.add(fModels[i]); 165 } 166 } 167 } 168 return (IFragmentModel[]) result.toArray(new IFragmentModel[result.size()]); 169 } 170 171 protected void addPluginAndDependencies( 172 IPluginModelBase model, 173 ArrayList selected, 174 boolean addFragments) { 175 176 boolean containsVariable = false; 177 if (!selected.contains(model)) { 178 selected.add(model); 179 boolean hasextensibleAPI = ClasspathUtilCore.hasExtensibleAPI(model); 180 if (!addFragments && !hasextensibleAPI && model instanceof IPluginModel) { 181 IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); 182 for (int i = 0; i < libraries.length; i++) { 183 if (ClasspathUtilCore.containsVariables(libraries[i].getName())) { 184 containsVariable = true; 185 break; 186 } 187 } 188 } 189 addDependencies(model, selected, addFragments || containsVariable || hasextensibleAPI); 190 } 191 } 192 193 protected void addDependencies( 194 IPluginModelBase model, 195 ArrayList selected, 196 boolean addFragments) { 197 198 IPluginImport[] required = model.getPluginBase().getImports(); 199 if (required.length > 0) { 200 for (int i = 0; i < required.length; i++) { 201 IPluginModelBase found = findModel(required[i].getId()); 202 if (found != null) { 203 addPluginAndDependencies(found, selected, addFragments); 204 } 205 } 206 } 207 208 if (addFragments) { 209 if (model instanceof IPluginModel) { 210 IFragmentModel[] fragments = findFragments(((IPluginModel)model).getPlugin()); 211 for (int i = 0; i < fragments.length; i++) { 212 addPluginAndDependencies(fragments[i], selected, addFragments); 213 } 214 } else { 215 IFragment fragment = ((IFragmentModel) model).getFragment(); 216 IPluginModelBase found = findModel(fragment.getPluginId()); 217 if (found != null) { 218 addPluginAndDependencies(found, selected, addFragments); 219 } 220 } 221 } 222 } 223 224 public IPluginModelBase[] getModelsToImport() { 225 TableItem[] items = fImportListViewer.getTable().getItems(); 226 ArrayList result = new ArrayList (); 227 for (int i = 0; i < items.length; i++) { 228 result.add(items[i].getData()); 229 } 230 return (IPluginModelBase[]) result.toArray(new IPluginModelBase[result.size()]); 231 } 232 233 public void storeSettings() { 234 IDialogSettings settings = getDialogSettings(); 235 settings.put(SETTINGS_ADD_FRAGMENTS, fAddFragmentsButton.getSelection()); 236 if (fAutoBuildButton != null) 237 settings.put(SETTINGS_AUTOBUILD, fAutoBuildButton.getSelection()); 238 } 239 240 243 public void modelsChanged(IModelProviderEvent event) { 244 fRefreshNeeded = true; 245 } 246 247 public boolean forceAutoBuild() { 248 return fAutoBuildButton != null && getDialogSettings().getBoolean(SETTINGS_AUTOBUILD); 249 } 250 251 } 252 | Popular Tags |