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