Search in sources :

Example 1 with SQLSyntaxConstants

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);
}
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 2 with SQLSyntaxConstants

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);
        }
    }
}
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)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 BorderLayout (java.awt.BorderLayout)1 JScrollPane (javax.swing.JScrollPane)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 SQLTemplateDescriptor (org.apache.cayenne.map.SQLTemplateDescriptor)1 JCayenneTextPane (org.apache.cayenne.swing.components.textpane.JCayenneTextPane)1