sysmodelmgr/com.symbian.smt.gui/src/com/symbian/smt/gui/OpenFileActionProvider.java
changeset 0 522a326673b6
equal deleted inserted replaced
-1:000000000000 0:522a326673b6
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 package com.symbian.smt.gui;
       
    19 
       
    20 import org.eclipse.jface.action.IMenuManager;
       
    21 import org.eclipse.swt.widgets.Shell;
       
    22 import org.eclipse.ui.IActionBars;
       
    23 import org.eclipse.ui.PlatformUI;
       
    24 import org.eclipse.ui.navigator.CommonActionProvider;
       
    25 import org.eclipse.ui.navigator.ICommonActionConstants;
       
    26 import org.eclipse.ui.navigator.ICommonActionExtensionSite;
       
    27 import org.eclipse.ui.navigator.ICommonMenuConstants;
       
    28 import org.eclipse.ui.navigator.ICommonViewerSite;
       
    29 import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
       
    30 
       
    31 /**
       
    32  * @author barbararosi-schwartz
       
    33  * 
       
    34  */
       
    35 public class OpenFileActionProvider extends CommonActionProvider {
       
    36 
       
    37 	private OpenFileAction openFileAction;
       
    38 	private IActionBars actionBars;
       
    39 
       
    40 	/*
       
    41 	 * (non-Javadoc)
       
    42 	 * 
       
    43 	 * @see org.eclipse.ui.actions.ActionGroup#dispose()
       
    44 	 */
       
    45 	@Override
       
    46 	public void dispose() {
       
    47 		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
       
    48 		
       
    49 		if ((shell != null) && (! shell.isDisposed())) {
       
    50 			actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, null);
       
    51 		}
       
    52 		
       
    53 		super.dispose();
       
    54 	}
       
    55 
       
    56 	/*
       
    57 	 * (non-Javadoc)
       
    58 	 * 
       
    59 	 * @see
       
    60 	 * org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars
       
    61 	 * )
       
    62 	 */
       
    63 	@Override
       
    64 	public void fillActionBars(IActionBars actionBars) {
       
    65 		this.actionBars = actionBars;
       
    66 
       
    67 		try {
       
    68 			if (openFileAction.isEnabled()) {
       
    69 				actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN,
       
    70 						openFileAction);
       
    71 			}
       
    72 		} catch (Exception ignore) {
       
    73 			// Consuming CoreException that is thrown because the URI is missing
       
    74 			// for resources that are URLs
       
    75 		}
       
    76 	}
       
    77 
       
    78 	/*
       
    79 	 * (non-Javadoc)
       
    80 	 * 
       
    81 	 * @see
       
    82 	 * org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.
       
    83 	 * action.IMenuManager)
       
    84 	 */
       
    85 	@Override
       
    86 	public void fillContextMenu(IMenuManager menu) {
       
    87 		try {
       
    88 			if (openFileAction.isEnabled()) {
       
    89 				menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN,
       
    90 						openFileAction);
       
    91 			}
       
    92 		} catch (Exception ignore) {
       
    93 			// Consuming CoreException that is thrown because the URI is missing
       
    94 			// for resources that are URLs
       
    95 		}
       
    96 	}
       
    97 
       
    98 	/*
       
    99 	 * (non-Javadoc)
       
   100 	 * 
       
   101 	 * @see
       
   102 	 * org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator
       
   103 	 * .ICommonActionExtensionSite)
       
   104 	 */
       
   105 	@Override
       
   106 	public void init(ICommonActionExtensionSite site) {
       
   107 		ICommonViewerSite viewSite = site.getViewSite();
       
   108 
       
   109 		if (viewSite instanceof ICommonViewerWorkbenchSite) {
       
   110 			ICommonViewerWorkbenchSite workbenchSite = (ICommonViewerWorkbenchSite) viewSite;
       
   111 
       
   112 			openFileAction = new OpenFileAction(workbenchSite.getPage(),
       
   113 					workbenchSite.getSelectionProvider());
       
   114 		}
       
   115 	}
       
   116 
       
   117 }