KickJava   Java API By Example, From Geeks To Geeks.

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


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.IWorkbenchPage;
16 import org.eclipse.ui.PartInitException;
17 import org.eclipse.ui.PlatformUI;
18 import org.eclipse.ui.views.IViewDescriptor;
19
20 /**
21  * @since 3.3
22  *
23  */

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