📄 hibern8ide.java
字号:
String key = (String) keys.next(); String queryString = (String) map.get(key); namedQueries.add(new NamedQueryAction(key, queryString)); } } if (map != null && map.size() == 0) { namedQueries.add(new JMenuItem("<<No named Queries>>")); } return namedQueries; } class NamedQueryAction extends AbstractAction { String query; NamedQueryAction(String name, String query) { super(name); this.query = query.trim(); } public void actionPerformed(ActionEvent e) { editor.setText(query); } } /** * @return */ private Container buildConfigGraph() { graph = new JGraph(); return new JScrollPane(graph); } /** * @return */ private Container buildConfigTree() { tree = new JTree(new DefaultTreeModel(null)); ToolTipManager.sharedInstance().registerComponent(tree); ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE); tree.setCellRenderer(new MappingsTreeCellRenderer()); tree.setDragEnabled(true); tree.setTransferHandler(new TransferHandler() { public int getSourceActions(JComponent c) { return COPY; } protected Transferable createTransferable(JComponent c) { if (c instanceof JTree) { JTree localTree = (JTree) c; TreePath[] paths = localTree.getSelectionPaths(); if (paths == null || paths.length == 0) { return null; } StringBuffer plainBuf = new StringBuffer(); StringBuffer htmlBuf = new StringBuffer(); for (int i = 0; i < paths.length; i++) { TreePath path = paths[i]; BaseNode node = (BaseNode) path.getLastPathComponent(); String label = node.getHQL(); plainBuf.append(label + "\n"); } // remove the last newline plainBuf.deleteCharAt(plainBuf.length() - 1); htmlBuf.append("</ul>\n</body>\n</html>"); localTree = null; return new StringSelection(plainBuf.toString()); } else { return null; } } }); tree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY()); if (path != null && (path.getLastPathComponent() instanceof BaseNode)) { executeQuery(((BaseNode) path.getLastPathComponent()).getHQL()); } } } }); return new JScrollPane(tree); } /** * @param node */ protected void executeQuery(String hql) { editor.setText(hql); } /** * @return */ private Container buildMessagePanel() { JList list = new JList(); errorList = new ErrorListModel(); list.setModel(errorList); list.setCellRenderer(new ErrorCellRenderer()); return new JScrollPane(list); } /** * @return */ private Container buildConfigPanel() { JPanel p = new ConfigurationUI(new ConfigurationUI.ConfigurationUIListener() { public void configurationChanged(File configfile, Properties props, List mappingFiles) { reconfig(configfile, props, mappingFiles); } }); return p; } /** * @return */ private Container buildHQLCommander() { StyledEditorKit kit = null; kit = new REHqlTypes.Kit(); editor = new JEditorPane(); editor.setEditorKit(kit); new DropTarget(editor, new DropTargetAdapter() { public void drop(DropTargetDropEvent e) { try { DataFlavor stringFlavor = DataFlavor.stringFlavor; Transferable tr = e.getTransferable(); if (e.isDataFlavorSupported(stringFlavor)) { String text = (String) tr.getTransferData(stringFlavor); e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); editor.setText(text); e.dropComplete(true); } else { e.rejectDrop(); } } catch (IOException ioe) { ioe.printStackTrace(); } catch (UnsupportedFlavorException ufe) { ufe.printStackTrace(); } } }); //editor.setPreferredSize(new Dimension()); editor.setMinimumSize(new Dimension(10, 10)); editor.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); //editor.setTokenMarker(new HQLTokenMarker()); Container panel = buildQueryPageViewer(queryPages); editorTableSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editor, panel); editorTableSplitPane.setOneTouchExpandable(true); JPanel p = new JPanel(new BorderLayout()); p.add(editorTableSplitPane, BorderLayout.CENTER); JToolBar tbar = new JToolBar(); tbar.setFloatable(false); history = new History(); final JComboBox box = new JComboBox(history); box.setEditable(false); box.setAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { editor.setText((String) box.getSelectedItem()); } }); tbar.add(executeAction); tbar.add(executeCriteriaAction); tbar.add(backHistoryAction); tbar.add(forwardHistoryAction); tbar.add(box); p.add(tbar, BorderLayout.NORTH); return p; } /** * @param queryPages * @return */ private Container buildQueryPageViewer(final QueryPageModel qPages) { final JTabbedPane pane = new JTabbedPane(); final Icon stickyIcon = new ImageIcon(Hibern8IDE.class.getResource("images/pindown.jpg")); final Icon nonStickyIcon = new ImageIcon(Hibern8IDE.class.getResource("images/pinup.jpg")); qPages.addListDataListener(new ListDataListener() { public void intervalAdded(ListDataEvent e) { contentsChanged(e); } public void intervalRemoved(ListDataEvent e) { contentsChanged(e); } public void contentsChanged(ListDataEvent e) { int oldIndex = pane.getSelectedIndex(); pane.removeAll(); for (Iterator iter = qPages.pages.iterator(); iter.hasNext();) { QueryPage element = (QueryPage) iter.next(); String tabTitle = element.getID() + ":" + element.getQueryString(); JComponent comp = null; Icon icon; if (element.isSticky()) { icon = stickyIcon; } else { icon = nonStickyIcon; } if (element.getExceptions().size() > 0) { JTextArea ta = new JTextArea(); StringBuffer str = new StringBuffer(); str.append(element.getExceptions().size() + " errors occurred while listing (and calling getPathNames).\n"); for (Iterator iterator = element.getExceptions().iterator(); iterator.hasNext();) { Throwable error = (Throwable) iterator.next(); str.append(error + "\n"); while(error != null && error.getCause()!=null && error.getCause()!=error) { error = error.getCause(); str.append(error + "\n"); } } ta.setText(str.toString()); comp = new JScrollPane(ta); } else { BeanTableModel btm = new BeanTableModel(); btm.setColumns(element.getPathNames()); btm.setData(element.getList()); final JTable table = new JTable(btm); // doubleclick and ENTER should do the same. final Action sel = new AbstractAction() { public void actionPerformed(ActionEvent ae) { int row = table.getSelectedRow(); int col = table.getSelectedColumn(); if (row >= 0 && col >= 0) { Object o = table.getModel().getValueAt(row, col); Inspector.basicInspect(o); } } }; table.registerKeyboardAction(sel, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent ae) { if (ae.getClickCount() == 2) { sel.actionPerformed(null); } } }); comp = new JScrollPane(table); } pane.addTab(tabTitle, icon, comp); } if (oldIndex < pane.getTabCount() && oldIndex >= 0) { pane.setSelectedIndex(oldIndex); } else if (pane.getTabCount() > 0) { pane.setSelectedIndex(pane.getTabCount() - 1); } } }); pane.addMouseListener(new MouseAdapter() { /* (non-Javadoc) * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent) */ /* (non-Javadoc) * @see java.awt.event.MouseAdapter#mouseReleased(java.awt.event.MouseEvent) */ public void mouseReleased(MouseEvent e) { handleMouse(e, true); } public void mouseClicked(MouseEvent e) { handleMouse(e, false); } private void handleMouse(final MouseEvent e, boolean toggleSticky) { final int i = ((TabbedPaneUI) pane.getUI()).tabForCoordinate(pane, e.getX(), e.getY()); QueryPage qp = null; if (i > -1) { qp = qPages.get(i); } final QueryPage actionQP = qp; if (e.isPopupTrigger()) { JPopupMenu pop = new JPopupMenu(); Action removeTab = new AbstractAction("Remove tab") { public void actionPerformed(ActionEvent ae) { if (i != -1) { qPages.remove(i); } } }; Action hqlToEditor = new AbstractAction("Copy HQL into editor") { public void actionPerformed(ActionEvent ae) { if (actionQP != null) { editor.setText(actionQP.getQueryString()); } } }; pop.add(hqlToEditor); pop.add(removeTab); pop.show(pane, e.getX(), e.getY()); } else if (toggleSticky && e.getButton() != MouseEvent.NOBUTTON) { if (actionQP != null) { actionQP.setSticky(!actionQP.isSticky()); qPages.update(i); } else { System.out.println("No QueryPage found at " + i); } } } }); return pane; } private void reportException(Throwable ef) { ef.printStackTrace(); errorList.addError(ef); messagesConfigTabs.setSelectedIndex(messagesConfigTabs.indexOfTab("Messages")); } private void reportInfo(String string) { errorList.addInfo(string); messagesConfigTabs.setSelectedIndex(messagesConfigTabs.indexOfTab("Messages")); } public class RunSchemaExport extends AbstractAction { RunSchemaExport() { super("Run schema export"); } public void actionPerformed(ActionEvent e) { try { int result = JOptionPane.showConfirmDialog(mainWindow, "Are you sure you want to (re)create the database schema ? All data can get lost!", "Create database schema", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { new SchemaExport(configuration).create(false, true); } } catch (HibernateException ef) { reportException(ef); } } } /** * @author max * */ public class ExecuteQuery extends AbstractAction { int execcount = 0; ExecuteQuery() { super("Execute query"); //initialize the action fields with what you want putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK)); putValue(ACTION_COMMAND_KEY, "execQuery"); putValue(LONG_DESCRIPTION, "Execute the HQL Query"); putValue(MNEMONIC_KEY, new Integer('q')); putValue(SHORT_DESCRIPTION, "Execute Query"); //putValue(SMALL_ICON, icon); } public void actionPerformed(ActionEvent e) { try { if (sf == null) { reportInfo("Hibernate not yet configured."); return; } Session session = sf.openSession(); QueryPage qp = new HQLQueryPage(session, editor.getText()); qp.setId(++execcount); queryPages.add(qp); history.addElement(editor.getText()); } catch (HibernateException e1) { reportException(e1); } } } public class ExecuteJava extends AbstractAction { int execcount = 0; ExecuteJava() { super("Execute Java"); //initialize the action fields with what you want putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK)); putValue(ACTION_COMMAND_KEY, "execJava"); putValue(LONG_DESCRIPTION, "Execute Java code and show the result"); putValue(MNEMONIC_KEY, new Integer('j')); putValue(SHORT_DESCRIPTION, "Execute Java"); //putValue(SMALL_ICON, icon); } public void actionPerformed(ActionEvent e) { try { if (sf == null) { reportInfo("Hibernate not yet configured."); return; } Session session = sf.openSession(); QueryPage qp = new JavaPage(session, editor.getText()); qp.setId(++execcount); queryPages.add(qp); history.addElement(editor.getText()); } catch (HibernateException e1) { reportException(e1); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -