1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.internal.ui.text.template.contentassist;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.core.runtime.Assert;

import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IInformationControlCreatorExtension;

import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.text.java.hover.SourceViewerInformationControl;


public final class TemplateInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension {

    private SourceViewerInformationControl fControl;

    /**
     * The orientation to be used by this hover.
     * Allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
     * @since 3.2
     */
    private int fOrientation;

    /**
     * @param orientation the orientation, allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
     */
    public TemplateInformationControlCreator(int orientation) {
        Assert.isLegal(orientation == SWT.RIGHT_TO_LEFT || orientation == SWT.LEFT_TO_RIGHT);
        fOrientation= orientation;
    }

    /*
     * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
     */
    public IInformationControl createInformationControl(Shell parent) {
        fControl= new SourceViewerInformationControl(parent, false, fOrientation, JavaPlugin.getAdditionalInfoAffordanceString());
        fControl.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
                fControl= null;
            }
        });
        return fControl;
    }

    /*
     * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReuse(org.eclipse.jface.text.IInformationControl)
     */
    public boolean canReuse(IInformationControl control) {
        return fControl == control && fControl != null;
    }

    /*
     * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReplace(org.eclipse.jface.text.IInformationControlCreator)
     */
    public boolean canReplace(IInformationControlCreator creator) {
        return (creator != null && getClass() == creator.getClass());
    }
}
			
			

Browsed Source: [clear]