KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > CloseHelpTrayHandler


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal;
12
13 import org.eclipse.core.commands.AbstractHandler;
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.help.ui.internal.views.HelpTray;
17 import org.eclipse.jface.dialogs.TrayDialog;
18 import org.eclipse.swt.widgets.Display;
19 import org.eclipse.swt.widgets.Shell;
20
21 /**
22  * The command handler that gets invoked when the "Close User Assistance
23  * Tray" command is invoked. It finds the current active dialog, and if it
24  * has the tray open, it closes it.
25  */

26 public class CloseHelpTrayHandler extends AbstractHandler {
27
28     /**
29      * Executes the command.
30      */

31     public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
32         Display display = Display.getCurrent();
33         if (display == null) {
34             display = Display.getDefault();
35         }
36         if (display != null) {
37             Shell shell = Display.getCurrent().getActiveShell();
38             if (shell != null && !shell.isDisposed()) {
39                 Object JavaDoc shellData = shell.getData();
40                 if (shellData instanceof TrayDialog) {
41                     TrayDialog trayDialog = (TrayDialog)shellData;
42                     if (trayDialog.getTray() instanceof HelpTray) {
43                         trayDialog.closeTray();
44                     }
45                 }
46             }
47         }
48         return null;
49     }
50 }
51
Popular Tags