1 11 package org.eclipse.ui.internal.ide.dialogs; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.IProjectDescription; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.jface.dialogs.ErrorDialog; 23 import org.eclipse.jface.dialogs.MessageDialog; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.jface.wizard.Wizard; 26 import org.eclipse.osgi.util.NLS; 27 import org.eclipse.ui.ICapabilityUninstallWizard; 28 import org.eclipse.ui.IWorkbench; 29 import org.eclipse.ui.PlatformUI; 30 import org.eclipse.ui.actions.WorkspaceModifyOperation; 31 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 32 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 33 34 43 public class RemoveCapabilityWizard extends Wizard implements 44 ICapabilityUninstallWizard { 45 private IProject project; 46 47 private String [] natureIds; 48 49 53 RemoveCapabilityWizard() { 54 super(); 55 } 56 57 60 public void init(IWorkbench workbench, IStructuredSelection selection, 61 IProject project, String [] natureIds) { 62 this.project = project; 63 this.natureIds = natureIds; 64 } 65 66 69 public boolean performFinish() { 70 return updateNatures(); 71 } 72 73 76 private boolean updateNatures() { 77 WorkspaceModifyOperation op = new WorkspaceModifyOperation() { 79 protected void execute(IProgressMonitor monitor) 80 throws CoreException { 81 try { 82 IProjectDescription description = project.getDescription(); 83 String [] oldIds = description.getNatureIds(); 84 ArrayList newIds = new ArrayList (oldIds.length); 85 for (int i = 0; i < oldIds.length; i++) { 86 boolean keepNature = true; 87 for (int j = 0; j < natureIds.length; j++) { 88 if (natureIds[j].equals(oldIds[i])) { 89 keepNature = false; 90 break; 91 } 92 } 93 if (keepNature) 94 newIds.add(oldIds[i]); 95 } 96 String [] results = new String [newIds.size()]; 97 newIds.toArray(results); 98 description.setNatureIds(results); 99 project.setDescription(description, monitor); 100 } finally { 101 monitor.done(); 102 } 103 } 104 }; 105 106 try { 108 getContainer().run(true, true, op); 109 } catch (InterruptedException e) { 110 return false; 111 } catch (InvocationTargetException e) { 112 Throwable t = e.getTargetException(); 113 if (t instanceof CoreException) { 114 ErrorDialog.openError(getShell(), IDEWorkbenchMessages.RemoveCapabilityWizard_errorMessage, 115 null, ((CoreException) t).getStatus()); 117 } else { 118 IDEWorkbenchPlugin.getDefault().getLog().log( 120 new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, t 121 .toString(), t)); 122 MessageDialog 123 .openError( 124 getShell(), 125 IDEWorkbenchMessages.RemoveCapabilityWizard_errorMessage, 126 NLS.bind(IDEWorkbenchMessages.RemoveCapabilityWizard_internalError, t.getMessage())); 127 } 128 return false; 129 } 130 131 return true; 132 } 133 } 134 | Popular Tags |