core/com.nokia.carbide.cpp/src/com/nokia/carbide/cpp/ProductStartup.java
author wpaul
Wed, 25 Mar 2009 12:24:24 -0500
changeset 9 6ef327765a4e
parent 2 d760517a8095
child 127 c937102a5510
permissions -rw-r--r--
added copyright
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
     1
/*
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
     3
* All rights reserved.
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
     4
* This component and the accompanying materials are made available
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
     6
* which accompanies this distribution, and is available
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
     8
*
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
     9
* Initial Contributors:
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
    10
* Nokia Corporation - initial contribution.
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
    11
*
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
    12
* Contributors:
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
    13
*
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
    14
* Description: 
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
    15
*
6ef327765a4e added copyright
wpaul
parents: 2
diff changeset
    16
*/
2
cawthron
parents:
diff changeset
    17
package com.nokia.carbide.cpp;
cawthron
parents:
diff changeset
    18
cawthron
parents:
diff changeset
    19
import java.lang.reflect.InvocationHandler;
cawthron
parents:
diff changeset
    20
import java.lang.reflect.Method;
cawthron
parents:
diff changeset
    21
import java.lang.reflect.Proxy;
cawthron
parents:
diff changeset
    22
cawthron
parents:
diff changeset
    23
import org.eclipse.jface.action.ActionContributionItem;
cawthron
parents:
diff changeset
    24
import org.eclipse.jface.action.IAction;
cawthron
parents:
diff changeset
    25
import org.eclipse.jface.action.IContributionItem;
cawthron
parents:
diff changeset
    26
import org.eclipse.jface.action.MenuManager;
cawthron
parents:
diff changeset
    27
import org.eclipse.jface.preference.IPreferenceStore;
cawthron
parents:
diff changeset
    28
import org.eclipse.swt.widgets.Display;
cawthron
parents:
diff changeset
    29
import org.eclipse.ui.IStartup;
cawthron
parents:
diff changeset
    30
import org.eclipse.ui.IWindowListener;
cawthron
parents:
diff changeset
    31
import org.eclipse.ui.IWorkbenchWindow;
cawthron
parents:
diff changeset
    32
import org.eclipse.ui.PlatformUI;
cawthron
parents:
diff changeset
    33
import org.eclipse.ui.internal.WorkbenchWindow;
cawthron
parents:
diff changeset
    34
cawthron
parents:
diff changeset
    35
public class ProductStartup implements IStartup {
cawthron
parents:
diff changeset
    36
cawthron
parents:
diff changeset
    37
cawthron
parents:
diff changeset
    38
	public void replaceAboutAction(final IWorkbenchWindow window)
cawthron
parents:
diff changeset
    39
	{
cawthron
parents:
diff changeset
    40
		
cawthron
parents:
diff changeset
    41
		if (window == null || !(window instanceof WorkbenchWindow))
cawthron
parents:
diff changeset
    42
			return;
cawthron
parents:
diff changeset
    43
		MenuManager manager = ((WorkbenchWindow)window).getMenuManager();
cawthron
parents:
diff changeset
    44
		final IPreferenceStore store = ProductPlugin.getDefault().getPreferenceStore();
cawthron
parents:
diff changeset
    45
cawthron
parents:
diff changeset
    46
		for (IContributionItem item : manager.getItems()) {
cawthron
parents:
diff changeset
    47
			if (item instanceof MenuManager) {
cawthron
parents:
diff changeset
    48
				MenuManager mgr = (MenuManager) item;
cawthron
parents:
diff changeset
    49
				if (item.getId().equals("help"))
cawthron
parents:
diff changeset
    50
				{
cawthron
parents:
diff changeset
    51
					final IContributionItem contrib = mgr.remove("about");
cawthron
parents:
diff changeset
    52
cawthron
parents:
diff changeset
    53
					if (contrib instanceof ActionContributionItem) {
cawthron
parents:
diff changeset
    54
						final IAction about = ((ActionContributionItem) contrib)
cawthron
parents:
diff changeset
    55
								.getAction();
cawthron
parents:
diff changeset
    56
						mgr.add(new ActionContributionItem((IAction) Proxy
cawthron
parents:
diff changeset
    57
								.newProxyInstance(about.getClass()
cawthron
parents:
diff changeset
    58
										.getClassLoader(),
cawthron
parents:
diff changeset
    59
										new Class[] { IAction.class },
cawthron
parents:
diff changeset
    60
										new InvocationHandler() {
cawthron
parents:
diff changeset
    61
cawthron
parents:
diff changeset
    62
											public Object invoke(Object arg0, Method method, Object[] arg2) throws Throwable {
cawthron
parents:
diff changeset
    63
cawthron
parents:
diff changeset
    64
												if ("runWithEvent"
cawthron
parents:
diff changeset
    65
														.equals(method
cawthron
parents:
diff changeset
    66
																.getName())
cawthron
parents:
diff changeset
    67
														|| "run".equals(method
cawthron
parents:
diff changeset
    68
																.getName())) {
cawthron
parents:
diff changeset
    69
													new CustomAboutDialog(
cawthron
parents:
diff changeset
    70
															window.getShell())
cawthron
parents:
diff changeset
    71
															.open();
cawthron
parents:
diff changeset
    72
													return null;
cawthron
parents:
diff changeset
    73
												}
cawthron
parents:
diff changeset
    74
												return method.invoke(about,
cawthron
parents:
diff changeset
    75
														arg2);
cawthron
parents:
diff changeset
    76
																						}
cawthron
parents:
diff changeset
    77
										})));
cawthron
parents:
diff changeset
    78
					}
cawthron
parents:
diff changeset
    79
					
cawthron
parents:
diff changeset
    80
				}
cawthron
parents:
diff changeset
    81
			}
cawthron
parents:
diff changeset
    82
		}
cawthron
parents:
diff changeset
    83
cawthron
parents:
diff changeset
    84
	}
cawthron
parents:
diff changeset
    85
	
cawthron
parents:
diff changeset
    86
	public void initializeMenus() {
cawthron
parents:
diff changeset
    87
cawthron
parents:
diff changeset
    88
		PlatformUI.getWorkbench().addWindowListener(new IWindowListener() {
cawthron
parents:
diff changeset
    89
cawthron
parents:
diff changeset
    90
			public void windowActivated(IWorkbenchWindow window) {
cawthron
parents:
diff changeset
    91
			}
cawthron
parents:
diff changeset
    92
cawthron
parents:
diff changeset
    93
			public void windowClosed(IWorkbenchWindow window) {
cawthron
parents:
diff changeset
    94
			}
cawthron
parents:
diff changeset
    95
cawthron
parents:
diff changeset
    96
			public void windowDeactivated(IWorkbenchWindow window) {
cawthron
parents:
diff changeset
    97
			}
cawthron
parents:
diff changeset
    98
cawthron
parents:
diff changeset
    99
			public void windowOpened(IWorkbenchWindow window) {
cawthron
parents:
diff changeset
   100
				replaceAboutAction(window);
cawthron
parents:
diff changeset
   101
			}
cawthron
parents:
diff changeset
   102
		});
cawthron
parents:
diff changeset
   103
cawthron
parents:
diff changeset
   104
		Display.getDefault().asyncExec(new Runnable() {
cawthron
parents:
diff changeset
   105
			public void run() {
cawthron
parents:
diff changeset
   106
				replaceAboutAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
cawthron
parents:
diff changeset
   107
			}
cawthron
parents:
diff changeset
   108
		});
cawthron
parents:
diff changeset
   109
		
cawthron
parents:
diff changeset
   110
	}
cawthron
parents:
diff changeset
   111
cawthron
parents:
diff changeset
   112
	public void earlyStartup() {
cawthron
parents:
diff changeset
   113
		
cawthron
parents:
diff changeset
   114
		initializeMenus();
cawthron
parents:
diff changeset
   115
		
cawthron
parents:
diff changeset
   116
	}
cawthron
parents:
diff changeset
   117
cawthron
parents:
diff changeset
   118
}