トニーの答えは良いですが、時には
super.createSourceViewer(composite, ruler, styles);
は親のレイアウトを変更し、実際のエディタ領域には、RTAはトニーの答えにコメントと同じように行方不明になります。
私はRTAとまったく同じことをしたいときにこの問題に遭遇しました。
はここに私のソリューションです:
@Override
protected ISourceViewer createSourceViewer(Composite parent,
IVerticalRuler ruler, int styles) {
changeParentLayout(parent);
Label label = createPathLabel(parent);
ISourceViewer viewer = super.createSourceViewer(parent, ruler, styles);
updateSourceViewerLayout(parent, label);
return viewer;
}
//change the parent layout to grid layout,
//so that the source file area can be shown
protected void changeParentLayout(Composite parent) {
parent.setLayout(new GridLayout(1, false));
}
//i need a label here, ToolBar will be the same
protected Label createPathLabel(Composite parent) {
Label lblNewLabel = new Label(parent, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false, 1, 1));
lblNewLabel.setText(getFilePath());
return lblNewLabel;
}
//after adding the label i need and call super.createSourceViewer()
//now all widgets are ready, we need to change the editor area's layout data to grid data
//here if you only have two widgets: label and area, you can directly choose the edit area widget. i used a loop to find all sub widgets
protected void updateSourceViewerLayout(Composite parent, Label label) {
Control[] children = parent.getChildren();
if (children.length < 2) return;
for (Control child : children) {
if (child != label) {
child.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
}
}
}
private String getFilePath() {
//get the path I want
return "";
}
出典
2014-11-18 07:25:23
tom
私はplsはそれを修正する上記のコードでこれをしようとしていた、ワットは、このコードで間違って起こっています。 – RTA
スーパーコールに渡す2番目の「コンポジット」(上記3を参照)を作成する必要があります。 –
上記のコードで次の行を追加しましたが、今開いていたエディタと重なっています。Composite child = new Composite(parent、SWT.NONE);child.setLayoutData(new GridData(GridData.FILL、GridData.FILL、true、true));戻り値super.createSourceViewer(子、定規、スタイル); – RTA