source: trunk/org.modelica.mdt.ui/src/org/modelica/mdt/ui/hover/ModelicaSourceHover.java

Last change on this file was 694, checked in by adrpo, 13 years ago
  • updates to org.modelica.mdt.ui


File size: 3.0 KB
Line 
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
12package org.modelica.mdt.ui.hover;
13
14import org.eclipse.swt.SWT;
15import org.eclipse.swt.widgets.Shell;
16
17import org.eclipse.jface.text.IInformationControl;
18import org.eclipse.jface.text.IInformationControlCreator;
19import org.eclipse.jface.text.IRegion;
20import org.eclipse.jface.text.ITextHoverExtension;
21import org.eclipse.jface.text.ITextHoverExtension2;
22import org.eclipse.jface.text.ITextViewer;
23import org.eclipse.jface.text.information.IInformationProviderExtension2;
24
25import org.eclipse.ui.IEditorPart;
26import org.eclipse.ui.part.IWorkbenchPartOrientation;
27import org.modelica.mdt.core.IModelicaElement;
28
29/**
30 * Provides source as hover info for Modelica elements.
31 */
32public class ModelicaSourceHover extends AbstractModelicaEditorTextHover
33    implements ITextHoverExtension, ITextHoverExtension2, IInformationProviderExtension2 {
34
35    /*
36     * @see ModelicaElementHover
37     */
38    protected String getHoverInfo(IModelicaElement[] result) {
39        int nResults= result.length;
40
41        if (nResults > 1)
42            return null;
43
44        IModelicaElement curr= result[0];
45        return curr.getElementName();
46    }
47
48
49    /*
50     * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
51     * @since 3.0
52     */
53    public IInformationControlCreator getHoverControlCreator() {
54        return new IInformationControlCreator() {
55            public IInformationControl createInformationControl(Shell parent) {
56                IEditorPart editor= getEditor(); 
57                int shellStyle= SWT.TOOL | SWT.NO_TRIM;
58                if (editor instanceof IWorkbenchPartOrientation)
59                    shellStyle |= ((IWorkbenchPartOrientation)editor).getOrientation();
60                return new SourceViewerInformationControl(parent, shellStyle, SWT.NONE, getTooltipAffordanceString());
61            }
62        };
63    }
64
65    /*
66     * @see IInformationProviderExtension2#getInformationPresenterControlCreator()
67     * @since 3.0
68     */
69    public IInformationControlCreator getInformationPresenterControlCreator() {
70        return new IInformationControlCreator() {
71            public IInformationControl createInformationControl(Shell parent) {
72                int style= SWT.V_SCROLL | SWT.H_SCROLL;
73                int shellStyle= SWT.RESIZE | SWT.TOOL;
74                IEditorPart editor= getEditor(); 
75                if (editor instanceof IWorkbenchPartOrientation)
76                    shellStyle |= ((IWorkbenchPartOrientation)editor).getOrientation();
77                return new SourceViewerInformationControl(parent, shellStyle, style);
78            }
79        };
80    }
81
82
83    public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion)
84    {
85        // TODO Auto-generated method stub
86        return getHoverInfo(textViewer, hoverRegion);
87    }
88}
Note: See TracBrowser for help on using the repository browser.