KickJava   Java API By Example, From Geeks To Geeks.

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


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

24 public class EditorElement extends QuickAccessElement {
25
26     private static final String JavaDoc DIRTY_MARK = "*"; //$NON-NLS-1$
27

28     private static final String JavaDoc separator = " - "; //$NON-NLS-1$
29

30     private IEditorReference editorReference;
31
32     /* package */EditorElement(IEditorReference editorReference, EditorProvider editorProvider) {
33         super(editorProvider);
34         this.editorReference = editorReference;
35     }
36
37     public void execute() {
38         IWorkbenchPart part = editorReference.getPart(true);
39         if (part != null) {
40             IWorkbenchPage activePage = PlatformUI.getWorkbench()
41                     .getActiveWorkbenchWindow().getActivePage();
42             if (activePage != null) {
43                 activePage.activate(part);
44             }
45         }
46     }
47
48     public String JavaDoc getId() {
49         return editorReference.getId() + editorReference.getTitleToolTip();
50     }
51
52     public ImageDescriptor getImageDescriptor() {
53         return ImageDescriptor.createFromImage(editorReference.getTitleImage());
54     }
55
56     public String JavaDoc getLabel() {
57         boolean dirty = editorReference.isDirty();
58         return (dirty ? DIRTY_MARK : "") + editorReference.getTitle() + separator + editorReference.getTitleToolTip(); //$NON-NLS-1$
59
}
60
61     public String JavaDoc getSortLabel() {
62         return editorReference.getTitle();
63     }
64
65     public int hashCode() {
66         final int prime = 31;
67         int result = 1;
68         result = prime * result
69                 + ((editorReference == null) ? 0 : editorReference.hashCode());
70         return result;
71     }
72
73     public boolean equals(Object JavaDoc obj) {
74         if (this == obj)
75             return true;
76         if (obj == null)
77             return false;
78         if (getClass() != obj.getClass())
79             return false;
80         final EditorElement other = (EditorElement) obj;
81         if (editorReference == null) {
82             if (other.editorReference != null)
83                 return false;
84         } else if (!editorReference.equals(other.editorReference))
85             return false;
86         return true;
87     }
88 }
89
Popular Tags