diff -r 000000000000 -r a02c979e8dfd srcanaapps/apiquerytool/com.nokia.s60tools.apiquery/src/com/nokia/s60tools/apiquery/ui/actions/ToolsMenuAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/srcanaapps/apiquerytool/com.nokia.s60tools.apiquery/src/com/nokia/s60tools/apiquery/ui/actions/ToolsMenuAction.java Sat Jan 09 10:04:11 2010 +0530 @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +package com.nokia.s60tools.apiquery.ui.actions; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IViewReference; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; + +import com.nokia.s60tools.apiquery.shared.util.console.APIQueryConsole; +import com.nokia.s60tools.apiquery.ui.views.main.MainView; +import com.nokia.s60tools.util.console.IConsolePrintUtility; + +public class ToolsMenuAction implements IWorkbenchWindowActionDelegate { + + /** + * Reference to workbench window + */ + private IWorkbenchWindow window; + + /** + * Constructor. + */ + public ToolsMenuAction(){ + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + */ + public void init(IWorkbenchWindow window) { + this.window = window; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + try { + IWorkbenchPage page = window.getActivePage(); + + // Checking if view is already open + IViewReference[] viewRefs = page.getViewReferences(); + for (int i = 0; i < viewRefs.length; i++) { + IViewReference reference = viewRefs[i]; + String id = reference.getId(); + if(id.equalsIgnoreCase(MainView.ID)){ + // Found, restoring the view + IViewPart viewPart = reference.getView(true); + page.activate(viewPart); + return; + } + } + + // View was not found, opening it up as a new view. + page.showView(MainView.ID); + + } catch (Exception e) { + e.printStackTrace(); + APIQueryConsole.getInstance().println(e.getMessage(), + IConsolePrintUtility.MSG_ERROR); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + } + +}