Commit e25dc99e authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Basic implementation of Ttcn3SourceViewerControl (issue #449)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent b3d1292d
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.designer.editors.controls;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
/**
* A custom TTCN3 source viewer control for the TTCN3 editor
* Used to display code fragments in a popup window (code peek)
*
* @author Miklos Magyari
*
*/
public class Ttcn3SourceViewControl implements IInformationControl {
private Shell myshell;
private SourceViewer viewer;
private int maxWidth = SWT.DEFAULT;
private int maxHeight = SWT.DEFAULT;
public Ttcn3SourceViewControl(Shell parent) {
myshell = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP | SWT.TOOL | SWT.LEFT_TO_RIGHT | SWT.RESIZE);
Composite composite = myshell;
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
composite.setLayoutData(gridData);
viewer = new SourceViewer(composite, null, 0);
viewer.setEditable(false);
StyledText st = viewer.getTextWidget();
gridData = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
st.setLayoutData(gridData);
st.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.character == 0x1B)
myshell.dispose();
}
@Override
public void keyReleased(KeyEvent e) {}
});
}
@Override
public void setInformation(String information) {
if (information == null) {
viewer.setInput(null);
return;
}
IDocument doc = new Document(information);
viewer.setInput(doc);
}
@Override
public void setSizeConstraints(int maxWidth, int maxHeight) {
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
}
@Override
public Point computeSizeHint() {
int x = SWT.DEFAULT;
int y = SWT.DEFAULT;
Point size = myshell.computeSize(x, y);
return size;
}
@Override
public void setVisible(boolean visible) {
myshell.setVisible(visible);
}
@Override
public void setSize(int width, int height) {
myshell.setSize(width, height);
}
@Override
public void setLocation(Point location) {
myshell.setLocation(location);
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void addDisposeListener(DisposeListener listener) {
// TODO Auto-generated method stub
}
@Override
public void removeDisposeListener(DisposeListener listener) {
// TODO Auto-generated method stub
}
@Override
public void setForegroundColor(Color foreground) {
// TODO Auto-generated method stub
}
@Override
public void setBackgroundColor(Color background) {
// TODO Auto-generated method stub
}
@Override
public boolean isFocusControl() {
// TODO Auto-generated method stub
return false;
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
@Override
public void addFocusListener(FocusListener listener) {
// TODO Auto-generated method stub
}
@Override
public void removeFocusListener(FocusListener listener) {
// TODO Auto-generated method stub
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment