Fixed grammar in text messages.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / createui / CreateStepFour.java
1 /** @file
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 package org.tianocore.frameworkwizard.far.createui;
15
16 import java.awt.event.MouseEvent;
17 import java.awt.event.MouseListener;
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22
23 import javax.swing.JButton;
24 import javax.swing.JFileChooser;
25 import javax.swing.JLabel;
26 import javax.swing.JPanel;
27 import javax.swing.JTextArea;
28 import javax.swing.JTextField;
29
30 import org.tianocore.frameworkwizard.common.DataType;
31 import org.tianocore.frameworkwizard.common.IDefaultTableModel;
32 import org.tianocore.frameworkwizard.common.IFileFilter;
33 import org.tianocore.frameworkwizard.common.Log;
34 import org.tianocore.frameworkwizard.common.Tools;
35 import org.tianocore.frameworkwizard.common.ui.IDialog;
36 import org.tianocore.frameworkwizard.far.AggregationOperation;
37 import org.tianocore.frameworkwizard.far.Far;
38 import org.tianocore.frameworkwizard.far.FarStringDefinition;
39 import org.tianocore.frameworkwizard.far.PackageQuery;
40 import org.tianocore.frameworkwizard.far.PackageQueryInterface;
41 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
42 import org.tianocore.frameworkwizard.workspace.Workspace;
43
44 public class CreateStepFour extends IDialog implements MouseListener {
45
46 /**
47 *
48 */
49 private static final long serialVersionUID = -7397213364965470902L;
50
51 private JPanel jContentPane = null;
52
53 private JTextArea jTextAreaInstruction = null;
54
55 private JLabel jLabel = null;
56
57 private JLabel jLabel2 = null;
58
59 private JTextField jTextFieldSaveToFile = null;
60
61 private JButton jButtonBrowser = null;
62
63 // private JScrollPane jScrollPane = null;
64 private JButton jButtonCancel = null;
65
66 private JButton jButtonFinish = null;
67
68 private JButton jButtonPrevious = null;
69
70 private IDefaultTableModel model = null;
71
72 private CreateStepThree stepThree = null;
73
74 // private JTable jTable = null;
75 public CreateStepFour(IDialog iDialog, boolean modal, CreateStepThree stepThree) {
76 this(iDialog, modal);
77 this.stepThree = stepThree;
78 }
79
80 /**
81 * This method initializes jTextArea
82 *
83 * @return javax.swing.JTextArea
84 */
85 private JTextArea getJTextArea() {
86 if (jTextAreaInstruction == null) {
87 jTextAreaInstruction = new JTextArea();
88 jTextAreaInstruction.setBounds(new java.awt.Rectangle(30, 7, 642, 50));
89 jTextAreaInstruction.setText("Step 4: Choose a file \n");
90 jTextAreaInstruction.setEditable(false);
91 }
92 return jTextAreaInstruction;
93 }
94
95 /**
96 * This method initializes jTextField1
97 *
98 * @return javax.swing.JTextField
99 */
100 private JTextField getJTextField1() {
101 if (jTextFieldSaveToFile == null) {
102 jTextFieldSaveToFile = new JTextField();
103 jTextFieldSaveToFile.setBounds(new java.awt.Rectangle(147,70,412,20));
104 }
105 return jTextFieldSaveToFile;
106 }
107
108 /**
109 * This method initializes jButtonBrowser
110 *
111 * @return javax.swing.JButton
112 */
113 private JButton getJButtonBrower() {
114 if (jButtonBrowser == null) {
115 jButtonBrowser = new JButton();
116 jButtonBrowser.setBounds(new java.awt.Rectangle(570, 70, 100, 20));
117 jButtonBrowser.setText("Browser...");
118 jButtonBrowser.addMouseListener(this);
119 }
120 return jButtonBrowser;
121 }
122
123 /**
124 * This method initializes jScrollPane
125 *
126 * @return javax.swing.JScrollPane
127 */
128 // private JScrollPane getJScrollPane() {
129 // if (jScrollPane == null) {
130 // jScrollPane = new JScrollPane();
131 // jScrollPane.setBounds(new java.awt.Rectangle(139,85,500,100));
132 // jScrollPane.setViewportView(getJTable());
133 // }
134 // return jScrollPane;
135 // }
136 /**
137 * This method initializes jButtonCancel
138 *
139 * @return javax.swing.JButton
140 */
141 private JButton getJButtonCancel() {
142 if (jButtonCancel == null) {
143 jButtonCancel = new JButton();
144 jButtonCancel.setBounds(new java.awt.Rectangle(570, 330, 90, 20));
145 jButtonCancel.setText("Cancel");
146 jButtonCancel.addMouseListener(this);
147 }
148 return jButtonCancel;
149 }
150
151 /**
152 * This method initializes jButtonFinish
153 *
154 * @return javax.swing.JButton
155 */
156 private JButton getJButtonFinish() {
157 if (jButtonFinish == null) {
158 jButtonFinish = new JButton();
159 jButtonFinish.setBounds(new java.awt.Rectangle(470, 330, 90, 20));
160 jButtonFinish.setText("Finish");
161 jButtonFinish.addMouseListener(this);
162 }
163 return jButtonFinish;
164 }
165
166 /**
167 * This method initializes jButtonPrevious
168 *
169 * @return javax.swing.JButton
170 */
171 private JButton getJButtonPrevious() {
172 if (jButtonPrevious == null) {
173 jButtonPrevious = new JButton();
174 jButtonPrevious.setBounds(new java.awt.Rectangle(370, 330, 90, 20));
175 jButtonPrevious.setText("Previous");
176 jButtonPrevious.addMouseListener(this);
177 jButtonPrevious.setVisible(false);
178 }
179 return jButtonPrevious;
180 }
181
182 /**
183 * This is the default constructor
184 */
185 public CreateStepFour(IDialog iDialog, boolean modal) {
186 super(iDialog, modal);
187 initialize();
188 }
189
190 /**
191 * This method initializes this
192 *
193 * @return void
194 */
195 private void initialize() {
196 this.setSize(700, 400);
197 this.setContentPane(getJContentPane());
198 this.setTitle(FarStringDefinition.CREATE_STEP_FOUR_TITLE);
199 this.centerWindow();
200 }
201
202 /**
203 * This method initializes jContentPane
204 *
205 * @return javax.swing.JPanel
206 */
207 private JPanel getJContentPane() {
208 if (jContentPane == null) {
209 jLabel2 = new JLabel();
210 jLabel2.setBounds(new java.awt.Rectangle(30,70,111,18));
211 jLabel2.setText("File to Save: ");
212 jLabel = new JLabel();
213 jLabel.setBounds(new java.awt.Rectangle(29,108,320,20));
214 jLabel.setText("This FAR will depend on the following packages: ");
215 jLabel.setVisible(false);
216 jContentPane = new JPanel();
217 jContentPane.setLayout(null);
218 jContentPane.add(getJTextArea(), null);
219 jContentPane.add(jLabel, null);
220 // jContentPane.add(getJScrollPane(), null);
221 jContentPane.add(getJButtonCancel(), null);
222 jContentPane.add(getJButtonFinish(), null);
223 jContentPane.add(getJButtonPrevious(), null);
224 jContentPane.add(jLabel2, null);
225 jContentPane.add(getJTextField1(), null);
226 jContentPane.add(getJButtonBrower(), null);
227 }
228 return jContentPane;
229 }
230
231 public void mouseClicked(MouseEvent e) {
232 if (e.getSource() == jButtonCancel) {
233 this.setVisible(false);
234 } else if (e.getSource() == jButtonFinish) {
235 //
236 // Add some logic process here
237 // Guid Check, File Check etc.
238 //
239 if (this.jTextFieldSaveToFile.getText() == null) {
240 Log.wrn("Create far", "Please input the Far name!");
241 }
242 try {
243 //
244 // Create an output stream for JAR
245 //
246
247 Far far = new Far(new File(this.jTextFieldSaveToFile.getText()));
248
249 far.creatFar(this.getPreviousStep().getPreviousStep().getSelectedPackages(),
250 this.getPreviousStep().getPreviousStep().getSelectedPlatforms(), this.getPreviousStep()
251 .getFileFilter(),
252 this.getPreviousStep().getPreviousStep().getPreviousStep().getFarHeader());
253 } catch (Exception exp) {
254 Log.wrn("Create far", exp.getMessage());
255 Log.err("Create far", exp.getMessage());
256 return;
257 }
258 getPreviousStep().getPreviousStep().getPreviousStep().returnType = DataType.RETURN_TYPE_OK;
259 getPreviousStep().getPreviousStep().dispose();
260 getPreviousStep().dispose();
261 this.setVisible(false);
262 this.dispose();
263 } else if (e.getSource() == jButtonPrevious) {
264 stepThree.setVisible(true);
265 this.setVisible(false);
266 } else if (e.getSource() == jButtonBrowser) {
267 JFileChooser fc = new JFileChooser();
268 fc.setAcceptAllFileFilterUsed(false);
269 fc.addChoosableFileFilter(new IFileFilter(DataType.FAR_SURFACE_AREA_EXT));
270 fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));
271
272 int result = fc.showSaveDialog(new JPanel());
273 if (result == JFileChooser.APPROVE_OPTION) {
274 this.jTextFieldSaveToFile.setText(Tools.addPathExt(fc.getSelectedFile().getPath(),
275 DataType.RETURN_TYPE_FAR_SURFACE_AREA));
276 }
277 }
278 }
279
280 public void mousePressed(MouseEvent e) {
281 // TODO Auto-generated method stub
282
283 }
284
285 public void mouseReleased(MouseEvent e) {
286 // TODO Auto-generated method stub
287
288 }
289
290 public void mouseEntered(MouseEvent e) {
291 // TODO Auto-generated method stub
292
293 }
294
295 public void mouseExited(MouseEvent e) {
296 // TODO Auto-generated method stub
297
298 }
299
300 public CreateStepThree getPreviousStep() {
301 return stepThree;
302 }
303
304 /**
305 * This method initializes jTable
306 *
307 * @return javax.swing.JTable
308 */
309 // private JTable getJTable() {
310 // if (jTable == null) {
311 // jTable = new JTable();
312 // model = new PartialTableModel();
313 // jTable = new JTable(model);
314 // jTable.setRowHeight(20);
315 // jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
316 // model.addColumn("GUID");
317 // model.addColumn("Version");
318 // model.addColumn("Name");
319 //
320 // jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
321 // }
322 // if (this.stepThree != null) {
323 // prepareTable();
324 // }
325 // return jTable;
326 // }
327 public void prepareTable() {
328 model.setRowCount(0);
329
330 List<PackageIdentification> packageList = new ArrayList<PackageIdentification>();
331 //
332 // Change here to get packages and platforms from FAR
333 //
334 List<PackageIdentification> selectedPackages = getPreviousStep().getPreviousStep().getSelectedPackages();
335 PackageQueryInterface pq = new PackageQuery();
336
337 Iterator<PackageIdentification> iter = selectedPackages.iterator();
338 while (iter.hasNext()) {
339 PackageIdentification item = iter.next();
340 List<PackageIdentification> list = pq.getPackageDependencies(item.getSpdFile());
341 packageList = AggregationOperation.union(list, packageList);
342 }
343
344 packageList = AggregationOperation.minus(packageList, selectedPackages);
345
346 iter = packageList.iterator();
347 while (iter.hasNext()) {
348 String[] str = new String[3];
349 PackageIdentification item = iter.next();
350 str[2] = item.getName();
351 str[1] = item.getVersion();
352 str[0] = item.getGuid();
353 model.addRow(str);
354 }
355 }
356 }
357