document.addPositionCategory(TEMPLATE_POSITION); document.addPositionUpdater(fgTemplateUpdater); try { document.addPosition(TEMPLATE_POSITION, new Position(start, templateString.length())); } catch (BadPositionCategoryException e) { JavaPlugin.log(e); Assert.isTrue(false); }
	public void apply(IDocument document) {	    try {	        		    if (fTemplateBuffer == null)				fTemplateBuffer= fContext.evaluate(fTemplate);			int start= fRegion.getOffset();			int end= fRegion.getOffset() + fRegion.getLength();						String templateString= fTemplateBuffer.getString();			// backup and replace with template			fOldText= document.get(start, end - start);						document.replace(start, end - start, templateString);				// register template position			document.addPositionCategory(TEMPLATE_POSITION);			document.addPositionUpdater(fgTemplateUpdater);			try {				document.addPosition(TEMPLATE_POSITION, new Position(start, templateString.length()));			} catch (BadPositionCategoryException e) {				JavaPlugin.log(e);				Assert.isTrue(false);				}			// translate positions			LinkedPositionManager manager= new LinkedPositionManager(document);			TemplatePosition[] variables= fTemplateBuffer.getVariables();			for (int i= 0; i != variables.length; i++) {				TemplatePosition variable= variables[i];				if (variable.isResolved())					continue;								int[] offsets= variable.getOffsets();				int length= variable.getLength();								for (int j= 0; j != offsets.length; j++)					manager.addPosition(offsets[j] + start, length);			}						LinkedPositionUI editor= new LinkedPositionUI(fViewer, manager);			editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start);			editor.setCancelListener(this);			editor.enter();			fSelectedRegion= editor.getSelectedRegion();					} catch (BadLocationException e) {			JavaPlugin.log(e);				openErrorDialog(e);		    	    	    } catch (CoreException e) {	       	JavaPlugin.log(e);				openErrorDialog(e);		    	    }	    	}