use of org.apache.cayenne.swing.components.textpane.syntax.SQLSyntaxConstants 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);
}
use of org.apache.cayenne.swing.components.textpane.syntax.SQLSyntaxConstants 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