Source Code Cross Referenced for AntDeployInputReplacementsPanel.java in  » J2EE » enhydra-IDE-plugin » org » enhydra » kelp » ant » deployer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » enhydra IDE plugin » org.enhydra.kelp.ant.deployer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.kelp.ant.deployer;
002:
003:        // ToolBox imports
004:        import org.enhydra.tool.common.IconSet;
005:
006:        // Kelp imports
007:        import org.enhydra.kelp.common.event.SwingTableSelectionEvent;
008:        import org.enhydra.kelp.common.event.SwingTableSelectionListener;
009:        import org.enhydra.kelp.common.node.OtterTemplateNode;
010:        import org.enhydra.kelp.common.node.OtterNode;
011:        import org.enhydra.kelp.common.node.OtterProject;
012:
013:        // Standard imports
014:        import java.awt.*;
015:        import java.awt.event.ActionEvent;
016:        import java.awt.event.ActionListener;
017:        import java.beans.*;
018:        import java.util.ResourceBundle;
019:        import java.util.ArrayList;
020:        import java.util.Arrays;
021:        import java.util.Vector;
022:        import javax.swing.*;
023:        import javax.swing.event.ListSelectionEvent;
024:        import javax.swing.event.ListSelectionListener;
025:        import javax.swing.table.AbstractTableModel;
026:        import javax.swing.table.DefaultTableModel;
027:        import java.util.HashMap;
028:        import org.enhydra.kelp.ant.node.AntProject;
029:        import java.util.Iterator;
030:        import java.util.Map;
031:
032:        //
033:        public class AntDeployInputReplacementsPanel extends JPanel implements 
034:                ListSelectionListener, SwingTableSelectionListener {
035:            static ResourceBundle res = ResourceBundle
036:                    .getBundle("org.enhydra.kelp.common.Res"); // nores
037:            private OtterNode node = null;
038:            private GridBagLayout layoutMain;
039:            private JTable table;
040:            private JScrollPane scrollTable;
041:            private JButton buttonAdd;
042:            private JButton buttonEdit;
043:            private JButton buttonRemove;
044:            private JButton buttonReset;
045:            private JButton buttonUp;
046:            private JButton buttonDown;
047:            private LocalButtonListener buttonListener;
048:            private LocalTableModel tableModel = new LocalTableModel();
049:            private int currentSelectionIndex = -1;
050:            private SwingTableSelectionListener[] swingTableSelectionListeners = new SwingTableSelectionListener[0];
051:            private String[][] defaultTable = null;
052:            private AntProject project = null;
053:
054:            public AntDeployInputReplacementsPanel() {
055:                try {
056:                    jbInit();
057:                    pmInit();
058:                } catch (Exception e) {
059:                    e.printStackTrace();
060:                }
061:            }
062:
063:            public void clearAll() {
064:                buttonAdd.removeActionListener(buttonListener);
065:                buttonEdit.removeActionListener(buttonListener);
066:                buttonReset.removeActionListener(buttonListener);
067:                buttonRemove.removeActionListener(buttonListener);
068:                buttonUp.removeActionListener(buttonListener);
069:                buttonDown.removeActionListener(buttonListener);
070:                removeSwingTableSelectionListener(this );
071:                table.getSelectionModel().removeListSelectionListener(this );
072:                tableModel.removeTableModelListener(table);
073:                tableModel.removeAllRows();
074:                table.setModel(new DefaultTableModel());
075:                removeAll();
076:                tableModel = null;
077:                buttonListener = null;
078:                node = null;
079:                swingTableSelectionListeners = null;
080:            }
081:
082:            /**
083:             * ListSelectionListener event
084:             */
085:            public void valueChanged(ListSelectionEvent e) {
086:                ListSelectionModel lsm = (ListSelectionModel) e.getSource();
087:
088:                if (lsm.isSelectionEmpty()) {
089:                    currentSelectionIndex = -1;
090:                } else {
091:                    currentSelectionIndex = lsm.getMinSelectionIndex();
092:                }
093:                fireSwingTableSelectionEvent();
094:            }
095:
096:            private void fireSwingTableSelectionEvent() {
097:                for (int i = 0; i < swingTableSelectionListeners.length; i++) {
098:                    swingTableSelectionListeners[i]
099:                            .onSwingTableSelection(new SwingTableSelectionEvent(
100:                                    this , currentSelectionIndex));
101:                }
102:            }
103:
104:            public synchronized void addSwingTableSelectionListener(
105:                    SwingTableSelectionListener l) {
106:                ArrayList list = null;
107:
108:                list = new ArrayList(Arrays
109:                        .asList(swingTableSelectionListeners));
110:                if (!list.contains(l)) {
111:                    list.add(l);
112:                    list.trimToSize();
113:                    swingTableSelectionListeners = new SwingTableSelectionListener[list
114:                            .size()];
115:                    swingTableSelectionListeners = (SwingTableSelectionListener[]) list
116:                            .toArray(swingTableSelectionListeners);
117:                }
118:                list.clear();
119:            }
120:
121:            public synchronized void removeSwingTableSelectionListener(
122:                    SwingTableSelectionListener l) {
123:                ArrayList list = null;
124:
125:                list = new ArrayList(Arrays
126:                        .asList(swingTableSelectionListeners));
127:                if (list.contains(l)) {
128:                    list.remove(l);
129:                    list.trimToSize();
130:                    swingTableSelectionListeners = new SwingTableSelectionListener[list
131:                            .size()];
132:                    swingTableSelectionListeners = (SwingTableSelectionListener[]) list
133:                            .toArray(swingTableSelectionListeners);
134:                }
135:                list.clear();
136:            }
137:
138:            public void onSwingTableSelection(SwingTableSelectionEvent event) {
139:                boolean selection = (!event.isSelectionNull());
140:
141:                buttonEdit.setEnabled(selection);
142:                buttonRemove.setEnabled(selection);
143:                if (selection) {
144:                    int index = event.getSelectionIndex();
145:                    boolean down = (index < tableModel.getRowCount() - 1);
146:                    boolean up = (index > 0);
147:
148:                    buttonUp.setEnabled(up);
149:                    buttonDown.setEnabled(down);
150:                } else {
151:                    buttonUp.setEnabled(false);
152:                    buttonDown.setEnabled(false);
153:                }
154:            }
155:
156:            public OtterNode getNode() {
157:                return node;
158:            }
159:
160:            public void setNode(OtterNode n) {
161:                node = n;
162:            }
163:
164:            public void setIconView(boolean b) {
165:                if (b) {
166:                    buttonAdd.setIcon(IconSet.getNewRowIcon());
167:                    buttonAdd.setText(new String());
168:                    buttonDown.setIcon(IconSet.getDownIcon());
169:                    buttonDown.setText(new String());
170:                    buttonEdit.setIcon(IconSet.getRowIcon());
171:                    buttonEdit.setText(new String());
172:                    buttonUp.setIcon(IconSet.getUpIcon());
173:                    buttonUp.setText(new String());
174:                    buttonRemove.setIcon(IconSet.getDeleteRowIcon());
175:                    buttonRemove.setText(new String());
176:                    buttonReset.setIcon(IconSet.getUndoIcon());
177:                    buttonReset.setText(new String());
178:                } else {
179:                    buttonAdd.setIcon(null);
180:                    buttonAdd.setText(res.getString("buttonAdd_Text"));
181:                    buttonDown.setIcon(null);
182:                    buttonDown.setText(res.getString("buttonDown_Text"));
183:                    buttonEdit.setIcon(null);
184:                    buttonEdit.setText(res.getString("Edit"));
185:                    buttonUp.setIcon(null);
186:                    buttonUp.setText(res.getString("buttonUp_Text"));
187:                    buttonRemove.setIcon(null);
188:                    buttonRemove.setText(res.getString("Remove"));
189:                    buttonReset.setIcon(null);
190:                    buttonReset.setText(res.getString("buttonReset_Text"));
191:                }
192:            }
193:
194:            public boolean isIconView() {
195:                return (buttonAdd.getIcon() == null);
196:            }
197:
198:            public void readProperties() {
199:                OtterProject project = null;
200:
201:                if (node == null) {
202:                    System.err
203:                            .println("AntDeployInputReplacementsPanel.readProperties(): node is null");
204:                } else {
205:                    project = node.getProject();
206:                    if (node instanceof  OtterTemplateNode) {
207:                    } else {
208:                        enableUI(true);
209:                    }
210:                    if (project.isDefaultProject()) {
211:                        buttonAdd.setEnabled(false);
212:                        buttonDown.setEnabled(false);
213:                        buttonUp.setEnabled(false);
214:                        buttonReset.setEnabled(false);
215:                    } else {
216:                        setReplacementTable(project.getReplacementTable());
217:                    }
218:                }
219:                invalidate();
220:            }
221:
222:            public void writeProperties() {
223:                OtterProject project = null;
224:
225:                if (node == null) {
226:                    System.err
227:                            .println("AntDeployInputReplacementsPanel.writeProperties() - node null");
228:                    return;
229:                } else {
230:                    project = node.getProject();
231:                }
232:                if (project.isDefaultProject()) {
233:
234:                    // done
235:                } else {
236:                    project.setReplacementTable(getReplacementTable());
237:                }
238:            }
239:
240:            public boolean isDataEqual() {
241:                String[][] projReps = new String[0][0];
242:                String[][] memReps = new String[0][0];
243:                boolean equal = false;
244:                OtterProject project = null;
245:
246:                if (node == null) {
247:                    System.err
248:                            .println("AntDeployInputReplacementsPanel.isDataEqual(): node is null");
249:                } else {
250:                    project = node.getProject();
251:                    projReps = project.getReplacementTable();
252:                    memReps = getReplacementTable();
253:                    if (projReps.length == memReps.length) {
254:                        equal = true;
255:                        for (int i = 0; i < memReps.length; i++) {
256:                            if (equal
257:                                    && (projReps[i].length == memReps[i].length)) {
258:                                for (int j = 0; j < memReps[i].length; j++) {
259:                                    if (projReps[i][j].equals(memReps[i][j])) {
260:                                    } else {
261:                                        equal = false;
262:                                        break;
263:                                    }
264:                                }
265:                            } else {
266:                                equal = false;
267:                                break;
268:                            }
269:                        }
270:                    }
271:                }
272:                return equal;
273:            }
274:
275:            public void enableUI(boolean enable) {
276:                table.setEnabled(enable);
277:                buttonAdd.setEnabled(enable);
278:                buttonEdit.setEnabled(currentSelectionIndex > -1);
279:                buttonRemove.setEnabled(currentSelectionIndex > -1);
280:                buttonReset.setEnabled(enable);
281:            }
282:
283:            //
284:            //
285:            private String[][] getReplacementTable() {
286:                String[][] repTable = null;
287:                LocalRow row = null;
288:                int length = tableModel.getRowCount();
289:
290:                repTable = new String[length][2];
291:                for (int i = 0; i < length; i++) {
292:                    row = tableModel.getRow(i);
293:                    repTable[i][0] = row.getFind();
294:                    repTable[i][1] = row.getReplaceWith();
295:                }
296:                return repTable;
297:            }
298:
299:            private void setReplacementTable(String[][] repTable) {
300:                tableModel.removeAllRows();
301:                for (int i = 0; i < repTable.length; i++) {
302:                    tableModel.addRow(repTable[i][0], repTable[i][1]);
303:                }
304:                removeTableSelections();
305:            }
306:
307:            private void removeTableSelections() {
308:                if (table.getSelectedRow() > -1) {
309:                    table.removeRowSelectionInterval(table.getSelectedRow(),
310:                            table.getSelectedRow());
311:                }
312:                currentSelectionIndex = -1;
313:                fireSwingTableSelectionEvent();
314:                table.updateUI();
315:            }
316:
317:            private void setDefaultTable() {
318:                int result = JOptionPane.YES_OPTION;
319:
320:                if (tableModel.getRowCount() > 0) {
321:                    result = JOptionPane.showConfirmDialog(this , res
322:                            .getString("Replace_current_set"), res
323:                            .getString("Switch_to_Default"),
324:                            JOptionPane.YES_NO_OPTION);
325:                }
326:                if (result == JOptionPane.YES_OPTION) {
327:
328:                    //            OtterProject project = node.getProject();
329:                    //            String[][]   def = new String[0][0];
330:                    //
331:                    //            try {
332:                    //                def = ConfigTool.createReplacementStringArray(project.getRootPath(),
333:                    //                        project.getDeployRootPath(),
334:                    //                        ToolBoxInfo.getJavaPath());
335:                    //                def =
336:                    //                    Backward.createReplacementTable(def,
337:                    //                                                    PathUtil.getInputTemplates(project));
338:                    //            } catch (ToolException e) {
339:                    //                def = new String[0][0];
340:                    //                e.printStackTrace();
341:                    //            }
342:                    setReplacementTable(defaultTable);
343:                }
344:            }
345:
346:            private void addRow() {
347:                AntDeployReplaceEditorDialog d = null;
348:
349:                if (getTopLevelAncestor() instanceof  JDialog) {
350:                    JDialog parentDialog = (JDialog) this .getTopLevelAncestor();
351:
352:                    d = new AntDeployReplaceEditorDialog(parentDialog, res
353:                            .getString("Add_Replace_Text"), true);
354:                    d.setFind(new String());
355:                    d.setReplaceWith(new String());
356:                    d.show();
357:                    if (d.getOption() == AntDeployReplaceEditorDialog.ACTION_OK) {
358:                        if (d.getFind().trim().length() > 0) {
359:                            tableModel.addRow(d.getFind(), d.getReplaceWith());
360:                            removeTableSelections();
361:                        }
362:                    }
363:                }
364:            }
365:
366:            private void removeCurrent() {
367:                int result = 0;
368:
369:                if (currentSelectionIndex > -1
370:                        && currentSelectionIndex < tableModel.getRowCount()) {
371:                    result = JOptionPane.showConfirmDialog(this , res
372:                            .getString("Remove_current"), res
373:                            .getString("Confirm_Remove"),
374:                            JOptionPane.YES_NO_OPTION);
375:                    if (result == JOptionPane.YES_OPTION) {
376:                        tableModel.removeRow(currentSelectionIndex);
377:                        removeTableSelections();
378:                    }
379:                }
380:            }
381:
382:            private void editCurrent() {
383:                AntDeployReplaceEditorDialog d = null;
384:                LocalRow row = tableModel.getRow(currentSelectionIndex);
385:
386:                if (getTopLevelAncestor() instanceof  JDialog) {
387:                    JDialog parentDialog = (JDialog) this .getTopLevelAncestor();
388:
389:                    d = new AntDeployReplaceEditorDialog(parentDialog, res
390:                            .getString("Edit_Replace_Text"), true);
391:                    d.setFind(row.getFind());
392:                    d.setReplaceWith(row.getReplaceWith());
393:                    d.show();
394:                    if (d.getOption() == AntDeployReplaceEditorDialog.ACTION_OK) {
395:                        if (d.getFind().trim().length() > 0) {
396:                            row.setFind(d.getFind());
397:                            row.setReplaceWith(d.getReplaceWith());
398:                            table.updateUI();
399:                        }
400:                    }
401:                }
402:            }
403:
404:            private void moveRowUp() {
405:                tableModel.moveUp(currentSelectionIndex);
406:                table.updateUI();
407:            }
408:
409:            private void moveRowDown() {
410:                tableModel.moveDown(currentSelectionIndex);
411:                table.updateUI();
412:            }
413:
414:            private void pmInit() throws Exception {
415:                buttonEdit.setEnabled(false);
416:                buttonEdit.setToolTipText(res
417:                        .getString("buttonEdit_ToolTipText"));
418:                buttonRemove.setEnabled(false);
419:                buttonRemove.setToolTipText(res
420:                        .getString("buttonRemove_ToolTipText"));
421:                buttonListener = new LocalButtonListener();
422:                buttonAdd.addActionListener(buttonListener);
423:                buttonAdd
424:                        .setToolTipText(res.getString("buttonAdd_ToolTipText"));
425:                buttonEdit.addActionListener(buttonListener);
426:                buttonReset.addActionListener(buttonListener);
427:                buttonReset.setToolTipText(res
428:                        .getString("buttonReset_ToolTipText"));
429:                buttonRemove.addActionListener(buttonListener);
430:                buttonUp.addActionListener(buttonListener);
431:                buttonUp.setToolTipText(res.getString("buttonUp_ToolTipText"));
432:                buttonDown.addActionListener(buttonListener);
433:                buttonDown.setToolTipText(res
434:                        .getString("buttonDown_ToolTipText"));
435:                tableModel = new LocalTableModel();
436:                table.setModel(tableModel);
437:
438:                // table.setDefaultRenderer(String.class, new CellRendererWithToolTip());
439:                tableModel.addTableModelListener(table);
440:                table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
441:                table.getTableHeader().setUpdateTableInRealTime(false);
442:                table.getTableHeader().setReorderingAllowed(false);
443:                ListSelectionModel rowSM = table.getSelectionModel();
444:
445:                rowSM.addListSelectionListener(this );
446:                addSwingTableSelectionListener(this );
447:                setIconView(false);
448:            }
449:
450:            private void jbInit() throws Exception {
451:                layoutMain = (GridBagLayout) Beans.instantiate(getClass()
452:                        .getClassLoader(), GridBagLayout.class.getName());
453:                table = (JTable) Beans.instantiate(getClass().getClassLoader(),
454:                        JTable.class.getName());
455:                buttonAdd = (JButton) Beans.instantiate(getClass()
456:                        .getClassLoader(), JButton.class.getName());
457:                buttonEdit = (JButton) Beans.instantiate(getClass()
458:                        .getClassLoader(), JButton.class.getName());
459:                buttonRemove = (JButton) Beans.instantiate(getClass()
460:                        .getClassLoader(), JButton.class.getName());
461:                buttonReset = (JButton) Beans.instantiate(getClass()
462:                        .getClassLoader(), JButton.class.getName());
463:                buttonUp = (JButton) Beans.instantiate(getClass()
464:                        .getClassLoader(), JButton.class.getName());
465:                buttonDown = (JButton) Beans.instantiate(getClass()
466:                        .getClassLoader(), JButton.class.getName());
467:                scrollTable = new JScrollPane(table);
468:                table.setToolTipText(new String());
469:                table.sizeColumnsToFit(JTable.AUTO_RESIZE_ALL_COLUMNS);
470:                table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
471:                table.setColumnSelectionAllowed(false);
472:                scrollTable.setMinimumSize(new Dimension(300, 100));
473:                scrollTable.setPreferredSize(new Dimension(300, 100));
474:                scrollTable.getViewport().add(table, BorderLayout.CENTER);
475:
476:                //
477:                this .setLayout(layoutMain);
478:                this .add(scrollTable, new GridBagConstraints(3, 0, 6, 1, 0.8,
479:                        0.2, GridBagConstraints.CENTER,
480:                        GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0));
481:                this .add(buttonAdd, new GridBagConstraints(3, 1, 1, 1, 0.1,
482:                        0.0, GridBagConstraints.CENTER,
483:                        GridBagConstraints.NONE, new Insets(2, 1, 5, 1), 0, 0));
484:                this .add(buttonEdit, new GridBagConstraints(4, 1, 1, 1, 0.1,
485:                        0.0, GridBagConstraints.CENTER,
486:                        GridBagConstraints.NONE, new Insets(2, 1, 5, 1), 0, 0));
487:                this .add(buttonRemove, new GridBagConstraints(5, 1, 1, 1, 0.1,
488:                        0.0, GridBagConstraints.CENTER,
489:                        GridBagConstraints.NONE, new Insets(2, 1, 5, 1), 0, 0));
490:                this .add(buttonReset, new GridBagConstraints(8, 1, 1, 1, 0.1,
491:                        0.0, GridBagConstraints.CENTER,
492:                        GridBagConstraints.NONE, new Insets(2, 1, 5, 1), 0, 0));
493:                this .add(buttonUp, new GridBagConstraints(6, 1, 1, 1, 0.1, 0.0,
494:                        GridBagConstraints.CENTER, GridBagConstraints.NONE,
495:                        new Insets(2, 1, 5, 1), 0, 0));
496:                this .add(buttonDown, new GridBagConstraints(7, 1, 1, 1, 0.1,
497:                        0.0, GridBagConstraints.CENTER,
498:                        GridBagConstraints.NONE, new Insets(2, 1, 5, 1), 0, 0));
499:            }
500:
501:            public void setProject(OtterProject otterProject) {
502:                if (otterProject instanceof  AntProject) {
503:                    project = (AntProject) otterProject;
504:                    initOptions();
505:                } else
506:                    System.err.println("DEBUG project must be AntProject");//FIXME throw Exception
507:            }
508:
509:            private void initOptions() {
510:                HashMap replacementsMap = project.getReplacements();
511:                Iterator replacementsIterator = replacementsMap.entrySet()
512:                        .iterator();
513:                defaultTable = new String[replacementsMap.size()][2];
514:                int i = 0;
515:                Map.Entry mapEntry = null;
516:                while (replacementsIterator.hasNext()) {
517:                    mapEntry = (Map.Entry) replacementsIterator.next();
518:                    defaultTable[i][0] = (String) mapEntry.getKey();
519:                    defaultTable[i][1] = (String) mapEntry.getValue();
520:                    i++;
521:                }
522:                setReplacementTable(defaultTable);
523:            }
524:
525:            private void saveOptions() {
526:                HashMap replacementsMap = new HashMap();
527:                String[][] replacementsTable = this .getReplacementTable();
528:                for (int i = 0; i < replacementsTable.length; i++) {
529:                    replacementsMap.put(replacementsTable[i][0],
530:                            replacementsTable[i][1]);
531:                }
532:                project.setReplacements(replacementsMap);
533:            }
534:
535:            //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
536:
537:            //
538:            private class LocalButtonListener implements  ActionListener {
539:                public void actionPerformed(ActionEvent e) {
540:                    Object source = e.getSource();
541:
542:                    if (source == buttonReset) {
543:                        setDefaultTable();
544:                    } else if (source == buttonRemove) {
545:                        removeCurrent();
546:                    } else if (source == buttonAdd) {
547:                        addRow();
548:                    } else if (source == buttonEdit) {
549:                        editCurrent();
550:                    } else if (source == buttonUp) {
551:                        moveRowUp();
552:                    } else if (source == buttonDown) {
553:                        moveRowDown();
554:                    }
555:
556:                    saveOptions();
557:                }
558:
559:            }
560:
561:            //
562:            private class LocalTableModel extends AbstractTableModel {
563:                private Vector rowVector = new Vector();
564:
565:                public LocalTableModel() {
566:                }
567:
568:                public int getRowCount() {
569:                    int count = 0;
570:
571:                    if (rowVector != null) {
572:                        count = rowVector.size();
573:                    }
574:                    return count;
575:                }
576:
577:                public int getColumnCount() {
578:                    return 2;
579:                }
580:
581:                public String getColumnName(int columnIndex) {
582:                    String name = new String();
583:
584:                    switch (columnIndex) {
585:                    case 0:
586:                        name = res.getString("Text_to_find");
587:                        break;
588:                    case 1:
589:                        name = res.getString("Replace_with");
590:                        break;
591:                    }
592:                    return name;
593:                }
594:
595:                public Class getColumnClass(int columnIndex) {
596:                    Class columnClass = null;
597:                    Object value = getValueAt(0, columnIndex);
598:
599:                    if (value != null) {
600:                        columnClass = value.getClass();
601:                    }
602:                    return columnClass;
603:                }
604:
605:                public boolean isCellEditable(int rowIndex, int columnIndex) {
606:                    return false;
607:                }
608:
609:                public Object getValueAt(int rowIndex, int columnIndex) {
610:                    Object value = null;
611:
612:                    if (!isTableEmpty()) {
613:                        LocalRow row = (LocalRow) rowVector.elementAt(rowIndex);
614:                        LocalCell cell = new LocalCell(columnIndex, row);
615:
616:                        value = cell.getValue();
617:                    }
618:                    return value;
619:                }
620:
621:                public void setValueAt(Object aValue, int rowIndex,
622:                        int columnIndex) {
623:                    if (!isTableEmpty()) {
624:                        LocalRow row = (LocalRow) rowVector.elementAt(rowIndex);
625:                        LocalCell cell = new LocalCell(columnIndex, row);
626:
627:                        cell.setValue(aValue);
628:                        fireTableCellUpdated(columnIndex, rowIndex);
629:                    }
630:                }
631:
632:                protected LocalRow getRow(int rowIndex) {
633:                    LocalRow row = null;
634:
635:                    if (!isTableEmpty()) {
636:                        if (rowVector.size() > rowIndex) {
637:                            row = (LocalRow) rowVector.elementAt(rowIndex);
638:                        }
639:                    }
640:                    return row;
641:                }
642:
643:                protected void saveMap() {
644:                    OtterProject project = node.getProject();
645:                    int rowCount = rowVector.size();
646:                    String[][] map = new String[rowCount][2];
647:                    LocalRow row = null;
648:
649:                    for (int i = 0; i < rowCount; i++) {
650:                        row = (LocalRow) rowVector.elementAt(i);
651:                        map[i][0] = row.getFind();
652:                        map[i][1] = row.getReplaceWith();
653:                    }
654:                    project.setPackageMap(map);
655:                }
656:
657:                protected void populateModel() {
658:                    OtterProject project = node.getProject();
659:                    String[][] map = project.getPackageMap();
660:
661:                    if (map != null) {
662:                        int rowCount = map.length;
663:
664:                        for (int i = 0; i < rowCount; i++) {
665:                            addRow(map[i][0], map[i][1]);
666:                        }
667:                    }
668:                }
669:
670:                // /
671:                // /
672:                private boolean isTableEmpty() {
673:                    boolean empty = true;
674:
675:                    if (rowVector != null) {
676:                        if (rowVector.size() > 0) {
677:                            empty = false;
678:                        }
679:                    }
680:                    return empty;
681:                }
682:
683:                private void addRow(String f, String p) {
684:                    LocalRow newRow = null;
685:
686:                    newRow = new LocalRow(f, p);
687:                    rowVector.addElement(newRow);
688:                    fireTableDataChanged();
689:                }
690:
691:                private void removeRow(int index) {
692:                    if (index < rowVector.size()) {
693:                        rowVector.removeElementAt(index);
694:                        fireTableDataChanged();
695:                    }
696:                }
697:
698:                private void moveUp(int index) {
699:                    if (index > 0 && index < rowVector.size()) {
700:                        Object current = rowVector.elementAt(index);
701:                        Object previous = rowVector.elementAt(index - 1);
702:
703:                        rowVector.setElementAt(current, index - 1);
704:                        rowVector.setElementAt(previous, index);
705:                        fireTableDataChanged();
706:                    }
707:                }
708:
709:                private void moveDown(int index) {
710:                    if (index < (rowVector.size() - 1)) {
711:                        Object current = rowVector.elementAt(index);
712:                        Object next = rowVector.elementAt(index + 1);
713:
714:                        rowVector.setElementAt(current, index + 1);
715:                        rowVector.setElementAt(next, index);
716:                        fireTableDataChanged();
717:                    }
718:                }
719:
720:                private void removeAllRows() {
721:                    rowVector.removeAllElements();
722:                    fireTableDataChanged();
723:                }
724:
725:            }
726:
727:            //
728:            private class LocalRow {
729:                private String find = new String();
730:                private String replaceWith = new String();
731:
732:                public LocalRow(String f, String rw) {
733:                    find = f;
734:                    replaceWith = rw;
735:                }
736:
737:                public String getFind() {
738:                    return find;
739:                }
740:
741:                public void setFind(String f) {
742:                    find = f;
743:                    saveToProject();
744:                }
745:
746:                public String getReplaceWith() {
747:                    return replaceWith;
748:                }
749:
750:                public void setReplaceWith(String rw) {
751:                    replaceWith = rw;
752:                    saveToProject();
753:                }
754:
755:                private void saveToProject() {
756:                }
757:
758:            }
759:
760:            //
761:            private class LocalCell {
762:                private LocalRow row;
763:                private int column;
764:
765:                public LocalCell(int c, LocalRow r) {
766:                    column = c;
767:                    row = r;
768:                }
769:
770:                public boolean setValue(Object value) {
771:                    boolean set = true;
772:
773:                    switch (column) {
774:                    case 0:
775:                        row.setFind((String) value);
776:                        break;
777:                    case 1:
778:                        row.setReplaceWith((String) value);
779:                        break;
780:                    default:
781:                        set = false;
782:                        break;
783:                    }
784:                    return set;
785:                }
786:
787:                public Object getValue() {
788:                    Object value = null;
789:
790:                    switch (column) {
791:                    case 0:
792:                        value = row.getFind();
793:                        break;
794:                    case 1:
795:                        value = row.getReplaceWith();
796:                        break;
797:                    }
798:                    return value;
799:                }
800:
801:                //
802:                //
803:                protected LocalRow getRow() {
804:                    return row;
805:                }
806:
807:            }
808:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.