1 11 package org.eclipse.ant.internal.ui.views.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import com.ibm.icu.text.MessageFormat; 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.Set ; 18 import org.eclipse.ant.internal.ui.AntUIImages; 19 import org.eclipse.ant.internal.ui.IAntUIConstants; 20 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 21 import org.eclipse.ant.internal.ui.model.AntProjectNode; 22 import org.eclipse.ant.internal.ui.model.AntProjectNodeProxy; 23 import org.eclipse.ant.internal.ui.model.AntTargetNode; 24 import org.eclipse.ant.internal.ui.views.AntView; 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.jface.viewers.IStructuredSelection; 29 import org.eclipse.ui.PlatformUI; 30 import org.eclipse.ui.texteditor.IUpdate; 31 32 35 public class RefreshBuildFilesAction extends Action implements IUpdate { 36 37 private AntView fView; 38 39 45 public RefreshBuildFilesAction(AntView view) { 46 super(AntViewActionMessages.RefreshBuildFilesAction_Refresh_Buildfiles_1, AntUIImages.getImageDescriptor(IAntUIConstants.IMG_REFRESH)); 47 setToolTipText(AntViewActionMessages.RefreshBuildFilesAction_Refresh_Buildfiles_1); 48 fView = view; 49 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IAntUIHelpContextIds.REFRESH_BUILDFILE_ACTION); 50 } 51 52 55 public void run() { 56 final Set projects= getSelectedProjects(); 57 if (projects.isEmpty()) { 58 AntProjectNode[] allProjects= fView.getProjects(); 60 for (int i = 0; i < allProjects.length; i++) { 61 projects.add(allProjects[i]); 62 } 63 } 64 final Iterator iter= projects.iterator(); 65 if (!iter.hasNext()) { 66 return; 67 } 68 69 try { 70 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 71 public void run(IProgressMonitor monitor) { 72 monitor.beginTask(AntViewActionMessages.RefreshBuildFilesAction_Refreshing_buildfiles_3, projects.size()); 73 AntProjectNodeProxy project; 74 while (iter.hasNext()) { 75 project= (AntProjectNodeProxy) iter.next(); 76 monitor.subTask(MessageFormat.format(AntViewActionMessages.RefreshBuildFilesAction_Refreshing__0__4, new String [] {project.getBuildFileName()})); 77 project.parseBuildFile(true); 78 monitor.worked(1); 79 } 80 } 81 }); 82 } catch (InvocationTargetException e) { 83 } catch (InterruptedException e) { 84 } 85 fView.getViewer().refresh(); 86 } 87 88 93 private Set getSelectedProjects() { 94 IStructuredSelection selection = (IStructuredSelection) fView.getViewer().getSelection(); 95 HashSet set= new HashSet (); 96 Iterator iter = selection.iterator(); 97 Object data; 98 while (iter.hasNext()) { 99 data= iter.next(); 100 if (data instanceof AntProjectNode) { 101 set.add(data); 102 } else if (data instanceof AntTargetNode) { 103 set.add(((AntTargetNode) data).getProjectNode()); 104 } 105 } 106 return set; 107 } 108 109 112 public void update() { 113 setEnabled(fView.getProjects().length > 0); 114 } 115 116 } 117 | Popular Tags |