use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class TTCN3Editor method createPartControl.
@Override
public void createPartControl(final Composite parent) {
super.createPartControl(parent);
projectionViewer = (ProjectionViewer) getSourceViewer();
projectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
projectionSupport.install();
projectionViewer.doOperation(ProjectionViewer.TOGGLE);
annotationModel = projectionViewer.getProjectionAnnotationModel();
getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
TTCN3Editor.this.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
}
});
getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection.isEmpty() || !(selection instanceof TextSelection) || "".equals(((TextSelection) selection).getText())) {
return;
}
final TextSelection textSelection = (TextSelection) selection;
final int offset = textSelection.getOffset() + textSelection.getLength();
occurrencesMarker.markOccurences(getDocument(), offset);
}
});
IFile file = (IFile) getEditorInput().getAdapter(IFile.class);
if (file != null) {
EditorTracker.put(file, this);
}
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class TTCNPPEditor method createPartControl.
@Override
public void createPartControl(final Composite parent) {
super.createPartControl(parent);
projectionViewer = (ProjectionViewer) getSourceViewer();
projectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
projectionSupport.install();
projectionViewer.doOperation(ProjectionViewer.TOGGLE);
annotationModel = projectionViewer.getProjectionAnnotationModel();
getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
TTCNPPEditor.this.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
}
});
getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection.isEmpty() || !(selection instanceof TextSelection) || "".equals(((TextSelection) selection).getText())) {
return;
}
final TextSelection textSelection = (TextSelection) selection;
final int offset = textSelection.getOffset() + textSelection.getLength();
occurrencesMarker.markOccurences(getDocument(), offset);
}
});
IFile file = (IFile) getEditorInput().getAdapter(IFile.class);
if (file != null) {
EditorTracker.put(file, this);
}
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class GotoMatchingBracketAction method run.
@Override
public void run(final IAction action) {
if (targetEditor == null) {
return;
}
if (!selection.isEmpty()) {
if (selection instanceof TextSelection) {
TextSelection tSelection = (TextSelection) selection;
if (tSelection.getLength() != 0) {
return;
}
}
}
IDocument document = targetEditor.getDocument();
int carretOffset = targetEditor.getCarretOffset();
PairMatcher pairMatcher = new PairMatcher();
IRegion region = pairMatcher.match(document, carretOffset);
if (region == null) {
return;
}
int targetOffset;
if (region.getOffset() + 1 == carretOffset) {
targetOffset = region.getOffset() + region.getLength();
} else {
targetOffset = region.getOffset() + 1;
}
targetEditor.setCarretOffset(targetOffset);
targetEditor.selectAndReveal(targetOffset, 0);
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method doOpenDeclaration.
private final void doOpenDeclaration() {
if (targetEditor == null || !(targetEditor instanceof TTCNPPEditor)) {
return;
}
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
return;
}
if (!TITANNature.hasTITANNature(file.getProject())) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
return;
}
if (ResourceExclusionHelper.isExcluded(file)) {
MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
return;
}
IPreferencesService prefs = Platform.getPreferencesService();
boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
int offset;
if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
if (reportDebugInformation) {
TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
}
TextSelection tSelection = (TextSelection) selection;
offset = tSelection.getOffset() + tSelection.getLength();
} else {
offset = ((TTCNPPEditor) targetEditor).getCarretOffset();
}
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("Can not find the module.");
}
return;
}
IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
module.accept(visitor);
final Declaration decl = visitor.getReferencedDeclaration();
if (decl == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("No visible elements found");
}
return;
}
selectAndRevealDeclaration(decl.getIdentifier().getLocation());
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method doOpenDeclaration.
private final void doOpenDeclaration() {
if (targetEditor == null || !(targetEditor instanceof TTCN3Editor)) {
return;
}
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
return;
}
if (!TITANNature.hasTITANNature(file.getProject())) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
return;
}
if (ResourceExclusionHelper.isExcluded(file)) {
MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
return;
}
IPreferencesService prefs = Platform.getPreferencesService();
boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
int offset;
if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
if (reportDebugInformation) {
TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
}
TextSelection tSelection = (TextSelection) selection;
offset = tSelection.getOffset() + tSelection.getLength();
} else {
offset = ((TTCN3Editor) targetEditor).getCarretOffset();
}
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("The file " + file.getLocation() + "does not seem to contain a valid module.");
CompilationTimeStamp timestamp = projectSourceParser.getLastTimeChecked();
if (timestamp == null) {
TITANDebugConsole.println("The project " + file.getProject() + " was not yet analyzed semantically");
} else {
TITANDebugConsole.println("The project " + file.getProject() + " was last checked in " + projectSourceParser.getLastTimeChecked().toString());
}
}
return;
}
IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
module.accept(visitor);
final Declaration decl = visitor.getReferencedDeclaration();
if (decl == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("No visible elements found");
}
return;
}
selectAndRevealDeclaration(decl.getIdentifier().getLocation());
return;
}
Aggregations