@Override
  public void init(IViewSite site) throws PartInitException {
    super.init(site);

    fViewCnt++;
    String secondaryId = site.getSecondaryId();
    if (secondaryId != null) MemoryViewIdRegistry.registerView(secondaryId);

    // only do this the first time
    // not sure if there is a bug in the UI... if the view is
    // not a primary view and if it's hidden, the view is not
    // init and created until it becomes visible.
    if (fViewCnt == 1) {
      // also try to find other views and register
      if (DebugUIPlugin.getActiveWorkbenchWindow() != null
          && DebugUIPlugin.getActiveWorkbenchWindow().getActivePage() != null) {
        IViewReference references[] =
            DebugUIPlugin.getActiveWorkbenchWindow().getActivePage().getViewReferences();
        for (int i = 0; i < references.length; i++) {
          if (references[i].getSecondaryId() != null) {
            MemoryViewIdRegistry.registerView(references[i].getSecondaryId());
          }
        }
      }
    }

    fSyncService = new MemoryViewSynchronizationService();
  }
 /**
  * Since these actions are re-created each time the run/debug as menu is filled, the enablement of
  * this action is static.
  */
 private void updateEnablement() {
   IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
   boolean enabled = false;
   if (wb != null) {
     IWorkbenchPage page = wb.getActivePage();
     if (page != null) {
       ISelection selection = page.getSelection();
       if (selection instanceof IStructuredSelection) {
         IStructuredSelection structuredSelection = (IStructuredSelection) selection;
         try {
           // check enablement logic, if any
           Expression expression = fShortcut.getShortcutEnablementExpression();
           if (expression == null) {
             enabled = !structuredSelection.isEmpty();
           } else {
             List list = structuredSelection.toList();
             IEvaluationContext context = new EvaluationContext(null, list);
             context.addVariable("selection", list); // $NON-NLS-1$
             enabled = fShortcut.evalEnablementExpression(context, expression);
           }
         } catch (CoreException e) {
         }
       } else {
         IEditorPart editor = page.getActiveEditor();
         if (editor != null) {
           enabled = true;
         }
       }
     }
   }
   setEnabled(enabled);
 }
 protected IStructuredSelection getCurrentSelection() {
   IWorkbenchPage page = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage();
   if (page != null) {
     ISelection selection = page.getSelection();
     if (selection instanceof IStructuredSelection) {
       return (IStructuredSelection) selection;
     }
   }
   return null;
 }
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
  */
 @Override
 public boolean select(Viewer viewer, Object parentElement, Object element) {
   if (element instanceof ILaunchConfigurationType) {
     return true;
   }
   if (element instanceof ILaunchConfiguration) {
     ILaunchConfiguration config = (ILaunchConfiguration) element;
     try {
       IResource[] resources = config.getMappedResources();
       if (resources == null) {
         return true;
       }
       IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
       if (window == null) {
         return true;
       }
       IWorkbenchPage page = window.getActivePage();
       if (page == null) {
         return true;
       }
       IWorkingSet[] wsets = page.getWorkingSets();
       if (wsets.length < 1) {
         return true;
       }
       // remove breakpoint working sets
       ArrayList<IWorkingSet> ws = new ArrayList<IWorkingSet>();
       for (int i = 0; i < wsets.length; i++) {
         if (!IDebugUIConstants.BREAKPOINT_WORKINGSET_ID.equals(wsets[i].getId())) {
           ws.add(wsets[i]);
         }
       }
       if (ws.isEmpty()) {
         return true;
       }
       for (int i = 0; i < resources.length; i++) {
         if (workingSetContains(ws.toArray(new IWorkingSet[ws.size()]), resources[i])) {
           return true;
         }
       }
     } catch (CoreException e) {
     }
   }
   return false;
 }
 /**
  * Runs with either the active editor or workbench selection.
  *
  * @see IAction#run()
  */
 public void run() {
   IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
   if (wb != null) {
     IWorkbenchPage page = wb.getActivePage();
     if (page != null) {
       if (page.getActivePart() == page.getActiveEditor()) {
         IEditorPart editor = page.getActiveEditor();
         if (editor != null) {
           fShortcut.launch(editor, fMode);
         }
       } else if (page.getActivePart() instanceof IJobSettingsView) {
         ISelection selection = ((IJobSettingsView) page.getActivePart()).getSelection();
         fShortcut.launch(selection, fMode);
       } else {
         ISelection selection = page.getSelection();
         if (selection instanceof IStructuredSelection) {
           fShortcut.launch(selection, fMode);
         }
       }
     }
   }
 }
Esempio n. 6
0
 public void run(IAction action) {
   ISelection selection = getCurrentSelection();
   if (selection == null) {
     IWorkbenchPage page = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage();
     if (page != null) {
       selection = page.getSelection();
     }
   }
   if (selection instanceof TextSelection) {
     TextSelection textSelection = (TextSelection) selection;
     IExpressionManager expressionManager = DebugPlugin.getDefault().getExpressionManager();
     String expression;
     try {
       expression = textSelection.getText();
       // create the new watch expression
       createExpression(expressionManager, expression);
     } catch (Exception e) {
       PHPDebugEPLPlugin.logError(e);
     }
   }
   displayResult(null);
 }