01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.quickaccess;
11:
12: import org.eclipse.jface.action.ActionContributionItem;
13: import org.eclipse.jface.action.IAction;
14: import org.eclipse.jface.action.LegacyActionTools;
15: import org.eclipse.jface.resource.ImageDescriptor;
16:
17: /**
18: * @since 3.3
19: *
20: */
21: public class ActionElement extends QuickAccessElement {
22:
23: private static final String separator = " - "; //$NON-NLS-1$
24:
25: private ActionContributionItem item;
26:
27: /* package */ActionElement(ActionContributionItem item,
28: ActionProvider actionProvider) {
29: super (actionProvider);
30: this .item = item;
31: }
32:
33: public void execute() {
34: item.getAction().run();
35: }
36:
37: public String getId() {
38: return item.getId();
39: }
40:
41: public ImageDescriptor getImageDescriptor() {
42: return item.getAction().getImageDescriptor();
43: }
44:
45: public String getLabel() {
46: IAction action = item.getAction();
47: if (action.getToolTipText() != null
48: && action.getToolTipText().length() != 0) {
49: return LegacyActionTools.removeMnemonics(action.getText()
50: + separator + action.getToolTipText());
51: }
52: return LegacyActionTools.removeMnemonics(action.getText());
53: }
54:
55: public int hashCode() {
56: final int prime = 31;
57: int result = 1;
58: result = prime * result
59: + ((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: }
|