/** Add the new exception in the content pane */
  private void addCustomException() {
    String customException = addNewExceptionField.getText().trim();
    Object[] currentElements = contentProvider.getElements(inputElement);

    ArrayList<Object> currentElementsList = new ArrayList<Object>();
    for (int i = 0; i < currentElements.length; ++i) {
      Object element = currentElements[i];
      currentElementsList.add(element);
    }

    if (customException.isEmpty()) {
      return;
    }

    if (!currentElementsList.contains(customException)) {
      getViewer().add(customException);
      addNewExceptionField.setText("");
      ((PyExceptionListProvider) contentProvider).addUserConfiguredException(customException);
    } else {
      IStatus status =
          new Status(
              IStatus.WARNING,
              DebugUIPlugin.getUniqueIdentifier(),
              "Duplicate: This exception already exists");
      DebugUIPlugin.errorDialog(
          getShell(),
          DebugUIPlugin.removeAccelerators("Add Custom User Exception"),
          "Error",
          status);
    }
  }
  private void loadViewPanesVisibility() {
    String visiblePanes =
        Platform.getPreferencesService()
            .getString(DebugUIPlugin.getUniqueIdentifier(), getVisibilityPrefId(), null, null);

    if (visiblePanes != null && visiblePanes.length() > 0) {
      StringTokenizer tokenizer = new StringTokenizer(visiblePanes, ","); // $NON-NLS-1$
      while (tokenizer.hasMoreTokens()) {
        String paneId = tokenizer.nextToken();
        fVisibleViewPanes.add(paneId);
      }
    } else {
      for (int i = 0; i < defaultVisiblePaneIds.length; i++) {
        fVisibleViewPanes.add(defaultVisiblePaneIds[i]);
      }
    }

    Enumeration<String> enumeration = fViewPaneControls.keys();
    while (enumeration.hasMoreElements()) {
      String paneId = enumeration.nextElement();
      boolean visible = false;
      if (fVisibleViewPanes.contains(paneId)) visible = true;

      Control control = fViewPaneControls.get(paneId);
      control.setVisible(visible);

      IMemoryViewPane viewPane = fViewPanes.get(paneId);
      viewPane.setVisible(visible);
    }

    fSashForm.layout();
  }
  protected void setSelectionToClient(
      VirtualTreeModelViewer virtualViewer, ILabelProvider labelProvider, VirtualItem findItem) {
    virtualViewer.getTree().setSelection(new VirtualItem[] {findItem});
    ModelDelta stateDelta = new ModelDelta(virtualViewer.getInput(), IModelDelta.NO_CHANGE);
    virtualViewer.saveElementState(TreePath.EMPTY, stateDelta, IModelDelta.SELECT);
    // Set the force flag to all select delta in order to override model's selection policy.
    stateDelta.accept(
        new IModelDeltaVisitor() {
          @Override
          public boolean visit(IModelDelta delta, int depth) {
            if ((delta.getFlags() & IModelDelta.SELECT) != 0) {
              ((ModelDelta) delta).setFlags(delta.getFlags() | IModelDelta.FORCE);
            }
            return true;
          }
        });
    fClientViewer.updateViewer(stateDelta);

    ISelection selection = fClientViewer.getSelection();
    if (!selection.isEmpty()
        && selection instanceof IStructuredSelection
        && ((IStructuredSelection) selection).getFirstElement().equals(findItem.getData())) {
    } else {
      DebugUIPlugin.errorDialog(
          fClientViewer.getControl().getShell(),
          ActionMessages.VirtualFindAction_0,
          MessageFormat.format(
              ActionMessages.VirtualFindAction_1, new Object[] {labelProvider.getText(findItem)}),
          new Status(
              IStatus.ERROR,
              DebugUIPlugin.getUniqueIdentifier(),
              ActionMessages.VirtualFindAction_1));
    }
  }
  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);
      }
    }
  }
  public VirtualFindAction(TreeModelViewer viewer) {
    fClientViewer = viewer;

    setText(ActionMessages.FindAction_0);
    setId(DebugUIPlugin.getUniqueIdentifier() + ".FindElementAction"); // $NON-NLS-1$
    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(this, IDebugHelpContextIds.FIND_ELEMENT_ACTION);
    setActionDefinitionId(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE);
    fClientViewer = viewer;
  }
 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);
     }
   }
 }
  private void loadOrientation() {
    fViewOrientation =
        Platform.getPreferencesService()
            .getInt(
                DebugUIPlugin.getUniqueIdentifier(),
                getOrientationPrefId(),
                HORIZONTAL_VIEW_ORIENTATION,
                null);

    for (int i = 0; i < fOrientationActions.length; i++) {
      if (fOrientationActions[i].getOrientation() == fViewOrientation) {
        fOrientationActions[i].run();
      }
    }
    updateOrientationActions();
  }
 /**
  * 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;
 }
 /**
  * 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;
 }
Пример #10
0
/**
 * Provides a dialog for changing the maximum length allowed in the detail pane
 *
 * @since 3.0
 */
public class DetailPaneMaxLengthDialog extends TrayDialog {

  private static final String SETTINGS_ID =
      DebugUIPlugin.getUniqueIdentifier() + ".MAX_DETAILS_LENGTH_DIALOG"; // $NON-NLS-1$

  private Text fTextWidget;
  private Text fErrorTextWidget;
  private String fErrorMessage;
  private String fValue;
  private IInputValidator fValidator;

  /**
   * Constructs a new dialog on the given shell.
   *
   * @param parent shell
   */
  public DetailPaneMaxLengthDialog(Shell parent) {
    super(parent);
    setShellStyle(getShellStyle() | SWT.RESIZE);
    fValue =
        Integer.toString(
            DebugUIPlugin.getDefault()
                .getPreferenceStore()
                .getInt(IDebugUIConstants.PREF_MAX_DETAIL_LENGTH));
    fValidator =
        new IInputValidator() {
          public String isValid(String newText) {
            try {
              int num = Integer.parseInt(newText);
              if (num < 0) {
                return VariablesViewMessages.DetailPaneMaxLengthDialog_2;
              }
            } catch (NumberFormatException e) {
              return VariablesViewMessages.DetailPaneMaxLengthDialog_3;
            }
            return null;
          }
        };
  }

  /* (non-Javadoc)
   * @see org.eclipse.ui.dialogs.SelectionDialog#getDialogBoundsSettings()
   */
  protected IDialogSettings getDialogBoundsSettings() {
    IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
    IDialogSettings section = settings.getSection(SETTINGS_ID);
    if (section == null) {
      section = settings.addNewSection(SETTINGS_ID);
    }
    return section;
  }

  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
   */
  protected Control createContents(Composite parent) {
    getShell().setText(VariablesViewMessages.DetailPaneMaxLengthDialog_0);
    Control contents = super.createContents(parent);
    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(getDialogArea(), IDebugHelpContextIds.DETAIL_PANE_MAX_LENGTH_ACTION);
    return contents;
  }

  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
   */
  protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    Label label = new Label(composite, SWT.WRAP);
    label.setText(VariablesViewMessages.DetailPaneMaxLengthDialog_1);
    GridData data =
        new GridData(
            GridData.GRAB_HORIZONTAL
                | GridData.GRAB_VERTICAL
                | GridData.HORIZONTAL_ALIGN_FILL
                | GridData.VERTICAL_ALIGN_CENTER);
    data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    label.setLayoutData(data);
    label.setFont(parent.getFont());
    fTextWidget = new Text(composite, SWT.SINGLE | SWT.BORDER);
    fTextWidget.setLayoutData(
        new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    fTextWidget.setText(fValue);
    fTextWidget.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            validateInput();
            fValue = fTextWidget.getText();
          }
        });
    fErrorTextWidget = new Text(composite, SWT.READ_ONLY);
    fErrorTextWidget.setLayoutData(
        new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    fErrorTextWidget.setBackground(
        fErrorTextWidget.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    setErrorMessage(fErrorMessage);
    applyDialogFont(composite);
    return composite;
  }

  /* (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();
  }

  /**
   * Returns the string typed into this input dialog.
   *
   * @return the input string
   * @since 3.3
   */
  public String getValue() {
    return fValue;
  }

  /**
   * Validates the current input
   *
   * @since 3.3
   */
  private void validateInput() {
    String errorMessage = null;
    if (fValidator != null) {
      errorMessage = fValidator.isValid(fTextWidget.getText());
    }
    setErrorMessage(errorMessage);
  }

  /**
   * Sets the current error message or none if null
   *
   * @param errorMessage
   * @since 3.3
   */
  public void setErrorMessage(String errorMessage) {
    fErrorMessage = errorMessage;
    if (fErrorTextWidget != null && !fErrorTextWidget.isDisposed()) {
      fErrorTextWidget.setText(
          errorMessage == null ? IInternalDebugCoreConstants.EMPTY_STRING : errorMessage);
      fErrorTextWidget.getParent().update();
      // Access the ok button by id, in case clients have overridden button creation.
      // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=113643
      Control button = getButton(IDialogConstants.OK_ID);
      if (button != null) {
        button.setEnabled(errorMessage == null);
      }
    }
  }
}