1 11 12 package org.eclipse.ui.internal.quickaccess; 13 14 import org.eclipse.jface.resource.ImageDescriptor; 15 import org.eclipse.ui.IPerspectiveDescriptor; 16 import org.eclipse.ui.IWorkbenchPage; 17 import org.eclipse.ui.PlatformUI; 18 19 23 public class PerspectiveElement extends QuickAccessElement { 24 25 private final IPerspectiveDescriptor descriptor; 26 27 PerspectiveElement(IPerspectiveDescriptor descriptor, PerspectiveProvider perspectiveProvider) { 28 super(perspectiveProvider); 29 this.descriptor = descriptor; 30 } 31 32 public void execute() { 33 IWorkbenchPage activePage = PlatformUI.getWorkbench() 34 .getActiveWorkbenchWindow().getActivePage(); 35 if (activePage != null) { 36 activePage.setPerspective(descriptor); 37 } 38 } 39 40 public String getId() { 41 return descriptor.getId(); 42 } 43 44 public ImageDescriptor getImageDescriptor() { 45 return descriptor.getImageDescriptor(); 46 } 47 48 public String getLabel() { 49 return descriptor.getLabel(); 50 } 51 52 public int hashCode() { 53 final int prime = 31; 54 int result = 1; 55 result = prime * result 56 + ((descriptor == null) ? 0 : descriptor.hashCode()); 57 return result; 58 } 59 60 public boolean equals(Object obj) { 61 if (this == obj) 62 return true; 63 if (obj == null) 64 return false; 65 if (getClass() != obj.getClass()) 66 return false; 67 final PerspectiveElement other = (PerspectiveElement) obj; 68 if (descriptor == null) { 69 if (other.descriptor != null) 70 return false; 71 } else if (!descriptor.equals(other.descriptor)) 72 return false; 73 return true; 74 } 75 } 76 | Popular Tags |