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