Lines 45-51
Link Here
|
45 |
import org.eclipse.jface.fieldassist.ControlDecoration; |
45 |
import org.eclipse.jface.fieldassist.ControlDecoration; |
46 |
import org.eclipse.jface.fieldassist.FieldDecoration; |
46 |
import org.eclipse.jface.fieldassist.FieldDecoration; |
47 |
import org.eclipse.jface.fieldassist.FieldDecorationRegistry; |
47 |
import org.eclipse.jface.fieldassist.FieldDecorationRegistry; |
|
|
48 |
import org.eclipse.jface.fieldassist.IContentProposal; |
49 |
import org.eclipse.jface.fieldassist.IContentProposalListener; |
50 |
import org.eclipse.jface.fieldassist.IContentProposalListener2; |
48 |
import org.eclipse.jface.fieldassist.IContentProposalProvider; |
51 |
import org.eclipse.jface.fieldassist.IContentProposalProvider; |
|
|
52 |
import org.eclipse.jface.fieldassist.IControlContentAdapter; |
49 |
import org.eclipse.jface.fieldassist.TextContentAdapter; |
53 |
import org.eclipse.jface.fieldassist.TextContentAdapter; |
50 |
import org.eclipse.jface.layout.GridDataFactory; |
54 |
import org.eclipse.jface.layout.GridDataFactory; |
51 |
import org.eclipse.jface.resource.JFaceResources; |
55 |
import org.eclipse.jface.resource.JFaceResources; |
Lines 2000-2006
Link Here
|
2000 |
GridDataFactory.fillDefaults().hint(150, SWT.DEFAULT).applyTo(text); |
2004 |
GridDataFactory.fillDefaults().hint(150, SWT.DEFAULT).applyTo(text); |
2001 |
|
2005 |
|
2002 |
if (hasContentAssist(addCCattribute)) { |
2006 |
if (hasContentAssist(addCCattribute)) { |
2003 |
ContentAssistCommandAdapter adapter = applyContentAssist(text, |
2007 |
ContentAssistCommandAdapter adapter = applyCCContentAssist(text, |
2004 |
createContentProposalProvider(addCCattribute)); |
2008 |
createContentProposalProvider(addCCattribute)); |
2005 |
ILabelProvider propsalLabelProvider = createProposalLabelProvider(addCCattribute); |
2009 |
ILabelProvider propsalLabelProvider = createProposalLabelProvider(addCCattribute); |
2006 |
if (propsalLabelProvider != null) { |
2010 |
if (propsalLabelProvider != null) { |
Lines 3999-4002
Link Here
|
3999 |
return hyperlink; |
4003 |
return hyperlink; |
4000 |
} |
4004 |
} |
4001 |
|
4005 |
|
|
|
4006 |
/** |
4007 |
* Adds content assist to the given text field. |
4008 |
* |
4009 |
* @param text |
4010 |
* text field to decorate. |
4011 |
* @param proposalProvider |
4012 |
* instance providing content proposals |
4013 |
* @return the ContentAssistCommandAdapter for the field. |
4014 |
*/ |
4015 |
protected ContentAssistCommandAdapter applyCCContentAssist(Text text, IContentProposalProvider proposalProvider) { |
4016 |
ControlDecoration controlDecoration = new ControlDecoration(text, (SWT.TOP | SWT.LEFT)); |
4017 |
controlDecoration.setMarginWidth(0); |
4018 |
controlDecoration.setShowHover(true); |
4019 |
controlDecoration.setShowOnlyOnFocus(true); |
4020 |
|
4021 |
FieldDecoration contentProposalImage = FieldDecorationRegistry.getDefault().getFieldDecoration( |
4022 |
FieldDecorationRegistry.DEC_CONTENT_PROPOSAL); |
4023 |
controlDecoration.setImage(contentProposalImage.getImage()); |
4024 |
|
4025 |
TextContentAdapter textContentAdapter = new TextContentAdapter(); |
4026 |
|
4027 |
MultiContentAssistCommandAdapter adapter = new MultiContentAssistCommandAdapter(text, textContentAdapter, |
4028 |
proposalProvider, "org.eclipse.ui.edit.text.contentAssist.proposals", new char[0]); |
4029 |
MultiProposalListener listener = new MultiProposalListener(adapter); |
4030 |
|
4031 |
adapter.addContentProposalListener((IContentProposalListener) listener); |
4032 |
adapter.addContentProposalListener((IContentProposalListener2) listener); |
4033 |
|
4034 |
IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); |
4035 |
controlDecoration.setDescriptionText(NLS.bind("Content Assist Available ({0})", |
4036 |
bindingService.getBestActiveBindingFormattedFor(adapter.getCommandId()))); |
4037 |
|
4038 |
return adapter; |
4039 |
} |
4040 |
|
4041 |
static class MultiProposalListener implements IContentProposalListener, IContentProposalListener2 { |
4042 |
|
4043 |
private final MultiContentAssistCommandAdapter adapter; |
4044 |
|
4045 |
public MultiProposalListener(MultiContentAssistCommandAdapter adapter) { |
4046 |
super(); |
4047 |
this.adapter = adapter; |
4048 |
} |
4049 |
|
4050 |
private int getIndexOfLeftSeparator(String contents, int position) { |
4051 |
int i = contents.lastIndexOf(' ', position - 1); |
4052 |
i = Math.max(contents.lastIndexOf(',', position - 1), i); |
4053 |
return i; |
4054 |
} |
4055 |
|
4056 |
public void proposalAccepted(IContentProposal proposal) { |
4057 |
String contents = proposal.getContent(); |
4058 |
int position = proposal.getCursorPosition(); |
4059 |
int leftSeparator = getIndexOfLeftSeparator(contents, position); |
4060 |
|
4061 |
assert leftSeparator <= position; |
4062 |
if (leftSeparator != -1) { |
4063 |
Control c = adapter.getControl(); |
4064 |
if (c instanceof Text) { |
4065 |
Text t = (Text) c; |
4066 |
t.setSelection(leftSeparator); |
4067 |
adapter.reopen(); |
4068 |
} |
4069 |
} |
4070 |
} |
4071 |
|
4072 |
public void proposalPopupClosed(ContentProposalAdapter adapter) { |
4073 |
// ignore |
4074 |
|
4075 |
} |
4076 |
|
4077 |
public void proposalPopupOpened(ContentProposalAdapter adapter) { |
4078 |
// ignore |
4079 |
|
4080 |
} |
4081 |
}; |
4082 |
|
4083 |
private class MultiContentAssistCommandAdapter extends ContentAssistCommandAdapter { |
4084 |
|
4085 |
public MultiContentAssistCommandAdapter(Control control, IControlContentAdapter controlContentAdapter, |
4086 |
IContentProposalProvider proposalProvider, String commandId, char[] autoActivationCharacters) { |
4087 |
super(control, controlContentAdapter, proposalProvider, commandId, autoActivationCharacters); |
4088 |
// ignore |
4089 |
} |
4090 |
|
4091 |
public void reopen() { |
4092 |
this.openProposalPopup(); |
4093 |
} |
4094 |
|
4095 |
} |
4096 |
|
4002 |
} |
4097 |
} |