| /******************************************************************************* |
| * Copyright (c) 2003 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.ui.internal.progress; |
| import org.eclipse.jface.action.Action; |
| import org.eclipse.jface.action.IAction; |
| import org.eclipse.jface.action.IMenuListener; |
| import org.eclipse.jface.action.IMenuManager; |
| import org.eclipse.jface.action.MenuManager; |
| import org.eclipse.jface.action.Separator; |
| import org.eclipse.jface.viewers.IContentProvider; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.ISelectionProvider; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Menu; |
| import org.eclipse.ui.IViewPart; |
| import org.eclipse.ui.IWorkbenchActionConstants; |
| import org.eclipse.ui.part.ViewPart; |
| /** |
| * The ProgressView is the class that shows the details of the current |
| * workbench progress. |
| */ |
| public class ProgressView extends ViewPart implements IViewPart { |
| ProgressTreeViewer viewer; |
| Action cancelAction; |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
| */ |
| public void createPartControl(Composite parent) { |
| viewer = new ProgressTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); |
| viewer.setUseHashlookup(true); |
| viewer.setSorter(ProgressManagerUtil.getProgressViewerSorter()); |
| initContentProvider(); |
| ProgressManagerUtil.initLabelProvider(viewer); |
| initContextMenu(); |
| initPulldownMenu(); |
| getSite().setSelectionProvider(viewer); |
| } |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.ui.IWorkbenchPart#setFocus() |
| */ |
| public void setFocus() { |
| if (viewer != null) { |
| viewer.getControl().setFocus(); |
| } |
| } |
| /** |
| * Sets the content provider for the viewer. |
| */ |
| protected void initContentProvider() { |
| IContentProvider provider = new ProgressTreeContentProvider(viewer); |
| viewer.setContentProvider(provider); |
| viewer.setInput(provider); |
| } |
| /** |
| * Initialize the context menu for the receiver. |
| */ |
| private void initContextMenu() { |
| MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ |
| Menu menu = menuMgr.createContextMenu(viewer.getTree()); |
| createCancelAction(); |
| menuMgr.add(cancelAction); |
| menuMgr.addMenuListener(new IMenuListener() { |
| public void menuAboutToShow(IMenuManager manager) { |
| JobInfo info = getSelectedInfo(); |
| if (info == null) |
| return; |
| } |
| }); |
| menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
| getSite().registerContextMenu(menuMgr, viewer); |
| viewer.getTree().setMenu(menu); |
| } |
| private void initPulldownMenu() { |
| IMenuManager menuMgr = getViewSite().getActionBars().getMenuManager(); |
| menuMgr.add(new Action(ProgressMessages.getString("ProgressView.VerboseAction"), //$NON-NLS-1$ |
| IAction.AS_CHECK_BOX) { |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.jface.action.Action#run() |
| */ |
| public void run() { |
| ProgressViewUpdater updater = ProgressViewUpdater.getSingleton(); |
| updater.debug = !updater.debug; |
| setChecked(updater.debug); |
| updater.refreshAll(); |
| } |
| }); |
| } |
| /** |
| * Return the selected objects. If any of the selections are not JobInfos |
| * or there is no selection then return null. |
| * |
| * @return JobInfo[] or <code>null</code>. |
| */ |
| private IStructuredSelection getSelection() { |
| //If the provider has not been set yet move on. |
| ISelectionProvider provider = getSite().getSelectionProvider(); |
| if (provider == null) |
| return null; |
| ISelection currentSelection = provider.getSelection(); |
| if (currentSelection instanceof IStructuredSelection) { |
| return (IStructuredSelection) currentSelection; |
| } |
| return null; |
| } |
| /** |
| * Get the currently selected job info. Only return it if it is the only |
| * item selected and it is a JobInfo. |
| * |
| * @return |
| */ |
| JobInfo getSelectedInfo() { |
| IStructuredSelection selection = getSelection(); |
| if (selection != null && selection.size() == 1) { |
| JobTreeElement element = (JobTreeElement) selection.getFirstElement(); |
| if (element.isJobInfo()) |
| return (JobInfo) element; |
| } |
| return null; |
| } |
| /** |
| * Create the cancel action for the receiver. |
| * |
| * @return Action |
| */ |
| private void createCancelAction() { |
| cancelAction = new Action(ProgressMessages.getString("ProgressView.CancelAction")) {//$NON-NLS-1$ |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.jface.action.Action#run() |
| */ |
| public void run() { |
| viewer.cancelSelection(); |
| } |
| }; |
| |
| } |
| } |