View | Details | Raw Unified | Return to bug 187127 | Differences between
and this patch

Collapse All | Expand All

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

Return to bug 187127