01: /*******************************************************************************
02: * Copyright (c) 2006, 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.quickaccess;
11:
12: import org.eclipse.jface.resource.ImageDescriptor;
13: import org.eclipse.ui.IPerspectiveDescriptor;
14: import org.eclipse.ui.IWorkbenchPage;
15: import org.eclipse.ui.PlatformUI;
16:
17: /**
18: * @since 3.3
19: *
20: */
21: public class PerspectiveElement extends QuickAccessElement {
22:
23: private final IPerspectiveDescriptor descriptor;
24:
25: /* package */PerspectiveElement(IPerspectiveDescriptor descriptor,
26: PerspectiveProvider perspectiveProvider) {
27: super (perspectiveProvider);
28: this .descriptor = descriptor;
29: }
30:
31: public void execute() {
32: IWorkbenchPage activePage = PlatformUI.getWorkbench()
33: .getActiveWorkbenchWindow().getActivePage();
34: if (activePage != null) {
35: activePage.setPerspective(descriptor);
36: }
37: }
38:
39: public String getId() {
40: return descriptor.getId();
41: }
42:
43: public ImageDescriptor getImageDescriptor() {
44: return descriptor.getImageDescriptor();
45: }
46:
47: public String getLabel() {
48: return descriptor.getLabel();
49: }
50:
51: public int hashCode() {
52: final int prime = 31;
53: int result = 1;
54: result = prime * result
55: + ((descriptor == null) ? 0 : descriptor.hashCode());
56: return result;
57: }
58:
59: public boolean equals(Object obj) {
60: if (this == obj)
61: return true;
62: if (obj == null)
63: return false;
64: if (getClass() != obj.getClass())
65: return false;
66: final PerspectiveElement other = (PerspectiveElement) obj;
67: if (descriptor == null) {
68: if (other.descriptor != null)
69: return false;
70: } else if (!descriptor.equals(other.descriptor))
71: return false;
72: return true;
73: }
74: }
|