1 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 24 public class EditorElement extends QuickAccessElement { 25 26 private static final String DIRTY_MARK = "*"; 28 private static final String separator = " - "; 30 private IEditorReference editorReference; 31 32 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 getId() { 49 return editorReference.getId() + editorReference.getTitleToolTip(); 50 } 51 52 public ImageDescriptor getImageDescriptor() { 53 return ImageDescriptor.createFromImage(editorReference.getTitleImage()); 54 } 55 56 public String getLabel() { 57 boolean dirty = editorReference.isDirty(); 58 return (dirty ? DIRTY_MARK : "") + editorReference.getTitle() + separator + editorReference.getTitleToolTip(); } 60 61 public String 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 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 |