KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > MarkerUpdater


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.texteditor;
12
13 import org.eclipse.jface.text.BadLocationException;
14 import org.eclipse.jface.text.IDocument;
15 import org.eclipse.jface.text.Position;
16
17 import org.eclipse.core.resources.IMarker;
18
19
20 /**
21  * Updates a marker's positional attributes which are start position, end position,
22  * and line number.
23  */

24 class MarkerUpdater implements IMarkerUpdater {
25
26     private final static String JavaDoc[] ATTRIBUTES= {IMarker.CHAR_START, IMarker.CHAR_END, IMarker.LINE_NUMBER};
27
28     /*
29      * @see IMarkerUpdater#getAttribute()
30      */

31     public String JavaDoc[] getAttribute() {
32         return ATTRIBUTES;
33     }
34
35     /*
36      * @see IMarkerUpdater#getMarkerType()
37      */

38     public String JavaDoc getMarkerType() {
39         return null;
40     }
41
42     /*
43      * @see IMarkerUpdater#updateMarker(IMarker, IDocument, Position)
44      */

45     public boolean updateMarker(IMarker marker, IDocument document, Position position) {
46
47         if (position.isDeleted())
48             return false;
49
50         if (MarkerUtilities.getCharStart(marker) != -1 && MarkerUtilities.getCharEnd(marker) != -1) {
51             MarkerUtilities.setCharStart(marker, position.getOffset());
52             MarkerUtilities.setCharEnd(marker, position.getOffset() + position.getLength());
53         }
54         if (MarkerUtilities.getLineNumber(marker) != -1) {
55             try {
56                 // marker line numbers are 1-based
57
MarkerUtilities.setLineNumber(marker, document.getLineOfOffset(position.getOffset()) + 1);
58             } catch (BadLocationException x) {
59             }
60         }
61
62         return true;
63     }
64 }
65
Popular Tags