/**
  * Compares two line breakpoints.
  *
  * @param b1
  * @param b2
  * @param name1
  * @param name2
  * @return
  */
 private int compareLineBreakpoints(IBreakpoint b1, IBreakpoint b2, String name1, String name2) {
   int colon1 = name1.indexOf(':');
   if (colon1 != -1) {
     int colon2 = name2.indexOf(':');
     if (colon2 != -1) {
       String upToColon1 = name1.substring(0, colon1);
       if (name2.startsWith(upToColon1)) {
         int l1 = 0;
         int l2 = 0;
         try {
           l1 = ((ILineBreakpoint) b1).getLineNumber();
         } catch (CoreException e) {
           DebugUIPlugin.log(e);
         }
         try {
           l2 = ((ILineBreakpoint) b2).getLineNumber();
         } catch (CoreException e) {
           DebugUIPlugin.log(e);
         }
         return l1 - l2;
       }
     }
   }
   return name1.compareTo(name2);
 }
  private void storeViewPaneVisibility() {
    fVisibleViewPanes.clear();
    StringBuffer visibleViewPanes = new StringBuffer();

    Enumeration<String> enumeration = fViewPaneControls.keys();

    while (enumeration.hasMoreElements()) {
      String paneId = enumeration.nextElement();

      Control control = fViewPaneControls.get(paneId);
      if (control.isVisible()) {
        visibleViewPanes.append(paneId);
        visibleViewPanes.append(","); // $NON-NLS-1$
        fVisibleViewPanes.add(paneId);
      }
    }
    IEclipsePreferences node = InstanceScope.INSTANCE.getNode(DebugUIPlugin.getUniqueIdentifier());
    if (node != null) {
      try {
        node.put(getVisibilityPrefId(), visibleViewPanes.toString());
        node.flush();
      } catch (BackingStoreException e) {
        DebugUIPlugin.log(e);
      }
    }
  }
Пример #3
0
  /**
   * Store renderings as preferences. If renderings are stored, renderings can be persisted even
   * after the memory view is closed.
   */
  private void storeRenderings() {
    Preferences prefs = DebugUIPlugin.getDefault().getPluginPreferences();
    String renderingsStr = IInternalDebugCoreConstants.EMPTY_STRING;
    try {
      renderingsStr = getRenderingsAsXML();
    } catch (IOException e) {
      DebugUIPlugin.log(e);
    } catch (ParserConfigurationException e) {
      DebugUIPlugin.log(e);
    } catch (TransformerException e) {
      DebugUIPlugin.log(e);
    }

    String prefid = getPrefId();

    if (renderingsStr != null) prefs.setValue(prefid, renderingsStr);
    else prefs.setToDefault(prefid);
  }
  @Override
  public void run() {
    final VirtualViewerListener listener = new VirtualViewerListener();
    VirtualTreeModelViewer virtualViewer = initVirtualViewer(fClientViewer, listener);

    ProgressMonitorDialog dialog =
        new TimeTriggeredProgressMonitorDialog(fClientViewer.getControl().getShell(), 500);
    final IProgressMonitor monitor = dialog.getProgressMonitor();
    dialog.setCancelable(true);

    try {
      dialog.run(
          true,
          true,
          new IRunnableWithProgress() {
            @Override
            public void run(final IProgressMonitor m)
                throws InvocationTargetException, InterruptedException {
              synchronized (listener) {
                listener.fProgressMonitor = m;
                listener.fProgressMonitor.beginTask(
                    DebugUIPlugin.removeAccelerators(getText()), listener.fRemainingUpdatesCount);
              }

              while ((!listener.fLabelUpdatesComplete || !listener.fViewerUpdatesComplete)
                  && !listener.fProgressMonitor.isCanceled()) {
                Thread.sleep(1);
              }
              synchronized (listener) {
                listener.fProgressMonitor = null;
              }
            }
          });
    } catch (InvocationTargetException e) {
      DebugUIPlugin.log(e);
      return;
    } catch (InterruptedException e) {
      return;
    }

    VirtualItem root = virtualViewer.getTree();
    if (!monitor.isCanceled()) {
      List<VirtualItem> list = new ArrayList<VirtualItem>();
      collectAllChildren(root, list);
      FindLabelProvider labelProvider = new FindLabelProvider(virtualViewer, list);
      VirtualItem result = performFind(list, labelProvider);
      if (result != null) {
        setSelectionToClient(virtualViewer, labelProvider, result);
      }
    }

    virtualViewer.removeLabelUpdateListener(listener);
    virtualViewer.removeViewerUpdateListener(listener);
    virtualViewer.dispose();
  }
Пример #5
0
 /* (non-Javadoc)
  * @see org.eclipse.jface.dialogs.Dialog#okPressed()
  */
 protected void okPressed() {
   String text = getValue();
   try {
     DebugUIPlugin.getDefault()
         .getPreferenceStore()
         .setValue(IDebugUIConstants.PREF_MAX_DETAIL_LENGTH, Integer.parseInt(text));
   } catch (NumberFormatException e) {
     DebugUIPlugin.log(e);
   }
   super.okPressed();
 }
 private void saveOrientation() {
   IEclipsePreferences node = InstanceScope.INSTANCE.getNode(DebugUIPlugin.getUniqueIdentifier());
   if (node != null) {
     try {
       node.putInt(getOrientationPrefId(), fViewOrientation);
       node.flush();
     } catch (BackingStoreException e) {
       DebugUIPlugin.log(e);
     }
   }
 }
 /**
  * If the dragged data is a structured selection, get any IVariables in it and create expressions
  * for each of them. Insert the created expressions at the currently selected target or add them
  * to the end of the collection if no target is selected.
  *
  * @param selection Structured selection containing IVariables
  * @return whether the drop was successful
  */
 private boolean performVariableOrWatchAdaptableDrop(IStructuredSelection selection) {
   List expressions = new ArrayList(selection.size());
   for (Iterator itr = selection.iterator(); itr.hasNext(); ) {
     Object element = itr.next();
     String expressionText = createExpressionString(element);
     if (expressionText != null) {
       IExpression expression = createExpression(expressionText);
       if (expression != null) {
         expressions.add(expression);
       } else {
         DebugUIPlugin.log(
             new Status(
                 IStatus.ERROR,
                 DebugUIPlugin.getUniqueIdentifier(),
                 "Drop failed.  Watch expression could not be created for the text "
                     + expressionText)); //$NON-NLS-1$
         return false;
       }
     } else {
       return false;
     }
   }
   if (expressions.size() == selection.size()) {
     IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager();
     if (manager instanceof ExpressionManager) {
       IExpression targetExpression = getTargetExpression(getCurrentTarget());
       if (targetExpression != null) {
         ((ExpressionManager) manager)
             .insertExpressions(
                 (IExpression[]) expressions.toArray(new IExpression[expressions.size()]),
                 targetExpression,
                 fInsertBefore);
       } else {
         ((ExpressionManager) manager)
             .addExpressions(
                 (IExpression[]) expressions.toArray(new IExpression[expressions.size()]));
       }
       return true;
     }
   }
   return false;
 }
  /**
   * Compares two breakpoints.
   *
   * @param b1
   * @param b2
   * @return
   */
  private int doCompare(IBreakpoint b1, IBreakpoint b2) {
    String text1 = IInternalDebugCoreConstants.EMPTY_STRING;
    String text2 = IInternalDebugCoreConstants.EMPTY_STRING;

    text1 += b1.getModelIdentifier();
    text2 += b2.getModelIdentifier();

    IMarker marker1 = b1.getMarker();
    IMarker marker2 = b2.getMarker();
    try {
      if (marker1.exists() && marker2.exists()) {
        text1 += SPACE + marker1.getType();
        text2 += SPACE + marker2.getType();
      }
    } catch (CoreException e) {
      DebugUIPlugin.log(e);
    }

    int result = text1.compareTo(text2);
    if (result != 0) {
      return result;
    }

    // model and type are the same
    if (fContext != null) {
      String name1 = fContext.getModelPresentation().getText(b1);
      String name2 = fContext.getModelPresentation().getText(b2);

      boolean lineBreakpoint = false;
      try {
        lineBreakpoint = marker1.isSubtypeOf(IBreakpoint.LINE_BREAKPOINT_MARKER);
      } catch (CoreException ce) {
      }
      if (lineBreakpoint) {
        return compareLineBreakpoints(b1, b2, name1, name2);
      }

      return name1.compareTo(name2);
    }

    return result;
  }
 /**
  * Creates a new watch expression from an IVariable using the watch expression factory adapter for
  * that variable.
  *
  * @param variable the variable to use to create the watch expression
  * @return the string to be used to create expression, return <code>null</code> if no expression
  *     is to be created
  */
 private String createExpressionString(Object element) {
   try {
     if (element instanceof IVariable) {
       IVariable variable = (IVariable) element;
       IWatchExpressionFactoryAdapter factory = getFactory(variable);
       String exp = variable.getName();
       if (factory != null) {
         // if a factory exists, use it to create expression,
         // otherwise just use variable name
         exp = factory.createWatchExpression(variable);
       }
       return exp;
     } else {
       IWatchExpressionFactoryAdapter2 factory2 = getFactory2(element);
       if (factory2 != null) {
         return factory2.createWatchExpression(element);
       }
     }
   } catch (CoreException e) {
     DebugUIPlugin.log(e.getStatus());
   }
   return null;
 }
 /**
  * Performs the drop when text was dragged. Creates a new watch expression from the text. Inserts
  * the expression at the currently selected target or adds it to the end of the collection if no
  * target is selected.
  *
  * @param text string to use to create the expression
  * @return whether the drop was successful
  */
 private boolean performTextDrop(String text) {
   IExpression expression = createExpression(text);
   if (expression != null) {
     IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager();
     if (manager instanceof ExpressionManager) {
       IExpression targetExpression = getTargetExpression(getCurrentTarget());
       if (targetExpression != null) {
         ((ExpressionManager) manager)
             .insertExpressions(new IExpression[] {expression}, targetExpression, fInsertBefore);
       } else {
         ((ExpressionManager) manager).addExpression(expression);
       }
       return true;
     }
   }
   DebugUIPlugin.log(
       new Status(
           IStatus.ERROR,
           DebugUIPlugin.getUniqueIdentifier(),
           "Drop failed.  Watch expression could not be created for the text "
               + text)); //$NON-NLS-1$
   return false;
 }
Пример #11
0
  /** Load renderings currently stored. */
  private void loadPersistedRenderings(String prefId) {
    String renderingsStr = DebugUIPlugin.getDefault().getPluginPreferences().getString(prefId);
    if (renderingsStr.length() == 0) {
      return;
    }
    Element root;
    try {
      root = DebugPlugin.parseDocument(renderingsStr);
    } catch (CoreException e) {
      DebugUIPlugin.logErrorMessage(
          "An exception occurred while loading memory renderings."); //$NON-NLS-1$
      return;
    }
    if (!root.getNodeName().equals(RENDERINGS_TAG)) {
      DebugUIPlugin.logErrorMessage(
          "Invalid format encountered while loading memory renderings."); //$NON-NLS-1$
      return;
    }
    NodeList list = root.getChildNodes();
    boolean renderingsAdded = false;
    for (int i = 0, numItems = list.getLength(); i < numItems; i++) {
      Node node = list.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        if (!element.getNodeName().equals(MEMORY_RENDERING_TAG)) {
          DebugUIPlugin.logErrorMessage(
              "Invalid XML element encountered while loading memory rendering."); //$NON-NLS-1$
          continue;
        }
        String memoryBlockHashCode = element.getAttribute(MEMORY_BLOCK);
        String renderingId = element.getAttribute(RENDERING_ID);

        IMemoryBlock[] memoryBlocks =
            DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks();
        IMemoryBlock memoryBlock = null;
        for (int j = 0; j < memoryBlocks.length; j++) {
          if (Integer.toString(memoryBlocks[j].hashCode()).equals(memoryBlockHashCode))
            memoryBlock = memoryBlocks[j];
        }

        if (memoryBlock != null) {
          IMemoryRenderingType[] types =
              DebugUITools.getMemoryRenderingManager().getRenderingTypes(memoryBlock);
          IMemoryRenderingType type = null;
          for (int k = 0; k < types.length; k++) {
            if (types[k].getId().equals(renderingId)) type = types[k];
          }

          // if memory block is not found, the rendering is no longer valid
          // simply ignore the rendering
          if (type != null) {
            try {

              IMemoryRendering rendering = type.createRendering();
              if (rendering != null) {
                rendering.init(fViewPane, memoryBlock);
                if (!fRenderings.contains(rendering)) {
                  fRenderings.add(rendering);
                  renderingsAdded = true;
                }
              }
            } catch (CoreException e1) {
              DebugUIPlugin.log(e1);
            }
          }
        }
      }
    }
    if (renderingsAdded) {
      DebugPlugin.getDefault().addDebugEventListener(this);
    }
  }