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