Search in sources :

Example 1 with LinkedModeModel

use of org.eclipse.jface.text.link.LinkedModeModel in project che by eclipse.

the class ParameterGuessingProposal method ensurePositionCategoryInstalled.

private void ensurePositionCategoryInstalled(final IDocument document, LinkedModeModel model) {
    if (!document.containsPositionCategory(getCategory())) {
        document.addPositionCategory(getCategory());
        fUpdater = new InclusivePositionUpdater(getCategory());
        document.addPositionUpdater(fUpdater);
        model.addLinkingListener(new ILinkedModeListener() {

            /*
				 * @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.jface.text.link.LinkedModeModel, int)
				 */
            public void left(LinkedModeModel environment, int flags) {
                ensurePositionCategoryRemoved(document);
            }

            public void suspend(LinkedModeModel environment) {
            }

            public void resume(LinkedModeModel environment, int flags) {
            }
        });
    }
}
Also used : InclusivePositionUpdater(org.eclipse.jface.text.link.InclusivePositionUpdater) LinkedModeModel(org.eclipse.jface.text.link.LinkedModeModel) ILinkedModeListener(org.eclipse.jface.text.link.ILinkedModeListener) Point(org.eclipse.swt.graphics.Point)

Example 2 with LinkedModeModel

use of org.eclipse.jface.text.link.LinkedModeModel in project ow by vtst.

the class AbstractCompletionProposal method setUpLinkedMode.

/**
   * Set up the linked mode for the replacement text.
   * @param document  The document in which the replacement is made.
   * @param replacementOffset  The offset at which the replacement is made.
   * @param fragments   The fragments to insert.
   * @param closingChar  The closing character (used for the exit mode).
   * @throws BadLocationException
   */
private void setUpLinkedMode(IDocument document, int replacementOffset, Iterable<Fragment> fragments) throws BadLocationException {
    int currentOffset = replacementOffset;
    boolean hasLinkedFragment = false;
    LinkedModeModel model = new LinkedModeModel();
    for (Fragment fragment : fragments) {
        int length = fragment.getText().length();
        if (fragment instanceof LinkedFragment) {
            LinkedPositionGroup group = new LinkedPositionGroup();
            group.addPosition(new LinkedPosition(document, currentOffset, length, LinkedPositionGroup.NO_STOP));
            model.addGroup(group);
            hasLinkedFragment = true;
        }
        currentOffset += length;
    }
    if (!hasLinkedFragment)
        return;
    model.forceInstall();
    LinkedModeUI ui = new EditorLinkedModeUI(model, context.getViewer());
    ui.setExitPosition(context.getViewer(), currentOffset, 0, Integer.MAX_VALUE);
    ui.setExitPolicy(new ExitPolicy(makeExitCharactersForLinkedMode(), document));
    ui.setDoContextInfo(true);
    ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
    ui.enter();
    IRegion region = ui.getSelectedRegion();
    regionToSelect = new Point(region.getOffset(), region.getLength());
}
Also used : IExitPolicy(org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy) LinkedPositionGroup(org.eclipse.jface.text.link.LinkedPositionGroup) LinkedPosition(org.eclipse.jface.text.link.LinkedPosition) EditorLinkedModeUI(org.eclipse.ui.texteditor.link.EditorLinkedModeUI) LinkedModeModel(org.eclipse.jface.text.link.LinkedModeModel) LinkedModeUI(org.eclipse.jface.text.link.LinkedModeUI) EditorLinkedModeUI(org.eclipse.ui.texteditor.link.EditorLinkedModeUI) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

LinkedModeModel (org.eclipse.jface.text.link.LinkedModeModel)2 Point (org.eclipse.swt.graphics.Point)2 IRegion (org.eclipse.jface.text.IRegion)1 ILinkedModeListener (org.eclipse.jface.text.link.ILinkedModeListener)1 InclusivePositionUpdater (org.eclipse.jface.text.link.InclusivePositionUpdater)1 LinkedModeUI (org.eclipse.jface.text.link.LinkedModeUI)1 IExitPolicy (org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy)1 LinkedPosition (org.eclipse.jface.text.link.LinkedPosition)1 LinkedPositionGroup (org.eclipse.jface.text.link.LinkedPositionGroup)1 EditorLinkedModeUI (org.eclipse.ui.texteditor.link.EditorLinkedModeUI)1