1 11 package org.eclipse.pde.internal.ui.editor.plugin; 12 import java.lang.reflect.InvocationTargetException ; 13 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.jdt.core.IJavaElement; 20 import org.eclipse.jdt.core.IJavaProject; 21 import org.eclipse.jdt.core.JavaCore; 22 import org.eclipse.jdt.ui.JavaUI; 23 import org.eclipse.jdt.ui.wizards.NewTypeWizardPage; 24 import org.eclipse.jface.dialogs.IDialogSettings; 25 import org.eclipse.jface.operation.IRunnableWithProgress; 26 import org.eclipse.jface.wizard.Wizard; 27 import org.eclipse.pde.core.plugin.IPluginModelBase; 28 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 29 import org.eclipse.pde.internal.ui.PDEPlugin; 30 import org.eclipse.pde.internal.ui.PDEPluginImages; 31 import org.eclipse.pde.internal.ui.PDEUIMessages; 32 import org.eclipse.ui.IWorkbenchPage; 33 import org.eclipse.ui.PlatformUI; 34 import org.eclipse.ui.actions.WorkspaceModifyOperation; 35 import org.eclipse.ui.ide.IDE; 36 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; 37 public class JavaAttributeWizard extends Wizard { 38 39 private static String STORE_SECTION = "JavaAttributeWizard"; 41 private String fClassName; 42 private IProject fProject; 43 private ISchemaAttribute fAttInfo; 44 private IPluginModelBase fModel; 45 protected NewTypeWizardPage fMainPage; 46 47 public JavaAttributeWizard(JavaAttributeValue value) { 48 this(value.getProject(), value.getModel(), value.getAttributeInfo(), value.getClassName()); 49 } 50 51 public JavaAttributeWizard(IProject project, IPluginModelBase model, ISchemaAttribute attInfo, String className) { 52 fClassName = className; 53 fModel = model; 54 fProject = project; 55 fAttInfo = attInfo; 56 setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWPPRJ_WIZ); 57 IDialogSettings masterSettings = PDEPlugin.getDefault().getDialogSettings(); 58 setDialogSettings(getSettingsSection(masterSettings)); 59 setWindowTitle(PDEUIMessages.JavaAttributeWizard_wtitle); 60 setNeedsProgressMonitor(true); 61 } 62 63 private IDialogSettings getSettingsSection(IDialogSettings master) { 64 IDialogSettings setting = master.getSection(STORE_SECTION); 65 if (setting == null) 66 setting = master.addNewSection(STORE_SECTION); 67 return setting; 68 } 69 70 public void addPages() { 71 fMainPage = new JavaAttributeWizardPage(fProject, fModel, fAttInfo, fClassName); 72 addPage(fMainPage); 73 ((JavaAttributeWizardPage)fMainPage).init(); 74 } 75 76 public boolean performFinish() { 77 IRunnableWithProgress op = new WorkspaceModifyOperation() { 78 protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException { 79 fMainPage.createType(monitor); 80 } 81 }; 82 try { 83 PlatformUI.getWorkbench().getProgressService().runInUI( 84 PDEPlugin.getActiveWorkbenchWindow(), op, 85 PDEPlugin.getWorkspace().getRoot()); 86 IResource resource = fMainPage.getModifiedResource(); 87 if (resource != null) { 88 selectAndReveal(resource); 89 if (fProject.hasNature(JavaCore.NATURE_ID)) { 90 IJavaProject jProject = JavaCore.create(fProject); 91 IJavaElement jElement = jProject.findElement(resource.getProjectRelativePath().removeFirstSegments(1)); 92 if (jElement != null) 93 JavaUI.openInEditor(jElement); 94 } else if (resource instanceof IFile) { 95 IWorkbenchPage page = PDEPlugin.getActivePage(); 96 IDE.openEditor(page, (IFile) resource, true); 97 } 98 } 99 } catch (InvocationTargetException e) { 100 PDEPlugin.logException(e); 101 } catch (InterruptedException e) { 102 PDEPlugin.logException(e); 103 } catch (CoreException e) { 104 PDEPlugin.logException(e); 105 } 106 return true; 107 } 108 109 protected void selectAndReveal(IResource newResource) { 110 BasicNewResourceWizard.selectAndReveal(newResource, PDEPlugin.getActiveWorkbenchWindow()); 111 } 112 113 public String getQualifiedName() { 114 if (fMainPage.getCreatedType() == null) 115 return null; 116 return fMainPage.getCreatedType().getFullyQualifiedName('$'); 117 } 118 119 public String getQualifiedNameWithArgs() { 120 String name = getQualifiedName(); 121 if (name == null) 122 return null; 123 if (fMainPage instanceof JavaAttributeWizardPage) { 124 String classArgs = ((JavaAttributeWizardPage)fMainPage).getClassArgs(); 125 if (classArgs != null && classArgs.length() > 0) 126 return name + ':' + classArgs; 127 } 128 return name; 129 } 130 } 131 | Popular Tags |