1 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 24 public class ViewElement extends QuickAccessElement { 25 26 private final IViewDescriptor viewDescriptor; 27 28 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 getId() { 45 return viewDescriptor.getId(); 46 } 47 48 public ImageDescriptor getImageDescriptor() { 49 return viewDescriptor.getImageDescriptor(); 50 } 51 52 public String 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 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 |