コード例 #1
0
  /* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */
  public void selectionChanged(SelectionChangedEvent event) {

    RuleViolation violation = selectedViolationFrom(event);
    if (violation == null) return;

    String varName = violation.getVariableName();
    if (StringUtil.isEmpty(varName)) return;

    int beginLine = violation.getBeginLine();
    int endLine = violation.getEndLine();

    if (beginLine != 0 && endLine != 0) {
      try {
        int offset = getDocument().getLineOffset(violation.getBeginLine() - 1);
        int length = getDocument().getLineOffset(violation.getEndLine()) - offset;
        highlight(offset, length);
      } catch (BadLocationException ble) {
        logError(
            StringKeys.ERROR_RUNTIME_EXCEPTION + "Exception when selecting a line in the editor",
            ble);
      }

      // showMethodToMarker(marker);
      showMethodToViolation(violation);

      // then we calculate and color _a possible_ Path
      // for this Error in the Dataflow
      DataflowGraph graph = graphViewer.getGraph();
      if (!graphViewer.isDisposed() && graph != null) {
        graph.markPath(beginLine, endLine, varName);
      }
    }
  }
コード例 #2
0
  /**
   * Shows or hides the DataflowAnomalyTable, set the right text for the button.
   *
   * @param isShown, true if the Table should be visible, false otherwise
   */
  private void showTableArea(boolean isShown) {
    tableViewer.setVisible(isShown);

    // if the AnomalyTable is visible, an Area is 50% of the View
    // set the new Size and update the SwitchButton's Label
    if (isShown) {
      ((GridData) graphViewer.getLayoutData()).horizontalSpan = 1;
      switchButton.setText(getString(StringKeys.VIEW_DATAFLOW_SWITCHBUTTON_HIDE));

      // refresh the table if it isn't refreshed yet.
      if (!isTableRefreshed) {
        refreshDFATable(getResource());
      }
    } else {
      ((GridData) graphViewer.getLayoutData()).horizontalSpan = 2;
      switchButton.setText(getString(StringKeys.VIEW_DATAFLOW_SWITCHBUTTON_SHOW));
    }

    // lay out to update the View
    dfaFrame.layout(true, true);
  }
コード例 #3
0
  /**
   * Shows the DataflowGraph (and Dataflow-Anomalies) for a Method.
   *
   * @param pmdMethod Method to show in the graph
   */
  protected void showMethod(final ASTMethodDeclaration pmdMethod) {
    if (pmdMethod != null) {

      String resourceString = getDocument().get();
      // give the Data to the GraphViewer
      graphViewer.setVisible(true);
      graphViewer.setData(pmdMethod, resourceString);
      graphViewer.addMouseListener(
          new MouseAdapter() {

            public void mouseDown(MouseEvent e) {
              int row = (int) ((double) e.y / DataflowGraphViewer.ROW_HEIGHT);
              graphViewer.getGraph().demark();
              graphViewer.getGraph().markNode(row);
              highlightLine(pmdMethod.getDataFlowNode().getFlow().get(row).getLine() - 1);
              tableViewer.getTable().deselectAll();
            }
          });
      showTableArea(isTableShown);
    }
  }
コード例 #4
0
  /* @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite) */
  @Override
  public void createControl(Composite parent) {
    dfaFrame = new Composite(parent, SWT.NONE);

    // //////////////////////////////////////////////////
    // upper title area

    Composite titleArea = new Composite(dfaFrame, SWT.NONE);
    GridData tableData = new GridData(GridData.FILL_HORIZONTAL);
    tableData.horizontalSpan = 2;
    titleArea.setLayoutData(tableData);
    titleArea.setLayout(new GridLayout(4, false));

    Label methodLabel = new Label(titleArea, 0);
    methodLabel.setText("Method: ");

    buildMethodSelector(titleArea);

    // a label for the spacing
    Label label = new Label(titleArea, SWT.NONE);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // the Button for showing or hiding the Anomaly-List
    switchButton = new Button(titleArea, SWT.RIGHT);
    switchButton.setLayoutData(new GridData(130, 25));
    switchButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent se) {
            isTableShown = !isTableShown;
            showTableArea(isTableShown);

            if (!isTableShown) {
              if (graphViewer == null || graphViewer.getGraph() == null) {
                return;
              }

              final DataflowGraph graph = graphViewer.getGraph();
              if (graph.isMarked()) {
                graph.demark();
              }
            }
          }
        });

    switchButton.setText(getString(StringKeys.VIEW_DATAFLOW_SWITCHBUTTON_SHOW));

    // //////////////////////////////////////////////////
    // the DataflowGraphViewer (left Part)
    graphViewer = new DataflowGraphViewer(dfaFrame, SWT.NONE);
    graphViewer.setVisible(false);

    // //////////////////////////////////////////////////
    // the DataflowAnomalyTable (right Part)
    tableViewer = new DataflowAnomalyTableViewer(dfaFrame, SWT.BORDER);
    tableViewer.addSelectionChangedListener(this);
    tableViewer.setContentProvider(new DataflowAnomalyTableContentProvider());
    tableViewer.setLabelProvider(new DataflowAnomalyTableLabelProvider());
    isTableRefreshed = false;

    GridLayout mainLayout = new GridLayout(2, true);
    mainLayout.horizontalSpacing = mainLayout.verticalSpacing = 7;
    mainLayout.marginWidth = 3;
    mainLayout.marginHeight = 3;
    dfaFrame.setLayout(mainLayout);

    // hide the table
    showTableArea(false);
    showFirstMethod();
  }