use of org.eclipse.ui.swt.IFocusService in project mylyn.docs by eclipse.
the class MarkupEditor method createSourceViewer.
@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
sourceViewerConfiguration.initializeDefaultFonts();
tabFolder = new CTabFolder(parent, SWT.BOTTOM);
{
sourceTab = new CTabItem(tabFolder, SWT.NONE);
updateSourceTabLabel();
viewer = new MarkupProjectionViewer(tabFolder, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles | SWT.WRAP);
sourceTab.setControl(((Viewer) viewer).getControl());
tabFolder.setSelection(sourceTab);
}
try {
previewTab = new CTabItem(tabFolder, SWT.NONE);
previewTab.setText(Messages.MarkupEditor_preview);
previewTab.setToolTipText(Messages.MarkupEditor_preview_tooltip);
browser = new Browser(tabFolder, SWT.NONE);
// bug 260479: open hyperlinks in a browser
browser.addLocationListener(new LocationListener() {
public void changed(LocationEvent event) {
event.doit = false;
}
public void changing(LocationEvent event) {
// if it looks like an absolute URL
if (event.location.matches("([a-zA-Z]{3,8})://?.*")) {
// $NON-NLS-1$
// workaround for browser problem (bug 262043)
// $NON-NLS-1$
int idxOfSlashHash = event.location.indexOf("/#");
if (idxOfSlashHash != -1) {
// allow javascript-based scrolling to work
if (!event.location.startsWith("file:///#")) {
// $NON-NLS-1$
event.doit = false;
}
return;
}
// workaround end
event.doit = false;
try {
PlatformUI.getWorkbench().getBrowserSupport().createBrowser(// $NON-NLS-1$
"org.eclipse.ui.browser").openURL(new URL(event.location));
} catch (Exception e) {
new URLHyperlink(new Region(0, 1), event.location).open();
}
}
}
});
previewTab.setControl(browser);
} catch (SWTError e) {
// disable preview, the exception is probably due to the internal browser not being available
if (previewTab != null) {
previewTab.dispose();
previewTab = null;
}
logPreviewTabUnavailable(e);
}
tabFolder.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent selectionevent) {
widgetSelected(selectionevent);
}
public void widgetSelected(SelectionEvent selectionevent) {
if (isShowingPreview()) {
updatePreview();
}
}
});
viewer.getTextWidget().addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
updateOutlineSelection();
}
});
viewer.getTextWidget().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (isRelevantKeyCode(e.keyCode)) {
updateOutlineSelection();
}
}
private boolean isRelevantKeyCode(int keyCode) {
// for some reason not all key presses result in a selection change
switch(keyCode) {
case SWT.ARROW_DOWN:
case SWT.ARROW_LEFT:
case SWT.ARROW_RIGHT:
case SWT.ARROW_UP:
case SWT.PAGE_DOWN:
case SWT.PAGE_UP:
return true;
}
return false;
}
});
viewer.getTextWidget().addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
updateOutlineSelection();
}
});
IFocusService focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
if (focusService != null) {
focusService.addFocusTracker(viewer.getTextWidget(), MarkupEditor.EDITOR_SOURCE_VIEWER);
}
viewer.getTextWidget().setData(MarkupLanguage.class.getName(), getMarkupLanguage());
viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
getSourceViewerDecorationSupport(viewer);
updateDocument();
if (preferencesListener == null) {
preferencesListener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (viewer.getTextWidget() == null || viewer.getTextWidget().isDisposed()) {
return;
}
if (isFontPreferenceChange(event)) {
viewer.getTextWidget().getDisplay().asyncExec(new Runnable() {
public void run() {
reloadPreferences();
}
});
}
}
};
WikiTextUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(preferencesListener);
}
return viewer;
}
use of org.eclipse.ui.swt.IFocusService in project mylyn.docs by eclipse.
the class MarkupTaskEditorExtension method createEditor.
@SuppressWarnings("unchecked")
@Override
public SourceViewer createEditor(TaskRepository taskRepository, Composite parent, int style, IAdaptable context) {
final MarkupLanguageType markupLanguageCopy = createRepositoryMarkupLanguage(taskRepository);
configureMarkupLanguage(taskRepository, markupLanguageCopy);
SourceViewer viewer = new MarkupSourceViewer(parent, null, style | SWT.WRAP, markupLanguageCopy);
// configure the viewer
MarkupSourceViewerConfiguration configuration = createSourceViewerConfiguration(taskRepository, viewer, context);
configuration.setEnableSelfContainedIncrementalFind(true);
configuration.setMarkupLanguage(markupLanguageCopy);
configuration.setShowInTarget(new ShowInTargetBridge(viewer));
viewer.configure(configuration);
// we want the viewer to show annotations
viewer.showAnnotations(true);
DefaultMarkerAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
MarkerAnnotationPreferences annotationPreferences = new MarkerAnnotationPreferences();
// configure viewer annotation/decoration support
final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(viewer, null, annotationAccess, EditorsUI.getSharedTextColors());
// hook the support up to the preference store
Iterator<AnnotationPreference> e = annotationPreferences.getAnnotationPreferences().iterator();
while (e.hasNext()) {
AnnotationPreference preference = e.next();
support.setAnnotationPreference(preference);
}
support.setCursorLinePainterPreferenceKeys(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR);
support.setMarginPainterPreferenceKeys(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN);
support.install(new EditorExtensionPreferenceStore(EditorsUI.getPreferenceStore(), viewer.getControl()));
viewer.getControl().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
support.dispose();
}
});
IFocusService focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
if (focusService != null) {
focusService.addFocusTracker(viewer.getTextWidget(), MarkupEditor.EDITOR_SOURCE_VIEWER);
}
viewer.getTextWidget().setData(MarkupLanguage.class.getName(), markupLanguageCopy);
viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
return viewer;
}
use of org.eclipse.ui.swt.IFocusService in project mylyn.docs by eclipse.
the class MarkupTaskEditorExtension method createViewer.
@Override
public SourceViewer createViewer(TaskRepository taskRepository, Composite parent, int style, IAdaptable context) {
if (markupLanguage == null) {
throw new IllegalStateException();
}
MarkupViewer markupViewer = new MarkupViewer(parent, null, style | SWT.FLAT | SWT.WRAP);
MarkupLanguageType markupLanguageCopy = createRepositoryMarkupLanguage(taskRepository);
configureMarkupLanguage(taskRepository, markupLanguageCopy);
markupViewer.setMarkupLanguage(markupLanguageCopy);
MarkupViewerConfiguration configuration = createViewerConfiguration(taskRepository, markupViewer, context);
configuration.setDisableHyperlinkModifiers(true);
configuration.setEnableSelfContainedIncrementalFind(true);
if (markupLanguageCopy instanceof AbstractMarkupLanguage && ((AbstractMarkupLanguage) markupLanguageCopy).isDetectingRawHyperlinks()) {
// bug 264612 don't detect hyperlinks twice
configuration.addHyperlinkDetectorDescriptorFilter(new DefaultHyperlinkDetectorDescriptorFilter(// $NON-NLS-1$
"org.eclipse.mylyn.tasks.ui.hyperlinks.detectors.url"));
}
markupViewer.configure(configuration);
markupViewer.setEditable(false);
markupViewer.getTextWidget().setCaret(null);
if (JFaceResources.getFontRegistry().hasValueFor(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_DEFAULT_FONT)) {
markupViewer.getTextWidget().setFont(JFaceResources.getFontRegistry().get(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_DEFAULT_FONT));
}
if (JFaceResources.getFontRegistry().hasValueFor(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_MONOSPACE_FONT)) {
markupViewer.setDefaultMonospaceFont(JFaceResources.getFontRegistry().get(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_MONOSPACE_FONT));
}
markupViewer.setStylesheet(WikiTextUiPlugin.getDefault().getPreferences().getStylesheet());
IFocusService focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
if (focusService != null) {
focusService.addFocusTracker(markupViewer.getTextWidget(), MARKUP_VIEWER);
}
markupViewer.getTextWidget().setData(ISourceViewer.class.getName(), markupViewer);
return markupViewer;
}
use of org.eclipse.ui.swt.IFocusService in project mylyn.docs by eclipse.
the class WikiTextSourceEditor method createSourceViewer.
@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
if (getMarkupLanguage() == null) {
// $NON-NLS-1$
setMarkupLanguage(ServiceLocator.getInstance().getMarkupLanguage("Textile"));
}
viewer = createMarkupSourceViewer(parent, ruler, styles);
IFocusService focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
if (focusService != null) {
focusService.addFocusTracker(viewer.getTextWidget(), EDITOR_SOURCE_VIEWER);
}
viewer.getTextWidget().setData(MarkupLanguage.class.getName(), getMarkupLanguage());
viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
viewer.getTextWidget().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
detectOutlineLocationChanged();
}
});
viewer.getTextWidget().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (isRelevantKeyCode(e.keyCode)) {
detectOutlineLocationChanged();
}
}
private boolean isRelevantKeyCode(int keyCode) {
// for some reason not all key presses result in a selection change
switch(keyCode) {
case SWT.ARROW_DOWN:
case SWT.ARROW_LEFT:
case SWT.ARROW_RIGHT:
case SWT.ARROW_UP:
case SWT.PAGE_DOWN:
case SWT.PAGE_UP:
return true;
}
return false;
}
});
viewer.getTextWidget().addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
detectOutlineLocationChanged();
}
});
getSourceViewerDecorationSupport(viewer);
updateDocument();
return viewer;
}
use of org.eclipse.ui.swt.IFocusService in project dbeaver by dbeaver.
the class UIUtils method addFocusTracker.
public static void addFocusTracker(IServiceLocator serviceLocator, String controlID, Control control) {
IFocusService focusService = serviceLocator.getService(IFocusService.class);
if (focusService == null) {
focusService = UIUtils.getActiveWorkbenchWindow().getService(IFocusService.class);
}
if (focusService != null) {
IFocusService finalFocusService = focusService;
finalFocusService.addFocusTracker(control, controlID);
control.addDisposeListener(e -> {
// Unregister from focus service
finalFocusService.removeFocusTracker(control);
});
} else {
log.debug("Focus service not found in " + serviceLocator);
}
}
Aggregations