1 11 package org.eclipse.pde.internal.ui.editor.feature; 12 13 import java.lang.reflect.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.jface.operation.*; 18 import org.eclipse.jface.viewers.*; 19 import org.eclipse.jface.wizard.*; 20 import org.eclipse.pde.internal.core.*; 21 import org.eclipse.pde.internal.core.feature.*; 22 import org.eclipse.pde.internal.core.ifeature.*; 23 import org.eclipse.pde.internal.ui.*; 24 import org.eclipse.pde.internal.ui.elements.*; 25 import org.eclipse.pde.internal.ui.parts.*; 26 import org.eclipse.pde.internal.ui.wizards.*; 27 import org.eclipse.swt.*; 28 import org.eclipse.swt.layout.*; 29 import org.eclipse.swt.widgets.*; 30 import org.eclipse.ui.*; 31 import org.eclipse.ui.forms.widgets.*; 32 import org.eclipse.ui.help.*; 33 34 public class RequiredFeaturesWizardPage extends WizardPage { 35 public static final String KEY_TITLE = "FeatureEditor.RequiresSection.newFeature.title"; public static final String KEY_DESC = "FeatureEditor.RequiresSection.newFeature.desc"; public static final String KEY_FEATURES = 38 "FeatureEditor.RequiresSection.newFeature.label"; public static final String KEY_ADDING = "FeatureEditor.RequiresSection.newFeature.adding"; public static final String KEY_UPDATING = 41 "FeatureEditor.RequiresSection.newFeature.updating"; private IFeatureModel model; 43 private TablePart checkboxTablePart; 44 private CheckboxTableViewer pluginViewer; 45 46 class PluginContentProvider 47 extends DefaultContentProvider 48 implements IStructuredContentProvider { 49 public Object [] getElements(Object parent) { 50 return getChoices(); 51 } 52 } 53 54 class TablePart extends WizardCheckboxTablePart { 55 public TablePart() { 56 super(PDEPlugin.getResourceString(KEY_FEATURES)); 57 } 58 public void updateCounter(int count) { 59 super.updateCounter(count); 60 setPageComplete(count>0); 61 } 62 protected StructuredViewer createStructuredViewer( 63 Composite parent, 64 int style, 65 FormToolkit toolkit) { 66 StructuredViewer viewer = 67 super.createStructuredViewer(parent, style, toolkit); 68 viewer.setSorter(ListUtil.FEATURE_SORTER); 69 return viewer; 70 } 71 } 72 73 public RequiredFeaturesWizardPage(IFeatureModel model) { 74 super("RequiredFeaturesPage"); this.model = model; 76 setTitle(PDEPlugin.getResourceString(KEY_TITLE)); 77 setDescription(PDEPlugin.getResourceString(KEY_DESC)); 78 setPageComplete(false); 79 80 checkboxTablePart = new TablePart(); 81 PDEPlugin.getDefault().getLabelProvider().connect(this); 82 } 83 84 public void dispose() { 85 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 86 super.dispose(); 87 } 88 89 public void createControl(Composite parent) { 90 Composite container = new Composite(parent, SWT.NULL); 91 GridLayout layout = new GridLayout(); 92 layout.numColumns = 2; 93 container.setLayout(layout); 94 95 createPluginList(container); 96 initialize(); 97 setControl(container); 98 Dialog.applyDialogFont(container); 99 WorkbenchHelp.setHelp(container, IHelpContextIds.FEATURE_INCLUDED_FEATURES_WIZARD); 100 } 101 102 protected void createPluginList(Composite parent) { 103 checkboxTablePart.createControl(parent); 104 pluginViewer = checkboxTablePart.getTableViewer(); 105 pluginViewer.setContentProvider(new PluginContentProvider()); 106 pluginViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); 107 pluginViewer.addFilter(new ViewerFilter() { 108 public boolean select(Viewer v, Object parent, Object object) { 109 if (object instanceof IFeatureModel) { 110 IFeatureModel model = (IFeatureModel) object; 111 return !isOnTheList(model); 112 } 113 return true; 114 } 115 }); 116 GridData gd = (GridData)checkboxTablePart.getControl().getLayoutData(); 117 gd.heightHint = 300; 118 } 119 120 private boolean isOnTheList(IFeatureModel candidate) { 121 IFeatureImport[] imports = model.getFeature().getImports(); 122 IFeature cfeature = candidate.getFeature(); 123 124 if (isThisModel(cfeature)) return true; 125 126 for (int i = 0; i < imports.length; i++) { 127 IFeatureImport iimport = imports[i]; 128 129 if (iimport.getType()==IFeatureImport.PLUGIN) continue; 130 if (iimport.getId().equals(cfeature.getId()) && 131 iimport.getVersion().equals(cfeature.getVersion())) return true; 132 } 133 return false; 134 } 135 136 private boolean isThisModel(IFeature cfeature) { 137 IFeature thisFeature = this.model.getFeature(); 138 139 return cfeature.getId().equals(thisFeature.getId()) && 140 cfeature.getVersion().equals(thisFeature.getVersion()); 141 } 142 143 public void init(IWorkbench workbench) { 144 } 145 146 private void initialize() { 147 pluginViewer.setInput(model.getFeature()); 148 checkboxTablePart.setSelection(new Object [0]); 149 } 150 151 private Object [] getChoices() { 152 WorkspaceModelManager mng = PDECore.getDefault().getWorkspaceModelManager(); 153 return mng.getFeatureModels(); 154 } 155 156 public boolean finish() { 157 final Object [] candidates = checkboxTablePart.getSelection(); 158 IRunnableWithProgress op = new IRunnableWithProgress() { 159 public void run(IProgressMonitor monitor) throws InvocationTargetException { 160 try { 161 doAdd(candidates, monitor); 162 } catch (CoreException e) { 163 throw new InvocationTargetException(e); 164 } 165 } 166 }; 167 try { 168 getContainer().run(false, false, op); 169 } catch (InterruptedException e) { 170 return false; 171 } catch (InvocationTargetException e) { 172 PDEPlugin.logException(e); 173 return false; 174 } 175 return true; 176 } 177 178 private void doAdd(Object [] candidates, IProgressMonitor monitor) throws CoreException { 179 monitor.beginTask( 180 PDEPlugin.getResourceString(KEY_ADDING), 181 candidates.length + 1); 182 IFeature feature = model.getFeature(); 183 IFeatureImport[] added = new IFeatureImport[candidates.length]; 184 for (int i = 0; i < candidates.length; i++) { 185 IFeatureModel candidate = (IFeatureModel) candidates[i]; 186 String name = candidate.getFeature().getLabel(); 187 monitor.subTask(candidate.getResourceString(name)); 188 FeatureImport iimport = (FeatureImport) model.getFactory().createImport(); 189 iimport.loadFrom(candidate.getFeature()); 190 added[i] = iimport; 191 monitor.worked(1); 192 } 193 monitor.subTask(""); monitor.setTaskName(PDEPlugin.getResourceString(KEY_UPDATING)); 195 feature.addImports(added); 196 monitor.worked(1); 197 } 198 } 199 | Popular Tags |