]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/packaging/ui/SpdPackageHeaders.java
Adapt to new Main UI interface.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / packaging / ui / SpdPackageHeaders.java
1 /** @file
2 Java class SpdPackageHeaders is GUI for create library definition elements of spd file.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 package org.tianocore.frameworkwizard.packaging.ui;
14
15 import java.awt.Dimension;
16 import java.awt.event.ActionEvent;
17 import java.awt.event.ComponentEvent;
18 import java.io.File;
19
20 import javax.swing.DefaultCellEditor;
21 import javax.swing.JFileChooser;
22 import javax.swing.JOptionPane;
23 import javax.swing.JPanel;
24 import javax.swing.JRadioButton;
25 import javax.swing.JTable;
26 import javax.swing.JTextField;
27 import javax.swing.JComboBox;
28 import javax.swing.JLabel;
29 import javax.swing.JScrollPane;
30 import javax.swing.JButton;
31 import javax.swing.JFrame;
32 import javax.swing.ListSelectionModel;
33 import javax.swing.event.InternalFrameAdapter;
34 import javax.swing.event.InternalFrameEvent;
35 import javax.swing.event.ListSelectionEvent;
36 import javax.swing.event.ListSelectionListener;
37 import javax.swing.event.TableModelEvent;
38 import javax.swing.event.TableModelListener;
39 import javax.swing.table.DefaultTableModel;
40 import javax.swing.table.TableColumn;
41 import javax.swing.table.TableModel;
42
43 import org.tianocore.PackageSurfaceAreaDocument;
44 import org.tianocore.frameworkwizard.common.DataValidation;
45 import org.tianocore.frameworkwizard.common.Tools;
46 import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageType;
47 import org.tianocore.frameworkwizard.common.ui.IInternalFrame;
48 import org.tianocore.frameworkwizard.common.ui.StarLabel;
49
50 /**
51 GUI for create library definition elements of spd file.
52
53 @since PackageEditor 1.0
54 **/
55 public class SpdPackageHeaders extends IInternalFrame implements TableModelListener{
56 /**
57 *
58 */
59 private static final long serialVersionUID = 1L;
60
61 static JFrame frame;
62
63 private SpdFileContents sfc = null;
64
65 private OpeningPackageType docConsole = null;
66
67 private DefaultTableModel model = null;
68
69 private JPanel jContentPane = null;
70
71 private JRadioButton jRadioButtonSelect = null;
72
73 private JComboBox jComboBoxSelect = null;
74
75 private JButton jButtonAdd = null;
76
77 private JButton jButtonRemove = null;
78
79 private JButton jButtonClearAll = null;
80
81 private JButton jButtonCancel = null;
82
83 private JButton jButtonOk = null;
84
85 private JLabel jLabel = null;
86
87 private JTextField jTextField = null;
88
89 private JButton jButtonBrowse = null;
90
91 private StarLabel jStarLabel1 = null;
92
93 private StarLabel jStarLabel2 = null;
94
95 private JScrollPane jScrollPane = null;
96
97 private JScrollPane jScrollPane1 = null;
98
99 private int selectedRow = -1;
100
101 private JTable jTable = null;
102
103
104
105 /**
106 This method initializes this
107
108 **/
109 private void initialize() {
110
111 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
112
113 }
114
115 /**
116 This method initializes jRadioButtonSelect
117
118 @return javax.swing.JRadioButton
119 **/
120 private JRadioButton getJRadioButtonSelect() {
121 if (jRadioButtonSelect == null) {
122 jRadioButtonSelect = new JRadioButton();
123 jRadioButtonSelect.setBounds(new java.awt.Rectangle(9,10,198,20));
124 jRadioButtonSelect.setText("Select Existing ModuleType");
125 jRadioButtonSelect.addActionListener(this);
126 jRadioButtonSelect.setSelected(true);
127 }
128 return jRadioButtonSelect;
129 }
130
131 /**
132 This method initializes jComboBoxSelect
133
134 @return javax.swing.JComboBox
135 **/
136 private JComboBox getJComboBoxSelect() {
137 if (jComboBoxSelect == null) {
138 jComboBoxSelect = new JComboBox();
139 jComboBoxSelect.setBounds(new java.awt.Rectangle(220, 10, 260, 20));
140 jComboBoxSelect.setPreferredSize(new java.awt.Dimension(260,20));
141
142 jComboBoxSelect.setEnabled(true);
143 }
144 return jComboBoxSelect;
145 }
146
147 /**
148 This method initializes jTable
149
150 @return javax.swing.JTable
151 *
152 private JTable getJTable() {
153 if (jTable == null) {
154 model = new PackageHeaderTableModel();
155 model.addColumn("ModuleType");
156 model.addColumn("IncludeHeader");
157
158
159 }
160 return jTable;
161 }*/
162 /**
163 This method initializes jButtonAdd
164
165 @return javax.swing.JButton
166 **/
167 private JButton getJButtonAdd() {
168 if (jButtonAdd == null) {
169 jButtonAdd = new JButton();
170 jButtonAdd.setBounds(new java.awt.Rectangle(189,119,73,20));
171 jButtonAdd.setText("Add");
172 jButtonAdd.addActionListener(this);
173 }
174 return jButtonAdd;
175 }
176
177 /**
178 This method initializes jButtonRemove
179
180 @return javax.swing.JButton
181 **/
182 private JButton getJButtonRemove() {
183 if (jButtonRemove == null) {
184 jButtonRemove = new JButton();
185 jButtonRemove.setBounds(new java.awt.Rectangle(271,119,87,20));
186 jButtonRemove.setText("Remove");
187 jButtonRemove.addActionListener(this);
188 }
189 return jButtonRemove;
190 }
191
192 /**
193 This method initializes jButtonRemoveAll
194
195 @return javax.swing.JButton
196 **/
197 private JButton getJButtonClearAll() {
198 if (jButtonClearAll == null) {
199 jButtonClearAll = new JButton();
200 jButtonClearAll.setBounds(new java.awt.Rectangle(374,119,90,20));
201 jButtonClearAll.setText("Clear All");
202 jButtonClearAll.addActionListener(this);
203 }
204 return jButtonClearAll;
205 }
206
207 /**
208 This method initializes jButtonCancel
209
210 @return javax.swing.JButton
211 **/
212 private JButton getJButtonCancel() {
213 if (jButtonCancel == null) {
214 jButtonCancel = new JButton();
215 jButtonCancel.setPreferredSize(new java.awt.Dimension(90, 20));
216 jButtonCancel.setLocation(new java.awt.Point(390, 305));
217 jButtonCancel.setText("Cancel");
218 jButtonCancel.setSize(new java.awt.Dimension(90, 20));
219 jButtonCancel.setVisible(false);
220 jButtonCancel.addActionListener(this);
221 }
222 return jButtonCancel;
223 }
224
225 /**
226 This method initializes jButton
227
228 @return javax.swing.JButton
229 **/
230 private JButton getJButtonOk() {
231 if (jButtonOk == null) {
232 jButtonOk = new JButton();
233 jButtonOk.setSize(new java.awt.Dimension(90, 20));
234 jButtonOk.setText("OK");
235 jButtonOk.setLocation(new java.awt.Point(290, 305));
236 jButtonOk.setVisible(false);
237 jButtonOk.addActionListener(this);
238 }
239 return jButtonOk;
240 }
241
242 /**
243 This is the default constructor
244 **/
245 public SpdPackageHeaders() {
246 super();
247 initialize();
248 init();
249
250 }
251
252 public SpdPackageHeaders(PackageSurfaceAreaDocument.PackageSurfaceArea inPsa){
253 this();
254 sfc = new SpdFileContents(inPsa);
255 init(sfc);
256 }
257
258 public SpdPackageHeaders(OpeningPackageType opt) {
259 this(opt.getXmlSpd());
260 docConsole = opt;
261 }
262 /**
263 This method initializes this
264
265 @return void
266 **/
267 private void init() {
268
269 this.setContentPane(getJScrollPane());
270 this.setTitle("Library Class Declarations");
271 this.setBounds(new java.awt.Rectangle(0, 0, 500, 370));
272 this.setVisible(true);
273 this.addInternalFrameListener(new InternalFrameAdapter(){
274 public void internalFrameDeactivated(InternalFrameEvent e){
275 if (jTable.isEditing()) {
276 jTable.getCellEditor().stopCellEditing();
277 }
278 }
279 });
280 initFrame();
281 }
282
283 private void init(SpdFileContents sfc){
284 if (sfc.getSpdPackageHeaderCount() == 0) {
285 return ;
286 }
287 String[][] saa = new String[sfc.getSpdPackageHeaderCount()][2];
288 sfc.getSpdPackageHeaders(saa);
289 int i = 0;
290 while (i < saa.length) {
291 model.addRow(saa[i]);
292 i++;
293 }
294 }
295
296 private JScrollPane getJScrollPane(){
297 if (jScrollPane == null){
298 jScrollPane = new JScrollPane();
299 jScrollPane.setViewportView(getJContentPane());
300 }
301 return jScrollPane;
302 }
303 /**
304 This method initializes jContentPane
305
306 @return javax.swing.JPanel
307 **/
308 private JPanel getJContentPane() {
309 if (jContentPane == null) {
310 jStarLabel1 = new StarLabel();
311 jStarLabel1.setLocation(new java.awt.Point(0, 10));
312 jStarLabel2 = new StarLabel();
313 jStarLabel2.setLocation(new java.awt.Point(0,62));
314 jLabel = new JLabel();
315 jLabel.setBounds(new java.awt.Rectangle(14,62,199,22));
316 jLabel.setText("Include Header for Module Type");
317
318 jContentPane = new JPanel();
319 jContentPane.setPreferredSize(new Dimension(480, 325));
320 jContentPane.setLayout(null);
321 jContentPane.add(jLabel, null);
322 jContentPane.add(jStarLabel1, null);
323 jContentPane.add(jStarLabel2, null);
324 jContentPane.add(getJRadioButtonSelect(), null);
325 jContentPane.add(getJComboBoxSelect(), null);
326 jContentPane.add(getJButtonAdd(), null);
327 jContentPane.add(getJButtonRemove(), null);
328 jContentPane.add(getJButtonClearAll(), null);
329 jContentPane.add(getJButtonCancel(), null);
330 jContentPane.add(getJButtonOk(), null);
331
332 jContentPane.add(getJTextField(), null);
333 jContentPane.add(getJButtonBrowse(), null);
334 jContentPane.add(getJScrollPane1(), null);
335 }
336 return jContentPane;
337 }
338
339 /**
340 fill ComboBoxes with pre-defined contents
341 **/
342 private void initFrame() {
343 jComboBoxSelect.addItem("BASE");
344 jComboBoxSelect.addItem("SEC");
345 jComboBoxSelect.addItem("PEI_CORE");
346 jComboBoxSelect.addItem("PEIM");
347 jComboBoxSelect.addItem("DXE_CORE");
348 jComboBoxSelect.addItem("DXE_DRIVER");
349 jComboBoxSelect.addItem("DXE_RUNTIME_DRIVER");
350 jComboBoxSelect.addItem("DXE_SAL_DRIVER");
351 jComboBoxSelect.addItem("DXE_SMM_DRIVER");
352 jComboBoxSelect.addItem("TOOLS");
353 jComboBoxSelect.addItem("UEFI_DRIVER");
354 jComboBoxSelect.addItem("UEFI_APPLICATION");
355 jComboBoxSelect.addItem("USER_DEFINED");
356 jComboBoxSelect.setSelectedIndex(0);
357 }
358
359 /* (non-Javadoc)
360 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
361 */
362 public void actionPerformed(ActionEvent arg0) {
363
364 docConsole.setSaved(false);
365 if (arg0.getSource() == jButtonOk) {
366 this.save();
367 this.dispose();
368
369 }
370 if (arg0.getSource() == jButtonCancel) {
371 this.dispose();
372 }
373
374 if (arg0.getSource() == jButtonAdd) {
375 String strLibClass = "";
376
377 if (jRadioButtonSelect.isSelected()) {
378 strLibClass = jComboBoxSelect.getSelectedItem().toString();
379 }
380 //ToDo: check before add
381 String[] row = {"", ""};
382 row[0] = strLibClass;
383 row[1] = jTextField.getText().replace('\\', '/');
384 if (!dataValidation(row)) {
385 return;
386 }
387 model.addRow(row);
388 sfc.genSpdModuleHeaders(row[0], row[1], null, null, null, null, null, null);
389 }
390 //
391 // remove selected line
392 //
393 if (arg0.getSource() == jButtonRemove) {
394 if (jTable.isEditing()){
395 jTable.getCellEditor().stopCellEditing();
396 }
397 int rowSelected = selectedRow;
398 if (rowSelected >= 0) {
399 model.removeRow(rowSelected);
400 sfc.removeSpdPkgHeader(rowSelected);
401 }
402 }
403
404 if (arg0.getSource() == jButtonClearAll) {
405 if (model.getRowCount() == 0) {
406 return;
407 }
408 model.setRowCount(0);
409 sfc.removeSpdPkgHeader();
410 }
411
412 }
413
414 private boolean dataValidation(String[] row) {
415 if (!DataValidation.isPathAndFilename(row[1])) {
416 JOptionPane.showMessageDialog(this, "Include header path is NOT PathAndFilename type.");
417 return false;
418 }
419
420 return true;
421 }
422
423 /**
424 Add contents in list to sfc
425 **/
426 protected void save() {
427
428 }
429
430 /**
431 This method initializes jTextField
432
433 @return javax.swing.JTextField
434 **/
435 private JTextField getJTextField() {
436 if (jTextField == null) {
437 jTextField = new JTextField();
438 jTextField.setBounds(new java.awt.Rectangle(13,90,346,21));
439 jTextField.setPreferredSize(new java.awt.Dimension(345,20));
440 }
441 return jTextField;
442 }
443
444 /**
445 This method initializes jButtonBrowse
446
447 @return javax.swing.JButton
448 **/
449 private JButton getJButtonBrowse() {
450 if (jButtonBrowse == null) {
451 jButtonBrowse = new JButton();
452 jButtonBrowse.setBounds(new java.awt.Rectangle(374,89,92,21));
453 jButtonBrowse.setText("Browse");
454 jButtonBrowse.setPreferredSize(new java.awt.Dimension(92,20));
455 jButtonBrowse.addActionListener(new javax.swing.AbstractAction() {
456 /**
457 *
458 */
459 private static final long serialVersionUID = 1L;
460
461 public void actionPerformed(ActionEvent e) {
462 //
463 // Select files from current workspace
464 //
465 String dirPrefix = Tools.dirForNewSpd.substring(0, Tools.dirForNewSpd.lastIndexOf(File.separator));
466 JFileChooser chooser = new JFileChooser(dirPrefix);
467 File theFile = null;
468 String headerDest = null;
469
470 chooser.setMultiSelectionEnabled(false);
471 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
472 int retval = chooser.showOpenDialog(frame);
473 if (retval == JFileChooser.APPROVE_OPTION) {
474
475 theFile = chooser.getSelectedFile();
476 String file = theFile.getPath();
477 if (!file.startsWith(dirPrefix)) {
478 JOptionPane.showMessageDialog(frame, "You can only select files in current package!");
479 return;
480 }
481
482
483 }
484 else {
485 return;
486 }
487
488 headerDest = theFile.getPath();
489 int fileIndex = headerDest.indexOf(System.getProperty("file.separator"), dirPrefix.length());
490
491 jTextField.setText(headerDest.substring(fileIndex + 1).replace('\\', '/'));
492
493 }
494 });
495 }
496 return jButtonBrowse;
497 }
498
499 /**
500 * This method initializes jScrollPane
501 *
502 * @return javax.swing.JScrollPane
503 */
504 private JScrollPane getJScrollPane1() {
505 if (jScrollPane1 == null) {
506 jScrollPane1 = new JScrollPane();
507 jScrollPane1.setBounds(new java.awt.Rectangle(13,149,453,165));
508 jScrollPane1.setViewportView(getJTable());
509 }
510 return jScrollPane1;
511 }
512
513 /**
514 * This method initializes jTable
515 *
516 * @return javax.swing.JTable
517 */
518 private JTable getJTable() {
519 if (jTable == null) {
520 model = new DefaultTableModel();
521 jTable = new JTable(model);
522 jTable.setRowHeight(20);
523 model.addColumn("ModuleType");
524 model.addColumn("IncludeHeader");
525 TableColumn typeColumn = jTable.getColumnModel().getColumn(0);
526 JComboBox jComboBoxSelect = new JComboBox();
527 jComboBoxSelect.addItem("BASE");
528 jComboBoxSelect.addItem("SEC");
529 jComboBoxSelect.addItem("PEI_CORE");
530 jComboBoxSelect.addItem("PEIM");
531 jComboBoxSelect.addItem("DXE_CORE");
532 jComboBoxSelect.addItem("DXE_DRIVER");
533 jComboBoxSelect.addItem("DXE_RUNTIME_DRIVER");
534 jComboBoxSelect.addItem("DXE_SAL_DRIVER");
535 jComboBoxSelect.addItem("DXE_SMM_DRIVER");
536 jComboBoxSelect.addItem("TOOLS");
537 jComboBoxSelect.addItem("UEFI_DRIVER");
538 jComboBoxSelect.addItem("UEFI_APPLICATION");
539 jComboBoxSelect.addItem("USER_DEFINED");
540 typeColumn.setCellEditor(new DefaultCellEditor(jComboBoxSelect));
541
542 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
543 jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
544 public void valueChanged(ListSelectionEvent e) {
545 if (e.getValueIsAdjusting()){
546 return;
547 }
548 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
549 if (lsm.isSelectionEmpty()) {
550 return;
551 }
552 else{
553 selectedRow = lsm.getMinSelectionIndex();
554 }
555 }
556 });
557
558 jTable.getModel().addTableModelListener(this);
559 }
560 return jTable;
561 }
562
563 public void tableChanged(TableModelEvent arg0) {
564 // TODO Auto-generated method stub
565 int row = arg0.getFirstRow();
566 TableModel m = (TableModel)arg0.getSource();
567 if (arg0.getType() == TableModelEvent.UPDATE){
568 String pkg = m.getValueAt(row, 0) + "";
569 String hdr = m.getValueAt(row, 1) + "";
570 String[] rowData = {pkg, hdr};
571 if (!dataValidation(rowData)) {
572 return;
573 }
574 docConsole.setSaved(false);
575 sfc.updateSpdPkgHdr(row, pkg, hdr);
576 }
577 }
578
579 public void componentResized(ComponentEvent arg0) {
580 int intPreferredWidth = 500;
581
582 resizeComponentWidth(this.jComboBoxSelect, this.getWidth(), intPreferredWidth);
583 resizeComponentWidth(this.jTextField, this.getWidth(), intPreferredWidth);
584 resizeComponentWidth(this.jScrollPane, this.getWidth(), intPreferredWidth);
585 relocateComponentX(this.jButtonBrowse, this.getWidth(), this.getPreferredSize().width, 30);
586 }
587
588 public static void main(String[] args){
589 new SpdPackageHeaders().setVisible(true);
590 }
591 }
592
593