List of usage examples for org.eclipse.jface.fieldassist IContentProposal getCursorPosition
public int getCursorPosition();
From source file:com.amalto.workbench.proposal.ContentProposalAdapterExtended.java
License:Open Source License
private void proposalAccepted(IContentProposal proposal) { // In all cases, notify listeners of an accepted proposal. final Object[] listenerArray = proposalListeners.getListeners(); for (int i = 0; i < listenerArray.length; i++) { if (listenerArray[i] instanceof IContentProposalExtendedListener) { ((IContentProposalExtendedListener) listenerArray[i]).proposalBeforeModifyControl(proposal); }/*from w w w .j a v a 2 s.c o m*/ } if (controlContentAdapter instanceof IControlContentAdapterExtended) { ((IControlContentAdapterExtended) controlContentAdapter).setUsedFilterValue(filterText); } switch (proposalAcceptanceStyle) { case (PROPOSAL_REPLACE): setControlContent(proposal.getContent(), proposal.getCursorPosition()); break; case (PROPOSAL_INSERT): insertControlContent(proposal.getContent(), proposal.getCursorPosition()); break; default: // do nothing. Typically a listener is installed to handle this in // a custom way. break; } // In all cases, notify listeners of an accepted proposal. for (int i = 0; i < listenerArray.length; i++) { ((IContentProposalListener) listenerArray[i]).proposalAccepted(proposal); } }
From source file:custom.jface.widgets.ContentProposalAdapterPlus.java
License:Open Source License
private void proposalAccepted(IContentProposal proposal) { switch (proposalAcceptanceStyle) { case (PROPOSAL_REPLACE): setControlContent(proposal.getContent(), proposal.getCursorPosition()); break;/*from w ww .j av a 2s . c o m*/ case (PROPOSAL_INSERT): insertControlContent(proposal.getContent(), proposal.getCursorPosition()); break; default: // do nothing. Typically a listener is installed to handle this in // a custom way. break; } // In all cases, notify listeners of an accepted proposal. notifyProposalAccepted(proposal); }
From source file:org.cs3.pdt.console.internal.views.completion.ContentProposalAdapter.java
License:Open Source License
private void proposalAccepted(IContentProposal proposal, int stateMask) { switch (proposalAcceptanceStyle) { case (PROPOSAL_REPLACE): setControlContent(proposal.getContent(stateMask), proposal.getCursorPosition()); break;//ww w . j av a 2 s. com case (PROPOSAL_INSERT): insertControlContent(proposal.getContent(stateMask), proposal.getCursorPosition()); break; default: // do nothing. Typically a listener is installed to handle this in // a custom way. break; } // In all cases, notify listeners of an accepted proposal. notifyProposalAccepted(proposal); }
From source file:org.eclipse.sirius.tests.unit.common.interpreter.CompoundInterpreterTestCase.java
License:Open Source License
/** * Ensures that we get interpreters empty expressions that match a non empty * context. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428770 *//*from ww w. j a va2 s. com*/ public void testCompletionPerPrefixFirstChar() { for (ContentProposal emptyExpression : availableEmptyExpressions) { String firstChar = emptyExpression.getProposal().substring(0, 1); List<ContentProposal> proposals = getProposals(firstChar); ContentProposalConverter converter = new ContentProposalConverter(firstChar); // The following assert is valid for: "[/]" "<%%>" "ocl:" "var:" // "service:" and "feature" assertEquals("Proposals should contains only one proposal", 1, proposals.size()); // Proposals are interpreter prefixes assertTrue("Proposals should be contained by available empty expressions", availableEmptyExpressions.containsAll(proposals)); ContentProposal proposal = proposals.get(0); IContentProposal jfaceProposal = converter.convertToJFaceContentProposal(proposal); // Check JFace proposal assertEquals("", proposal.getProposal(), firstChar + jfaceProposal.getContent()); // Check JFace cursor position assertEquals("JFace proposal cursor position is not well computed", proposal.getCursorPosition() - (proposal.getProposal().length() - jfaceProposal.getContent().length()), jfaceProposal.getCursorPosition()); } }
From source file:org.polymap.rhei.batik.toolkit.TextProposalDecorator.java
License:Open Source License
public TextProposalDecorator(Text control) { this.control = control; // proposal/* w w w.j av a2 s . co m*/ proposalProvider = new SimpleContentProposalProvider(new String[0]); proposalProvider.setFiltering(false); TextContentAdapter controlAdapter = new TextContentAdapter() { public void insertControlContents(@SuppressWarnings("hiding") Control control, String text, int cursorPosition) { ((Text) control).setText(text); ((Text) control).setSelection(text.length()); } }; proposal = new XContentProposalAdapter(control, controlAdapter, proposalProvider, null, null); proposal.setPropagateKeys(true); proposal.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE); // delay until popupSize is filled control.getDisplay().asyncExec(() -> { popupSize.ifPresent(size -> proposal.setPopupSize(size)); }); proposal.addContentProposalListener(new IContentProposalListener() { public void proposalAccepted(IContentProposal _proposal) { control.setText(_proposal.getContent() + " "); control.setSelection(_proposal.getCursorPosition() + 1, _proposal.getCursorPosition() + 1); if (eventOnAccept.get()) { Event event = new Event(); event.keyCode = SWT.Selection; event.display = control.getDisplay(); event.type = SWT.KeyUp; control.notifyListeners(SWT.KeyUp, event); } } }); control.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent ev) { currentSearchTxtValue = control.getText(); if (currentSearchTxtValue.length() < 1) { proposalProvider.setProposals(new String[0]); } else { new ProposalJob().schedule(activationDelayMillis.get()); // close popup: visual feedback for user that key has been recognized; // also, otherwise proposal would check in the current entries proposalProvider.setProposals(new String[] {}); } } }); }
From source file:org.polymap.rhei.fulltext.ui.FulltextProposal.java
License:Open Source License
public FulltextProposal(FulltextIndex index, final Text control) { this.index = index; this.control = control; // proposal/*from w ww . ja v a2 s . c o m*/ proposalProvider = new SimpleContentProposalProvider(new String[0]); proposalProvider.setFiltering(false); TextContentAdapter controlAdapter = new TextContentAdapter() { public void insertControlContents(@SuppressWarnings("hiding") Control control, String text, int cursorPosition) { ((Text) control).setText(text); ((Text) control).setSelection(text.length()); } }; proposal = new XContentProposalAdapter(control, controlAdapter, proposalProvider, null, null); proposal.setPropagateKeys(true); proposal.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE); // delay until popupSize is filled control.getDisplay().asyncExec(() -> { popupSize.ifPresent(size -> proposal.setPopupSize(size)); }); proposal.addContentProposalListener(new IContentProposalListener() { public void proposalAccepted(IContentProposal _proposal) { control.setText(_proposal.getContent() + " "); control.setSelection(_proposal.getCursorPosition() + 1, _proposal.getCursorPosition() + 1); if (eventOnAccept.get()) { Event event = new Event(); event.keyCode = SWT.Selection; event.display = control.getDisplay(); event.type = SWT.KeyUp; control.notifyListeners(SWT.KeyUp, event); } } }); control.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent ev) { // close popup: visual feedback for user that key has been recognized; // also, otherwise proposal would check in the current entries proposalProvider.setProposals(new String[0]); // proposal.closeProposalPopup(); currentSearchTxtValue = control.getText(); if (currentSearchTxtValue.length() < 1) { proposalProvider.setProposals(new String[0]); } else { new ProposalJob().schedule(activationDelayMillis.get()); } } }); }
From source file:org.talend.commons.ui.swt.proposal.ContentProposalAdapterExtended.java
License:Open Source License
private void proposalAccepted(IContentProposal proposal) { // In all cases, notify listeners of an accepted proposal. final Object[] listenerArray = proposalListeners.getListeners(); for (Object element : listenerArray) { if (element instanceof IContentProposalExtendedListener) { ((IContentProposalExtendedListener) element).proposalBeforeModifyControl(proposal); }//w ww . j a v a 2s .c o m } if (controlContentAdapter instanceof IControlContentAdapterExtended) { ((IControlContentAdapterExtended) controlContentAdapter).setUsedFilterValue(filterText); } // Remove the selected text before applying proposal. See bug 0004266: Replace value with context value using // CTRL+Space. removeSelectedText(); switch (proposalAcceptanceStyle) { case (PROPOSAL_REPLACE): setControlContent(proposal.getContent(), proposal.getCursorPosition()); break; case (PROPOSAL_INSERT): insertControlContent(proposal.getContent(), proposal.getCursorPosition()); break; default: // do nothing. Typically a listener is installed to handle this in // a custom way. break; } // In all cases, notify listeners of an accepted proposal. for (Object element : listenerArray) { ((IContentProposalListener) element).proposalAccepted(proposal); } }
From source file:org.talend.sqlbuilder.ui.proposal.SQLEditorProposalAdapter.java
License:Open Source License
private void proposalAccepted(IContentProposal proposal) { // In all cases, notify listeners of an accepted proposal. final Object[] listenerArray = proposalListeners.getListeners(); for (int i = 0; i < listenerArray.length; i++) { if (listenerArray[i] instanceof IContentProposalExtendedListener) { ((IContentProposalExtendedListener) listenerArray[i]).proposalBeforeModifyControl(proposal); }//from w ww .j a va 2 s . co m } if (controlContentAdapter instanceof IControlContentAdapterExtended) { ((IControlContentAdapterExtended) controlContentAdapter).setUsedFilterValue(filterText); } switch (proposalAcceptanceStyle) { case (PROPOSAL_REPLACE): setControlContent(proposal.getContent(), proposal.getCursorPosition()); break; case (PROPOSAL_INSERT): insertControlContent(proposal.getContent(), proposal.getCursorPosition()); break; default: // do nothing. Typically a listener is installed to handle this in // a custom way. break; } // In all cases, notify listeners of an accepted proposal. for (int i = 0; i < listenerArray.length; i++) { ((IContentProposalListener) listenerArray[i]).proposalAccepted(proposal); } }