001: package com.xoetrope.carousel.services;
002:
003: import java.io.File;
004:
005: import java.awt.BorderLayout;
006: import java.awt.Color;
007: import java.awt.GridLayout;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.awt.event.ItemEvent;
011: import java.awt.event.ItemListener;
012: import javax.swing.JButton;
013: import javax.swing.JComboBox;
014: import javax.swing.JDialog;
015: import javax.swing.JLabel;
016: import javax.swing.JPanel;
017: import javax.swing.JTextField;
018: import javax.swing.border.LineBorder;
019:
020: import net.xoetrope.editor.project.XEditorProject;
021:
022: /**
023: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
024: * the GNU Public License (GPL), please see license.txt for more details. If
025: * you make commercial use of this software you must purchase a commercial
026: * license from Xoetrope.</p>
027: * <p> $Revision: 1.4 $</p>
028: */
029: public class DataSourceEditor extends JDialog implements
030: ActionListener, ItemListener {
031: JComboBox lstDataTypes;
032: JPanel pnlControls, pnlEditor, pnlHeader;
033: JButton btnSave, btnCancel;
034: JTextField txtDataSourceName;
035: boolean saveDetails = false;
036: public static final String DATA_STATIC = "Static";
037: public static final String DATA_DATABASE = "Database";
038: public static final String DATA_SOAP = "Soap";
039:
040: // Panel controls
041: JButton btnCreateStatic;
042: JPanel pnlStaticData;
043: JTextField txtStaticFileName;
044:
045: XEditorProject currentProject;
046:
047: public DataSourceEditor(XEditorProject project) {
048: currentProject = project;
049: pnlHeader = new JPanel(new GridLayout(2, 2));
050: pnlEditor = new JPanel();
051: pnlControls = new JPanel();
052: getContentPane().add(pnlHeader, BorderLayout.NORTH);
053: getContentPane().add(pnlEditor, BorderLayout.CENTER);
054: getContentPane().add(pnlControls, BorderLayout.SOUTH);
055:
056: String[] listData = { DATA_STATIC, DATA_DATABASE, DATA_SOAP };
057: lstDataTypes = new JComboBox(listData);
058: lstDataTypes.addItemListener(this );
059: txtDataSourceName = new JTextField();
060:
061: pnlHeader.add(new JLabel("Data source type"),
062: BorderLayout.CENTER);
063: pnlHeader.add(lstDataTypes);
064: pnlHeader.add(new JLabel("Data source name"),
065: BorderLayout.SOUTH);
066: pnlHeader.add(txtDataSourceName, BorderLayout.SOUTH);
067:
068: btnSave = new JButton("Save");
069: btnCancel = new JButton("Cancel");
070: pnlControls.add(btnSave);
071: pnlControls.add(btnCancel);
072: btnSave.addActionListener(this );
073: btnCancel.addActionListener(this );
074:
075: createPanels();
076: }
077:
078: private void createPanels() {
079: createStaticPanel();
080: }
081:
082: private void createStaticPanel() {
083: pnlStaticData = new JPanel(new GridLayout(2, 2));
084: pnlStaticData.setBorder(new LineBorder(Color.black));
085: txtStaticFileName = new JTextField();
086: btnCreateStatic = new JButton("Edit");
087: btnCreateStatic.addActionListener(this );
088: getContentPane().add(pnlStaticData);
089: pnlStaticData.add(new JLabel("File name"));
090: pnlStaticData.add(txtStaticFileName);
091: pnlStaticData.add(btnCreateStatic);
092: }
093:
094: public void actionPerformed(ActionEvent evt) {
095: if (evt.getSource().equals(btnSave)) {
096: saveDataSet();
097: saveDetails = true;
098: setVisible(false);
099: } else if (evt.getSource().equals(btnCancel)) {
100: saveDetails = false;
101: setVisible(false);
102: } else if (evt.getSource().equals(btnCreateStatic)) {
103: createStaticDataset();
104: }
105: }
106:
107: private void saveDataSet() {
108: String fileName = currentProject.getPath() + File.separator
109: + "resources" + File.separator
110: + txtStaticFileName.getText();
111: getModelManager().addStaticDataSource(
112: txtDataSourceName.getText(),
113: txtStaticFileName.getText());
114: getModelManager().writeDatasets(currentProject);
115: }
116:
117: private ModelManager getModelManager() {
118: RouteManager routeMgr = (RouteManager) currentProject
119: .getObject(ProjectRouteManager.ROUTE_MGR_LOOKUP);
120: return routeMgr.getModelMgr();
121: }
122:
123: private void createStaticDataset() {
124: String fileName = currentProject.getPath() + File.separator
125: + "resources" + File.separator
126: + txtStaticFileName.getText();
127: }
128:
129: public void itemStateChanged(ItemEvent evt) {
130: hidePanels();
131: String datatype = (String) lstDataTypes.getSelectedItem();
132: if (datatype.compareTo(DATA_STATIC) == 0) {
133: pnlStaticData.setVisible(true);
134: } else if (datatype.compareTo(DATA_DATABASE) == 0) {
135:
136: } else if (datatype.compareTo(DATA_SOAP) == 0) {
137:
138: }
139: }
140:
141: private void hidePanels() {
142: pnlStaticData.setVisible(false);
143: }
144:
145: public boolean addDataSource() {
146: setSize(300, 300);
147: setModal(true);
148: setVisible(true);
149: return saveDetails;
150: }
151:
152: String getDataSetName() {
153: return txtDataSourceName.getText();
154: }
155:
156: String getDatasetType() {
157: return (String) lstDataTypes.getSelectedItem();
158: }
159:
160: }
|