comparison dwtx/jface/text/hyperlink/AbstractHyperlinkDetector.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtx.jface.text.hyperlink.AbstractHyperlinkDetector;
14
15 import dwt.dwthelper.utils;
16
17 import dwtx.core.runtime.Assert;
18 import dwtx.core.runtime.IAdaptable;
19
20
21 /**
22 * A hyperlink detector that can provide adapters through
23 * a context that can be set by the creator of this hyperlink
24 * detector.
25 * <p>
26 * Clients may subclass.
27 * </p>
28 *
29 * @since 3.3
30 */
31 public abstract class AbstractHyperlinkDetector : IHyperlinkDetector, IHyperlinkDetectorExtension {
32
33 /**
34 * The context of this hyperlink detector.
35 */
36 private IAdaptable fContext;
37
38 /**
39 * Sets this hyperlink detector's context which
40 * is responsible to provide the adapters.
41 *
42 * @param context the context for this hyperlink detector
43 * @throws IllegalArgumentException if the context is <code>null</code>
44 * @throws IllegalStateException if this method is called more than once
45 */
46 public final void setContext(IAdaptable context) throws IllegalStateException, IllegalArgumentException {
47 Assert.isLegal(context !is null);
48 if (fContext !is null)
49 throw new IllegalStateException();
50 fContext= context;
51 }
52
53 /*
54 * @see dwtx.jface.text.hyperlink.IHyperlinkDetectorExtension#dispose()
55 */
56 public void dispose() {
57 fContext= null;
58 }
59
60 /**
61 * Returns an object which is an instance of the given class
62 * and provides additional context for this hyperlink detector.
63 *
64 * @param adapterClass the adapter class to look up
65 * @return an instance that can be cast to the given class,
66 * or <code>null</code> if this object does not
67 * have an adapter for the given class
68 */
69 protected final Object getAdapter(Class adapterClass) {
70 Assert.isLegal(adapterClass !is null);
71 if (fContext !is null)
72 return fContext.getAdapter(adapterClass);
73 return null;
74 }
75
76 }