KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > console > HyperlinkUpdater


1 /*******************************************************************************
2  * Copyright (c) 2007 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.internal.console;
12
13 import org.eclipse.jface.text.BadPositionCategoryException;
14 import org.eclipse.jface.text.DefaultPositionUpdater;
15 import org.eclipse.ui.internal.console.ConsoleHyperlinkPosition;
16
17 /**
18  * When any region of a hyperlink is replaced, the hyperlink needs to be deleted.
19  *
20  * @since 3.3
21  */

22 public class HyperlinkUpdater extends DefaultPositionUpdater {
23
24     /**
25      * @param category
26      */

27     public HyperlinkUpdater() {
28         super(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY);
29     }
30     /**
31      * When any region of a hyperlink is replaced, the hyperlink needs to be deleted.
32      *
33      * @return <code>true</code> if position has NOT been deleted
34      */

35     protected boolean notDeleted() {
36
37         int positionEnd = fPosition.offset + fPosition.length - 1;
38         int editEnd = fOffset + fLength - 1;
39         if ((fOffset <= fPosition.offset && (editEnd > fPosition.offset)) ||
40             (fOffset < positionEnd && (editEnd > positionEnd)) ||
41             (fOffset >= fPosition.offset && fOffset <= positionEnd) ||
42             (editEnd >= fPosition.offset && editEnd <= positionEnd)) {
43
44             fPosition.delete();
45
46             try {
47                 fDocument.removePosition(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY, fPosition);
48             } catch (BadPositionCategoryException x) {
49             }
50
51             return false;
52         }
53
54         return true;
55     }
56 }
57
Popular Tags