private void createAnnotations(final ISourceNode linecoverage) { AnnotationModelEvent event = new AnnotationModelEvent(this); clear(event); final int firstline = linecoverage.getFirstLine(); final int lastline = Math.min(linecoverage.getLastLine(), document.getNumberOfLines()); try { for (int l = firstline; l <= lastline; l++) { final ILine line = linecoverage.getLine(l); if (line.getStatus() != ICounter.EMPTY) { final IRegion region = document.getLineInformation(l - 1); final CoverageAnnotation ca = new CoverageAnnotation( region.getOffset(), region.getLength(), line); annotations.add(ca); event.annotationAdded(ca); } } } catch (BadLocationException ex) { EclEmmaUIPlugin.log(ex); } fireModelChanged(event); }
@Override public void modelChanged(AnnotationModelEvent event) { // if (event instanceof CompilationUnitAnnotationModelEvent) { // CompilationUnitAnnotationModelEvent cuEvent= (CompilationUnitAnnotationModelEvent) event; // if (cuEvent.includesProblemMarkerAnnotationChanges()) { // boolean hasChanges= false; // synchronized (this) { // IResource changedResource= cuEvent.getUnderlyingResource(); // hasChanges= fResourcesWithAnnotationChanges.add(changedResource); // } // if (hasChanges) { // fireChanges(); // } // } // } }
private void fireModelChanged(AnnotationModelEvent event) { event.markSealed(); if (!event.isEmpty()) { for (final IAnnotationModelListener l : annotationModelListeners) { if (l instanceof IAnnotationModelListenerExtension) { ((IAnnotationModelListenerExtension) l).modelChanged(event); } else { l.modelChanged(this); } } } }
/** * @see IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent) */ public void modelChanged(AnnotationModelEvent event) { Object[] listeners= fListenerList.getListeners(); for (int i= 0; i < listeners.length; i++) { Object curr= listeners[i]; if (curr instanceof IAnnotationModelListenerExtension) { ((IAnnotationModelListenerExtension) curr).modelChanged(event); } } }
public void modelChanged(AnnotationModelEvent event) { if (event instanceof CompilationUnitAnnotationModelEvent) { CompilationUnitAnnotationModelEvent cuEvent= (CompilationUnitAnnotationModelEvent) event; if (cuEvent.includesProblemMarkerAnnotationChanges()) { boolean hasChanges= false; synchronized (this) { IResource changedResource= cuEvent.getUnderlyingResource(); hasChanges= fResourcesWithAnnotationChanges.add(changedResource); } if (hasChanges) { fireChanges(); } } } }
@Override public void modelChanged(AnnotationModelEvent event) { if (!event.isValid()) { return; } if (event.isWorldChange()) { update(); return; } Annotation[] annotations = event.getAddedAnnotations(); int length = annotations.length; for (int i = 0; i < length; i++) { if (!skip(annotations[i].getType())) { update(); return; } } annotations = event.getRemovedAnnotations(); length = annotations.length; for (int i = 0; i < length; i++) { if (!skip(annotations[i].getType())) { update(); return; } } annotations = event.getChangedAnnotations(); length = annotations.length; for (int i = 0; i < length; i++) { if (!skip(annotations[i].getType())) { update(); return; } } }
private void clear() { AnnotationModelEvent event = new AnnotationModelEvent(this); clear(event); fireModelChanged(event); }
private void clear(AnnotationModelEvent event) { for (final CoverageAnnotation ca : annotations) { event.annotationRemoved(ca, ca.getPosition()); } annotations.clear(); }
public void addAnnotationModelListener(IAnnotationModelListener listener) { if (!annotationModelListeners.contains(listener)) { annotationModelListeners.add(listener); fireModelChanged(new AnnotationModelEvent(this, true)); } }
/** * Sets the sentence translation. * * @param sentence the new sentence translation */ private AnnotationModelEvent setSentenceTranslation(BTSSenctence sentence, boolean postSelection) { // TODO: allow for multiple sentence translations to be highlighted simultaneously // i.e. create method setSentenceTranslation(List<BTSSentence>) which gets passed // a Collection containing all sentences detected within a BTSTextSelectionEvent final AnnotationModelEvent ev = new AnnotationModelEvent(annotationModel); if (sentence != null && !sentence.equals(selectedSentence)) { selectedSentence = sentence; if (selectedSentence.getTranslation() == null) { Command command = AddCommand.create(editingDomain, selectedSentence, BtsCorpusModelPackage.BTS_SENCTENCE__TRANSLATION, BtsmodelFactory.eINSTANCE .createBTSTranslations()); editingDomain.getCommandStack().execute(command); } sentenceTranslate_Editor.setEnabled(userMayEdit); sentenceTranslate_Editor.load(selectedSentence.getTranslation(), editingDomain, false); BTSModelAnnotation am = modelAnnotationMap.get(sentence.get_id()); if (am != null) { if (!am.equals(highlightedSentenceAnnotation) || !am.getType().endsWith(".highlighted")) { // highlight current translation am.setHighlighted(true); ev.annotationChanged(am); // remove previous highlight if (highlightedSentenceAnnotation != null) { highlightedSentenceAnnotation.setHighlighted(false); ev.annotationChanged(highlightedSentenceAnnotation); } highlightedSentenceAnnotation = am; } if (!postSelection) { // make sure annotation is visible in text editor Position pos = annotationModel.getPosition(am); if (pos != null) embeddedEditor.getViewer().revealRange(pos.getOffset(), pos.length); // In order to limit workload, only repaint text editor (including highlight of line(s) // containing this sentence) if method call seems to come from selection listener // in EgyTextTranslationPart. This is indicated by postSelection being false. // (if postSelection is true, repaint has most likely already been invoked in processSelection) sync.asyncExec(new Runnable() { public void run() { // TODO this can be improved in order to reduce work load repainting large texts if (painter == null || embeddedEditor.getViewer().getTextWidget().isDisposed()) return; painter.modelChanged(ev); painter.paint(IPainter.INTERNAL); ruler.update(); ruler.relayout(); oruler.update(); embeddedEditor.getViewer().getTextWidget().redraw(); } }); return null; } } if (postSelection) selectionService.setSelection(sentence); return ev; } return null; }
@Override protected AnnotationModelEvent createAnnotationModelEvent() { return new CompilationUnitAnnotationModelEvent(this, getResource()); }