KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > i18n > wizard > TestStringWizardPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.i18n.wizard;
22
23
24 import java.awt.BorderLayout JavaDoc;
25 import java.awt.Component JavaDoc;
26 import java.awt.Container JavaDoc;
27 import java.awt.Dialog JavaDoc;
28 import java.awt.GridBagConstraints JavaDoc;
29 import java.awt.GridBagLayout JavaDoc;
30 import java.awt.event.ActionEvent JavaDoc;
31 import java.awt.event.ActionListener JavaDoc;
32 import java.awt.event.MouseEvent JavaDoc;
33 import java.awt.Insets JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.EventObject JavaDoc;
36 import java.util.HashSet JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.Map JavaDoc;
39 import java.util.Set JavaDoc;
40 import javax.swing.DefaultCellEditor JavaDoc;
41 import javax.swing.DefaultComboBoxModel JavaDoc;
42 import javax.swing.JButton JavaDoc;
43 import javax.swing.JComponent JavaDoc;
44 import javax.swing.JLabel JavaDoc;
45 import javax.swing.JPanel JavaDoc;
46 import javax.swing.JTable JavaDoc;
47 import javax.swing.JTextField JavaDoc;
48 import javax.swing.table.AbstractTableModel JavaDoc;
49 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
50 import javax.swing.table.TableCellEditor JavaDoc;
51 import javax.swing.AbstractCellEditor JavaDoc;
52 import org.netbeans.api.java.classpath.ClassPath;
53
54 import org.netbeans.modules.i18n.HardCodedString;
55 import org.netbeans.modules.i18n.I18nString;
56 import org.netbeans.modules.i18n.I18nSupport;
57 import org.netbeans.modules.i18n.I18nUtil;
58 import org.netbeans.modules.i18n.PropertyPanel;
59
60 import org.openide.DialogDescriptor;
61 import org.openide.loaders.DataObject;
62 import org.openide.util.HelpCtx;
63 import org.openide.util.NbBundle;
64 import org.openide.WizardDescriptor;
65 import org.openide.DialogDisplayer;
66
67
68 /**
69  * <code>WizardDescriptor.Panel</code> used for to show found missing keys.
70  * It is the fourth and last panel of I18N Test Wizard.
71  *
72  * @author Peter Zavadsky
73  * @see Panel
74  */

75 final class TestStringWizardPanel extends JPanel JavaDoc {
76     
77     /** Column index of check box column. */
78     private static final int COLUMN_INDEX_CHECK = 0;
79     /** Column index of hard string column. */
80     private static final int COLUMN_INDEX_HARDSTRING = 1;
81     /** Column index of key column. */
82     private static final int COLUMN_INDEX_KEY = 2;
83     /** Column index of value column. */
84     private static final int COLUMN_INDEX_VALUE = 3;
85
86     /** Local copy of i18n wizard data. */
87     private final Map JavaDoc sourceMap = Util.createWizardSourceMap();
88
89     /** Table model for <code>stringTable</code>. */
90     private final AbstractTableModel JavaDoc tableModel = new TestStringTableModel();
91     
92     /** Creates new form HardCodedStringsPanel */
93     private TestStringWizardPanel() {
94         
95         initComponents();
96         
97         postInitComponents();
98         
99         initTable();
100
101         setComboModel(sourceMap);
102     }
103
104         
105     /** Sets combo model only for source which were some found strings in. */
106     private void setComboModel(Map JavaDoc sourceMap) {
107         Object JavaDoc[] sources = sourceMap.keySet().toArray();
108         
109         ArrayList JavaDoc nonEmptySources = new ArrayList JavaDoc();
110         
111         for(int i = 0; i < sources.length; i++) {
112             if(!((SourceData)sourceMap.get(sources[i])).getStringMap().isEmpty())
113                 nonEmptySources.add(sources[i]);
114         }
115         
116         sourceCombo.setModel(new DefaultComboBoxModel JavaDoc(nonEmptySources.toArray()));
117     }
118     
119     /** Adds additional init of components. */
120     private void postInitComponents() {
121         sourceLabel.setLabelFor(sourceCombo);
122         testStringLabel.setLabelFor(testStringTable);
123     }
124
125     /** Getter for <code>resources</code> property. */
126     public Map JavaDoc getSourceMap() {
127         return sourceMap;
128     }
129     
130     /** Setter for <code>resources</code> property. */
131     public void setSourceMap(Map JavaDoc sourceMap) {
132         this.sourceMap.clear();
133         this.sourceMap.putAll(sourceMap);
134         
135         setComboModel(sourceMap);
136     }
137     
138     /** Gets string map for specified source data object. Utility method. */
139     private Map JavaDoc getStringMap() {
140         SourceData sourceData = (SourceData)sourceMap.get(sourceCombo.getSelectedItem());
141         return sourceData == null ? null : sourceData.getStringMap();
142     }
143
144     /** Gets hard coded strings user wish to not proceed. */
145     private Set JavaDoc getRemovedStrings() {
146         SourceData sourceData = (SourceData)sourceMap.get(sourceCombo.getSelectedItem());
147         if(sourceData == null)
148             return null;
149         
150         if(sourceData.getRemovedStrings() == null)
151             sourceData.setRemovedStrings(new HashSet JavaDoc());
152         
153         return sourceData.getRemovedStrings();
154     }
155     
156     /** Inits table component. */
157     private void initTable() {
158         testStringTable.setDefaultRenderer(HardCodedString.class, new DefaultTableCellRenderer JavaDoc() {
159             public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value,
160                 boolean isSelected, boolean hasFocus, int row, int column) {
161                     
162                 JLabel JavaDoc label = (JLabel JavaDoc)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
163
164                 HardCodedString hcString = (HardCodedString)value;
165
166                 if(hcString != null)
167                     label.setText(hcString.getText());
168                 else
169                     label.setText(""); // NOI18N
170

171                 return label;
172             }
173         });
174         
175         testStringTable.setDefaultRenderer(I18nString.class, new DefaultTableCellRenderer JavaDoc() {
176             
177             public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value,
178                 boolean isSelected, boolean hasFocus, int row, int column) {
179
180                 I18nString i18nString = (I18nString)value;
181
182                 JLabel JavaDoc label = (JLabel JavaDoc)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
183
184                 int modelColumn = testStringTable.convertColumnIndexToModel(column);
185                 
186                 if(i18nString != null) {
187                     if(modelColumn == COLUMN_INDEX_KEY) {
188                         label.setText(i18nString.getKey());
189                     } else {
190                         label.setText(i18nString.getValue());
191                     }
192
193                 } else
194                     label.setText(""); // NOI18N
195

196                 
197                 return label;
198             }
199         });
200
201         testStringTable.setDefaultEditor(I18nString.class, new DefaultCellEditor JavaDoc(new JTextField JavaDoc()) {
202             
203             public Component JavaDoc getTableCellEditorComponent(
204                 JTable JavaDoc table, Object JavaDoc value,
205                 boolean isSelected,
206                 int row, int column) {
207
208                 I18nString i18nString = (I18nString)value;
209                 
210                 int modelColumn = testStringTable.convertColumnIndexToModel(column);
211                 
212                 if(modelColumn == COLUMN_INDEX_KEY)
213                     value = i18nString == null ? "" : i18nString.getKey(); // NOI18N
214
else if(modelColumn == COLUMN_INDEX_VALUE)
215                     value = i18nString == null ? "" : i18nString.getValue(); // NOI18N
216
else
217                     value = ""; // NOI18N
218

219                 return super.getTableCellEditorComponent(table, value, isSelected, row, column);
220             }
221         });
222         
223         // PENDING: Setting the size of columns with check box and customize button editor.
224
testStringTable.getColumnModel().getColumn(COLUMN_INDEX_CHECK).setMaxWidth(30);
225     }
226     
227     /** This method is called from within the constructor to
228      * initialize the form.
229      * WARNING: Do NOT modify this code. The content of this method is
230      * always regenerated by the Form Editor.
231      */

232     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
233
private void initComponents() {
234         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
235
236         sourceLabel = new javax.swing.JLabel JavaDoc();
237         sourceCombo = new javax.swing.JComboBox JavaDoc();
238         testStringLabel = new javax.swing.JLabel JavaDoc();
239         scrollPane = new javax.swing.JScrollPane JavaDoc();
240         testStringTable = new javax.swing.JTable JavaDoc();
241
242         setLayout(new java.awt.GridBagLayout JavaDoc());
243
244         org.openide.awt.Mnemonics.setLocalizedText(sourceLabel, NbBundle.getBundle(HardStringWizardPanel.class).getString("LBL_Source")); // NOI18N
245
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
246         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
247         add(sourceLabel, gridBagConstraints);
248
249         sourceCombo.setRenderer(new SourceWizardPanel.DataObjectListCellRenderer());
250         sourceCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
251             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
252                 sourceComboActionPerformed(evt);
253             }
254         });
255         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
256         gridBagConstraints.gridx = 0;
257         gridBagConstraints.gridy = 1;
258         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
259         gridBagConstraints.weightx = 1.0;
260         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
261         add(sourceCombo, gridBagConstraints);
262
263         org.openide.awt.Mnemonics.setLocalizedText(testStringLabel, NbBundle.getBundle(HardStringWizardPanel.class).getString("LBL_missing_keys")); // NOI18N
264
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
265         gridBagConstraints.gridx = 0;
266         gridBagConstraints.gridy = 2;
267         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
268         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 0, 0, 0);
269         add(testStringLabel, gridBagConstraints);
270
271         scrollPane.setPreferredSize(new java.awt.Dimension JavaDoc(100, 100));
272
273         testStringTable.setModel(tableModel);
274         scrollPane.setViewportView(testStringTable);
275
276         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
277         gridBagConstraints.gridx = 0;
278         gridBagConstraints.gridy = 3;
279         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
280         gridBagConstraints.weightx = 1.0;
281         gridBagConstraints.weighty = 1.0;
282         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
283         add(scrollPane, gridBagConstraints);
284     }// </editor-fold>//GEN-END:initComponents
285

286     private void sourceComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_sourceComboActionPerformed
287
if(((SourceData)sourceMap.get(sourceCombo.getSelectedItem())).getStringMap().isEmpty()) {
288             // There are no hardcoded strings found for this selected source.
289
JLabel JavaDoc label = new JLabel JavaDoc(NbBundle.getBundle(TestStringWizardPanel.class).getString("TXT_AllI18nStringsSource"));
290             label.setHorizontalAlignment(JLabel.CENTER);
291             scrollPane.setViewportView(label);
292         } else {
293             scrollPane.setViewportView(testStringTable);
294             tableModel.fireTableDataChanged();
295         }
296         tableModel.fireTableDataChanged();
297     }//GEN-LAST:event_sourceComboActionPerformed
298

299     // Variables declaration - do not modify//GEN-BEGIN:variables
300
private javax.swing.JScrollPane JavaDoc scrollPane;
301     private javax.swing.JComboBox JavaDoc sourceCombo;
302     private javax.swing.JLabel JavaDoc sourceLabel;
303     private javax.swing.JLabel JavaDoc testStringLabel;
304     private javax.swing.JTable JavaDoc testStringTable;
305     // End of variables declaration//GEN-END:variables
306

307     /** Table model for this class. */
308     private class TestStringTableModel extends AbstractTableModel JavaDoc {
309         
310         /** Constructor. */
311         public TestStringTableModel() {
312         }
313         
314         
315         /** Implements superclass abstract method. */
316         public int getColumnCount() {
317             return 4;
318         }
319         
320         /** Implemenst superclass abstract method. */
321         public int getRowCount() {
322             Map JavaDoc stringMap = getStringMap();
323             return stringMap == null ? 0 : stringMap.size();
324         }
325         
326         /** Implements superclass abstract method. */
327         public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
328             Map JavaDoc stringMap = getStringMap();
329             
330             if(stringMap == null)
331                 return null;
332             
333             if(columnIndex == COLUMN_INDEX_CHECK) {
334                 return !getRemovedStrings().contains(stringMap.keySet().toArray()[rowIndex]) ? Boolean.TRUE : Boolean.FALSE;
335             } else if(columnIndex == COLUMN_INDEX_HARDSTRING) {
336                 return stringMap.keySet().toArray()[rowIndex];
337             } else {
338                 return stringMap.values().toArray()[rowIndex];
339             }
340         }
341         
342         /** Overrides superclass method.
343          * @return false for all columns but the value and check box column */

344         public boolean isCellEditable(int rowIndex, int columnIndex) {
345             if(columnIndex == COLUMN_INDEX_CHECK || columnIndex == COLUMN_INDEX_VALUE)
346                 return true;
347             else
348                 return false;
349         }
350         
351         /** Overrides superclass method. */
352         public void setValueAt(Object JavaDoc value, int rowIndex, int columnIndex) {
353             Map JavaDoc stringMap = getStringMap();
354             
355             if(stringMap == null)
356                 return;
357             
358             if(columnIndex == COLUMN_INDEX_CHECK && value instanceof Boolean JavaDoc) {
359                 Object JavaDoc hardString = stringMap.keySet().toArray()[rowIndex];
360                 
361                 Set JavaDoc removedStrings = getRemovedStrings();
362                 
363                 if(((Boolean JavaDoc)value).booleanValue())
364                     removedStrings.remove(hardString);
365                 else
366                     removedStrings.add(hardString);
367             }
368             
369             if(columnIndex == COLUMN_INDEX_VALUE) {
370                 I18nString i18nString = (I18nString)getStringMap().values().toArray()[rowIndex];
371
372                 i18nString.setValue(value.toString());
373             }
374         }
375         
376         /** Overrides superclass method.
377          * @return DataObject.class */

378         public Class JavaDoc getColumnClass(int columnIndex) {
379             if(columnIndex == COLUMN_INDEX_CHECK)
380                 return Boolean JavaDoc.class;
381             else if(columnIndex == COLUMN_INDEX_HARDSTRING)
382                 return HardCodedString.class;
383             else
384                 return I18nString.class;
385         }
386
387         /** Overrides superclass method. */
388         public String JavaDoc getColumnName(int column) {
389             if(column == COLUMN_INDEX_HARDSTRING)
390                 return NbBundle.getBundle(HardStringWizardPanel.class).getString("LBL_HardString");
391             else if(column == COLUMN_INDEX_KEY)
392                 return NbBundle.getBundle(HardStringWizardPanel.class).getString("LBL_Key");
393             else if(column == COLUMN_INDEX_VALUE)
394                 return NbBundle.getBundle(HardStringWizardPanel.class).getString("LBL_Value");
395             else
396                 return " "; // NOI18N
397
}
398     } // End of ResourceTableModel nested class.
399

400
401     /** Cell editor for the right most 'customize' column. It shows dialog
402      * constructed from <code>PropertyPanel</code> which provides actual custmization of the
403      * <code>I18nString</code> instance.
404      * @see org.netbeans.modules.i18n.PropertyPanel
405      */

406     public static class CustomizeCellEditor extends AbstractCellEditor JavaDoc
407     implements TableCellEditor JavaDoc, ActionListener JavaDoc {
408
409         /** <code>I18nString</code> instance to be edited by this editor. */
410         private I18nString i18nString;
411         
412         /** Editor component, in our case <code>JButton</code>. */
413         private JButton JavaDoc editorComponent;
414
415         
416         /** Constructor. */
417         public CustomizeCellEditor() {
418             editorComponent = new JButton JavaDoc("..."); // NOI18N
419

420             editorComponent.addActionListener(new ActionListener JavaDoc() {
421                 public void actionPerformed(ActionEvent JavaDoc evt) {
422                     PropertyPanel panel = i18nString.getSupport().getPropertyPanel();
423                     panel.setI18nString(i18nString);
424
425                     DialogDescriptor dd = new DialogDescriptor(panel,"Customize Property");
426                     dd.setModal(true);
427                     dd.setOptionType(DialogDescriptor.DEFAULT_OPTION);
428                     dd.setOptions(new Object JavaDoc[] {DialogDescriptor.OK_OPTION});
429                     dd.setAdditionalOptions(new Object JavaDoc[0]);
430                     dd.setButtonListener(CustomizeCellEditor.this);
431
432                     Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dd);
433                     dialog.setVisible(true);
434                 }
435             });
436         }
437
438         /** Implements <code>TableCellEditor</code> interface. */
439         public Component JavaDoc getTableCellEditorComponent(JTable JavaDoc table, Object JavaDoc value, boolean isSelected, int row, int column) {
440             i18nString = (I18nString)value;
441             
442             return editorComponent;
443         }
444         
445         /** Implements <code>TableCellEditor</code> interface. */
446         public Object JavaDoc getCellEditorValue() {
447             return i18nString;
448         }
449
450         /** Implements <code>TableCellEditor</code> interface. */
451         public boolean isCellEditable(EventObject JavaDoc anEvent) {
452             if(anEvent instanceof MouseEvent JavaDoc) {
453                 // Counts needed to start editing.
454
return ((MouseEvent JavaDoc)anEvent).getClickCount() >= 1;
455             }
456             return true;
457         }
458
459         /** Implements <code>TableCellEditor</code> interface. */
460         public boolean shouldSelectCell(EventObject JavaDoc anEvent) {
461             return true;
462         }
463
464         /** Implements <code>TableCellEditor</code> interface. */
465         public boolean stopCellEditing() {
466             fireEditingStopped();
467             return true;
468         }
469
470         /** Implements <code>TableCellEditor</code> interface. */
471         public void cancelCellEditing() {
472            fireEditingCanceled();
473         }
474         
475         /** Implements <code>ActionListener</code> interface. */
476         public void actionPerformed(ActionEvent JavaDoc evt) {
477             stopCellEditing();
478         }
479
480     }
481     
482     
483     /** <code>WizardDescriptor.Panel</code> used for <code>HardCodedStringPanel</code>.
484      * @see I18nWizardDescriptorPanel
485      * @see org.openide.WizardDescriptor.Panel*/

486     public static class Panel extends I18nWizardDescriptor.Panel
487     implements WizardDescriptor.FinishablePanel, I18nWizardDescriptor.ProgressMonitor {
488
489         /** Empty label component. */
490         private final JLabel JavaDoc emptyLabel;
491
492         /** Test wizard panel component. */
493         private transient TestStringWizardPanel testStringPanel;
494         
495         public Panel() {
496             emptyLabel = new JLabel JavaDoc(NbBundle.getBundle(TestStringWizardPanel.class).getString("TXT_AllI18nStrings"));
497             emptyLabel.setHorizontalAlignment(JLabel.CENTER);
498             emptyLabel.setVerticalAlignment(JLabel.CENTER);
499         }
500         
501
502         
503         /** Gets component to display. Implements superclass abstract method.
504          * @return this instance */

505         protected Component JavaDoc createComponent() {
506             JPanel JavaDoc panel = new JPanel JavaDoc();
507             panel.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(TestStringWizardPanel.class).getString("ACS_TestStringWizardPanel"));
508             
509             panel.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(2)); // NOI18N
510
panel.setName(NbBundle.getBundle(TestStringWizardPanel.class).getString("TXT_FoundMissingResource"));
511             panel.setPreferredSize(I18nWizardDescriptor.PREFERRED_DIMENSION);
512             panel.setLayout(new GridBagLayout JavaDoc());
513             GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
514             constraints.weightx = 1.0;
515             constraints.weighty = 1.0;
516             constraints.fill = GridBagConstraints.BOTH;
517             panel.add(getUI(), constraints);
518             return panel;
519         }
520
521         /** Gets if panel is valid. Overrides superclass method. */
522         public boolean isValid() {
523             return true;
524         }
525         
526         /**
527          */

528         public boolean isFinishPanel() {
529             return true;
530         }
531         
532         /** Reads settings at the start when the panel comes to play. Overrides superclass method. */
533         public void readSettings(Object JavaDoc settings) {
534         super.readSettings(settings);
535             getUI().setSourceMap(getMap());
536             
537             JPanel JavaDoc panel = (JPanel JavaDoc)getComponent();
538             if(foundStrings(getMap())) {
539                 if(panel.isAncestorOf(emptyLabel)) {
540                     panel.remove(emptyLabel);
541                     GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
542                     constraints.weightx = 1.0;
543                     constraints.weighty = 1.0;
544                     constraints.fill = GridBagConstraints.BOTH;
545                     panel.add(getUI(), constraints);
546                 }
547             } else {
548                 if(panel.isAncestorOf(getUI())) {
549                     panel.remove(getUI());
550                     GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
551                     constraints.weightx = 1.0;
552                     constraints.weighty = 1.0;
553                     constraints.fill = GridBagConstraints.BOTH;
554                     panel.add(emptyLabel, constraints);
555                 }
556             }
557         }
558         
559         /** Stores settings at the end of panel show. Overrides superclass method. */
560         public void storeSettings(Object JavaDoc settings) {
561         super.storeSettings(settings);
562             // Update sources.
563
(getMap()).clear();
564             (getMap()).putAll(getUI().getSourceMap());
565         }
566         
567         /** Searches hard coded strings in sources and puts found hard coded string - i18n string pairs
568          * into settings. Implements <code>ProgressMonitor</code> interface method. */

569         public void doLongTimeChanges() {
570             if (foundStrings(getMap())) {
571                 // Replace panel.
572
final ProgressWizardPanel progressPanel = new ProgressWizardPanel(true);
573                 progressPanel.setMainText(NbBundle.getBundle(getClass()).getString("LBL_Internationalizing"));
574                 progressPanel.setMainProgress(0);
575
576                 ((Container JavaDoc)getComponent()).remove(getUI());
577                 GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
578                 constraints.weightx = 1.0;
579                 constraints.weighty = 1.0;
580                 constraints.fill = GridBagConstraints.BOTH;
581                 ((Container JavaDoc)getComponent()).add(progressPanel, constraints);
582                 ((JComponent JavaDoc)getComponent()).revalidate();
583                 getComponent().repaint();
584
585                 // Add missing key-value pairs into resource.
586
Map JavaDoc sourceMap = getUI().getSourceMap();
587
588                 Iterator JavaDoc sourceIterator = sourceMap.keySet().iterator();
589
590                 // For each source perform the task.
591
for(int i=0; sourceIterator.hasNext(); i++) {
592                     Object JavaDoc source = sourceIterator.next();
593
594                     // Get source data.
595
SourceData sourceData = (SourceData)sourceMap.get(source);
596
597                     // Get i18n support for this source.
598
I18nSupport support = sourceData.getSupport();
599
600                     // Get string map.
601
Map JavaDoc stringMap = sourceData.getStringMap();
602
603                     // Get removed strings.
604
Set JavaDoc removed = sourceData.getRemovedStrings();
605
606                     // Do actual replacement.
607
Iterator JavaDoc it = stringMap.keySet().iterator();
608
609                     ClassPath cp = ClassPath.getClassPath( ((DataObject)source).getPrimaryFile(), ClassPath.SOURCE );
610                     progressPanel.setSubText(Util.getString("LBL_Source")+" "+cp.getResourceName( ((DataObject)source).getPrimaryFile(), '.', false)); //NOI18N
611

612                     for(int j=0; it.hasNext(); j++) {
613                         HardCodedString hcString = (HardCodedString)it.next();
614                         I18nString i18nString = (I18nString)stringMap.get(hcString);
615
616                         if(removed != null && removed.contains(hcString))
617                             // Don't proceed.
618
continue;
619
620                         // Actually put missing property into bundle with origin comment.
621
String JavaDoc comment = i18nString.getComment();
622                         if (source instanceof DataObject && (comment == null || "".equals(comment) ) ) {
623                             DataObject dobj = (DataObject) source;
624                             cp = ClassPath.getClassPath( dobj.getPrimaryFile(), ClassPath.SOURCE );
625                             comment = cp.getResourceName( dobj.getPrimaryFile(), '.', false );
626                         }
627
628                         // we may have already added it in, it is the referenced from
629
// multiple sources, merge comments
630
String JavaDoc key = i18nString.getKey();
631                         String JavaDoc prev = support.getResourceHolder().getCommentForKey(key);
632                         comment += (prev == null ? "" : " " + prev); // NOI18N
633
support.getResourceHolder().addProperty(i18nString.getKey(), i18nString.getValue(), comment, false);
634
635                         progressPanel.setSubProgress((int)((j+1)/(float)stringMap.size() * 100));
636                     } // End of inner for.
637

638                     // Provide additional changes if there are some.
639
if(support.hasAdditionalCustomizer()) {
640                         support.performAdditionalChanges();
641                     }
642
643                     progressPanel.setMainProgress((int)((i+1)/(float)sourceMap.size() * 100));
644                 } // End of outer for.
645
} // if (foundStrings(getMap()))
646
}
647         
648         /** Implements <code>ProgressMonitor</code> interface method. Does nothing. */
649         public void reset() {
650         }
651
652         /** Indicates if there were found some hardcoded strings in any of selected sources.
653          * @return true if at least one hard coded string was found. */

654         private static boolean foundStrings(Map JavaDoc sourceMap) {
655             Iterator JavaDoc it = sourceMap.keySet().iterator();
656
657             while(it.hasNext()) {
658                 SourceData sourceData = (SourceData)sourceMap.get(it.next());
659                 if(!sourceData.getStringMap().isEmpty())
660                     return true;
661             }
662
663             return false;
664         }
665         
666         /** Gets help. Implements superclass abstract method. */
667         public HelpCtx getHelp() {
668             return new HelpCtx(I18nUtil.HELP_ID_TESTING);
669         }
670         
671         private synchronized TestStringWizardPanel getUI() {
672             if (testStringPanel == null) {
673                 testStringPanel = new TestStringWizardPanel();
674             }
675             return testStringPanel;
676         }
677     } // End of nested PanelDescriptor class.
678
}
679
Popular Tags