Example #1
0
 private void evaluateInternal() {
   String text = editorTextArea.getSelectedText();
   if (text == null || text.length() == 0) {
     text = editorTextArea.getText();
   }
   evaluateInternal(text);
 }
Example #2
0
 public void evaluate(final String sql) {
   int caretPosition = editorTextArea.getSelectionStart();
   if (caretPosition == editorTextArea.getSelectionEnd()) {
     String text = editorTextArea.getText();
     if ((caretPosition == 0 || text.charAt(caretPosition - 1) == '\n')
         && (text.length() <= caretPosition || text.charAt(caretPosition) == '\n')) {
       editorTextArea.insert(sql + '\n', caretPosition);
     }
   }
   evaluateInternal(sql);
 }
Example #3
0
 private int getWordStart() {
   int caretPosition = editorTextArea.getCaretPosition();
   int wordStart = caretPosition;
   while (wordStart > 0) {
     try {
       char c = editorTextArea.getText(wordStart - 1, 1).charAt(0);
       if (!Character.isLetterOrDigit(c) && c != '_') {
         break;
       }
     } catch (BadLocationException e) {
       e.printStackTrace();
     }
     wordStart--;
   }
   return wordStart;
 }
Example #4
0
  private void showCompletion() {
    try {
      int caretPosition = editorTextArea.getCaretPosition();
      int wordStart = getWordStart();
      CompletionCandidate[] words =
          getFilteredWords(wordStart, editorTextArea.getText(wordStart, caretPosition - wordStart));
      if (words.length == 0) {
        return;
      }
      final JPopupMenu w = new JPopupMenu();
      final JList jList = new JList(words);
      jList.setCellRenderer(
          new DefaultListCellRenderer() {
            private ImageIcon tableIcon =
                new ImageIcon(
                    getClass().getResource("/org/jooq/debug/console/resources/Table16.png"));
            private ImageIcon tableColumnIcon =
                new ImageIcon(
                    getClass().getResource("/org/jooq/debug/console/resources/TableColumn16.png"));
            private ImageIcon sqlIcon =
                new ImageIcon(
                    getClass().getResource("/org/jooq/debug/console/resources/SQL16.png"));

            @Override
            public Component getListCellRendererComponent(
                JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
              Component c =
                  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
              if (c instanceof JLabel) {
                Icon icon;
                switch (((CompletionCandidate) value).getKeyWordType()) {
                  case TABLE:
                    icon = tableIcon;
                    break;
                  case TABLE_COlUMN:
                    icon = tableColumnIcon;
                    break;
                  default:
                    icon = sqlIcon;
                    break;
                }
                ((JLabel) c).setIcon(icon);
              }
              return c;
            }
          });
      jList.setSelectedIndex(0);
      jList.addKeyListener(
          new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
              switch (e.getKeyCode()) {
                case KeyEvent.VK_PAGE_UP:
                case KeyEvent.VK_PAGE_DOWN:
                case KeyEvent.VK_UP:
                case KeyEvent.VK_DOWN:
                case KeyEvent.VK_HOME:
                case KeyEvent.VK_END:
                  return;
                case KeyEvent.VK_ESCAPE:
                  w.setVisible(false);
                  return;
                case KeyEvent.VK_ENTER:
                  editorTextArea.replaceRange(
                      ((CompletionCandidate) jList.getSelectedValue()).toString(),
                      getWordStart(),
                      editorTextArea.getCaretPosition());
                  w.setVisible(false);
                  return;
              }
              editorTextArea.dispatchEvent(
                  new KeyEvent(
                      editorTextArea,
                      e.getID(),
                      e.getWhen(),
                      e.getModifiers(),
                      e.getKeyCode(),
                      e.getKeyChar(),
                      e.getKeyLocation()));
              if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED
                  || e.getKeyCode() == KeyEvent.VK_LEFT
                  || e.getKeyCode() == KeyEvent.VK_RIGHT) {
                adjustListContent();
              }
            }

            @Override
            public void keyReleased(KeyEvent e) {
              switch (e.getKeyCode()) {
                case KeyEvent.VK_PAGE_UP:
                case KeyEvent.VK_PAGE_DOWN:
                case KeyEvent.VK_UP:
                case KeyEvent.VK_DOWN:
                case KeyEvent.VK_HOME:
                case KeyEvent.VK_END:
                case KeyEvent.VK_ESCAPE:
                case KeyEvent.VK_ENTER:
                  return;
              }
              editorTextArea.dispatchEvent(
                  new KeyEvent(
                      editorTextArea,
                      e.getID(),
                      e.getWhen(),
                      e.getModifiers(),
                      e.getKeyCode(),
                      e.getKeyChar(),
                      e.getKeyLocation()));
              if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED
                  || e.getKeyCode() == KeyEvent.VK_LEFT
                  || e.getKeyCode() == KeyEvent.VK_RIGHT) {
                adjustListContent();
              }
            }

            @Override
            public void keyTyped(KeyEvent e) {
              switch (e.getKeyCode()) {
                case KeyEvent.VK_PAGE_UP:
                case KeyEvent.VK_PAGE_DOWN:
                case KeyEvent.VK_UP:
                case KeyEvent.VK_DOWN:
                case KeyEvent.VK_HOME:
                case KeyEvent.VK_END:
                case KeyEvent.VK_ESCAPE:
                case KeyEvent.VK_ENTER:
                  return;
              }
              editorTextArea.dispatchEvent(
                  new KeyEvent(
                      editorTextArea,
                      e.getID(),
                      e.getWhen(),
                      e.getModifiers(),
                      e.getKeyCode(),
                      e.getKeyChar(),
                      e.getKeyLocation()));
              if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED
                  || e.getKeyCode() == KeyEvent.VK_LEFT
                  || e.getKeyCode() == KeyEvent.VK_RIGHT) {
                adjustListContent();
              }
            }

            private void adjustListContent() {
              try {
                int wordStart = getWordStart();
                CompletionCandidate[] words =
                    getFilteredWords(
                        wordStart,
                        editorTextArea.getText(
                            wordStart, editorTextArea.getCaretPosition() - wordStart));
                if (words.length == 0) {
                  w.setVisible(false);
                  return;
                }
                jList.setListData(words);
                jList.setSelectedIndex(0);
              } catch (BadLocationException e) {
                e.printStackTrace();
              }
            }
          });
      jList.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
              if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                editorTextArea.replaceRange(
                    ((CompletionCandidate) jList.getSelectedValue()).toString(),
                    getWordStart(),
                    editorTextArea.getCaretPosition());
                w.setVisible(false);
              }
            }
          });
      w.add(new JScrollPane(jList), BorderLayout.CENTER);
      w.setPreferredSize(new Dimension(200, 200));
      Rectangle position = editorTextArea.modelToView(caretPosition);
      w.show(editorTextArea, position.x + position.width, position.y + position.height);
      jList.requestFocus();
    } catch (BadLocationException e) {
      e.printStackTrace();
    }
  }
Example #5
0
 EditorPane(QueryExecutorCreator queryExecutorCreator) {
   super(new BorderLayout());
   this.queryExecutorCreator = queryExecutorCreator;
   setOpaque(false);
   JPanel northPanel = new JPanel(new BorderLayout());
   northPanel.setOpaque(false);
   JToolBar northWestPanel = new JToolBar();
   northWestPanel.setOpaque(false);
   northWestPanel.setFloatable(false);
   startButton =
       new JButton(
           new ImageIcon(getClass().getResource("/org/jooq/debug/console/resources/Play16.png")));
   startButton.setOpaque(false);
   startButton.setFocusable(false);
   //        startButton.setMargin(new Insets(2, 2, 2, 2));
   startButton.setToolTipText("Run the (selected) text (F5)");
   startButton.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           evaluateInternal();
         }
       });
   northWestPanel.add(startButton);
   stopButton =
       new JButton(
           new ImageIcon(getClass().getResource("/org/jooq/debug/console/resources/Stop16.png")));
   stopButton.setVisible(false);
   stopButton.setOpaque(false);
   stopButton.setFocusable(false);
   //        stopButton.setMargin(new Insets(2, 2, 2, 2));
   stopButton.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           closeLastExecution();
         }
       });
   northWestPanel.add(stopButton);
   northPanel.add(northWestPanel, BorderLayout.WEST);
   JPanel northEastPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 2));
   northEastPanel.setOpaque(false);
   JCheckBox limitCheckBox = new JCheckBox("Parse 10000 rows max", isUsingMaxRowCount);
   limitCheckBox.addItemListener(
       new ItemListener() {
         @Override
         public void itemStateChanged(ItemEvent e) {
           isUsingMaxRowCount = e.getStateChange() == ItemEvent.SELECTED;
         }
       });
   limitCheckBox.setOpaque(false);
   northEastPanel.add(limitCheckBox);
   northEastPanel.add(Box.createHorizontalStrut(5));
   northEastPanel.add(new JLabel("No display when rows >"));
   NumberFormat numberFormat = NumberFormat.getIntegerInstance();
   displayedRowCountField = new JFormattedTextField(numberFormat);
   displayedRowCountField.setHorizontalAlignment(JFormattedTextField.RIGHT);
   displayedRowCountField.setValue(100000);
   displayedRowCountField.setColumns(7);
   northEastPanel.add(displayedRowCountField);
   northPanel.add(northEastPanel, BorderLayout.CENTER);
   add(northPanel, BorderLayout.NORTH);
   editorTextArea = new SqlTextArea();
   editorTextArea.addKeyListener(
       new KeyAdapter() {
         @Override
         public void keyPressed(KeyEvent e) {
           boolean isControlDown = e.isControlDown();
           switch (e.getKeyCode()) {
             case KeyEvent.VK_SPACE:
               if (isControlDown) {
                 showCompletion();
               }
               break;
             case KeyEvent.VK_F5:
               if (startButton.isVisible()) {
                 evaluateInternal();
               }
               break;
             case KeyEvent.VK_ESCAPE:
               new Thread("SQLConsole - Interruption") {
                 @Override
                 public void run() {
                   closeLastExecution();
                 }
               }.start();
               break;
           }
         }
       });
   RTextScrollPane editorTextAreaScrollPane = new RTextScrollPane(editorTextArea);
   southPanel = new JPanel(new BorderLayout());
   southPanel.setOpaque(false);
   JSplitPane verticalSplitPane =
       new InvisibleSplitPane(
           JSplitPane.VERTICAL_SPLIT, true, editorTextAreaScrollPane, southPanel);
   verticalSplitPane.setOpaque(false);
   add(verticalSplitPane, BorderLayout.CENTER);
   verticalSplitPane.setDividerLocation(150);
 }
Example #6
0
 public void adjustDefaultFocus() {
   editorTextArea.requestFocusInWindow();
 }
Example #7
0
  public BreakpointHitEditor(
      final Debugger debugger,
      final DebuggerPane debuggerPane,
      final BreakpointHitNode breakpointHitNode) {
    super(new BorderLayout());
    setOpaque(false);
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setOpaque(false);
    JPanel breakpointHitExecutionPane = new JPanel(new GridBagLayout());
    breakpointHitExecutionPane.setBorder(BorderFactory.createEmptyBorder(2, 5, 5, 5));
    breakpointHitExecutionPane.setOpaque(false);
    hit = breakpointHitNode.getUserObject();
    int y = 0;
    breakpointHitExecutionPane.add(
        new JLabel("Query:"),
        new GridBagConstraints(
            0,
            y++,
            1,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));
    SqlTextArea sqlTextArea = new SqlTextArea();
    String sql = hit.getSQL();
    String parameterDescription = hit.getParameterDescription();
    if (parameterDescription != null) {
      sql += "\n -> " + parameterDescription;
    }
    sqlTextArea.setText(sql + "\n");
    sqlTextArea.setCaretPosition(0);
    breakpointHitExecutionPane.add(
        new RTextScrollPane(sqlTextArea),
        new GridBagConstraints(
            0,
            y++,
            1,
            1,
            1,
            1,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    if (hit.isBeforeExecution()) {
      replaceCheckbox = new JCheckBox("Replace with statement");
      replaceCheckbox.setOpaque(false);
      replaceCheckbox.addItemListener(
          new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
              adjustStates();
            }
          });
      breakpointHitExecutionPane.add(
          replaceCheckbox,
          new GridBagConstraints(
              0,
              y++,
              1,
              1,
              0,
              0,
              GridBagConstraints.WEST,
              GridBagConstraints.NONE,
              new Insets(5, 0, 0, 0),
              0,
              0));
      replaceTextArea = new SqlTextArea();
      replacePane = new RTextScrollPane(replaceTextArea);
      breakpointHitExecutionPane.add(
          replacePane,
          new GridBagConstraints(
              0,
              y++,
              1,
              1,
              1,
              1,
              GridBagConstraints.WEST,
              GridBagConstraints.BOTH,
              new Insets(2, 20, 0, 0),
              0,
              0));
    }
    JPanel executionTypePane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    // For now, this choice is not exposed.
    executionTypePane.setVisible(hit.isBeforeExecution());
    executionTypePane.setOpaque(false);
    ButtonGroup executionTypeGroup = new ButtonGroup();

    final JRadioButton executeTypeNoneRadioButton = new JRadioButton("Execute");
    executeTypeNoneRadioButton.setOpaque(false);
    executeTypeNoneRadioButton.setSelected(true);
    executionTypeGroup.add(executeTypeNoneRadioButton);
    executionTypePane.add(executeTypeNoneRadioButton);

    final JRadioButton executeTypeBreakRadioButton = new JRadioButton("Execute and break");
    executeTypeBreakRadioButton.setOpaque(false);
    executionTypeGroup.add(executeTypeBreakRadioButton);
    executionTypePane.add(executeTypeBreakRadioButton);

    final JRadioButton executeTypeSkipRadioButton = new JRadioButton("Skip");
    executeTypeSkipRadioButton.setOpaque(false);
    executionTypeGroup.add(executeTypeSkipRadioButton);
    executionTypePane.add(executeTypeSkipRadioButton);

    final JRadioButton executeTypeFailRadioButton = new JRadioButton("Throw exception");
    executeTypeFailRadioButton.setOpaque(false);
    executionTypeGroup.add(executeTypeFailRadioButton);
    executionTypePane.add(executeTypeFailRadioButton);

    breakpointHitExecutionPane.add(
        executionTypePane,
        new GridBagConstraints(
            0,
            y++,
            1,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 0, 0, 0),
            0,
            0));
    JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
    buttonPane.setOpaque(false);
    buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    JButton applyButton = new JButton("Proceed");
    applyButton.setOpaque(false);
    applyButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (hit.isBeforeExecution()) {
              String replacementSQL = null;
              ExecutionType type = RUN;
              if (executeTypeNoneRadioButton.isSelected()) {
                type = RUN;
                replacementSQL = replaceCheckbox.isSelected() ? replaceTextArea.getText() : null;
              } else if (executeTypeBreakRadioButton.isSelected()) {
                type = STEP;
                replacementSQL = replaceCheckbox.isSelected() ? replaceTextArea.getText() : null;
              } else if (executeTypeSkipRadioButton.isSelected()) {
                type = SKIP;
              } else if (executeTypeFailRadioButton.isSelected()) {
                type = FAIL;
              }

              hit.setExecutionType(type, replacementSQL);
            } else {
              hit.setExecutionType(RUN, null);
            }
            debuggerPane.proceedBreakpointHit(breakpointHitNode);
          }
        });
    buttonPane.add(applyButton);
    breakpointHitExecutionPane.add(
        buttonPane,
        new GridBagConstraints(
            0,
            y,
            1,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    adjustStates();
    tabbedPane.addTab("Execution", breakpointHitExecutionPane);
    tabbedPane.addTab(
        "Editor",
        new EditorsPane(
            new QueryExecutorCreator() {
              @Override
              public QueryExecutor createQueryExecutor() {
                return debugger.createBreakpointHitStatementExecutor(hit.getThreadID());
              }
            },
            false));
    add(tabbedPane);
  }