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.IEditorReference;
14: import org.eclipse.ui.IWorkbenchPage;
15: import org.eclipse.ui.IWorkbenchPart;
16: import org.eclipse.ui.PlatformUI;
17:
18: /**
19: * @since 3.3
20: *
21: */
22: public class EditorElement extends QuickAccessElement {
23:
24: private static final String DIRTY_MARK = "*"; //$NON-NLS-1$
25:
26: private static final String separator = " - "; //$NON-NLS-1$
27:
28: private IEditorReference editorReference;
29:
30: /* package */EditorElement(IEditorReference editorReference,
31: EditorProvider editorProvider) {
32: super (editorProvider);
33: this .editorReference = editorReference;
34: }
35:
36: public void execute() {
37: IWorkbenchPart part = editorReference.getPart(true);
38: if (part != null) {
39: IWorkbenchPage activePage = PlatformUI.getWorkbench()
40: .getActiveWorkbenchWindow().getActivePage();
41: if (activePage != null) {
42: activePage.activate(part);
43: }
44: }
45: }
46:
47: public String getId() {
48: return editorReference.getId()
49: + editorReference.getTitleToolTip();
50: }
51:
52: public ImageDescriptor getImageDescriptor() {
53: return ImageDescriptor.createFromImage(editorReference
54: .getTitleImage());
55: }
56:
57: public String getLabel() {
58: boolean dirty = editorReference.isDirty();
59: return (dirty ? DIRTY_MARK : "") + editorReference.getTitle() + separator + editorReference.getTitleToolTip(); //$NON-NLS-1$
60: }
61:
62: public String getSortLabel() {
63: return editorReference.getTitle();
64: }
65:
66: public int hashCode() {
67: final int prime = 31;
68: int result = 1;
69: result = prime
70: * result
71: + ((editorReference == null) ? 0 : editorReference
72: .hashCode());
73: return result;
74: }
75:
76: public boolean equals(Object obj) {
77: if (this == obj)
78: return true;
79: if (obj == null)
80: return false;
81: if (getClass() != obj.getClass())
82: return false;
83: final EditorElement other = (EditorElement) obj;
84: if (editorReference == null) {
85: if (other.editorReference != null)
86: return false;
87: } else if (!editorReference.equals(other.editorReference))
88: return false;
89: return true;
90: }
91: }
|