E4 RCPアプリケーションの場合は、まずいくつかのコードを付けました。
基本的にIEventBrokerを使用して、TextViewerのペインタをボタンで追加/削除します。
public class WhitespaceCharactersHandler {
boolean status;
@Execute
public void execute(final MToolItem item, IEventBroker broker) {
if (item.isSelected()){
status = true;
}
else{
status = false;
}
broker.post(EventConstants.WHITE_CHARACTERS_STATUS, status);
}
}
あらわす定数インターフェイスクラス
import org.eclipse.jface.text.WhitespaceCharacterPainter;
public class TheEditor{
@Inject MPart thePart;
private WhitespaceCharacterPainter whitespaceCharacterPainter;
@PostConstruct
public void postConstruct(Composite parent) {
TextViewer tv = new TextViewer(parent, SWT.MULTI | SWT.V_SCROLL |SWT.H_SCROLL);
whitespaceCharacterPainter = new WhitespaceCharacterPainter(tv);
tv.addPainter(whitespaceCharacterPainter);
whitespaceCharacterPainter.deactivate(true);
}
@Inject
@Optional
public void updatePartByWSButton(@UIEventTopic(EventConstants.WHITE_CHARACTERS_STATUS) boolean newButtonStatus) {
final MElementContainer<MUIElement>container = thePart.getParent();
if (thePart.equals((MPart)container.getSelectedElement())){
wsToolBarButtonStatus = newButtonStatus;
if(wsToolBarButtonStatus){
this.whitespaceCharacterPainter.paint(IPainter.CONFIGURATION);
}
else{
whitespaceCharacterPainter.deactivate(true);
tv.removePainter(whitespaceCharacterPainter);
}
}
}
}
ハンドラ上にコメントとしてStyledTextは
styledText = tv.getTextWidget();
から得ることができる
:
public interface EventConstants {
String WHITE_CHARACTERS_STATUS = "WHITE-CHARACTERS-STATUS";
}
拡張について[WhitespaceCharacterPainter](https://git.eclipse.org/c/platform/eclipse.platform.text.git/tree/org.eclipse.jface.text/src/org/eclipse/jface/text) /WhitespaceCharacterPainter.java)( 'TextViewer'を介して' StyledText'ウィジェットを使用します)? – howlger
いいアイデア!私はそれを試してみましょう... – NormanC