Search in sources :

Example 1 with JUndoableCayenneTextPane

use of org.apache.cayenne.modeler.util.JUndoableCayenneTextPane in project cayenne by apache.

the class EjbqlQueryScriptsTab method initView.

private void initView() {
    scriptArea = new JUndoableCayenneTextPane(new EJBQLSyntaxConstant());
    scriptArea.getDocument().addDocumentListener(this);
    scriptArea.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            try {
                String text = scriptArea.getDocument().getText(e.getOffset(), 1);
                if (text.equals(" ") || text.equals("\n") || text.equals("\t")) {
                    getQuery().setEjbql(scriptArea.getDocumentTextDirect());
                    validateEJBQL();
                }
            } catch (BadLocationException ex) {
                logger.warn("Error reading document", ex);
            }
        }

        public void removeUpdate(DocumentEvent e) {
            getQuery().setEjbql(scriptArea.getDocumentTextDirect());
            validateEJBQL();
        }
    });
    scriptArea.getPane().addFocusListener(new FocusListener() {

        EJBQLValidationThread thread;

        public void focusGained(FocusEvent e) {
            thread = new EJBQLValidationThread();
            thread.start();
        }

        public void focusLost(FocusEvent e) {
            thread.terminate();
        }
    });
    scriptArea.getPane().addKeyListener(new KeyListener() {

        boolean pasteOrCut;

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_END || e.getKeyCode() == KeyEvent.VK_HOME || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT || e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_UNDO) {
                getQuery().setEjbql(scriptArea.getText());
                validateEJBQL();
            }
            if ((e.getKeyCode() == KeyEvent.VK_V || e.getKeyCode() == KeyEvent.VK_X) && e.isControlDown()) {
                pasteOrCut = true;
            }
        }

        public void keyReleased(KeyEvent e) {
            if ((pasteOrCut && e.getKeyCode() == KeyEvent.VK_CONTROL) || e.getKeyCode() == KeyEvent.VK_DELETE) {
                scriptArea.removeHighlightText();
                getQuery().setEjbql(scriptArea.getText());
                validateEJBQL();
                pasteOrCut = false;
            }
        }

        public void keyTyped(KeyEvent e) {
        }
    });
    setLayout(new BorderLayout());
    add(scriptArea, BorderLayout.WEST);
    add(scriptArea.getScrollPane(), BorderLayout.CENTER);
    setVisible(true);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) DocumentEvent(javax.swing.event.DocumentEvent) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) JUndoableCayenneTextPane(org.apache.cayenne.modeler.util.JUndoableCayenneTextPane) KeyListener(java.awt.event.KeyListener) EJBQLSyntaxConstant(org.apache.cayenne.swing.components.textpane.syntax.EJBQLSyntaxConstant) FocusListener(java.awt.event.FocusListener) BadLocationException(javax.swing.text.BadLocationException)

Example 2 with JUndoableCayenneTextPane

use of org.apache.cayenne.modeler.util.JUndoableCayenneTextPane in project cayenne by apache.

the class SQLTemplateScriptsTab method initView.

protected void initView() {
    // create widgets, etc.
    scriptRefreshHandler = new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                displayScript();
            }
        }
    };
    scripts = new JList<>();
    scripts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    scripts.setCellRenderer(new DbAdapterListRenderer(DbAdapterInfo.getStandardAdapterLabels()));
    keys = new ArrayList<>(DbAdapterInfo.getStandardAdapters().length + 1);
    keys.addAll(Arrays.asList(DbAdapterInfo.getStandardAdapters()));
    Collections.sort(keys);
    keys.add(0, DEFAULT_LABEL);
    scripts.setModel(new DefaultComboBoxModel<>(keys.toArray(new String[0])));
    // assemble
    cc = new CellConstraints();
    textPane = new JUndoableCayenneTextPane(new SQLSyntaxConstants());
    textPane.setName(DEFAULT_LABEL);
    textPane.getDocument().addDocumentListener(new CustomListener(textPane.getName()));
    panes = new ArrayList<>();
    panes.add(textPane);
    builder = new PanelBuilder(new FormLayout("fill:100dlu, 3dlu, fill:100dlu:grow", "3dlu, fill:p:grow"));
    // orderings table must grow as the panel is resized
    builder.add(new JScrollPane(scripts, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), cc.xy(1, 2));
    builder.add(textPane.getPane(), cc.xy(3, 2));
    setLayout(new BorderLayout());
    add(builder.getPanel(), BorderLayout.CENTER);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JScrollPane(javax.swing.JScrollPane) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) SQLSyntaxConstants(org.apache.cayenne.swing.components.textpane.syntax.SQLSyntaxConstants) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) JUndoableCayenneTextPane(org.apache.cayenne.modeler.util.JUndoableCayenneTextPane) CellConstraints(com.jgoodies.forms.layout.CellConstraints)

Example 3 with JUndoableCayenneTextPane

use of org.apache.cayenne.modeler.util.JUndoableCayenneTextPane in project cayenne by apache.

the class SQLTemplateScriptsTab method displayScript.

/**
 * Shows selected script in the editor.
 */
void displayScript() {
    SQLTemplateDescriptor query = getQuery();
    if (query == null) {
        return;
    }
    String key = scripts.getSelectedValue();
    if (key == null) {
        return;
    }
    boolean exist = false;
    for (JCayenneTextPane textPane : panes) {
        if (textPane.getName().equals(key)) {
            exist = true;
            break;
        }
    }
    if (!exist) {
        JCayenneTextPane textPane = new JUndoableCayenneTextPane(new SQLSyntaxConstants());
        textPane.setName(key);
        textPane.getDocument().addDocumentListener(new CustomListener(textPane.getName()));
        builder.add(textPane.getPane(), cc.xy(3, 2));
        panes.add(textPane);
    }
    final String text = (key.equals(DEFAULT_LABEL)) ? query.getSql() : query.getAdapterSql().get(key);
    for (final JCayenneTextPane textPane : panes) {
        if (key.equals(textPane.getName())) {
            textPane.setDocumentTextDirect(text);
            textPane.getPane().setVisible(true);
            textPane.getPane().setEditable(true);
        } else {
            textPane.getPane().setVisible(false);
            textPane.getPane().setEditable(false);
        }
    }
}
Also used : SQLTemplateDescriptor(org.apache.cayenne.map.SQLTemplateDescriptor) JUndoableCayenneTextPane(org.apache.cayenne.modeler.util.JUndoableCayenneTextPane) SQLSyntaxConstants(org.apache.cayenne.swing.components.textpane.syntax.SQLSyntaxConstants) JCayenneTextPane(org.apache.cayenne.swing.components.textpane.JCayenneTextPane)

Aggregations

JUndoableCayenneTextPane (org.apache.cayenne.modeler.util.JUndoableCayenneTextPane)3 BorderLayout (java.awt.BorderLayout)2 SQLSyntaxConstants (org.apache.cayenne.swing.components.textpane.syntax.SQLSyntaxConstants)2 PanelBuilder (com.jgoodies.forms.builder.PanelBuilder)1 CellConstraints (com.jgoodies.forms.layout.CellConstraints)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 JScrollPane (javax.swing.JScrollPane)1 DocumentEvent (javax.swing.event.DocumentEvent)1 DocumentListener (javax.swing.event.DocumentListener)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 BadLocationException (javax.swing.text.BadLocationException)1 SQLTemplateDescriptor (org.apache.cayenne.map.SQLTemplateDescriptor)1 JCayenneTextPane (org.apache.cayenne.swing.components.textpane.JCayenneTextPane)1 EJBQLSyntaxConstant (org.apache.cayenne.swing.components.textpane.syntax.EJBQLSyntaxConstant)1