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 | |
---|
12 | package org.modelica.mdt.ui.hover; |
---|
13 | |
---|
14 | import org.eclipse.swt.SWT; |
---|
15 | import org.eclipse.swt.widgets.Shell; |
---|
16 | |
---|
17 | import org.eclipse.jface.text.IInformationControl; |
---|
18 | import org.eclipse.jface.text.IInformationControlCreator; |
---|
19 | import org.eclipse.jface.text.IRegion; |
---|
20 | import org.eclipse.jface.text.ITextHoverExtension; |
---|
21 | import org.eclipse.jface.text.ITextHoverExtension2; |
---|
22 | import org.eclipse.jface.text.ITextViewer; |
---|
23 | import org.eclipse.jface.text.information.IInformationProviderExtension2; |
---|
24 | |
---|
25 | import org.eclipse.ui.IEditorPart; |
---|
26 | import org.eclipse.ui.part.IWorkbenchPartOrientation; |
---|
27 | import org.modelica.mdt.core.IModelicaElement; |
---|
28 | |
---|
29 | /** |
---|
30 | * Provides source as hover info for Modelica elements. |
---|
31 | */ |
---|
32 | public 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 | } |
---|