1 11 package org.eclipse.pde.internal.ui.wizards.templates; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.runtime.Assert; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.jface.operation.IRunnableWithProgress; 20 import org.eclipse.jface.wizard.Wizard; 21 import org.eclipse.pde.core.plugin.IPluginBase; 22 import org.eclipse.pde.core.plugin.IPluginImport; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.core.plugin.IPluginReference; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEPluginImages; 27 import org.eclipse.pde.internal.ui.PDEUIMessages; 28 import org.eclipse.pde.ui.IExtensionWizard; 29 import org.eclipse.pde.ui.templates.BaseOptionTemplateSection; 30 import org.eclipse.pde.ui.templates.ITemplateSection; 31 import org.eclipse.ui.actions.WorkspaceModifyOperation; 32 33 47 48 public class NewExtensionTemplateWizard extends Wizard implements IExtensionWizard { 49 private ITemplateSection fSection; 50 private IProject fProject; 51 private IPluginModelBase fModel; 52 private boolean fUpdatedDependencies; 53 54 57 58 public NewExtensionTemplateWizard(ITemplateSection section) { 59 Assert.isNotNull(section); 60 setDialogSettings(PDEPlugin.getDefault().getDialogSettings()); 61 setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWEX_WIZ); 62 setNeedsProgressMonitor(true); 63 fSection = section; 64 } 65 66 public void init(IProject project, IPluginModelBase model) { 67 this.fProject = project; 68 this.fModel = model; 69 } 70 71 public void addPages() { 72 fSection.addPages(this); 73 setWindowTitle(fSection.getLabel()); 74 if (fSection instanceof BaseOptionTemplateSection) { 75 ((BaseOptionTemplateSection)fSection).initializeFields(fModel); 76 } 77 } 78 79 public boolean performFinish() { 80 IRunnableWithProgress operation = new WorkspaceModifyOperation() { 81 public void execute(IProgressMonitor monitor) { 82 try { 83 int totalWork = fSection.getNumberOfWorkUnits(); 84 monitor.beginTask(PDEUIMessages.NewExtensionTemplateWizard_generating, totalWork); 85 updateDependencies(); 86 fSection.execute(fProject, fModel, monitor); } catch (CoreException e) { 88 PDEPlugin.logException(e); 89 } finally { 90 monitor.done(); 91 } 92 } 93 }; 94 try { 95 getContainer().run(false, true, operation); 96 } catch (InvocationTargetException e) { 97 PDEPlugin.logException(e); 98 return false; 99 } catch (InterruptedException e) { 100 PDEPlugin.logException(e); 101 return false; 102 } 103 return true; 104 } 105 106 private void updateDependencies() throws CoreException { 107 IPluginReference[] refs = fSection.getDependencies(fModel.getPluginBase().getSchemaVersion()); 108 for (int i = 0; i < refs.length; i++) { 109 IPluginReference ref = refs[i]; 110 if (!modelContains(ref)) { 111 IPluginImport iimport = fModel.getPluginFactory().createImport(); 112 iimport.setId(ref.getId()); 113 iimport.setMatch(ref.getMatch()); 114 iimport.setVersion(ref.getVersion()); 115 fModel.getPluginBase().add(iimport); 116 fUpdatedDependencies = true; 117 } 118 } 119 } 120 121 private boolean modelContains(IPluginReference ref) { 122 IPluginBase plugin = fModel.getPluginBase(); 123 IPluginImport[] imports = plugin.getImports(); 124 for (int i = 0; i < imports.length; i++) { 125 IPluginImport iimport = imports[i]; 126 if (iimport.getId().equals(ref.getId())) { 127 return true; 129 } 130 } 131 return false; 132 } 133 134 public boolean updatedDependencies() { 135 return fUpdatedDependencies; 136 } 137 } 138 | Popular Tags |