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