KickJava   Java API By Example, From Geeks To Geeks.

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


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.preference.IPreferenceNode;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.ui.IWorkbenchWindow;
18 import org.eclipse.ui.PlatformUI;
19 import org.eclipse.ui.internal.dialogs.PropertyDialog;
20
21 /**
22  * @since 3.3
23  *
24  */

25 public class PropertiesElement extends QuickAccessElement {
26
27     private Object JavaDoc selectedElement;
28     private IPreferenceNode preferenceNode;
29     
30     /* package */PropertiesElement(Object JavaDoc selectedElement, IPreferenceNode preferenceNode, PropertiesProvider propertiesProvider) {
31         super(propertiesProvider);
32         this.selectedElement = selectedElement;
33         this.preferenceNode = preferenceNode;
34     }
35     
36     public void execute() {
37         IWorkbenchWindow window = PlatformUI.getWorkbench()
38                 .getActiveWorkbenchWindow();
39         if (window != null) {
40             PropertyDialog dialog = PropertyDialog.createDialogOn(window
41                     .getShell(), preferenceNode.getId(), selectedElement);
42             dialog.open();
43         }
44     }
45
46     public String JavaDoc getId() {
47         return preferenceNode.getId();
48     }
49
50     public ImageDescriptor getImageDescriptor() {
51         Image image = preferenceNode.getLabelImage();
52         if (image != null) {
53             ImageDescriptor descriptor = ImageDescriptor.createFromImage(image);
54             return descriptor;
55         }
56         return null;
57     }
58
59     public String JavaDoc getLabel() {
60         return preferenceNode.getLabelText();
61     }
62     
63     public int hashCode() {
64         final int prime = 31;
65         int result = 1;
66         result = prime * result
67                 + ((preferenceNode == null) ? 0 : preferenceNode.hashCode());
68         return result;
69     }
70
71     public boolean equals(Object JavaDoc obj) {
72         if (this == obj)
73             return true;
74         if (obj == null)
75             return false;
76         if (getClass() != obj.getClass())
77             return false;
78         final PropertiesElement other = (PropertiesElement) obj;
79         if (preferenceNode == null) {
80             if (other.preferenceNode != null)
81                 return false;
82         } else if (!preferenceNode.equals(other.preferenceNode))
83             return false;
84         return true;
85     }
86 }
87
Popular Tags