1 11 package org.eclipse.ant.internal.ui.views.actions; 12 import java.lang.reflect.InvocationTargetException ; 13 import com.ibm.icu.text.MessageFormat; 14 import org.eclipse.ant.internal.ui.AntUIImages; 15 import org.eclipse.ant.internal.ui.IAntUIConstants; 16 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 17 import org.eclipse.ant.internal.ui.model.AntProjectNode; 18 import org.eclipse.ant.internal.ui.model.AntProjectNodeProxy; 19 import org.eclipse.ant.internal.ui.views.AntView; 20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.jface.action.Action; 23 import org.eclipse.jface.operation.IRunnableWithProgress; 24 import org.eclipse.jface.window.Window; 25 import org.eclipse.swt.widgets.Display; 26 import org.eclipse.ui.PlatformUI; 27 28 32 public class SearchForBuildFilesAction extends Action { 33 private AntView view; 34 35 public SearchForBuildFilesAction(AntView view) { 36 super(AntViewActionMessages.SearchForBuildFilesAction_Search_1, AntUIImages.getImageDescriptor(IAntUIConstants.IMG_SEARCH)); 37 setToolTipText(AntViewActionMessages.SearchForBuildFilesAction_Add_build_files_with_search_2); 38 this.view= view; 39 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IAntUIHelpContextIds.SEARCH_FOR_BUILDFILES_ACTION); 40 } 41 42 46 public void run() { 47 SearchForBuildFilesDialog dialog= new SearchForBuildFilesDialog(); 48 if (dialog.open() != Window.CANCEL) { 49 final IFile[] files= dialog.getResults(); 50 final boolean includeErrorNodes= dialog.getIncludeErrorResults(); 51 final AntProjectNode[] existingProjects= view.getProjects(); 52 try { 53 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 54 public void run(IProgressMonitor monitor) { 55 monitor.beginTask(AntViewActionMessages.SearchForBuildFilesAction_Processing_search_results_3, files.length); 56 for (int i = 0; i < files.length && !monitor.isCanceled(); i++) { 57 String buildFileName= files[i].getFullPath().toString(); 58 monitor.subTask(MessageFormat.format(AntViewActionMessages.SearchForBuildFilesAction_Adding__0__4, new String [] {buildFileName})); 59 if (alreadyAdded(buildFileName)) { 60 continue; 62 } 63 final AntProjectNodeProxy project= new AntProjectNodeProxy(buildFileName); 64 project.parseBuildFile(); 66 monitor.worked(1); 67 if (includeErrorNodes || !(project.isErrorNode())) { 68 Display.getDefault().asyncExec(new Runnable () { 69 public void run() { 70 view.addProject(project); 71 } 72 }); 73 } 74 } 75 } 76 80 private boolean alreadyAdded(String buildFileName) { 81 for (int j = 0; j < existingProjects.length; j++) { 82 AntProjectNode existingProject = existingProjects[j]; 83 if (existingProject.getBuildFileName().equals(buildFileName)) { 84 return true; 85 } 86 } 87 return false; 88 } 89 }); 90 } catch (InvocationTargetException e) { 91 } catch (InterruptedException e) { 92 } 93 } 94 } 95 } 96 | Popular Tags |