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.preference.IPreferenceNode;
13: import org.eclipse.jface.resource.ImageDescriptor;
14: import org.eclipse.swt.graphics.Image;
15: import org.eclipse.ui.IWorkbenchWindow;
16: import org.eclipse.ui.PlatformUI;
17: import org.eclipse.ui.internal.dialogs.PropertyDialog;
18:
19: /**
20: * @since 3.3
21: *
22: */
23: public class PropertiesElement extends QuickAccessElement {
24:
25: private Object selectedElement;
26: private IPreferenceNode preferenceNode;
27:
28: /* package */PropertiesElement(Object selectedElement,
29: IPreferenceNode preferenceNode,
30: 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(
41: window.getShell(), preferenceNode.getId(),
42: selectedElement);
43: dialog.open();
44: }
45: }
46:
47: public String getId() {
48: return preferenceNode.getId();
49: }
50:
51: public ImageDescriptor getImageDescriptor() {
52: Image image = preferenceNode.getLabelImage();
53: if (image != null) {
54: ImageDescriptor descriptor = ImageDescriptor
55: .createFromImage(image);
56: return descriptor;
57: }
58: return null;
59: }
60:
61: public String getLabel() {
62: return preferenceNode.getLabelText();
63: }
64:
65: public int hashCode() {
66: final int prime = 31;
67: int result = 1;
68: result = prime
69: * result
70: + ((preferenceNode == null) ? 0 : preferenceNode
71: .hashCode());
72: return result;
73: }
74:
75: public boolean equals(Object obj) {
76: if (this == obj)
77: return true;
78: if (obj == null)
79: return false;
80: if (getClass() != obj.getClass())
81: return false;
82: final PropertiesElement other = (PropertiesElement) obj;
83: if (preferenceNode == null) {
84: if (other.preferenceNode != null)
85: return false;
86: } else if (!preferenceNode.equals(other.preferenceNode))
87: return false;
88: return true;
89: }
90: }
|