1 11 package org.eclipse.ant.internal.ui.views.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 import org.eclipse.ant.internal.ui.AntUIImages; 17 import org.eclipse.ant.internal.ui.AntUtil; 18 import org.eclipse.ant.internal.ui.IAntUIConstants; 19 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 20 import org.eclipse.ant.internal.ui.model.AntProjectNode; 21 import org.eclipse.ant.internal.ui.model.AntProjectNodeProxy; 22 import org.eclipse.ant.internal.ui.preferences.FileSelectionDialog; 23 import org.eclipse.ant.internal.ui.views.AntView; 24 import org.eclipse.core.resources.IFile; 25 import org.eclipse.core.runtime.IProgressMonitor; 26 import org.eclipse.jface.action.Action; 27 import org.eclipse.jface.operation.IRunnableWithProgress; 28 import org.eclipse.swt.widgets.Display; 29 import org.eclipse.ui.PlatformUI; 30 31 35 public class AddBuildFilesAction extends Action { 36 37 private AntView view; 38 39 public AddBuildFilesAction(AntView view) { 40 super(AntViewActionMessages.AddBuildFilesAction_1, AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ADD)); 41 this.view= view; 42 setToolTipText(AntViewActionMessages.AddBuildFilesAction_0); 43 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IAntUIHelpContextIds.ADD_BUILDFILE_ACTION); 44 } 45 46 49 public void run() { 50 String title= AntViewActionMessages.AddBuildFilesAction_2; 51 String message= AntViewActionMessages.AddBuildFilesAction_4; 52 String filterExtension= "xml"; String filterMessage= AntViewActionMessages.AddBuildFilesAction_5; 54 55 FileSelectionDialog dialog = new FileSelectionDialog(Display.getCurrent().getActiveShell(), getBuildFiles(), title, message, filterExtension, filterMessage); 56 dialog.open(); 57 final Object [] result= dialog.getResult(); 58 if (result == null) { 59 return; 60 } 61 62 try { 63 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 64 public void run(IProgressMonitor monitor) { 65 monitor.beginTask(AntViewActionMessages.AddBuildFilesAction_3, result.length); 66 for (int i = 0; i < result.length && !monitor.isCanceled(); i++) { 67 Object file = result[i]; 68 if (file instanceof IFile) { 69 String buildFileName= ((IFile)file).getFullPath().toString(); 70 final AntProjectNode project= new AntProjectNodeProxy(buildFileName); 71 project.getName(); 72 monitor.worked(1); 73 Display.getDefault().asyncExec(new Runnable () { 74 public void run() { 75 view.addProject(project); 76 } 77 }); 78 } 79 } 80 } 81 }); 82 } catch (InvocationTargetException e) { 83 } catch (InterruptedException e) { 84 } 85 } 86 87 private List getBuildFiles() { 88 AntProjectNode[] existingProjects= view.getProjects(); 89 List buildFiles= new ArrayList (existingProjects.length); 90 for (int j = 0; j < existingProjects.length; j++) { 91 AntProjectNode existingProject = existingProjects[j]; 92 buildFiles.add(AntUtil.getFile(existingProject.getBuildFileName())); 93 } 94 return buildFiles; 95 } 96 } 97 | Popular Tags |