1 11 package org.eclipse.ui.dialogs; 12 13 import com.ibm.icu.text.MessageFormat; 14 import java.util.Iterator ; 15 16 import org.eclipse.jface.preference.IPreferenceNode; 17 import org.eclipse.jface.preference.PreferenceManager; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.swt.events.SelectionAdapter; 20 import org.eclipse.swt.events.SelectionEvent; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.swt.widgets.Link; 24 import org.eclipse.ui.PlatformUI; 25 import org.eclipse.ui.internal.WorkbenchMessages; 26 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; 27 28 34 public class PreferenceLinkArea extends Object { 35 36 private Link pageLink; 37 38 57 public PreferenceLinkArea(Composite parent, int style, final String pageId, 58 String message, final IWorkbenchPreferenceContainer pageContainer, 59 final Object pageData) { 60 pageLink = new Link(parent, style); 61 62 IPreferenceNode node = getPreferenceNode(pageId); 63 String result; 64 if (node == null) { 65 result = NLS.bind( 66 WorkbenchMessages.PreferenceNode_NotFound, pageId); 67 } else { 68 result = MessageFormat.format(message, new String [] { node 69 .getLabelText() }); 70 71 pageLink.addSelectionListener(new SelectionAdapter() { 73 78 public void widgetSelected(SelectionEvent e) { 79 pageContainer.openPage(pageId, pageData); 80 } 81 }); 82 } 83 pageLink.setText(result); 84 85 } 86 87 93 private IPreferenceNode getPreferenceNode(String pageId) { 94 Iterator iterator = PlatformUI.getWorkbench().getPreferenceManager() 95 .getElements(PreferenceManager.PRE_ORDER).iterator(); 96 while (iterator.hasNext()) { 97 IPreferenceNode next = (IPreferenceNode) iterator.next(); 98 if (next.getId().equals(pageId)) { 99 return next; 100 } 101 } 102 return null; 103 } 104 105 110 public Control getControl() { 111 return pageLink; 112 } 113 } 114 | Popular Tags |