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.WorkbenchPreferenceDialog;
18:
19: /**
20: * @since 3.3
21: *
22: */
23: public class PreferenceElement extends QuickAccessElement {
24:
25: private static final String separator = " - "; //$NON-NLS-1$
26:
27: private IPreferenceNode preferenceNode;
28:
29: private String prefix;
30:
31: /* package */PreferenceElement(IPreferenceNode preferenceNode,
32: String prefix, PreferenceProvider preferenceProvider) {
33: super (preferenceProvider);
34: this .preferenceNode = preferenceNode;
35: this .prefix = prefix;
36: }
37:
38: public void execute() {
39: IWorkbenchWindow window = PlatformUI.getWorkbench()
40: .getActiveWorkbenchWindow();
41: if (window != null) {
42: WorkbenchPreferenceDialog dialog = WorkbenchPreferenceDialog
43: .createDialogOn(window.getShell(), preferenceNode
44: .getId());
45: dialog.open();
46: }
47: }
48:
49: public String getId() {
50: return preferenceNode.getId();
51: }
52:
53: public ImageDescriptor getImageDescriptor() {
54: Image image = preferenceNode.getLabelImage();
55: if (image != null) {
56: ImageDescriptor descriptor = ImageDescriptor
57: .createFromImage(image);
58: return descriptor;
59: }
60: return null;
61: }
62:
63: public String getLabel() {
64: if (prefix != null && prefix.length() > 0) {
65: return preferenceNode.getLabelText() + separator + prefix;
66: }
67: return preferenceNode.getLabelText();
68: }
69:
70: public int hashCode() {
71: final int prime = 31;
72: int result = 1;
73: result = prime
74: * result
75: + ((preferenceNode == null) ? 0 : preferenceNode
76: .hashCode());
77: return result;
78: }
79:
80: public boolean equals(Object obj) {
81: if (this == obj)
82: return true;
83: if (obj == null)
84: return false;
85: if (getClass() != obj.getClass())
86: return false;
87: final PreferenceElement other = (PreferenceElement) obj;
88: if (preferenceNode == null) {
89: if (other.preferenceNode != null)
90: return false;
91: } else if (!preferenceNode.equals(other.preferenceNode))
92: return false;
93: return true;
94: }
95: }
|