KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > OpenPerspectivePropertyTester


1 /*******************************************************************************
2  * Copyright (c) 2007 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
12 package org.eclipse.ui.internal;
13
14 import org.eclipse.core.expressions.PropertyTester;
15 import org.eclipse.ui.IPerspectiveDescriptor;
16 import org.eclipse.ui.IWorkbenchPage;
17
18 /**
19  * Tests if any Perspective is open or not.
20  *
21  * @since 3.3
22  *
23  */

24 public class OpenPerspectivePropertyTester extends PropertyTester {
25     private static final String JavaDoc PROPERTY_IS_PERSPECTIVE_OPEN = "isPerspectiveOpen"; //$NON-NLS-1$
26

27     /*
28      * (non-Javadoc)
29      *
30      * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object,
31      * java.lang.String, java.lang.Object[], java.lang.Object)
32      */

33     public boolean test(Object JavaDoc receiver, String JavaDoc property, Object JavaDoc[] args,
34             Object JavaDoc expectedValue) {
35         if (args.length == 0 && receiver instanceof WorkbenchWindow) {
36             final WorkbenchWindow window = (WorkbenchWindow) receiver;
37             if (PROPERTY_IS_PERSPECTIVE_OPEN.equals(property)) {
38                 IWorkbenchPage page = window.getActivePage();
39                 if (page != null) {
40                     IPerspectiveDescriptor persp = page.getPerspective();
41                     if (persp != null) {
42                         return true;
43                     }
44                 }
45             }
46         }
47         return false;
48     }
49
50 }
51
Popular Tags