1

複数のドキュメントを開くように設計された Eclipse RCP テキスト エディター アプリケーションの場合、印刷できない文字 (つまり、タブ、スペース、および CR) を表示するツールバー ボタンを組み込みました。

これらの文字を表示するために、jface ペインター WhitespaceCharacterPainter を追加/削除します。

sv.addPainter(whitespaceCharacterPainter);

ボタンは 1 つのパーツで正常に機能しますが、PartStack に複数のドキュメント (パーツ記述子の呼び出しによって作成された) がある場合、最後に作成されたパーツのみが印刷できない文字を表示/非表示にします。他のパーツは、新しいパーツが作成されたときの最後の状態のままです。ユーザーは、パーツを切り替えるか、ツールバーのボタンをクリックします。

ボタンが押されたとき、およびパーツが選択されたパーツになったときにパーツを更新するコードを添付しました (対応するタブの ckick によって)。ボタンハンドルも。

ヒントをいただければ幸いです。

//Code...
/** Indicates the status of the WhiteSpaceCharacterPainter button on the toolbar for this part. */
private boolean wsToolBarButtonStatus = false;
public StyledText st;
public SourceViewer sv;
@Inject MPart parte;
//Code...

/**
 * Update the part when the user push the WhiteSpace toolbar button.
 * Sets the sv.addPainter(whitespaceCharacterPainter) 
     * or sv.removePainter(whitespaceCharacterPainter);
     * 
     * @param newButtonStatus Receives the status of the button from the IEventBroker
     */
@Inject
@Optional
public void updatePartByWSButton(@UIEventTopic(NastranEditorEventConstants.WHITE_CHARACTERS_STATUS) boolean newButtonStatus) {
 final MElementContainer<MUIElement>container = parte.getParent();
    if (parte.equals((MPart)container.getSelectedElement())){
    System.out.println("EL PART ES EL SELECTED ELEMENT cuando se aprieta el boton\t" + parte.getLabel());
        //if(wsToolBarButtonStatus != newButtonStatus)
            wsToolBarButtonStatus = newButtonStatus;
            if(wsToolBarButtonStatus){
                sv.addPainter(whitespaceCharacterPainter);
                System.out.println("addPainter......");
            }
            else{
                try{
                    sv.removePainter(whitespaceCharacterPainter);
                    System.out.println("removePainter.....");
                }catch (NullPointerException e) {
                    //e.printStackTrace();
                }
            }
    }
} 
/**
 * Update the WhiteSpace toolbar button when the part is active.
 * Only the active part is updated 
 * 
 * @param activePart
 */
@Inject
@Optional
public void updateWSButtonByPart(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
    if (parte.equals(activePart)) {
        System.out.println("EL PART ACTIVO TIENE LABEL:\t" + parte.getLabel());
        MToolItem item = (MToolItem) modelService.find("es.robes.nastraneditor.toolbarbuttons.whitespacespainterbutton",app);
        item.setSelected(wsToolBarButtonStatus);
        if(wsToolBarButtonStatus){
            this.sv.addPainter(whitespaceCharacterPainter);
            System.out.println("addPainter......");
        }
        else{
            try{
                this.sv.removePainter(whitespaceCharacterPainter);
                System.out.println("removePainter......");
            }catch (NullPointerException e) {
                //e.printStackTrace();
            }
        } 
    }
}

ボタン ハンドラー:

public class WhiteSpacesHandler {
    boolean status;
    @Execute
    public void execute(final MToolItem item, IEventBroker broker) {
        System.out.println("MToolItem element ID: "+ item.getElementId());
        if (item.isSelected()){
            System.out.println("Item is selected");
            status = true;
        //broker.post(NastranEditorEventConstants.WHITE_CHARACTERS_ENABLED, status);
    }

    else{
        System.out.println("Item is not selected");
        status = false;
        }
        broker.post(NastranEditorEventConstants.WHITE_CHARACTERS_STATUS, status);
    }
}
4

0 に答える 0