Search in sources :

Example 1 with JCayenneTextPane

use of org.apache.cayenne.swing.components.textpane.JCayenneTextPane 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

SQLTemplateDescriptor (org.apache.cayenne.map.SQLTemplateDescriptor)1 JUndoableCayenneTextPane (org.apache.cayenne.modeler.util.JUndoableCayenneTextPane)1 JCayenneTextPane (org.apache.cayenne.swing.components.textpane.JCayenneTextPane)1 SQLSyntaxConstants (org.apache.cayenne.swing.components.textpane.syntax.SQLSyntaxConstants)1