001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.text;
011:
012: import java.util.Iterator;
013: import java.util.ResourceBundle;
014:
015: import org.eclipse.jface.text.IDocument;
016: import org.eclipse.jface.text.ITextOperationTarget;
017: import org.eclipse.jface.text.Position;
018: import org.eclipse.jface.text.source.Annotation;
019: import org.eclipse.jface.text.source.IAnnotationAccessExtension;
020: import org.eclipse.jface.text.source.ISourceViewer;
021: import org.eclipse.jface.text.source.IVerticalRulerInfo;
022: import org.eclipse.swt.widgets.Event;
023: import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
024: import org.eclipse.ui.texteditor.ITextEditor;
025: import org.eclipse.ui.texteditor.ITextEditorExtension;
026: import org.eclipse.ui.texteditor.SelectMarkerRulerAction;
027:
028: public class PDESelectAnnotationRulerAction extends
029: SelectMarkerRulerAction {
030:
031: private boolean fIsEditable;
032: private ITextEditor fTextEditor;
033: private Position fPosition;
034: private ResourceBundle fBundle;
035: private String fPrefix;
036:
037: public PDESelectAnnotationRulerAction(ResourceBundle bundle,
038: String prefix, ITextEditor editor, IVerticalRulerInfo ruler) {
039: super (bundle, prefix, editor, ruler);
040: fTextEditor = editor;
041: fBundle = bundle;
042: fPrefix = prefix;
043: }
044:
045: public void run() {
046: runWithEvent(null);
047: }
048:
049: /*
050: * @see org.eclipse.jface.action.IAction#runWithEvent(org.eclipse.swt.widgets.Event)
051: * @since 3.2
052: */
053: public void runWithEvent(Event event) {
054: if (fIsEditable) {
055: ITextOperationTarget operation = (ITextOperationTarget) fTextEditor
056: .getAdapter(ITextOperationTarget.class);
057: final int opCode = ISourceViewer.QUICK_ASSIST;
058: if (operation != null && operation.canDoOperation(opCode)) {
059: fTextEditor.selectAndReveal(fPosition.getOffset(),
060: fPosition.getLength());
061: operation.doOperation(opCode);
062: }
063: return;
064: }
065:
066: super .run();
067: }
068:
069: public void update() {
070: checkReadOnly();
071:
072: if (fIsEditable) {
073: initialize(fBundle, fPrefix + "QuickFix."); //$NON-NLS-1$
074: }
075:
076: super .update();
077: }
078:
079: private void checkReadOnly() {
080: fPosition = null;
081: fIsEditable = false;
082:
083: AbstractMarkerAnnotationModel model = getAnnotationModel();
084: IAnnotationAccessExtension annotationAccess = getAnnotationAccessExtension();
085:
086: IDocument document = getDocument();
087: if (model == null)
088: return;
089:
090: Iterator iter = model.getAnnotationIterator();
091: int layer = Integer.MIN_VALUE;
092:
093: while (iter.hasNext()) {
094: Annotation annotation = (Annotation) iter.next();
095: if (annotation.isMarkedDeleted())
096: continue;
097:
098: int annotationLayer = annotationAccess.getLayer(annotation);
099: if (annotationAccess != null)
100: if (annotationLayer < layer)
101: continue;
102:
103: Position position = model.getPosition(annotation);
104: if (!includesRulerLine(position, document))
105: continue;
106:
107: boolean isReadOnly = fTextEditor instanceof ITextEditorExtension
108: && ((ITextEditorExtension) fTextEditor)
109: .isEditorInputReadOnly();
110: if (!isReadOnly) {
111: fPosition = position;
112: fIsEditable = true;
113: layer = annotationLayer;
114: continue;
115: }
116: }
117: }
118: }
|