]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateInformationControlCreator.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / text / template / contentassist / TemplateInformationControlCreator.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 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.swt.SWT;
14 import org.eclipse.swt.events.DisposeEvent;
15 import org.eclipse.swt.events.DisposeListener;
16 import org.eclipse.swt.widgets.Shell;
17
18 import org.eclipse.core.runtime.Assert;
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.JavaPlugin;
25 import org.eclipse.jdt.internal.ui.text.java.hover.SourceViewerInformationControl;
26
27
28 public final class TemplateInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension {
29
30         private SourceViewerInformationControl fControl;
31
32         /**
33          * The orientation to be used by this hover.
34          * Allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
35          * @since 3.2
36          */
37         private int fOrientation;
38
39         /**
40          * @param orientation the orientation, allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
41          */
42         public TemplateInformationControlCreator(int orientation) {
43                 Assert.isLegal(orientation == SWT.RIGHT_TO_LEFT || orientation == SWT.LEFT_TO_RIGHT);
44                 fOrientation= orientation;
45         }
46
47         /*
48          * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
49          */
50         public IInformationControl createInformationControl(Shell parent) {
51                 fControl= new SourceViewerInformationControl(parent, false, fOrientation, JavaPlugin.getAdditionalInfoAffordanceString());
52                 fControl.addDisposeListener(new DisposeListener() {
53                         public void widgetDisposed(DisposeEvent e) {
54                                 fControl= null;
55                         }
56                 });
57                 return fControl;
58         }
59
60         /*
61          * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReuse(org.eclipse.jface.text.IInformationControl)
62          */
63         public boolean canReuse(IInformationControl control) {
64                 return fControl == control && fControl != null;
65         }
66
67         /*
68          * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReplace(org.eclipse.jface.text.IInformationControlCreator)
69          */
70         public boolean canReplace(IInformationControlCreator creator) {
71                 return (creator != null && getClass() == creator.getClass());
72         }
73 }