KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > ant > deployer > AntDeployInputReplacementsPanel


1 package org.enhydra.kelp.ant.deployer;
2
3 // ToolBox imports
4
import org.enhydra.tool.ToolBoxInfo;
5 import org.enhydra.tool.common.IconSet;
6 import org.enhydra.tool.common.ToolException;
7 import org.enhydra.tool.configure.ConfigTool;
8
9 // Kelp imports
10
import org.enhydra.kelp.common.Backward;
11 import org.enhydra.kelp.common.PathUtil;
12 import org.enhydra.kelp.common.event.SwingTableSelectionEvent;
13 import org.enhydra.kelp.common.event.SwingTableSelectionListener;
14 import org.enhydra.kelp.common.node.OtterTemplateNode;
15 import org.enhydra.kelp.common.node.OtterNode;
16 import org.enhydra.kelp.common.node.OtterProject;
17
18 // Standard imports
19
import java.awt.*;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22 import java.awt.event.ItemEvent JavaDoc;
23 import java.awt.event.ItemListener JavaDoc;
24 import java.beans.*;
25 import java.io.File JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import java.util.Vector JavaDoc;
30 import javax.swing.*;
31 import javax.swing.event.ListSelectionEvent JavaDoc;
32 import javax.swing.event.ListSelectionListener JavaDoc;
33 import javax.swing.table.AbstractTableModel JavaDoc;
34 import javax.swing.table.DefaultTableModel JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import org.enhydra.kelp.ant.node.AntProject;
37 import java.util.Iterator JavaDoc;
38 import java.util.Set JavaDoc;
39 import java.util.Map JavaDoc;
40
41 //
42
public class AntDeployInputReplacementsPanel extends JPanel
43     implements ListSelectionListener JavaDoc, SwingTableSelectionListener {
44     static ResourceBundle JavaDoc res =
45         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
46
private OtterNode node = null;
47     private GridBagLayout layoutMain;
48     private JTable table;
49     private JScrollPane scrollTable;
50     private JButton buttonAdd;
51     private JButton buttonEdit;
52     private JButton buttonRemove;
53     private JButton buttonReset;
54     private JButton buttonUp;
55     private JButton buttonDown;
56     private LocalButtonListener buttonListener;
57     private LocalTableModel tableModel = new LocalTableModel();
58     private int currentSelectionIndex = -1;
59     private SwingTableSelectionListener[] swingTableSelectionListeners =
60         new SwingTableSelectionListener[0];
61     private String JavaDoc[][] defaultTable = null;
62     private AntProject project = null;
63
64     public AntDeployInputReplacementsPanel() {
65         try {
66             jbInit();
67             pmInit();
68         } catch (Exception JavaDoc e) {
69             e.printStackTrace();
70         }
71     }
72
73     public void clearAll() {
74         buttonAdd.removeActionListener(buttonListener);
75         buttonEdit.removeActionListener(buttonListener);
76         buttonReset.removeActionListener(buttonListener);
77         buttonRemove.removeActionListener(buttonListener);
78         buttonUp.removeActionListener(buttonListener);
79         buttonDown.removeActionListener(buttonListener);
80         removeSwingTableSelectionListener(this);
81         table.getSelectionModel().removeListSelectionListener(this);
82         tableModel.removeTableModelListener(table);
83         tableModel.removeAllRows();
84         table.setModel(new DefaultTableModel JavaDoc());
85         removeAll();
86         tableModel = null;
87         buttonListener = null;
88         node = null;
89         swingTableSelectionListeners = null;
90     }
91
92     /**
93      * ListSelectionListener event
94      */

95     public void valueChanged(ListSelectionEvent JavaDoc e) {
96         ListSelectionModel lsm = (ListSelectionModel) e.getSource();
97
98         if (lsm.isSelectionEmpty()) {
99             currentSelectionIndex = -1;
100         } else {
101             currentSelectionIndex = lsm.getMinSelectionIndex();
102         }
103         fireSwingTableSelectionEvent();
104     }
105
106     private void fireSwingTableSelectionEvent() {
107         for (int i = 0; i < swingTableSelectionListeners.length; i++) {
108             swingTableSelectionListeners[i].onSwingTableSelection(new SwingTableSelectionEvent(this,
109                     currentSelectionIndex));
110         }
111     }
112
113     public synchronized void addSwingTableSelectionListener(SwingTableSelectionListener l) {
114         ArrayList JavaDoc list = null;
115
116         list = new ArrayList JavaDoc(Arrays.asList(swingTableSelectionListeners));
117         if (!list.contains(l)) {
118             list.add(l);
119             list.trimToSize();
120             swingTableSelectionListeners =
121                 new SwingTableSelectionListener[list.size()];
122             swingTableSelectionListeners =
123                 (SwingTableSelectionListener[]) list.toArray(swingTableSelectionListeners);
124         }
125         list.clear();
126     }
127
128     public synchronized void removeSwingTableSelectionListener(SwingTableSelectionListener l) {
129         ArrayList JavaDoc list = null;
130
131         list = new ArrayList JavaDoc(Arrays.asList(swingTableSelectionListeners));
132         if (list.contains(l)) {
133             list.remove(l);
134             list.trimToSize();
135             swingTableSelectionListeners =
136                 new SwingTableSelectionListener[list.size()];
137             swingTableSelectionListeners =
138                 (SwingTableSelectionListener[]) list.toArray(swingTableSelectionListeners);
139         }
140         list.clear();
141     }
142
143     public void onSwingTableSelection(SwingTableSelectionEvent event) {
144         boolean selection = (!event.isSelectionNull());
145
146         buttonEdit.setEnabled(selection);
147         buttonRemove.setEnabled(selection);
148         if (selection) {
149             int index = event.getSelectionIndex();
150             boolean down = (index < tableModel.getRowCount() - 1);
151             boolean up = (index > 0);
152
153             buttonUp.setEnabled(up);
154             buttonDown.setEnabled(down);
155         } else {
156             buttonUp.setEnabled(false);
157             buttonDown.setEnabled(false);
158         }
159     }
160
161     public OtterNode getNode() {
162         return node;
163     }
164
165     public void setNode(OtterNode n) {
166         node = n;
167     }
168
169     public void setIconView(boolean b) {
170         if (b) {
171             buttonAdd.setIcon(IconSet.getNewRowIcon());
172             buttonAdd.setText(new String JavaDoc());
173             buttonDown.setIcon(IconSet.getDownIcon());
174             buttonDown.setText(new String JavaDoc());
175             buttonEdit.setIcon(IconSet.getRowIcon());
176             buttonEdit.setText(new String JavaDoc());
177             buttonUp.setIcon(IconSet.getUpIcon());
178             buttonUp.setText(new String JavaDoc());
179             buttonRemove.setIcon(IconSet.getDeleteRowIcon());
180             buttonRemove.setText(new String JavaDoc());
181             buttonReset.setIcon(IconSet.getUndoIcon());
182             buttonReset.setText(new String JavaDoc());
183         } else {
184             buttonAdd.setIcon(null);
185             buttonAdd.setText(res.getString("buttonAdd_Text"));
186             buttonDown.setIcon(null);
187             buttonDown.setText(res.getString("buttonDown_Text"));
188             buttonEdit.setIcon(null);
189             buttonEdit.setText(res.getString("Edit"));
190             buttonUp.setIcon(null);
191             buttonUp.setText(res.getString("buttonUp_Text"));
192             buttonRemove.setIcon(null);
193             buttonRemove.setText(res.getString("Remove"));
194             buttonReset.setIcon(null);
195             buttonReset.setText(res.getString("buttonReset_Text"));
196         }
197     }
198
199     public boolean isIconView() {
200         return (buttonAdd.getIcon() == null);
201     }
202
203     public void readProperties() {
204         String JavaDoc stringIn = null;
205         File JavaDoc fileIn = null;
206         OtterProject project = null;
207
208         if (node == null) {
209             System.err.println("AntDeployInputReplacementsPanel.readProperties(): node is null");
210         } else {
211             project = node.getProject();
212             if (node instanceof OtterTemplateNode) {}
213             else {
214                 enableUI(true);
215             }
216             if (project.isDefaultProject()) {
217                 buttonAdd.setEnabled(false);
218                 buttonDown.setEnabled(false);
219                 buttonUp.setEnabled(false);
220                 buttonReset.setEnabled(false);
221             } else {
222                 setReplacementTable(project.getReplacementTable());
223             }
224         }
225         invalidate();
226     }
227
228     public void writeProperties() {
229         OtterProject project = null;
230
231         if (node == null) {
232             System.err.println("AntDeployInputReplacementsPanel.writeProperties() - node null");
233             return;
234         } else {
235             project = node.getProject();
236         }
237         if (project.isDefaultProject()) {
238
239             // done
240
} else {
241             project.setReplacementTable(getReplacementTable());
242         }
243     }
244
245     public boolean isDataEqual() {
246         String JavaDoc[][] projReps = new String JavaDoc[0][0];
247         String JavaDoc[][] memReps = new String JavaDoc[0][0];
248         boolean equal = false;
249         OtterProject project = null;
250
251         if (node == null) {
252             System.err.println("AntDeployInputReplacementsPanel.isDataEqual(): node is null");
253         } else {
254             project = node.getProject();
255             projReps = project.getReplacementTable();
256             memReps = getReplacementTable();
257             if (projReps.length == memReps.length) {
258                 equal = true;
259                 for (int i = 0; i < memReps.length; i++) {
260                     if (equal && (projReps[i].length == memReps[i].length)) {
261                         for (int j = 0; j < memReps[i].length; j++) {
262                             if (projReps[i][j].equals(memReps[i][j])) {}
263                             else {
264                                 equal = false;
265                                 break;
266                             }
267                         }
268                     } else {
269                         equal = false;
270                         break;
271                     }
272                 }
273             }
274         }
275         return equal;
276     }
277
278     public void enableUI(boolean enable) {
279         table.setEnabled(enable);
280         buttonAdd.setEnabled(enable);
281         buttonEdit.setEnabled(currentSelectionIndex > -1);
282         buttonRemove.setEnabled(currentSelectionIndex > -1);
283         buttonReset.setEnabled(enable);
284     }
285
286     //
287
//
288
private String JavaDoc[][] getReplacementTable() {
289         String JavaDoc[][] repTable = null;
290         LocalRow row = null;
291         int length = tableModel.getRowCount();
292
293         repTable = new String JavaDoc[length][2];
294         for (int i = 0; i < length; i++) {
295             row = tableModel.getRow(i);
296             repTable[i][0] = row.getFind();
297             repTable[i][1] = row.getReplaceWith();
298         }
299         return repTable;
300     }
301
302     private void setReplacementTable(String JavaDoc[][] repTable) {
303         int length = tableModel.getRowCount();
304
305         tableModel.removeAllRows();
306         for (int i = 0; i < repTable.length; i++) {
307             tableModel.addRow(repTable[i][0], repTable[i][1]);
308         }
309         removeTableSelections();
310     }
311
312     private void removeTableSelections() {
313         if (table.getSelectedRow() > -1) {
314             table.removeRowSelectionInterval(table.getSelectedRow(),
315                                              table.getSelectedRow());
316         }
317         currentSelectionIndex = -1;
318         fireSwingTableSelectionEvent();
319         table.updateUI();
320     }
321
322     private void setDefaultTable() {
323         int result = JOptionPane.YES_OPTION;
324
325         if (tableModel.getRowCount() > 0) {
326             result =
327                 JOptionPane.showConfirmDialog(this,
328                                               res.getString("Replace_current_set"),
329                                               res.getString("Switch_to_Default"),
330                                               JOptionPane.YES_NO_OPTION);
331         }
332         if (result == JOptionPane.YES_OPTION) {
333
334 // OtterProject project = node.getProject();
335
// String[][] def = new String[0][0];
336
//
337
// try {
338
// def = ConfigTool.createReplacementStringArray(project.getRootPath(),
339
// project.getDeployRootPath(),
340
// ToolBoxInfo.getJavaPath());
341
// def =
342
// Backward.createReplacementTable(def,
343
// PathUtil.getInputTemplates(project));
344
// } catch (ToolException e) {
345
// def = new String[0][0];
346
// e.printStackTrace();
347
// }
348
setReplacementTable(defaultTable);
349         }
350     }
351
352     private void addRow() {
353         AntDeployReplaceEditorDialog d = null;
354
355         if (getTopLevelAncestor() instanceof JDialog) {
356             JDialog parentDialog = (JDialog) this.getTopLevelAncestor();
357
358             d = new AntDeployReplaceEditorDialog(parentDialog,
359                                         res.getString("Add_Replace_Text"),
360                                         true);
361             d.setFind(new String JavaDoc());
362             d.setReplaceWith(new String JavaDoc());
363             d.show();
364             if (d.getOption() == AntDeployReplaceEditorDialog.ACTION_OK) {
365                 if (d.getFind().trim().length() > 0) {
366                     tableModel.addRow(d.getFind(), d.getReplaceWith());
367                     removeTableSelections();
368                 }
369             }
370         }
371     }
372
373     private void removeCurrent() {
374         int result = 0;
375
376         if (currentSelectionIndex > -1
377                 && currentSelectionIndex < tableModel.getRowCount()) {
378             result =
379                 JOptionPane.showConfirmDialog(this,
380                                               res.getString("Remove_current"),
381                                               res.getString("Confirm_Remove"),
382                                               JOptionPane.YES_NO_OPTION);
383             if (result == JOptionPane.YES_OPTION) {
384                 tableModel.removeRow(currentSelectionIndex);
385                 removeTableSelections();
386             }
387         }
388     }
389
390     private void editCurrent() {
391         AntDeployReplaceEditorDialog d = null;
392         LocalRow row = tableModel.getRow(currentSelectionIndex);
393
394         if (getTopLevelAncestor() instanceof JDialog) {
395             JDialog parentDialog = (JDialog) this.getTopLevelAncestor();
396
397             d = new AntDeployReplaceEditorDialog(parentDialog,
398                                         res.getString("Edit_Replace_Text"),
399                                         true);
400             d.setFind(row.getFind());
401             d.setReplaceWith(row.getReplaceWith());
402             d.show();
403             if (d.getOption() == AntDeployReplaceEditorDialog.ACTION_OK) {
404                 if (d.getFind().trim().length() > 0) {
405                     row.setFind(d.getFind());
406                     row.setReplaceWith(d.getReplaceWith());
407                     table.updateUI();
408                 }
409             }
410         }
411     }
412
413     private void moveRowUp() {
414         tableModel.moveUp(currentSelectionIndex);
415         table.updateUI();
416     }
417
418     private void moveRowDown() {
419         tableModel.moveDown(currentSelectionIndex);
420         table.updateUI();
421     }
422
423     private void pmInit() throws Exception JavaDoc {
424         buttonEdit.setEnabled(false);
425         buttonEdit.setToolTipText(res.getString("buttonEdit_ToolTipText"));
426         buttonRemove.setEnabled(false);
427         buttonRemove.setToolTipText(res.getString("buttonRemove_ToolTipText"));
428         buttonListener = new LocalButtonListener();
429         buttonAdd.addActionListener(buttonListener);
430         buttonAdd.setToolTipText(res.getString("buttonAdd_ToolTipText"));
431         buttonEdit.addActionListener(buttonListener);
432         buttonReset.addActionListener(buttonListener);
433         buttonReset.setToolTipText(res.getString("buttonReset_ToolTipText"));
434         buttonRemove.addActionListener(buttonListener);
435         buttonUp.addActionListener(buttonListener);
436         buttonUp.setToolTipText(res.getString("buttonUp_ToolTipText"));
437         buttonDown.addActionListener(buttonListener);
438         buttonDown.setToolTipText(res.getString("buttonDown_ToolTipText"));
439         tableModel = new LocalTableModel();
440         table.setModel(tableModel);
441
442         // table.setDefaultRenderer(String.class, new CellRendererWithToolTip());
443
tableModel.addTableModelListener(table);
444         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
445         table.getTableHeader().setUpdateTableInRealTime(false);
446         table.getTableHeader().setReorderingAllowed(false);
447         ListSelectionModel rowSM = table.getSelectionModel();
448
449         rowSM.addListSelectionListener(this);
450         addSwingTableSelectionListener(this);
451         setIconView(false);
452     }
453
454     private void jbInit() throws Exception JavaDoc {
455         layoutMain =
456             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
457                                               GridBagLayout.class.getName());
458         table = (JTable) Beans.instantiate(getClass().getClassLoader(),
459                                            JTable.class.getName());
460         buttonAdd = (JButton) Beans.instantiate(getClass().getClassLoader(),
461                                                 JButton.class.getName());
462         buttonEdit = (JButton) Beans.instantiate(getClass().getClassLoader(),
463                                                  JButton.class.getName());
464         buttonRemove =
465             (JButton) Beans.instantiate(getClass().getClassLoader(),
466                                         JButton.class.getName());
467         buttonReset = (JButton) Beans.instantiate(getClass().getClassLoader(),
468                                                   JButton.class.getName());
469         buttonUp = (JButton) Beans.instantiate(getClass().getClassLoader(),
470                                                JButton.class.getName());
471         buttonDown = (JButton) Beans.instantiate(getClass().getClassLoader(),
472                                                  JButton.class.getName());
473         scrollTable = new JScrollPane(table);
474         table.setToolTipText(new String JavaDoc());
475         table.sizeColumnsToFit(JTable.AUTO_RESIZE_ALL_COLUMNS);
476         table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
477         table.setColumnSelectionAllowed(false);
478         scrollTable.setMinimumSize(new Dimension(300, 100));
479         scrollTable.setPreferredSize(new Dimension(300, 100));
480         scrollTable.getViewport().add(table, BorderLayout.CENTER);
481
482         //
483
this.setLayout(layoutMain);
484         this.add(scrollTable,
485                  new GridBagConstraints(3, 0, 6, 1, 0.8, 0.2,
486                                         GridBagConstraints.CENTER,
487                                         GridBagConstraints.BOTH,
488                                         new Insets(0, 0, 5, 0), 0, 0));
489         this.add(buttonAdd,
490                  new GridBagConstraints(3, 1, 1, 1, 0.1, 0.0,
491                                         GridBagConstraints.CENTER,
492                                         GridBagConstraints.NONE,
493                                         new Insets(2, 1, 5, 1), 0, 0));
494         this.add(buttonEdit,
495                  new GridBagConstraints(4, 1, 1, 1, 0.1, 0.0,
496                                         GridBagConstraints.CENTER,
497                                         GridBagConstraints.NONE,
498                                         new Insets(2, 1, 5, 1), 0, 0));
499         this.add(buttonRemove,
500                  new GridBagConstraints(5, 1, 1, 1, 0.1, 0.0,
501                                         GridBagConstraints.CENTER,
502                                         GridBagConstraints.NONE,
503                                         new Insets(2, 1, 5, 1), 0, 0));
504         this.add(buttonReset,
505                  new GridBagConstraints(8, 1, 1, 1, 0.1, 0.0,
506                                         GridBagConstraints.CENTER,
507                                         GridBagConstraints.NONE,
508                                         new Insets(2, 1, 5, 1), 0, 0));
509         this.add(buttonUp,
510                  new GridBagConstraints(6, 1, 1, 1, 0.1, 0.0,
511                                         GridBagConstraints.CENTER,
512                                         GridBagConstraints.NONE,
513                                         new Insets(2, 1, 5, 1), 0, 0));
514         this.add(buttonDown,
515                  new GridBagConstraints(7, 1, 1, 1, 0.1, 0.0,
516                                         GridBagConstraints.CENTER,
517                                         GridBagConstraints.NONE,
518                                         new Insets(2, 1, 5, 1), 0, 0));
519     }
520
521     public void setProject(OtterProject otterProject){
522         if(otterProject instanceof AntProject) {
523             project = (AntProject) otterProject;
524             initOptions();
525         }
526         else
527             System.err.println("DEBUG project must be AntProject");//FIXME throw Exception
528
}
529
530     private void initOptions(){
531         HashMap JavaDoc replacementsMap = project.getReplacements();
532         Iterator JavaDoc replacementsIterator = replacementsMap.entrySet().iterator();
533         defaultTable = new String JavaDoc[replacementsMap.size()][2];
534         int i = 0;
535         Map.Entry JavaDoc mapEntry = null;
536         while (replacementsIterator.hasNext()) {
537             mapEntry = (Map.Entry JavaDoc)replacementsIterator.next();
538             defaultTable[i][0] = (String JavaDoc)mapEntry.getKey();
539             defaultTable[i][1] = (String JavaDoc)mapEntry.getValue();
540             i++;
541         }
542         setReplacementTable(defaultTable);
543     }
544
545     private void saveOptions() {
546         HashMap JavaDoc replacementsMap = new HashMap JavaDoc();
547         String JavaDoc[][] replacementsTable = this.getReplacementTable();
548         for (int i = 0; i < replacementsTable.length; i++) {
549             replacementsMap.put(replacementsTable[i][0], replacementsTable[i][1]);
550         }
551         project.setReplacements(replacementsMap);
552     }
553 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
554

555     //
556
private class LocalButtonListener implements ActionListener JavaDoc {
557         public void actionPerformed(ActionEvent JavaDoc e) {
558             Object JavaDoc source = e.getSource();
559
560             if (source == buttonReset) {
561                 setDefaultTable();
562             } else if (source == buttonRemove) {
563                 removeCurrent();
564             } else if (source == buttonAdd) {
565                 addRow();
566             } else if (source == buttonEdit) {
567                 editCurrent();
568             } else if (source == buttonUp) {
569                 moveRowUp();
570             } else if (source == buttonDown) {
571                 moveRowDown();
572             }
573
574             saveOptions();
575         }
576
577     }
578
579     //
580
private class LocalTableModel extends AbstractTableModel JavaDoc {
581         private Vector JavaDoc rowVector = new Vector JavaDoc();
582
583         public LocalTableModel() {}
584
585         public int getRowCount() {
586             int count = 0;
587
588             if (rowVector != null) {
589                 count = rowVector.size();
590             }
591             return count;
592         }
593
594         public int getColumnCount() {
595             return 2;
596         }
597
598         public String JavaDoc getColumnName(int columnIndex) {
599             String JavaDoc name = new String JavaDoc();
600
601             switch (columnIndex) {
602             case 0:
603                 name = res.getString("Text_to_find");
604                 break;
605             case 1:
606                 name = res.getString("Replace_with");
607                 break;
608             }
609             return name;
610         }
611
612         public Class JavaDoc getColumnClass(int columnIndex) {
613             Class JavaDoc columnClass = null;
614             Object JavaDoc value = getValueAt(0, columnIndex);
615
616             if (value != null) {
617                 columnClass = value.getClass();
618             }
619             return columnClass;
620         }
621
622         public boolean isCellEditable(int rowIndex, int columnIndex) {
623             return false;
624         }
625
626         public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
627             Object JavaDoc value = null;
628
629             if (!isTableEmpty()) {
630                 LocalRow row = (LocalRow) rowVector.elementAt(rowIndex);
631                 LocalCell cell = new LocalCell(columnIndex, row);
632
633                 value = cell.getValue();
634             }
635             return value;
636         }
637
638         public void setValueAt(Object JavaDoc aValue, int rowIndex, int columnIndex) {
639             if (!isTableEmpty()) {
640                 LocalRow row = (LocalRow) rowVector.elementAt(rowIndex);
641                 LocalCell cell = new LocalCell(columnIndex, row);
642
643                 cell.setValue(aValue);
644                 fireTableCellUpdated(columnIndex, rowIndex);
645             }
646         }
647
648         protected LocalRow getRow(int rowIndex) {
649             LocalRow row = null;
650
651             if (!isTableEmpty()) {
652                 if (rowVector.size() > rowIndex) {
653                     row = (LocalRow) rowVector.elementAt(rowIndex);
654                 }
655             }
656             return row;
657         }
658
659         protected void saveMap() {
660             OtterProject project = node.getProject();
661             int rowCount = rowVector.size();
662             String JavaDoc[][] map = new String JavaDoc[rowCount][2];
663             LocalRow row = null;
664
665             for (int i = 0; i < rowCount; i++) {
666                 row = (LocalRow) rowVector.elementAt(i);
667                 map[i][0] = row.getFind();
668                 map[i][1] = row.getReplaceWith();
669             }
670             project.setPackageMap(map);
671         }
672
673         protected void populateModel() {
674             OtterProject project = node.getProject();
675             String JavaDoc[][] map = project.getPackageMap();
676
677             if (map != null) {
678                 int rowCount = map.length;
679
680                 for (int i = 0; i < rowCount; i++) {
681                     addRow(map[i][0], map[i][1]);
682                 }
683             }
684         }
685
686         // /
687
// /
688
private boolean isTableEmpty() {
689             boolean empty = true;
690
691             if (rowVector != null) {
692                 if (rowVector.size() > 0) {
693                     empty = false;
694                 }
695             }
696             return empty;
697         }
698
699         private void addRow(String JavaDoc f, String JavaDoc p) {
700             LocalRow newRow = null;
701
702             newRow = new LocalRow(f, p);
703             rowVector.addElement(newRow);
704             int size = rowVector.size();
705
706             fireTableDataChanged();
707         }
708
709         private void removeRow(int index) {
710             if (index < rowVector.size()) {
711                 rowVector.removeElementAt(index);
712                 fireTableDataChanged();
713             }
714         }
715
716         private void moveUp(int index) {
717             if (index > 0 && index < rowVector.size()) {
718                 Object JavaDoc current = rowVector.elementAt(index);
719                 Object JavaDoc previous = rowVector.elementAt(index - 1);
720
721                 rowVector.setElementAt(current, index - 1);
722                 rowVector.setElementAt(previous, index);
723                 fireTableDataChanged();
724             }
725         }
726
727         private void moveDown(int index) {
728             if (index < (rowVector.size() - 1)) {
729                 Object JavaDoc current = rowVector.elementAt(index);
730                 Object JavaDoc next = rowVector.elementAt(index + 1);
731
732                 rowVector.setElementAt(current, index + 1);
733                 rowVector.setElementAt(next, index);
734                 fireTableDataChanged();
735             }
736         }
737
738         private void removeAllRows() {
739             rowVector.removeAllElements();
740             fireTableDataChanged();
741         }
742
743     }
744
745     //
746
private class LocalRow {
747         private String JavaDoc find = new String JavaDoc();
748         private String JavaDoc replaceWith = new String JavaDoc();
749
750         public LocalRow(String JavaDoc f, String JavaDoc rw) {
751             find = f;
752             replaceWith = rw;
753         }
754
755         public String JavaDoc getFind() {
756             return find;
757         }
758
759         public void setFind(String JavaDoc f) {
760             find = f;
761             saveToProject();
762         }
763
764         public String JavaDoc getReplaceWith() {
765             return replaceWith;
766         }
767
768         public void setReplaceWith(String JavaDoc rw) {
769             replaceWith = rw;
770             saveToProject();
771         }
772
773         private void saveToProject() {}
774
775     }
776
777     //
778
private class LocalCell {
779         private LocalRow row;
780         private int column;
781
782         public LocalCell(int c, LocalRow r) {
783             column = c;
784             row = r;
785         }
786
787         public boolean setValue(Object JavaDoc value) {
788             boolean set = true;
789
790             switch (column) {
791             case 0:
792                 row.setFind((String JavaDoc) value);
793                 break;
794             case 1:
795                 row.setReplaceWith((String JavaDoc) value);
796                 break;
797             default:
798                 set = false;
799                 break;
800             }
801             return set;
802         }
803
804         public Object JavaDoc getValue() {
805             Object JavaDoc value = null;
806
807             switch (column) {
808             case 0:
809                 value = row.getFind();
810                 break;
811             case 1:
812                 value = row.getReplaceWith();
813                 break;
814             }
815             return value;
816         }
817
818         //
819
//
820
protected LocalRow getRow() {
821             return row;
822         }
823
824     }
825 }
826
Popular Tags