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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.text.template.contentassist;
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;
18 import org.eclipse.core.runtime.Assert;
20 import org.eclipse.jface.text.IInformationControl;
21 import org.eclipse.jface.text.IInformationControlCreator;
22 import org.eclipse.jface.text.IInformationControlCreatorExtension;
24 import org.eclipse.jdt.internal.ui.JavaPlugin;
25 import org.eclipse.jdt.internal.ui.text.java.hover.SourceViewerInformationControl;
28 public final class TemplateInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension {
30 private SourceViewerInformationControl fControl;
33 * The orientation to be used by this hover.
34 * Allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
37 private int fOrientation;
40 * @param orientation the orientation, allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
42 public TemplateInformationControlCreator(int orientation) {
43 Assert.isLegal(orientation == SWT.RIGHT_TO_LEFT || orientation == SWT.LEFT_TO_RIGHT);
44 fOrientation= orientation;
48 * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
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) {
61 * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReuse(org.eclipse.jface.text.IInformationControl)
63 public boolean canReuse(IInformationControl control) {
64 return fControl == control && fControl != null;
68 * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReplace(org.eclipse.jface.text.IInformationControlCreator)
70 public boolean canReplace(IInformationControlCreator creator) {
71 return (creator != null && getClass() == creator.getClass());