1 21 package org.apache.derby.ui.popup.actions; 22 23 import java.util.ArrayList ; 24 25 import org.apache.derby.ui.common.CommonNames; 26 import org.apache.derby.ui.common.Messages; 27 import org.apache.derby.ui.util.DerbyServerUtils; 28 import org.apache.derby.ui.util.DerbyUtils; 29 import org.apache.derby.ui.util.Logger; 30 import org.apache.derby.ui.util.SelectionUtil; 31 import org.eclipse.core.resources.IProject; 32 import org.eclipse.core.resources.IProjectDescription; 33 import org.eclipse.core.resources.IResource; 34 import org.eclipse.core.runtime.IStatus; 35 import org.eclipse.jdt.core.IClasspathEntry; 36 import org.eclipse.jdt.core.IJavaProject; 37 import org.eclipse.jdt.core.JavaCore; 38 import org.eclipse.jface.action.IAction; 39 import org.eclipse.jface.dialogs.MessageDialog; 40 import org.eclipse.jface.viewers.ISelection; 41 import org.eclipse.jface.window.ApplicationWindow; 42 import org.eclipse.swt.widgets.Shell; 43 import org.eclipse.ui.IObjectActionDelegate; 44 import org.eclipse.ui.IWorkbenchPart; 45 import org.eclipse.ui.IWorkbenchWindow; 46 import org.eclipse.ui.PlatformUI; 47 48 public class RemoveDerbyNature implements IObjectActionDelegate { 49 50 private IJavaProject currentJavaProject; 51 private IProject currentProject; 52 55 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 56 } 57 58 59 private static String [] removeDerbyNature(String [] natures){ 60 ArrayList arrL=new ArrayList (); 61 62 for (int i=0;i<natures.length;i++){ 63 if(!(natures[i].equalsIgnoreCase(CommonNames.DERBY_NATURE))){ 64 arrL.add(natures[i]); 65 } 66 } 67 String [] newNatures= new String [arrL.size()]; 68 for(int i=0;i<arrL.size();i++){ 69 newNatures[i]=(String )arrL.get(i); 70 } 71 return newNatures; 72 } 73 76 public void run(IAction action) { 77 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 78 try { 79 ((ApplicationWindow)window).setStatus(Messages.REMOVING_NATURE); 80 81 if(currentJavaProject==null){ 82 currentJavaProject=JavaCore.create(currentProject); 83 } 84 if(DerbyServerUtils.getDefault().getRunning(currentJavaProject.getProject())){ 86 DerbyServerUtils.getDefault().stopDerbyServer(currentJavaProject.getProject()); 87 } 88 IClasspathEntry[] rawClasspath = currentJavaProject.getRawClasspath(); 89 currentJavaProject.setRawClasspath(DerbyUtils.removeDerbyJars(rawClasspath), null); 90 91 IProjectDescription description = currentJavaProject.getProject().getDescription(); 92 String [] natures = description.getNatureIds(); 93 94 description.setNatureIds(removeDerbyNature(natures)); 95 currentJavaProject.getProject().setDescription(description, null); 96 currentJavaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); 98 ((ApplicationWindow)window).setStatus(Messages.DERBY_NATURE_REMOVED); 99 }catch (Exception e) { 100 Logger.log(Messages.ERROR_REMOVING_NATURE+" '"+currentJavaProject.getProject().getName()+"': "+e,IStatus.ERROR); 101 102 Shell shell = new Shell(); 103 MessageDialog.openInformation( 104 shell, 105 CommonNames.PLUGIN_NAME, 106 Messages.ERROR_REMOVING_NATURE+":\n" + 107 SelectionUtil.getStatusMessages(e)); 108 } 109 110 } 111 112 115 public void selectionChanged(IAction action, ISelection selection) { 116 currentJavaProject = SelectionUtil.findSelectedJavaProject(selection); 117 if(currentJavaProject==null){ 118 currentProject=org.apache.derby.ui.util.SelectionUtil.findSelectedProject(selection); 119 } 120 } 121 122 } 123 | Popular Tags |