1 11 12 package org.eclipse.ui.fieldassist; 13 14 import org.eclipse.jface.fieldassist.DecoratedField; 15 import org.eclipse.jface.fieldassist.FieldDecoration; 16 import org.eclipse.jface.fieldassist.FieldDecorationRegistry; 17 import org.eclipse.jface.fieldassist.IContentProposalProvider; 18 import org.eclipse.jface.fieldassist.IControlContentAdapter; 19 import org.eclipse.jface.fieldassist.IControlCreator; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.internal.WorkbenchMessages; 25 import org.eclipse.ui.keys.IBindingService; 26 27 40 public class ContentAssistField extends DecoratedField { 41 42 private ContentAssistCommandAdapter adapter; 43 44 private static final String CONTENT_ASSIST_DECORATION_ID = "org.eclipse.ui.fieldAssist.ContentAssistField"; 46 75 public ContentAssistField(Composite parent, int style, 76 IControlCreator controlCreator, 77 IControlContentAdapter controlContentAdapter, 78 IContentProposalProvider proposalProvider, String commandId, 79 char[] autoActivationCharacters) { 80 81 super(parent, style, controlCreator); 82 adapter = new ContentAssistCommandAdapter(getControl(), 83 controlContentAdapter, proposalProvider, commandId, 84 autoActivationCharacters); 85 86 addFieldDecoration(getFieldDecoration(), SWT.LEFT | SWT.TOP, true); 87 88 } 89 90 100 public void setEnabled(boolean enabled) { 101 adapter.setEnabled(enabled); 102 if (enabled) { 103 showDecoration(getFieldDecoration()); 104 } else { 105 hideDecoration(getFieldDecoration()); 106 } 107 } 108 109 114 private FieldDecoration getFieldDecoration() { 115 FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault(); 116 String decId = CONTENT_ASSIST_DECORATION_ID + adapter.getCommandId(); 118 FieldDecoration dec = registry.getFieldDecoration(decId); 119 120 if (dec == null) { 122 FieldDecoration originalDec = registry 123 .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL); 124 125 registry.registerFieldDecoration(decId, null, originalDec 126 .getImage()); 127 dec = registry.getFieldDecoration(decId); 128 } 129 IBindingService bindingService = (IBindingService) PlatformUI 132 .getWorkbench().getService(IBindingService.class); 133 dec.setDescription(NLS.bind( 134 WorkbenchMessages.ContentAssist_Cue_Description_Key, 135 bindingService.getBestActiveBindingFormattedFor(adapter 136 .getCommandId()))); 137 138 return dec; 140 } 141 142 149 public ContentAssistCommandAdapter getContentAssistCommandAdapter() { 150 return adapter; 151 } 152 } 153 | Popular Tags |