1 11 package org.eclipse.pde.internal.ui.wizards.extension; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.IContainer; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.IWorkspaceRoot; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.Path; 20 import org.eclipse.jface.operation.IRunnableWithProgress; 21 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 22 import org.eclipse.pde.core.plugin.IPluginModelBase; 23 import org.eclipse.pde.core.plugin.PluginRegistry; 24 import org.eclipse.pde.internal.core.PDECore; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 28 public class NewSchemaFileMainPage extends BaseExtensionPointMainPage { 29 private IPluginExtensionPoint fPoint; 30 private boolean isPluginIdFinal; 31 32 public NewSchemaFileMainPage(IContainer container) { 33 this(container, null, false); 34 } 35 36 public NewSchemaFileMainPage(IContainer container, IPluginExtensionPoint point, boolean isPluginIdFinal){ 37 super(container); 38 setTitle(PDEUIMessages.NewSchemaFileWizard_title); 39 setDescription(PDEUIMessages.NewSchemaFileWizard_desc); 40 this.fPoint = point; 41 this.isPluginIdFinal = isPluginIdFinal; 42 } 43 44 public boolean finish() { 45 IRunnableWithProgress operation = getOperation(); 46 try { 47 getContainer().run(true, true, operation); 48 if (fPoint != null){ 49 fPoint.setId(fIdText.getText()); 50 fPoint.setName(fNameText.getText()); 51 fPoint.setSchema(fSchemaText.getText()); 52 } 53 54 } catch (InvocationTargetException e) { 55 PDEPlugin.logException(e); 56 return false; 57 } catch (InterruptedException e) { 58 return false; 59 } catch (CoreException e){ 60 return false; 61 } 62 return true; 63 } 64 protected boolean isPluginIdNeeded() { 65 return true; 66 } 67 protected boolean isPluginIdFinal(){ 68 return isPluginIdFinal; 69 } 70 protected boolean isSharedSchemaSwitchNeeded() { 71 return true; 72 } 73 public void initializeValues(){ 74 if (fContainer!=null){ 75 fPluginIdText.setText(fContainer.getProject().getName()); 76 if (!isPluginIdFinal()) 77 fSchemaLocationText.setText(fContainer.getProject().getName() + "/" + fContainer.getProjectRelativePath().toString()); } 79 if (fPoint == null) 80 return; 81 if (fIdText!=null && fPoint.getId()!=null) 82 fIdText.setText(fPoint.getId()); 83 if (fNameText !=null && fPoint.getName() != null) 84 fNameText.setText(fPoint.getName()); 85 if (fSchemaText!= null && fPoint.getSchema()!=null) 86 fSchemaText.setText(fPoint.getSchema()); 87 88 fPluginIdText.setEnabled(!isPluginIdFinal); 89 fPluginBrowseButton.setEnabled(!isPluginIdFinal); 90 } 91 92 protected String validateFieldContents() { 93 String message = validatePluginID(); 94 if (message != null) 95 return message; 96 97 message = validateExtensionPointID(); 98 if (message != null) 99 return message; 100 101 message = validateExtensionPointName(); 102 if (message != null) 103 return message; 104 105 message = validateContainer(); 106 if (message != null) 107 return message; 108 109 message = validateExtensionPointSchema(); 110 if (message != null) 111 return message; 112 113 return null; 114 } 115 116 protected String validatePluginID() { 117 String pluginID = getPluginId(); 119 if (pluginID.length() == 0) 120 return PDEUIMessages.NewSchemaFileMainPage_missingPluginID; 121 122 IPluginModelBase model = PluginRegistry.findModel(pluginID); 124 if (model == null) 125 return PDEUIMessages.NewSchemaFileMainPage_nonExistingPluginID; 126 127 if (model.getUnderlyingResource() == null) 129 return PDEUIMessages.NewSchemaFileMainPage_externalPluginID; 130 131 return null; 132 } 133 134 protected String validateContainer() { 135 if (!isPluginIdFinal()) { 136 String newContainerName = fSchemaLocationText.getText().trim(); 138 if (newContainerName.length() == 0) 139 return PDEUIMessages.NewSchemaFileMainPage_missingContainer; 140 141 IWorkspaceRoot root = PDECore.getWorkspace().getRoot(); 143 IResource resource = root.findMember(new Path(newContainerName)); 144 if (resource instanceof IContainer) { 145 fContainer = (IContainer) resource; 146 } else { 147 fContainer = null; 148 return PDEUIMessages.NewSchemaFileMainPage_invalidContainer; 149 } 150 } 151 152 if (fContainer == null || !fContainer.exists()) 154 return PDEUIMessages.NewSchemaFileMainPage_nonExistingContainer; 155 156 return null; 157 } 158 159 } 160 | Popular Tags |