1 package com.bonevich.erj.ui;
2
3 import com.bonevich.erj.ErjConstants;
4 import com.bonevich.erj.app.Application;
5 import com.bonevich.erj.app.Project;
6 import com.bonevich.erj.db.DatabaseLogin;
7 import com.bonevich.erj.db.SupportedDatabase;
8
9 import javax.swing.*;
10 import java.awt.*;
11 import java.awt.event.*;
12 import java.io.File;
13 import java.util.Vector;
14
15 import javax.swing.border.*;
16
17 public class ProjectPropertiesDialog extends JDialog
18 implements ErjConstants
19 {
20 //////////////////////////////////////////////////////////
21 // Constants
22 public static final String NAME_STR = "Name: ";
23 public static final String AUTHOR_STR = "Author: ";
24 public static final String VERSION_STR = "Version: ";
25 public static final String JAR_STR = "JDBC Jar Path: ";
26 public static final String TARGET_DB_STR = "Target Database: ";
27 public static final String DESC_STR = "Description";
28 public static final String COMPONENTS_STR = "Project Components";
29 public static final String EDIT_STR = "Edit Project Properties";
30
31 //////////////////////////////////////////////////////////
32 // Attributes
33 private Project _project;
34
35 private JButton _okBtn = new JButton("OK");
36 private JButton _applyBtn = new JButton("Apply");
37 private JButton _cancelBtn = new JButton("Cancel");
38 private JTabbedPane _tabPane = new JTabbedPane(JTabbedPane.TOP);
39
40 private JPanel _propPane = new JPanel();
41 private JPanel _namePane = new JPanel();
42 private JLabel _nameLabel = new JLabel(NAME_STR);
43 private JTextField _nameText = new JTextField(30);
44 private JPanel _authorPane = new JPanel();
45 private JLabel _authorLabel = new JLabel(AUTHOR_STR);
46 private JTextField _authorText = new JTextField(30);
47 private JPanel _versionPane = new JPanel();
48 private JLabel _versionLabel = new JLabel(VERSION_STR);
49 private JTextField _versionText = new JTextField(30);
50 private JPanel _targetPane = new JPanel();
51 private JLabel _targetLabel = new JLabel(TARGET_DB_STR);
52 private JComboBox _targetList;
53 private JPanel _jarPane = new JPanel();
54 private JLabel _jarLabel = new JLabel(JAR_STR);
55 private JTextField _jarText = new JTextField(20);
56 private JButton _jarBrowseBtn = new JButton("Browse");
57 private JPanel _descPane = new JPanel();
58 private Border _descBrdr = BorderFactory.createTitledBorder(DESC_STR);
59 private JTextArea _descText = new JTextArea(5, 35);
60
61 {
62 _propPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
63 _nameLabel.setFont(EDITOR_FONT);
64 _nameLabel.setForeground(EDITOR_COLOR);
65 _authorLabel.setFont(EDITOR_FONT);
66 _authorLabel.setForeground(EDITOR_COLOR);
67 _versionLabel.setFont(EDITOR_FONT);
68 _versionLabel.setForeground(EDITOR_COLOR);
69 _targetLabel.setFont(EDITOR_FONT);
70 _targetLabel.setForeground(EDITOR_COLOR);
71 _jarLabel.setFont(EDITOR_FONT);
72 _jarLabel.setForeground(EDITOR_COLOR);
73 ((TitledBorder)_descBrdr).setTitleFont(EDITOR_FONT);
74 ((TitledBorder)_descBrdr).setTitleColor(EDITOR_COLOR);
75 }
76
77 private JFileChooser _jarPathChooser = new JFileChooser();
78
79 private JPanel _compPane = new JPanel();
80 private Border _compBrdr = BorderFactory.createTitledBorder(COMPONENTS_STR);
81 private JList _compList;
82
83 //////////////////////////////////////////////////////////
84 // Constructors
85 public ProjectPropertiesDialog(Project project)
86 {
87 super(ErjFrame.getInstance(), EDIT_STR, true);
88 _project = project;
89 setResizable(false);
90 initComponents();
91 updateUI();
92 }
93
94 private void initComponents()
95 {
96 initPropertiesTab();
97 initComponentsTab();
98
99 _tabPane.setSelectedComponent(_propPane);
100
101 pack();
102 setLocationRelativeTo(ErjFrame.getInstance());
103 addActionListeners();
104 }
105
106 private void initPropertiesTab()
107 {
108 _propPane.setLayout(new GridBagLayout());
109 GridBagConstraints constraints = new GridBagConstraints();
110
111 // name label and textbox
112 constraints.gridwidth = 1;
113 constraints.anchor = GridBagConstraints.WEST;
114 _propPane.add(_nameLabel, constraints);
115 _propPane.add(Box.createHorizontalStrut(10));
116 constraints.gridwidth = GridBagConstraints.REMAINDER;
117 _propPane.add(_nameText, constraints);
118
119 // author label and textbox
120 constraints.gridwidth = 1;
121 _propPane.add(_authorLabel, constraints);
122 _propPane.add(Box.createHorizontalStrut(10));
123 constraints.gridwidth = GridBagConstraints.REMAINDER;
124 _propPane.add(_authorText, constraints);
125
126 // version label and textbox
127 constraints.gridwidth = 1;
128 _propPane.add(_versionLabel, constraints);
129 _propPane.add(Box.createHorizontalStrut(10));
130 constraints.gridwidth = GridBagConstraints.REMAINDER;
131 _propPane.add(_versionText, constraints);
132
133 // target database label and combo-box
134 Vector dbNames = ErjFrame.getInstance().getApplication().getSupportedDatabaseNames();
135 _targetList = new JComboBox(dbNames);
136 _targetList.setEditable(false);
137
138 constraints.gridwidth = 1;
139 _propPane.add(_targetLabel, constraints);
140 _propPane.add(Box.createHorizontalStrut(10));
141 constraints.insets = new Insets(5,0,5,0);
142 constraints.gridwidth = GridBagConstraints.REMAINDER;
143 constraints.fill = GridBagConstraints.NONE;
144 _propPane.add(_targetList, constraints);
145
146 // jar path label, textbox, and browse button
147 constraints.gridwidth = 1;
148 constraints.insets = new Insets(0,0,0,0);
149 _propPane.add(_jarLabel, constraints);
150 _propPane.add(Box.createHorizontalStrut(10));
151 _propPane.add(_jarText, constraints);
152 _propPane.add(Box.createHorizontalStrut(10));
153 constraints.gridwidth = GridBagConstraints.REMAINDER;
154 constraints.fill = GridBagConstraints.NONE;
155 _propPane.add(_jarBrowseBtn, constraints);
156
157 // description text area and title border
158 _descPane.setLayout(new BorderLayout());
159 _descPane.setAlignmentX(Component.LEFT_ALIGNMENT);
160 _descPane.setBorder(_descBrdr);
161 _descText.setAlignmentX(Component.LEFT_ALIGNMENT);
162 _descText.setLineWrap(true);
163 _descText.setWrapStyleWord(true);
164 JScrollPane scrPane = new JScrollPane(_descText);
165 scrPane.setAlignmentX(Component.LEFT_ALIGNMENT);
166 scrPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
167 //scrPane.setPreferredSize(new Dimension(350, 100));
168 _descPane.add(scrPane, BorderLayout.CENTER);
169
170 constraints.gridwidth = GridBagConstraints.REMAINDER;
171 constraints.fill = GridBagConstraints.HORIZONTAL;
172 _propPane.add(_descPane, constraints);
173
174 // buttons
175 JPanel btnPane = new JPanel();
176 ((FlowLayout) btnPane.getLayout()).setAlignment(FlowLayout.CENTER);
177 btnPane.add(_okBtn);
178 btnPane.add(_applyBtn);
179 btnPane.add(_cancelBtn);
180
181 constraints.anchor = GridBagConstraints.SOUTH;
182 constraints.insets = new Insets(10,0,0,0);
183 constraints.fill = GridBagConstraints.HORIZONTAL;
184 constraints.gridwidth = 5;
185
186 _propPane.add(btnPane, constraints);
187
188 getContentPane().add(_tabPane, BorderLayout.CENTER);
189 _tabPane.addTab(
190 EDIT_STR,
191 null,
192 _propPane,
193 "Edit the name, author, version, and description of an ERJ project"
194 );
195 }
196
197 private void initComponentsTab()
198 {
199 _compList = new JList(_project.getComponents());
200 JScrollPane cmpPane = new JScrollPane(_compList);
201 cmpPane.setAlignmentX(Component.LEFT_ALIGNMENT);
202 cmpPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
203 _compPane.setBorder(_compBrdr);
204 _compPane.setLayout(new BorderLayout());
205 _compPane.add(cmpPane, BorderLayout.CENTER);
206
207 getContentPane().add(_tabPane, BorderLayout.CENTER);
208 _tabPane.addTab(
209 COMPONENTS_STR,
210 null,
211 _compPane,
212 "List of components in this ERJ project"
213 );
214 }
215
216 private void addActionListeners()
217 {
218 _jarBrowseBtn.addActionListener(
219 new ActionListener()
220 {
221 public void actionPerformed(ActionEvent e)
222 {
223 _jarPathChooser.addChoosableFileFilter(ErjFileFilter.JAR);
224 _jarPathChooser.addChoosableFileFilter(ErjFileFilter.ZIP);
225 _jarPathChooser.setFileFilter(ErjFileFilter.JAR);
226 int choice = _jarPathChooser.showOpenDialog(null);
227 if (choice == JFileChooser.APPROVE_OPTION)
228 {
229 File jarFile = _jarPathChooser.getSelectedFile();
230 _jarText.setText(jarFile.getAbsolutePath());
231 }
232 }
233 }
234 );
235
236 _okBtn.addActionListener(
237 new ActionListener()
238 {
239 public void actionPerformed(ActionEvent e)
240 {
241 //System.err.println("OK!! " + e.getSource());
242 updateProject();
243 dispose();
244 }
245 }
246 );
247
248 _applyBtn.addActionListener(
249 new ActionListener()
250 {
251 public void actionPerformed(ActionEvent e)
252 {
253 //System.err.println("Apply!! " + e.getSource());
254 updateProject();
255 }
256 }
257 );
258
259 _cancelBtn.addActionListener(
260 new ActionListener()
261 {
262 public void actionPerformed(ActionEvent e)
263 {
264 //System.err.println("Cancel!! " + e.getSource());
265 dispose();
266 }
267 }
268 );
269 }
270
271 private void updateUI()
272 {
273 _nameText.setText(_project.getName());
274 _authorText.setText(_project.getAuthor());
275 _versionText.setText(_project.getVersion());
276 DatabaseLogin target = _project.getTargetDatabase();
277 SupportedDatabase db = target.getSupportedDatabase();
278 if (db == null)
279 {
280 db = Application.getDefaultDatabase();
281 target.setSupportedDatabase(db);
282 }
283 _targetList.setSelectedItem(db.getDisplayName());
284 _jarText.setText(target.getJarPath());
285 _descText.setText(_project.getDescription());
286 }
287
288 private void updateProject()
289 {
290 _project.setName(_nameText.getText());
291 _project.setAuthor(_authorText.getText());
292 _project.setVersion(_versionText.getText());
293 _project.setDescription(_descText.getText());
294
295 // FIXME: need to throw up major warnings!
296 String dbName = (String) _targetList.getSelectedItem();
297 SupportedDatabase db = ErjFrame.getInstance().getApplication().getSupportedDatabase(dbName);
298 DatabaseLogin newTarget = db.createDatabaseLogin();
299 newTarget.setJarPath(_jarText.getText());
300 _project.setTargetDatabase(newTarget);
301 }
302
303 } /* end class ProjectPropertiesDialog */
This page was automatically generated by Maven