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.IContentProvider; 21 import org.eclipse.jface.viewers.ISelection; 22 import org.eclipse.jface.viewers.ISelectionProvider; 23 import org.eclipse.jface.viewers.IStructuredSelection; 24 import org.eclipse.swt.SWT; 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.internal.WorkbenchImages; 31 import org.eclipse.ui.part.ViewPart; 32 import org.eclipse.ui.preferences.ViewPreferencesAction; 33 34 38 public class JobView extends ViewPart implements IViewPart { 39 40 NewProgressViewer viewer; 41 42 Action cancelAction; 43 44 Action clearAllAction; 45 46 51 public void createPartControl(Composite parent) { 52 viewer = new NewProgressViewer(parent, SWT.MULTI | SWT.H_SCROLL 53 | SWT.V_SCROLL); 54 viewer.setUseHashlookup(true); 55 viewer.setSorter(ProgressManagerUtil.getProgressViewerSorter()); 56 initContentProvider(); 57 createClearAllAction(); 58 createCancelAction(); 59 initContextMenu(); 60 initPulldownMenu(); 61 initToolBar(); 62 getSite().setSelectionProvider(viewer); 63 } 64 65 70 public void setFocus() { 71 if (viewer != null) 72 viewer.setFocus(); 73 } 74 75 78 protected void initContentProvider() { 79 IContentProvider provider = new ProgressTreeContentProvider(viewer); 80 viewer.setContentProvider(provider); 81 viewer.setInput(provider); 82 } 83 84 87 private void initContextMenu() { 88 MenuManager menuMgr = new MenuManager("#PopupMenu"); Menu menu = menuMgr.createContextMenu(viewer.getControl()); 90 menuMgr.add(cancelAction); 91 menuMgr.addMenuListener(new IMenuListener() { 92 public void menuAboutToShow(IMenuManager manager) { 93 JobInfo info = getSelectedInfo(); 94 if (info == null) 95 return; 96 } 97 }); 98 menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); 99 getSite().registerContextMenu(menuMgr, viewer); 100 viewer.getControl().setMenu(menu); 101 } 102 103 private void initPulldownMenu() { 104 IMenuManager menuMgr = getViewSite().getActionBars().getMenuManager(); 105 menuMgr.add(clearAllAction); 106 menuMgr.add(new ViewPreferencesAction(){ 107 110 public void openViewPreferencesDialog() { 111 new JobsViewPreferenceDialog(viewer.getControl().getShell()).open(); 112 113 } 114 }); 115 116 } 117 118 private void initToolBar() { 119 IActionBars bars = getViewSite().getActionBars(); 120 IToolBarManager tm = bars.getToolBarManager(); 121 tm.add(clearAllAction); 122 } 123 124 130 private IStructuredSelection getSelection() { 131 ISelectionProvider provider = getSite().getSelectionProvider(); 133 if (provider == null) 134 return null; 135 ISelection currentSelection = provider.getSelection(); 136 if (currentSelection instanceof IStructuredSelection) { 137 return (IStructuredSelection) currentSelection; 138 } 139 return null; 140 } 141 142 148 JobInfo getSelectedInfo() { 149 IStructuredSelection selection = getSelection(); 150 if (selection != null && selection.size() == 1) { 151 JobTreeElement element = (JobTreeElement) selection 152 .getFirstElement(); 153 if (element.isJobInfo()) 154 return (JobInfo) element; 155 } 156 return null; 157 } 158 159 162 private void createCancelAction() { 163 cancelAction = new Action(ProgressMessages.ProgressView_CancelAction) { 164 169 public void run() { 170 viewer.cancelSelection(); 171 } 172 }; 173 174 } 175 176 179 private void createClearAllAction() { 180 clearAllAction = new Action(ProgressMessages.ProgressView_ClearAllAction) { 181 186 public void run() { 187 viewer.clearAll(); 188 } 189 }; 190 clearAllAction.setToolTipText(ProgressMessages.NewProgressView_RemoveAllJobsToolTip); 191 ImageDescriptor id = WorkbenchImages.getWorkbenchImageDescriptor("/elcl16/progress_remall.gif"); if (id != null) 193 clearAllAction.setImageDescriptor(id); 194 id = WorkbenchImages.getWorkbenchImageDescriptor("/dlcl16/progress_remall.gif"); if (id != null) 196 clearAllAction.setDisabledImageDescriptor(id); 197 } 198 } 199 | Popular Tags |