001 /******************************************************************************
002 * Copyright (C) MActor Developers. All rights reserved. *
003 * ---------------------------------------------------------------------------*
004 * This file is part of MActor. *
005 * *
006 * MActor is free software; you can redistribute it and/or modify *
007 * it under the terms of the GNU General Public License as published by *
008 * the Free Software Foundation; either version 2 of the License, or *
009 * (at your option) any later version. *
010 * *
011 * MActor is distributed in the hope that it will be useful, *
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
014 * GNU General Public License for more details. *
015 * *
016 * You should have received a copy of the GNU General Public License *
017 * along with MActor; if not, write to the Free Software *
018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
019 ******************************************************************************/
020 package org.mactor.ui.gui.project.editors;
021
022 import java.awt.BorderLayout;
023
024 import javax.swing.BorderFactory;
025 import javax.swing.JButton;
026 import javax.swing.JLabel;
027 import javax.swing.JPanel;
028 import javax.swing.JTextArea;
029 import javax.swing.JTextField;
030
031 import org.dom4j.Element;
032 import org.mactor.framework.MactorException;
033 import org.mactor.framework.data.jdbc.JdbcUtil;
034 import org.mactor.framework.spec.GlobalConfig.Group;
035 import org.mactor.ui.gui.AsyncAction;
036 import org.mactor.ui.gui.project.ProjectTreeNode;
037
038 public class GlobalConfigGroupNodeEditor extends AbstractNodeEditor {
039 Element data;
040 JTextField sql = new JTextField("select 1 from dual", 30);
041 JTextArea out = new JTextArea(10, 60);
042 SimpleRowPanel dbTestPanel = new SimpleRowPanel();
043 JButton testDBConnection = new JButton(new AsyncAction("Test DB Connection", false, new AsyncAction.AsyncRunnable() {
044 public void run() {
045 try {
046 Group g = Group.loadGroup(data);
047 JdbcUtil util = new JdbcUtil(g.getRequieredValue("driver"), g.getRequieredValue("url"), g.getRequieredValue("username"), g.getRequieredValue("password"));
048 util.execSingleCellQuerySql(sql.getText());
049 out.setText("OK");
050 } catch (Exception e) {
051 out.setText("Failed with:" + e.getMessage());
052 }
053 };
054 }));
055 public GlobalConfigGroupNodeEditor() {
056 super(new BorderLayout());
057 JPanel bp = new JPanel(new BorderLayout());
058 dbTestPanel.add(new JLabel("Test SQL:"));
059 dbTestPanel.add(sql);
060 dbTestPanel.add(testDBConnection);
061 bp.add(dbTestPanel, BorderLayout.WEST);
062 add(bp, BorderLayout.NORTH);
063 out.setEditable(false);
064 out.setBackground(getBackground());
065 out.setBorder(BorderFactory.createEmptyBorder());
066 out.setWrapStyleWord(true);
067 add(out, BorderLayout.CENTER);
068 }
069 public void applyChanges() {
070 }
071 public void setConfig(NodeEditorConfig config) throws MactorException {
072 }
073 public void setData(ProjectTreeNode node) throws MactorException {
074 this.data = (Element) node.getModelObject();
075 boolean isDbG = EditorUtil.isGlobalConfigDBGroupElement(data);
076 out.setVisible(isDbG);
077 dbTestPanel.setVisible(isDbG);
078 }
079 }