01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.core.expressions.PropertyTester;
13: import org.eclipse.ui.IPerspectiveDescriptor;
14: import org.eclipse.ui.IWorkbenchPage;
15:
16: /**
17: * Tests if any Perspective is open or not.
18: *
19: * @since 3.3
20: *
21: */
22: public class OpenPerspectivePropertyTester extends PropertyTester {
23: private static final String PROPERTY_IS_PERSPECTIVE_OPEN = "isPerspectiveOpen"; //$NON-NLS-1$
24:
25: /*
26: * (non-Javadoc)
27: *
28: * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object,
29: * java.lang.String, java.lang.Object[], java.lang.Object)
30: */
31: public boolean test(Object receiver, String property,
32: Object[] args, Object expectedValue) {
33: if (args.length == 0 && receiver instanceof WorkbenchWindow) {
34: final WorkbenchWindow window = (WorkbenchWindow) receiver;
35: if (PROPERTY_IS_PERSPECTIVE_OPEN.equals(property)) {
36: IWorkbenchPage page = window.getActivePage();
37: if (page != null) {
38: IPerspectiveDescriptor persp = page
39: .getPerspective();
40: if (persp != null) {
41: return true;
42: }
43: }
44: }
45: }
46: return false;
47: }
48:
49: }
|