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