Пример #1
0
 @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
 @Nullable
 public static IViewPart findView(IWorkbenchWindow workbenchWindow, String viewId) {
   IViewReference[] references = workbenchWindow.getActivePage().getViewReferences();
   for (IViewReference ref : references) {
     if (ref.getId().equals(viewId)) {
       return ref.getView(false);
     }
   }
   return null;
 }
Пример #3
0
 @Nullable
 public static <T> T findView(IWorkbenchWindow workbenchWindow, Class<T> viewClass) {
   IViewReference[] references = workbenchWindow.getActivePage().getViewReferences();
   for (IViewReference ref : references) {
     IViewPart view = ref.getView(false);
     if (view != null && viewClass.isAssignableFrom(view.getClass())) {
       return viewClass.cast(view);
     }
   }
   return null;
 }
Пример #4
0
 public static void updateMainWindowTitle(IWorkbenchWindow window) {
   IProject activeProject = DBeaverCore.getInstance().getProjectRegistry().getActiveProject();
   IProduct product = Platform.getProduct();
   String title = product == null ? "Unknown" : product.getName(); // $NON-NLS-1$
   if (activeProject != null) {
     title += " - " + activeProject.getName(); // $NON-NLS-1$
   }
   IWorkbenchPage activePage = window.getActivePage();
   if (activePage != null) {
     IEditorPart activeEditor = activePage.getActiveEditor();
     if (activeEditor != null) {
       title += " - [ " + activeEditor.getTitle() + " ]";
     }
   }
   window.getShell().setText(title);
 }
Пример #5
0
 @Nullable
 public static IWorkbenchPartSite getWorkbenchPartSite(IServiceLocator serviceLocator) {
   IWorkbenchPartSite partSite = serviceLocator.getService(IWorkbenchPartSite.class);
   if (partSite == null) {
     IWorkbenchPart activePart = serviceLocator.getService(IWorkbenchPart.class);
     if (activePart == null) {
       IWorkbenchWindow workbenchWindow = DBeaverUI.getActiveWorkbenchWindow();
       if (workbenchWindow != null) {
         IWorkbenchPage activePage = workbenchWindow.getActivePage();
         if (activePage != null) {
           activePart = activePage.getActivePart();
         }
       }
     }
     if (activePart != null) {
       partSite = activePart.getSite();
     }
   }
   return partSite;
 }