0
私はエディタではなくビューでこれを試しています。
私はoverViewRuler.addAnnotationType("My annotation type");
を呼び出してみましたし、またoverViewRuler.update();
何も動いていないようにみえ呼ばれます。ソースビューアの右側の概要ルーラにマークを表示する方法はありますか?
私はエディタではなくビューでこれを試しています。
私はoverViewRuler.addAnnotationType("My annotation type");
を呼び出してみましたし、またoverViewRuler.update();
何も動いていないようにみえ呼ばれます。ソースビューアの右側の概要ルーラにマークを表示する方法はありますか?
私は答えを見つけました。
問題がoverviewRulerPreferenceValue
= "真" のplugin.xmlで行方不明になった
ました。私は、誰かが試してみたい場合に備えて、以下の完全なコードを提供しています。ここで
package sourceviewsample; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.AnnotationModel; import org.eclipse.jface.text.source.CompositeRuler; import org.eclipse.jface.text.source.IAnnotationAccess; import org.eclipse.jface.text.source.IOverviewRuler; import org.eclipse.jface.text.source.ISharedTextColors; import org.eclipse.jface.text.source.LineNumberRulerColumn; import org.eclipse.jface.text.source.OverviewRuler; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.internal.editors.text.EditorsPlugin; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.texteditor.AnnotationPreference; import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; /** * An example of using a SourceViewer with Annotation support outside of the * TextEditor class. This annotations can be configured in the preferences if * the markerAnnotationSpecification is setup in the plugin.xml. * * To execute this, run as an Eclipse Application and then open a file using * Open with.. -> Other, and select Sample Editor. You will see the text that * comes in this example and the highlight. */ public class SampleEditor extends ViewPart { public static final String ANNO_TYPE = "com.mycompany.element"; public static final String ANNO_KEY_HIGHLIGHT = "annotateElemHighlight"; public static final String ANNO_KEY_OVERVIEW = "annotateElemOverviewRuler"; public static final String ANNO_KEY_VERTICAL = "annotateElemVertialRuler"; public static final String ANNO_KEY_TEXT = "annotateElemText"; public static final String ANNO_KEY_COLOR = "annotateElemColor"; protected SourceViewer _sourceViewer; protected SourceViewerDecorationSupport _sds; protected IDocument _document; protected AnnotationModel _annotationModel; protected String _docString = "this\nis\na\ntest\ndocument"; public SampleEditor() { super(); } public void createPartControl(Composite parent) { int VERTICAL_RULER_WIDTH = 12; int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION; ISharedTextColors sharedColors = EditorsPlugin.getDefault() .getSharedTextColors(); IAnnotationAccess iaccess = new IAnnotationAccess() { @Override public boolean isTemporary(Annotation annotation) { // TODO Auto-generated method stub return true; } @Override public boolean isMultiLine(Annotation annotation) { // TODO Auto-generated method stub return false; } @Override public Object getType(Annotation annotation) { // TODO Auto-generated method stub return ANNO_TYPE; } }; IOverviewRuler overviewRuler = new OverviewRuler(iaccess, VERTICAL_RULER_WIDTH, sharedColors); CompositeRuler ruler = new CompositeRuler(VERTICAL_RULER_WIDTH); _document = new Document(); _document.set(_docString); _annotationModel = new AnnotationModel(); _annotationModel.connect(_document); _sourceViewer = new SourceViewer(parent, ruler, overviewRuler, true, styles); _sourceViewer.configure(new SourceViewerConfiguration()); _sds = new SourceViewerDecorationSupport(_sourceViewer, overviewRuler, null, sharedColors); AnnotationPreference ap = new AnnotationPreference(); ap.setColorPreferenceKey(ANNO_KEY_COLOR); ap.setColorPreferenceValue(new RGB(150, 200, 250)); ap.setHighlightPreferenceKey(ANNO_KEY_HIGHLIGHT); ap.setVerticalRulerPreferenceKey(ANNO_KEY_VERTICAL); ap.setOverviewRulerPreferenceKey(ANNO_KEY_OVERVIEW); ap.setOverviewRulerPreferenceValue(true); ap.setTextPreferenceKey(ANNO_KEY_TEXT); ap.setAnnotationType(ANNO_TYPE); _sds.setAnnotationPreference(ap); _sds.install(EditorsPlugin.getDefault().getPreferenceStore()); _sourceViewer.setDocument(_document, _annotationModel); _sourceViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); ruler.addDecorator(0, new LineNumberRulerColumn()); overviewRuler.addAnnotationType(ANNO_TYPE); overviewRuler.getControl().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); Annotation annotation = new Annotation(false); annotation.setType(ANNO_TYPE); Position position = new Position(0, 4); _annotationModel.addAnnotation(annotation, position); try { _document.addPosition(position); } catch (BadLocationException e) { e.printStackTrace(); } overviewRuler.setModel(_annotationModel); } public void dispose() { // The _sourceViewer goes away automatically when the editor goes // away because it's hooked to the controls _sds.dispose(); } // // This stuff below is just needed to make the EditorPart happy // public void doSave(IProgressMonitor monitor) { } public void doSaveAs() { } // public void init(IEditorSite site, IEditorInput input) // throws PartInitException // { // setSite(site); // setInput(input); // } // // public boolean isDirty() // { // return false; // } public boolean isSaveAsAllowed() { return false; } public void setFocus() { } }
はplugin.xmlの同様
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <plugin> <extension point="org.eclipse.ui.editors.annotationTypes"> <type markerSeverity="0" name="com.mycompany.element"> </type> </extension> <extension point="org.eclipse.ui.editors.markerAnnotationSpecification"> <specification annotationType="com.mycompany.element" colorPreferenceKey="annotateElemColor" colorPreferenceValue="255,255,0" highlightPreferenceKey="annotateElemHighlight" highlightPreferenceValue="true" includeOnPreferencePage="true" label="Sample Annotation" overviewRulerPreferenceKey="annotateElemOverviewRuler" overviewRulerPreferenceValue="true" textPreferenceKey="annotateElemText" verticalRulerPreferenceKey="annotateElemVerticalRuler" verticalRulerPreferenceValue="true"> </specification> </extension> <extension point="org.eclipse.ui.views"> <view id="sourceviewsample.SampleEditor" name="Source Viewer" class="sourceviewsample.SampleEditor"/> </extension> </plugin>
である私は、コードはおそらくあなたが 'org.eclipse.ui.editors.annotationTypes'と'組織との注釈が定義されていることを想定していると思います。 eclipse.ui.editors.markerAnnotationSpecification'拡張ポイント。 –
注釈タイプを追加しましたが、注釈を追加しましたか? – nitind
はい私は注釈も追加しました:)私はマーカーを使用する場合に限り、それらの拡張ポイントが必要だと思いました。私が間違っている場合は私を修正してください – user1223879