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);
}
}
}
Aggregations