1 11 package org.eclipse.ui.internal.progress; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.action.IMenuListener; 15 import org.eclipse.jface.action.IMenuManager; 16 import org.eclipse.jface.action.IToolBarManager; 17 import org.eclipse.jface.action.MenuManager; 18 import org.eclipse.jface.action.Separator; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.jface.viewers.ISelectionProvider; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Menu; 27 import org.eclipse.ui.IActionBars; 28 import org.eclipse.ui.IViewPart; 29 import org.eclipse.ui.IWorkbenchActionConstants; 30 import org.eclipse.ui.PlatformUI; 31 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 32 import org.eclipse.ui.internal.WorkbenchImages; 33 import org.eclipse.ui.part.ViewPart; 34 import org.eclipse.ui.preferences.ViewPreferencesAction; 35 36 40 public class ProgressView extends ViewPart implements IViewPart { 41 42 DetailedProgressViewer viewer; 43 44 Action cancelAction; 45 46 Action clearAllAction; 47 48 49 54 public void createPartControl(Composite parent) { 55 viewer = new DetailedProgressViewer(parent, SWT.MULTI); 56 viewer.setComparator(ProgressManagerUtil.getProgressViewerComparator()); 57 58 viewer.getControl().setLayoutData( 59 new GridData(SWT.FILL, SWT.FILL, true, true)); 60 61 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, 62 IWorkbenchHelpContextIds.RESPONSIVE_UI); 63 64 initContentProvider(); 65 createClearAllAction(); 66 createCancelAction(); 67 initContextMenu(); 68 initPulldownMenu(); 69 initToolBar(); 70 getSite().setSelectionProvider(viewer); 71 } 72 73 78 public void setFocus() { 79 if (viewer != null) { 80 viewer.setFocus(); 81 } 82 } 83 84 87 protected void initContentProvider() { 88 ProgressViewerContentProvider provider = new ProgressViewerContentProvider(viewer, true ,true); 89 viewer.setContentProvider(provider); 90 viewer.setInput(ProgressManager.getInstance()); 91 } 92 93 96 private void initContextMenu() { 97 MenuManager menuMgr = new MenuManager("#PopupMenu"); Menu menu = menuMgr.createContextMenu(viewer.getControl()); 99 menuMgr.add(cancelAction); 100 menuMgr.addMenuListener(new IMenuListener() { 101 public void menuAboutToShow(IMenuManager manager) { 102 JobInfo info = getSelectedInfo(); 103 if (info == null) { 104 return; 105 } 106 } 107 }); 108 menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); 109 getSite().registerContextMenu(menuMgr, viewer); 110 viewer.getControl().setMenu(menu); 111 } 112 113 private void initPulldownMenu() { 114 IMenuManager menuMgr = getViewSite().getActionBars().getMenuManager(); 115 menuMgr.add(clearAllAction); 116 menuMgr.add(new ViewPreferencesAction() { 117 122 public void openViewPreferencesDialog() { 123 new JobsViewPreferenceDialog(viewer.getControl().getShell()) 124 .open(); 125 126 } 127 }); 128 129 } 130 131 private void initToolBar() { 132 IActionBars bars = getViewSite().getActionBars(); 133 IToolBarManager tm = bars.getToolBarManager(); 134 tm.add(clearAllAction); 135 } 136 137 143 private IStructuredSelection getSelection() { 144 ISelectionProvider provider = getSite().getSelectionProvider(); 146 if (provider == null) { 147 return null; 148 } 149 ISelection currentSelection = provider.getSelection(); 150 if (currentSelection instanceof IStructuredSelection) { 151 return (IStructuredSelection) currentSelection; 152 } 153 return null; 154 } 155 156 162 JobInfo getSelectedInfo() { 163 IStructuredSelection selection = getSelection(); 164 if (selection != null && selection.size() == 1) { 165 JobTreeElement element = (JobTreeElement) selection 166 .getFirstElement(); 167 if (element.isJobInfo()) { 168 return (JobInfo) element; 169 } 170 } 171 return null; 172 } 173 174 177 private void createCancelAction() { 178 cancelAction = new Action(ProgressMessages.ProgressView_CancelAction) { 179 184 public void run() { 185 viewer.cancelSelection(); 186 } 187 }; 188 189 } 190 191 194 private void createClearAllAction() { 195 clearAllAction = new Action( 196 ProgressMessages.ProgressView_ClearAllAction) { 197 202 public void run() { 203 FinishedJobs.getInstance().clearAll(); 204 } 205 }; 206 clearAllAction 207 .setToolTipText(ProgressMessages.NewProgressView_RemoveAllJobsToolTip); 208 ImageDescriptor id = WorkbenchImages 209 .getWorkbenchImageDescriptor("/elcl16/progress_remall.gif"); if (id != null) { 211 clearAllAction.setImageDescriptor(id); 212 } 213 id = WorkbenchImages 214 .getWorkbenchImageDescriptor("/dlcl16/progress_remall.gif"); if (id != null) { 216 clearAllAction.setDisabledImageDescriptor(id); 217 } 218 } 219 220 } 221 | Popular Tags |