KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > quickaccess > ActionElement


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
20  * @since 3.3
21  *
22  */

23 public class ActionElement extends QuickAccessElement {
24
25     private static final String JavaDoc separator = " - "; //$NON-NLS-1$
26

27     private ActionContributionItem item;
28
29     /* package */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 JavaDoc getId() {
39         return item.getId();
40     }
41
42     public ImageDescriptor getImageDescriptor() {
43         return item.getAction().getImageDescriptor();
44     }
45
46     public String JavaDoc 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 JavaDoc 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