KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > quickaccess > PerspectiveElement


1 /*******************************************************************************
2  * Copyright (c) 2006, 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.quickaccess;
13
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.ui.IPerspectiveDescriptor;
16 import org.eclipse.ui.IWorkbenchPage;
17 import org.eclipse.ui.PlatformUI;
18
19 /**
20  * @since 3.3
21  *
22  */

23 public class PerspectiveElement extends QuickAccessElement {
24
25     private final IPerspectiveDescriptor descriptor;
26
27     /* package */PerspectiveElement(IPerspectiveDescriptor descriptor, PerspectiveProvider perspectiveProvider) {
28         super(perspectiveProvider);
29         this.descriptor = descriptor;
30     }
31
32     public void execute() {
33         IWorkbenchPage activePage = PlatformUI.getWorkbench()
34                 .getActiveWorkbenchWindow().getActivePage();
35         if (activePage != null) {
36             activePage.setPerspective(descriptor);
37         }
38     }
39
40     public String JavaDoc getId() {
41         return descriptor.getId();
42     }
43
44     public ImageDescriptor getImageDescriptor() {
45         return descriptor.getImageDescriptor();
46     }
47
48     public String JavaDoc getLabel() {
49         return descriptor.getLabel();
50     }
51
52     public int hashCode() {
53         final int prime = 31;
54         int result = 1;
55         result = prime * result
56                 + ((descriptor == null) ? 0 : descriptor.hashCode());
57         return result;
58     }
59
60     public boolean equals(Object JavaDoc obj) {
61         if (this == obj)
62             return true;
63         if (obj == null)
64             return false;
65         if (getClass() != obj.getClass())
66             return false;
67         final PerspectiveElement other = (PerspectiveElement) obj;
68         if (descriptor == null) {
69             if (other.descriptor != null)
70                 return false;
71         } else if (!descriptor.equals(other.descriptor))
72             return false;
73         return true;
74     }
75 }
76
Popular Tags