KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > template > contentassist > TemplateInformationControlCreator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.ui.text.template.contentassist;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.DisposeEvent;
17 import org.eclipse.swt.events.DisposeListener;
18 import org.eclipse.swt.widgets.Shell;
19
20 import org.eclipse.jface.text.IInformationControl;
21 import org.eclipse.jface.text.IInformationControlCreator;
22 import org.eclipse.jface.text.IInformationControlCreatorExtension;
23
24 import org.eclipse.jdt.internal.ui.text.java.hover.SourceViewerInformationControl;
25
26
27 final public class TemplateInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension {
28
29     private SourceViewerInformationControl fControl;
30
31     /**
32      * The orientation to be used by this hover.
33      * Allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
34      * @since 3.2
35      */

36     private int fOrientation;
37
38     /**
39      * @param orientation the orientation, allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
40      */

41     public TemplateInformationControlCreator(int orientation) {
42         Assert.isLegal(orientation == SWT.RIGHT_TO_LEFT || orientation == SWT.LEFT_TO_RIGHT);
43         fOrientation= orientation;
44     }
45
46     /*
47      * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
48      */

49     public IInformationControl createInformationControl(Shell parent) {
50         fControl= new SourceViewerInformationControl(parent, SWT.TOOL | fOrientation, SWT.NONE);
51         fControl.addDisposeListener(new DisposeListener() {
52             public void widgetDisposed(DisposeEvent e) {
53                 fControl= null;
54             }
55         });
56         return fControl;
57     }
58
59     /*
60      * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReuse(org.eclipse.jface.text.IInformationControl)
61      */

62     public boolean canReuse(IInformationControl control) {
63         return fControl == control && fControl != null;
64     }
65
66     /*
67      * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReplace(org.eclipse.jface.text.IInformationControlCreator)
68      */

69     public boolean canReplace(IInformationControlCreator creator) {
70         return (creator != null && getClass() == creator.getClass());
71     }
72 }
73
Popular Tags