srcanaapps/apiquerytool/com.nokia.s60tools.apiquery/src/com/nokia/s60tools/apiquery/ui/actions/ToolsMenuAction.java
changeset 0 a02c979e8dfd
equal deleted inserted replaced
-1:000000000000 0:a02c979e8dfd
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17  
       
    18  
       
    19 package com.nokia.s60tools.apiquery.ui.actions;
       
    20 
       
    21 import org.eclipse.jface.action.IAction;
       
    22 import org.eclipse.jface.viewers.ISelection;
       
    23 import org.eclipse.ui.IViewPart;
       
    24 import org.eclipse.ui.IViewReference;
       
    25 import org.eclipse.ui.IWorkbenchPage;
       
    26 import org.eclipse.ui.IWorkbenchWindow;
       
    27 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
       
    28 
       
    29 import com.nokia.s60tools.apiquery.shared.util.console.APIQueryConsole;
       
    30 import com.nokia.s60tools.apiquery.ui.views.main.MainView;
       
    31 import com.nokia.s60tools.util.console.IConsolePrintUtility;
       
    32 
       
    33 public class ToolsMenuAction implements IWorkbenchWindowActionDelegate  {
       
    34 	
       
    35 	/**
       
    36 	 * Reference to workbench window
       
    37 	 */
       
    38 	private IWorkbenchWindow window;
       
    39 	
       
    40 	/**
       
    41 	 * Constructor.
       
    42 	 */
       
    43 	public ToolsMenuAction(){			
       
    44 	}
       
    45 
       
    46 	/* (non-Javadoc)
       
    47 	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
       
    48 	 */
       
    49 	public void dispose() {
       
    50 	}
       
    51 
       
    52 	/* (non-Javadoc)
       
    53 	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
       
    54 	 */
       
    55 	public void init(IWorkbenchWindow window) {
       
    56 		this.window = window;
       
    57 	}
       
    58 
       
    59 	/* (non-Javadoc)
       
    60 	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
       
    61 	 */
       
    62 	public void run(IAction action) {
       
    63 		try {
       
    64     		IWorkbenchPage page = window.getActivePage();
       
    65     		
       
    66     		// Checking if view is already open
       
    67     		IViewReference[] viewRefs = page.getViewReferences();
       
    68     		for (int i = 0; i < viewRefs.length; i++) {
       
    69 				IViewReference reference = viewRefs[i];
       
    70 				String id = reference.getId();
       
    71 				if(id.equalsIgnoreCase(MainView.ID)){
       
    72 					// Found, restoring the view
       
    73 					IViewPart viewPart = reference.getView(true);
       
    74 					page.activate(viewPart);
       
    75 					return;
       
    76 				}
       
    77 			}
       
    78     		
       
    79     		// View was not found, opening it up as a new view.
       
    80     		page.showView(MainView.ID);
       
    81 			
       
    82 		} catch (Exception e) {
       
    83 			e.printStackTrace();
       
    84 			APIQueryConsole.getInstance().println(e.getMessage(), 
       
    85 					 IConsolePrintUtility.MSG_ERROR);
       
    86 		}
       
    87 	}
       
    88 
       
    89 	/* (non-Javadoc)
       
    90 	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
       
    91 	 */
       
    92 	public void selectionChanged(IAction action, ISelection selection) {
       
    93 	}
       
    94 
       
    95 }