예제 #1
0
파일: UIUtils.java 프로젝트: ralic/dbeaver
 @Nullable
 public static ISelectionProvider getSelectionProvider(IServiceLocator serviceLocator) {
   ISelectionProvider selectionProvider = serviceLocator.getService(ISelectionProvider.class);
   if (selectionProvider != null) {
     return selectionProvider;
   }
   IWorkbenchPartSite partSite = getWorkbenchPartSite(serviceLocator);
   if (partSite == null) {
     IWorkbenchPart activePart = serviceLocator.getService(IWorkbenchPart.class);
     if (activePart == null) {
       IWorkbenchWindow activeWindow = DBeaverUI.getActiveWorkbenchWindow();
       if (activeWindow != null) {
         activePart = activeWindow.getActivePage().getActivePart();
       }
     }
     if (activePart != null) {
       partSite = activePart.getSite();
     }
   }
   if (partSite != null) {
     return partSite.getSelectionProvider();
   } else {
     return null;
   }
 }
예제 #2
0
파일: UIUtils.java 프로젝트: ralic/dbeaver
 /**
  * Eclipse hack. Disables/enabled all key bindings in specified site's part. Works only if host
  * editor is extender of AbstractTextEditor Uses reflection because setActionActivation is private
  * method TODO: find better way to disable key bindings or prioritize event handling to widgets
  *
  * @param partSite workbench part site
  * @param enable enable or disable
  */
 @Deprecated
 public static void enableHostEditorKeyBindings(IWorkbenchPartSite partSite, boolean enable) {
   IWorkbenchPart part = partSite.getPart();
   if (part instanceof AbstractTextEditor) {
     AbstractTextEditor hostEditor = (AbstractTextEditor) part;
     if (hostEditor instanceof BaseTextEditor) {
       StyledText textWidget = ((BaseTextEditor) hostEditor).getTextViewer().getTextWidget();
       if (textWidget == null || textWidget.isDisposed()) {
         return;
       }
     }
     try {
       Method activatorMethod =
           AbstractTextEditor.class.getDeclaredMethod("setActionActivation", Boolean.TYPE);
       activatorMethod.setAccessible(true);
       activatorMethod.invoke(hostEditor, enable);
     } catch (Throwable e) {
       if (e instanceof InvocationTargetException) {
         e = ((InvocationTargetException) e).getTargetException();
       }
       log.warn("Can't disable text editor action activations", e);
     }
     // hostEditor.getEditorSite().getActionBarContributor().setActiveEditor(hostEditor);
   }
 }
예제 #3
0
파일: UIUtils.java 프로젝트: ralic/dbeaver
  public static void enableHostEditorKeyBindingsSupport(
      final IWorkbenchPartSite partSite, Control control) {
    if (!(partSite.getPart() instanceof AbstractTextEditor)) {
      return;
    }

    final boolean[] activated = new boolean[] {false};
    control.addFocusListener(
        new FocusListener() {
          @Override
          public void focusGained(FocusEvent e) {
            if (!activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, false);
              activated[0] = true;
            }
          }

          @Override
          public void focusLost(FocusEvent e) {
            if (activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, true);
              activated[0] = false;
            }
          }
        });
    control.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            if (activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, true);
              activated[0] = false;
            }
          }
        });
  }