Skip to content
Snippets Groups Projects
Commit a740e286 authored by Oliver Rieger's avatar Oliver Rieger
Browse files

selection color modified

parent b75d66d5
Branches
Tags
No related merge requests found
...@@ -28,7 +28,15 @@ package de.fu_berlin.inf.dpp.activities; ...@@ -28,7 +28,15 @@ package de.fu_berlin.inf.dpp.activities;
*/ */
public interface IActivity { public interface IActivity {
/**
* set source jabber_id of producer of this IActivity.
* @param source jabber_id string
*/
public void setSource(String source); public void setSource(String source);
/**
* get jabber_id of remote producer
* @return jabber_id
*/
public String getSource(); public String getSource();
} }
...@@ -508,7 +508,7 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener ...@@ -508,7 +508,7 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener
file = sharedProject.getProject().getFile(textEdit.getEditor()); file = sharedProject.getProject().getFile(textEdit.getEditor());
} }
String text = fixDelimiters(file, textEdit.text); String text = fixDelimiters(file, textEdit.text);
replaceText(file, textEdit.offset, textEdit.replace, text); replaceText(file, textEdit.offset, textEdit.replace, text,textEdit.getSource());
Set<IEditorPart> editors = editorPool.getEditors(driverEditor); Set<IEditorPart> editors = editorPool.getEditors(driverEditor);
for (IEditorPart editorPart : editors) { for (IEditorPart editorPart : editors) {
...@@ -705,7 +705,7 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener ...@@ -705,7 +705,7 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener
return (sharedProject != null && resource.getProject() == sharedProject.getProject()); return (sharedProject != null && resource.getProject() == sharedProject.getProject());
} }
private void replaceText(IFile file, int offset, int replace, String text) { private void replaceText(IFile file, int offset, int replace, String text, String source) {
FileEditorInput input = new FileEditorInput(file); FileEditorInput input = new FileEditorInput(file);
IDocumentProvider provider = editorAPI.getDocumentProvider(input); IDocumentProvider provider = editorAPI.getDocumentProvider(input);
...@@ -719,7 +719,7 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener ...@@ -719,7 +719,7 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener
doc.replace(offset, replace, text); doc.replace(offset, replace, text);
IAnnotationModel model = provider.getAnnotationModel(input); IAnnotationModel model = provider.getAnnotationModel(input);
ContributionHelper.insertAnnotation(model, offset, text.length()); ContributionHelper.insertAnnotation(model, offset, text.length(),source);
// Don't disconnect from provider yet, because otherwise the text // Don't disconnect from provider yet, because otherwise the text
// changes would be lost. We only disconnect when the document is // changes would be lost. We only disconnect when the document is
......
...@@ -2,6 +2,10 @@ package de.fu_berlin.inf.dpp.editor.annotations; ...@@ -2,6 +2,10 @@ package de.fu_berlin.inf.dpp.editor.annotations;
import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.Annotation;
import de.fu_berlin.inf.dpp.Saros;
import de.fu_berlin.inf.dpp.User;
import de.fu_berlin.inf.dpp.net.JID;
public class AnnotationSaros extends Annotation { public class AnnotationSaros extends Annotation {
private String source; private String source;
...@@ -9,6 +13,18 @@ public class AnnotationSaros extends Annotation { ...@@ -9,6 +13,18 @@ public class AnnotationSaros extends Annotation {
AnnotationSaros(String type, boolean isPersistent, String text, String source) { AnnotationSaros(String type, boolean isPersistent, String text, String source) {
super(type, isPersistent, text); super(type, isPersistent, text);
this.source=source; this.source=source;
if(
// type.equals(ContributionAnnotation.TYPE)
// ||
type.equals(SelectionAnnotation.TYPE)){
// TODO: improve color assingment and dynamic handling
int colorid=getColorIdForUser(source) +1;
String mytype=type + "." + new Integer(colorid).toString();
setType(mytype);
}
} }
AnnotationSaros(String type, boolean isPersistent, String text) { AnnotationSaros(String type, boolean isPersistent, String text) {
...@@ -24,4 +40,16 @@ public class AnnotationSaros extends Annotation { ...@@ -24,4 +40,16 @@ public class AnnotationSaros extends Annotation {
this.source = source; this.source = source;
} }
protected int getColorIdForUser(String username){
User user= Saros.getDefault().getSessionManager().getSharedProject().
getParticipant(new JID(username));
int colorid=1;
if (user!=null) {
colorid=user.getColorID();
}
return colorid;
}
} }
...@@ -14,5 +14,6 @@ public class ContributionAnnotation extends AnnotationSaros { ...@@ -14,5 +14,6 @@ public class ContributionAnnotation extends AnnotationSaros {
public ContributionAnnotation(String label, String source) { public ContributionAnnotation(String label, String source) {
super(TYPE, false, label, source); super(TYPE, false, label, source);
} }
} }
...@@ -22,22 +22,7 @@ public class SelectionAnnotation extends AnnotationSaros { ...@@ -22,22 +22,7 @@ public class SelectionAnnotation extends AnnotationSaros {
public SelectionAnnotation(String label, String username) { public SelectionAnnotation(String label, String username) {
super(TYPE, false, label,username); super(TYPE, false, label,username);
// TODO: improve color assingment and dynamic handling
int colorid=getColorIdForUser(username) +1;
String mytype=TYPE + "." + new Integer(colorid).toString();
setType(mytype);
} }
int getColorIdForUser(String username){
User user= Saros.getDefault().getSessionManager().getSharedProject().
getParticipant(new JID(username));
int colorid=1;
if (user!=null) {
colorid=user.getColorID();
}
return colorid;
}
} }
...@@ -40,6 +40,29 @@ public class ContributionHelper { ...@@ -40,6 +40,29 @@ public class ContributionHelper {
} }
} }
/**
* Inserts a contribution annotation to given model if there is not already
* a contribution annotation at given position. This method should be called
* after the text has changed.
*/
public static void insertAnnotation(IAnnotationModel model, int offset, int length, String source) {
for (Iterator it = model.getAnnotationIterator(); it.hasNext();) {
Annotation annotation = (Annotation) it.next();
if (!annotation.getType().equals(ContributionAnnotation.TYPE))
continue;
if (model.getPosition(annotation).includes(offset))
return;
}
if (length > 0) {
Position position = new Position(offset, length);
AnnotationSaros annotation = new ContributionAnnotation("",source);
model.addAnnotation(annotation, position);
}
}
/** /**
* Splits the contribution annotation at given position, so that the * Splits the contribution annotation at given position, so that the
* following text change won't expand the annotation. This needs to be * following text change won't expand the annotation. This needs to be
...@@ -59,8 +82,9 @@ public class ContributionHelper { ...@@ -59,8 +82,9 @@ public class ContributionHelper {
Position pos2 = new Position(offset, pos.length - (offset - pos.offset)); Position pos2 = new Position(offset, pos.length - (offset - pos.offset));
model.removeAnnotation(annotation); model.removeAnnotation(annotation);
model.addAnnotation(new ContributionAnnotation(), pos1); /* get source information and create an split annotation.*/
model.addAnnotation(new ContributionAnnotation(), pos2); model.addAnnotation(new ContributionAnnotation("",((ContributionAnnotation)annotation).getSource()), pos1);
model.addAnnotation(new ContributionAnnotation("",((ContributionAnnotation)annotation).getSource()), pos2);
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment