01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.console;
11:
12: import org.eclipse.jface.text.BadPositionCategoryException;
13: import org.eclipse.jface.text.DefaultPositionUpdater;
14: import org.eclipse.ui.internal.console.ConsoleHyperlinkPosition;
15:
16: /**
17: * When any region of a hyperlink is replaced, the hyperlink needs to be deleted.
18: *
19: * @since 3.3
20: */
21: public class HyperlinkUpdater extends DefaultPositionUpdater {
22:
23: /**
24: * @param category
25: */
26: public HyperlinkUpdater() {
27: super (ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY);
28: }
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(
48: ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY,
49: fPosition);
50: } catch (BadPositionCategoryException x) {
51: }
52:
53: return false;
54: }
55:
56: return true;
57: }
58: }
|