1 11 12 package org.eclipse.ui.internal.quickaccess; 13 14 import org.eclipse.jface.action.ActionContributionItem; 15 import org.eclipse.jface.action.IAction; 16 import org.eclipse.jface.action.LegacyActionTools; 17 import org.eclipse.jface.resource.ImageDescriptor; 18 19 23 public class ActionElement extends QuickAccessElement { 24 25 private static final String separator = " - "; 27 private ActionContributionItem item; 28 29 ActionElement(ActionContributionItem item, ActionProvider actionProvider) { 30 super(actionProvider); 31 this.item = item; 32 } 33 34 public void execute() { 35 item.getAction().run(); 36 } 37 38 public String getId() { 39 return item.getId(); 40 } 41 42 public ImageDescriptor getImageDescriptor() { 43 return item.getAction().getImageDescriptor(); 44 } 45 46 public String getLabel() { 47 IAction action = item.getAction(); 48 if (action.getToolTipText() != null 49 && action.getToolTipText().length() != 0) { 50 return LegacyActionTools.removeMnemonics(action.getText() 51 + separator + action.getToolTipText()); 52 } 53 return LegacyActionTools.removeMnemonics(action.getText()); 54 } 55 56 public int hashCode() { 57 final int prime = 31; 58 int result = 1; 59 result = prime * result + ((item == null) ? 0 : item.hashCode()); 60 return result; 61 } 62 63 public boolean equals(Object obj) { 64 if (this == obj) 65 return true; 66 if (obj == null) 67 return false; 68 if (getClass() != obj.getClass()) 69 return false; 70 final ActionElement other = (ActionElement) obj; 71 if (item == null) { 72 if (other.item != null) 73 return false; 74 } else if (!item.equals(other.item)) 75 return false; 76 return true; 77 } 78 } 79 | Popular Tags |