1 package gov.nasa.pds.ltdt.gui;
2
3 import gov.nasa.pds.ltdt.gui.configuration.LTDTKeys;
4 import gov.nasa.pds.ltdt.gui.util.DictionaryUtility;
5 import gov.nasa.pds.ltdt.gui.util.ProcessWaitGlassPane;
6 import gov.nasa.pds.ltdt.gui.util.ProjectUtility;
7 import gov.nasa.pds.ltdt.gui.util.Utility;
8 import gov.nasa.pds.tools.dict.ElementDefinition;
9 import gov.nasa.pds.tools.dict.ObjectDefinition;
10 import gov.nasa.pds.tools.label.parser.ParseException;
11
12 import java.awt.Color;
13 import java.awt.Dimension;
14 import java.awt.Toolkit;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.awt.event.KeyEvent;
18 import java.io.BufferedReader;
19 import java.io.File;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.InputStreamReader;
23 import java.net.MalformedURLException;
24 import java.net.URL;
25 import java.util.HashMap;
26 import java.util.Properties;
27
28 import javax.swing.AbstractAction;
29 import javax.swing.Action;
30 import javax.swing.ImageIcon;
31 import javax.swing.JButton;
32 import javax.swing.JFileChooser;
33 import javax.swing.JMenu;
34 import javax.swing.JMenuBar;
35 import javax.swing.JMenuItem;
36 import javax.swing.JOptionPane;
37 import javax.swing.JToolBar;
38 import javax.swing.KeyStroke;
39 import javax.swing.event.UndoableEditEvent;
40 import javax.swing.event.UndoableEditListener;
41 import javax.swing.text.AbstractDocument;
42 import javax.swing.text.DefaultEditorKit;
43 import javax.swing.text.JTextComponent;
44 import javax.swing.undo.CannotRedoException;
45 import javax.swing.undo.CannotUndoException;
46 import javax.swing.undo.UndoManager;
47
48
49
50
51
52 public class Menu {
53
54
55
56
57
58 JMenuBar jmb;
59
60 JMenu jmFile;
61 JMenuItem jmiFileProjectGallery;
62
63
64
65
66
67
68
69
70 JMenuItem jmiFileNewProject;
71 JMenuItem jmiFileOpenProject;
72 JMenuItem jmiFileSaveProject;
73 JMenuItem jmiFileSaveProjectAs;
74 JMenuItem jmiFileCloseProject;
75
76
77 JMenuItem jmiFileExportTemplate;
78 JMenuItem jmiFileExportWDD;
79
80
81 JMenuItem jmiFileExportPSDD;
82 JMenuItem jmiFileExportLDD;
83 JMenuItem jmiFilePrint;
84 JMenuItem jmiFileQuit;
85
86 JMenu jmEdit;
87 JMenuItem jmiEditUndo;
88 JMenuItem jmiEditRedo;
89 JMenuItem jmiEditCut;
90 JMenuItem jmiEditCopy;
91 JMenuItem jmiEditPaste;
92 JMenuItem jmiEditSelectAll;
93
94 JMenu jmDict;
95 JMenuItem jmiDictAddObject;
96 JMenuItem jmiDictAddElement;
97
98 JMenuItem jmiDictModify;
99
100 JMenuItem jmiDictImport;
101
102 JMenu jmTools;
103 JMenuItem jmiToolsReformat;
104 JMenuItem jmiToolsValidate;
105 JMenu jmHelp;
106 JMenuItem jmiHelpAbout;
107
108 JToolBar jtb;
109
110
111
112
113
114
115 ImageIcon newProjectIcon;
116 URL newProjectURL;
117 JButton jbtnNewProj;
118
119
120 ImageIcon openProjectIcon;
121 URL openProjectURL;
122 JButton jbtnOpenProj;
123
124
125 ImageIcon saveProjectIcon;
126 URL saveProjectURL;
127 JButton jbtnSaveProj;
128
129
130 ImageIcon saveProjectAsIcon;
131 URL saveProjectAsURL;
132 JButton jbtnSaveProjAs;
133
134
135 ImageIcon closeProjectIcon;
136 URL closeProjectURL;
137 JButton jbtnCloseProject;
138
139
140 ImageIcon copyIcon;
141 URL copyURL;
142 JButton jbtnCopy;
143
144
145 ImageIcon cutIcon;
146 URL cutURL;
147 JButton jbtnCut;
148
149
150 ImageIcon pasteIcon;
151 URL pasteURL;
152 JButton jbtnPaste;
153
154
155 ImageIcon reformatIcon;
156 URL reformatURL;
157 JButton jbtnReformat;
158
159
160 ImageIcon validateIcon;
161 URL validateURL;
162 JButton jbtnValidate;
163
164
165 ImageIcon quitToolIcon;
166 URL quitToolURL;
167 JButton jbtnQuitTool;
168
169
170 ImageIcon toolHelpIcon;
171 URL toolHelpURL;
172 JButton jbtnToolHelp;
173
174 NewProjectAction newProjectAction = null;
175 OpenProjectAction openProjectAction = null;
176 SaveProjectAction saveProjectAction = null;
177 ReformatAction reformatAction = null;
178 ValidateAction validateAction = null;
179 QuitToolAction quitToolAction = null;
180 SaveProjectAsAction saveProjectAsAction = null;
181 CloseProjectAction closeProjectAction = null;
182 HelpAction helpAction = null;
183
184
185 UndoAction undoAction = null;
186 RedoAction redoAction = null;
187 UndoManager undo = new UndoManager();
188 AbstractDocument doc;
189 HashMap actions;
190
191
192 ActionListener wListener = null;
193
194
195 private MainWindow window = null;
196 private Properties props;
197 private URL dictionaryURL = null;
198
199 private final ProcessWaitGlassPane pw2 = new ProcessWaitGlassPane();
200
201 public Menu(Properties props, MainWindow window)
202 {
203
204 this.window = window;
205 this.props = props;
206
207 initToolBarIcons();
208
209 constructMenuBar();
210
211 constructToolBar();
212
213
214 doc = (AbstractDocument)window.editorPane.jta.getDocument();
215 doc.addUndoableEditListener(new TemplateUndoableEditListener());
216 }
217
218 private void initToolBarIcons() {
219
220 newProjectURL = null;
221 newProjectIcon = null;
222 newProjectAction = new NewProjectAction
223 ("Create New Project ...", newProjectIcon, "Create Project", null, props, window);
224
225 openProjectURL = this.getClass().getResource("document-open.png");
226 openProjectIcon = new ImageIcon(openProjectURL);
227 openProjectAction = new OpenProjectAction
228 ("Open Project ...",openProjectIcon,"Open Project", null, props, window);
229
230 saveProjectURL = this.getClass().getResource("document-save.png");
231 saveProjectIcon = new ImageIcon(saveProjectURL);
232 saveProjectAction = new SaveProjectAction
233 ("Save Project", saveProjectIcon, "Save Project", null, props, window);
234
235 saveProjectAsURL = this.getClass().getResource("document-save-as.png");
236 saveProjectAsIcon = new ImageIcon (saveProjectAsURL);
237 saveProjectAsAction = new SaveProjectAsAction
238 ("Save Project As ...", saveProjectAsIcon, "Save Project As", null, props, window);
239
240 closeProjectURL = null;
241 closeProjectIcon = null;
242 closeProjectAction = new CloseProjectAction
243 ("Close Project", closeProjectIcon, "Close Project", null, props, window);
244
245 reformatURL = this.getClass().getResource("view-refresh.png");
246 reformatIcon = new ImageIcon (reformatURL);
247 reformatAction = new ReformatAction
248 ("Reformat", reformatIcon, "Reformat Template", null, props, window);
249
250
251 validateURL = this.getClass().getResource("emblem-system.png");
252 validateIcon = new ImageIcon(validateURL);
253 validateAction = new ValidateAction
254 ("Validate", validateIcon, "Validate Template", null, props, window);
255
256
257 quitToolURL = null;
258 quitToolIcon = null;
259 quitToolAction = new QuitToolAction
260 ("Quit LTDTool",quitToolIcon,"Quit LTDTool", null, props, window);
261
262 toolHelpURL = null;
263 toolHelpIcon = null;
264 helpAction = new HelpAction
265 ("About LTDTool",toolHelpIcon,"About LTDTool", null, props, window);
266
267 undoAction = new UndoAction();
268 redoAction = new RedoAction();
269
270 copyURL = this.getClass().getResource("edit-copy.png");
271 copyIcon = new ImageIcon(copyURL);
272
273 cutURL = this.getClass().getResource("edit-cut.png");
274 cutIcon = new ImageIcon(cutURL);
275
276 pasteURL = this.getClass().getResource("edit-paste.png");
277 pasteIcon = new ImageIcon(pasteURL);
278 }
279
280 /***
281 * instantiate items on the menu bar and define event handler associations
282 */
283 private void constructMenuBar() {
284
285 jmb = new JMenuBar();
286
287
288 jmFile = new JMenu("File");
289 if (System.getProperty("os.name").startsWith("Windows")) {
290 jmFile.setMnemonic(KeyEvent.VK_F);
291 }
292
293 jmiFileProjectGallery=new JMenuItem("Project Gallery...");
294 jmiFileProjectGallery.addActionListener(new ActionListener() {
295
296 public void actionPerformed(ActionEvent ae) {
297 ProjectGalleryDialog pd=
298 new ProjectGalleryDialog (props, window, LTDTKeys.PROJECTGALLERYTITLE, -1);
299 pd.setVisible(false);
300 }
301
302 });
303
304
305
306
307
308
309
310
311
312
313 jmiFileNewProject = new JMenuItem(newProjectAction);
314 jmiFileNewProject.setIcon(null);
315 jmiFileNewProject.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
316 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
317
318
319 jmiFileOpenProject = new JMenuItem (openProjectAction);
320 jmiFileOpenProject.setIcon(null);
321 jmiFileOpenProject.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
322 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
323
324 jmiFileSaveProject = new JMenuItem (saveProjectAction);
325 jmiFileSaveProject.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
326 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
327 jmiFileSaveProject.setIcon(null);
328
329 jmiFileSaveProjectAs = new JMenuItem (saveProjectAsAction);
330 jmiFileSaveProjectAs.setIcon(null);
331
332 jmiFileCloseProject = new JMenuItem (closeProjectAction);
333 jmiFileCloseProject.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W,
334 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
335 jmiFileCloseProject.setIcon(null);
336
337
338
339 jmiFileExportTemplate = new JMenuItem ("Export Template ...");
340 jmiFileExportTemplate.setToolTipText("Export Template");
341 jmiFileExportTemplate.addActionListener(new ActionListener() {
342
343 public void actionPerformed(ActionEvent ae) {
344 Export.exportTemplate(props, window);
345 }
346 });
347
348 jmiFileExportWDD = new JMenuItem ("Export WDD ...");
349 jmiFileExportWDD.setToolTipText("Export WDD");
350 jmiFileExportWDD.addActionListener(new ActionListener() {
351
352 public void actionPerformed(ActionEvent ae) {
353 Export.exportWDD(props, window);
354 }
355 });
356
357
358
359
360
361
362
363
364
365
366 jmiFilePrint = new JMenuItem("Print");
367 jmiFilePrint.setEnabled(false);
368 jmiFilePrint.addActionListener(new ActionListener() {
369 public void actionPerformed(ActionEvent ae) {
370
371 }
372 });
373
374 jmiFileQuit = new JMenuItem(quitToolAction);
375 jmiFileQuit.setIcon(null);
376
377
378 jmEdit = new JMenu("Edit");
379 if (System.getProperty("os.name").startsWith("Windows")) {
380 jmEdit.setMnemonic(KeyEvent.VK_E);
381 }
382
383 jmiEditUndo = new JMenuItem(undoAction);
384 jmiEditUndo.setText("Undo");
385 jmiEditUndo.setToolTipText("Undo");
386 jmiEditUndo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,
387 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
388
389 jmiEditRedo = new JMenuItem(redoAction);
390 jmiEditRedo.setText("Redo");
391 jmiEditRedo.setToolTipText("Redo");
392 jmiEditRedo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y,
393 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
394
395
396 jmiEditCut = new JMenuItem (new DefaultEditorKit.CutAction());
397 jmiEditCut.setText("Cut");
398 jmiEditCut.setToolTipText("Cut");
399 jmiEditCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
400 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
401
402 jmiEditCopy = new JMenuItem (new DefaultEditorKit.CopyAction());
403 jmiEditCopy.setText("Copy");
404 jmiEditCopy.setToolTipText("Copy");
405 jmiEditCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
406 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
407
408 jmiEditPaste = new JMenuItem (new DefaultEditorKit.PasteAction());
409 jmiEditPaste.setText("Paste");
410 jmiEditPaste.setToolTipText("Paste");
411 jmiEditPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
412 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
413
414 jmiEditSelectAll = new JMenuItem ("Select All");
415 jmiEditSelectAll.setToolTipText("Select All");
416 jmiEditSelectAll.addActionListener( new ActionListener () {
417 public void actionPerformed(ActionEvent e) {
418 window.editorPane.jta.selectAll();
419 }
420 });
421 jmiEditSelectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,
422 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
423
424
425 jmDict = new JMenu ("Dictionary");
426 if (System.getProperty("os.name").startsWith("Windows")) {
427 jmDict.setMnemonic(KeyEvent.VK_D);
428 }
429
430
431 jmiDictImport = new JMenuItem ("Import ...");
432 jmiDictImport.setToolTipText("Import Dictionary");
433 jmiDictImport.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,
434 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
435 jmiDictImport.setActionCommand(LTDTKeys.GETDICTIONARYFROMFILE);
436 jmiDictImport.addActionListener(new ActionListener() {
437 public void actionPerformed(ActionEvent ae) {
438
439 importDataDictionary(ae);
440 }
441 });
442
443 jmiDictAddObject = new JMenuItem("Add Object ...");
444 jmiDictAddObject.setToolTipText("Add Object");
445 jmiDictAddObject.addActionListener(new ActionListener() {
446 public void actionPerformed(ActionEvent ae) {
447 new ObjectDialog (props, window, LTDTKeys.ADDOBJECTTITLE, null);
448 }
449
450 } );
451
452 jmiDictAddElement = new JMenuItem("Add Element ...");
453 jmiDictAddElement.setToolTipText("Add Element");
454 jmiDictAddElement.addActionListener(new ActionListener() {
455 public void actionPerformed(ActionEvent ae) {
456 new ElementDialog (props, window, LTDTKeys.ADDELEMENTTITLE, null);
457 }
458
459 } );
460
461 jmiDictModify = new JMenuItem("Modify Object/Element ...");
462 jmiDictModify.setToolTipText("Modify Object/Element");
463 jmiDictModify.addActionListener(new ActionListener() {
464
465 public void actionPerformed(ActionEvent ae) {
466 modifyDictionaryKeyword();
467 }
468 });
469
470
471
472
473 jmTools = new JMenu("Tools");
474 if (System.getProperty("os.name").startsWith("Windows")) {
475 jmTools.setMnemonic(KeyEvent.VK_T);
476 }
477
478
479 jmiToolsReformat = new JMenuItem(reformatAction);
480 jmiToolsReformat.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
481 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
482 jmiToolsReformat.setIcon(null);
483
484 jmiToolsValidate = new JMenuItem(validateAction);
485 jmiToolsValidate.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
486 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
487 jmiToolsValidate.setIcon(null);
488
489
490 jmHelp = new JMenu("Help");
491 if (System.getProperty("os.name").startsWith("Windows")) {
492 jmHelp.setMnemonic(KeyEvent.VK_H);
493 }
494
495 jmiHelpAbout = new JMenuItem(helpAction);
496
497
498
499
500
501 jmiHelpAbout.setIcon(null);
502
503
504
505
506
507 jmFile.add(jmiFileNewProject);
508
509
510
511
512 jmFile.add(jmiFileOpenProject);
513
514 jmFile.add(jmiFileSaveProject);
515 jmFile.add(jmiFileSaveProjectAs);
516 jmFile.add(jmiFileCloseProject);
517 jmFile.addSeparator();
518
519
520
521
522
523
524
525
526
527 jmFile.add(jmiFileExportTemplate);
528 jmFile.add(jmiFileExportWDD);
529 jmFile.addSeparator();
530
531 jmFile.add(jmiFilePrint);
532 jmFile.addSeparator();
533
534 jmFile.add(jmiFileQuit);
535
536
537 jmEdit.add(jmiEditUndo);
538 jmEdit.add(jmiEditRedo);
539 jmEdit.addSeparator();
540 jmEdit.add(jmiEditCut);
541 jmEdit.add(jmiEditCopy);
542 jmEdit.add(jmiEditPaste);
543 jmEdit.add(jmiEditSelectAll);
544
545
546
547
548
549 jmDict.add(jmiDictImport);
550 jmDict.add(jmiDictAddObject);
551 jmDict.add(jmiDictAddElement);
552 jmDict.add(jmiDictModify);
553
554
555
556 jmTools.add(jmiToolsReformat);
557 jmTools.add(jmiToolsValidate);
558
559
560 jmHelp.add(jmiHelpAbout);
561
562
563
564 jmb.add(jmFile);
565
566
567 jmb.add(jmEdit);
568
569
570 jmb.add(jmDict);
571
572
573 jmb.add(jmTools);
574
575
576 jmb.add(jmHelp);
577 }
578
579 private void constructToolBar() {
580
581 jtb = new JToolBar();
582 jtb.setFloatable(false);
583 jtb.setRollover(true);
584
585 jbtnOpenProj = new JButton(openProjectAction);
586 if (jbtnOpenProj.getIcon()!=null) jbtnOpenProj.setText("");
587
588 jbtnSaveProj = new JButton(saveProjectAction);
589 if (jbtnSaveProj.getIcon()!=null) jbtnSaveProj.setText("");
590
591 jbtnSaveProjAs = new JButton(saveProjectAsAction);
592 if (jbtnSaveProjAs.getIcon()!=null) jbtnSaveProjAs.setText("");
593
594 jbtnReformat = new JButton(reformatAction);
595 if (jbtnReformat.getIcon()!=null) jbtnReformat.setText("");
596
597 jbtnValidate = new JButton(validateAction);
598 if (jbtnValidate.getIcon()!=null) jbtnValidate.setText("");
599
600 jbtnCut = new JButton(new DefaultEditorKit.CutAction());
601 jbtnCut.setIcon(cutIcon);
602 jbtnCut.setToolTipText("Cut");
603 if (jbtnCut.getIcon()!=null) jbtnCut.setText("");
604
605 jbtnCopy = new JButton(new DefaultEditorKit.CopyAction());
606 jbtnCopy.setIcon(copyIcon);
607 jbtnCopy.setToolTipText("Copy");
608 if (jbtnCopy.getIcon()!=null) jbtnCopy.setText("");
609
610 jbtnPaste = new JButton(new DefaultEditorKit.PasteAction());
611 jbtnPaste.setIcon(pasteIcon);
612 jbtnPaste.setToolTipText("Paste");
613 if (jbtnPaste.getIcon()!=null) jbtnPaste.setText("");
614
615 jtb.add(jbtnOpenProj);
616 jtb.add(jbtnSaveProj);
617
618 jtb.addSeparator(new Dimension(20,15));
619 jtb.add(jbtnCut);
620 jtb.add(jbtnCopy);
621 jtb.add(jbtnPaste);
622 jtb.addSeparator(new Dimension(20,15));
623 jtb.add(jbtnReformat);
624 jtb.add(jbtnValidate);
625 }
626
627
628 JMenuBar getMenuBar() {
629 return jmb;
630 }
631
632 JToolBar getToolBar() {
633 return jtb;
634 }
635
636
637
638 private void createNewProject(ActionEvent ae) {
639
640 ProjectCreateDialog dlg = null;
641
642 if ("true".equals(props.getProperty(LTDTKeys.PROJECTALTERED))) {
643
644
645
646 int response=JOptionPane.showConfirmDialog(window,
647 "Do you want to save changes to this project?",
648 "Project Altered", JOptionPane.YES_NO_CANCEL_OPTION);
649 switch (response) {
650 case JOptionPane.YES_OPTION:
651 int status = ProjectSave.save(props, window);
652
653 dlg = new ProjectCreateDialog(props, window, LTDTKeys.NEWPROJECTTITLE, LTDTKeys.NEWEMPTYPROJECT);
654 if (dlg.getCreateSaveAsStatus()==LTDTKeys.SUCCESS) {
655
656 }
657 return;
658 case JOptionPane.NO_OPTION:
659 dlg = new ProjectCreateDialog(props, window, LTDTKeys.NEWPROJECTTITLE, LTDTKeys.NEWEMPTYPROJECT);
660 if (dlg.getCreateSaveAsStatus()==LTDTKeys.SUCCESS) {
661
662 }
663 return;
664
665 case JOptionPane.CLOSED_OPTION:
666 case JOptionPane.CANCEL_OPTION:
667 return;
668 default:;
669 }
670 }
671
672 else {
673 dlg = new ProjectCreateDialog(props, window, LTDTKeys.NEWPROJECTTITLE, LTDTKeys.NEWEMPTYPROJECT);
674 if (dlg.getCreateSaveAsStatus()==LTDTKeys.SUCCESS) {
675
676 }
677 else
678 return;
679 }
680
681
682
683 }
684
685 private void importDataDictionary(ActionEvent ae) {
686
687 if ((LTDTKeys.GETDICTIONARYFROMFILE).equals(ae.getActionCommand())) {
688
689 JFileChooser jfc = new JFileChooser();
690 if ((LTDTKeys.UNTITLED).equals(this.props.getProperty(LTDTKeys.PROJECTNAME)))
691 jfc.setCurrentDirectory(new File(System.getProperty("user.dir")));
692 else
693 jfc.setCurrentDirectory(new File(this.props.getProperty(LTDTKeys.PROJECTDIR)));
694
695 int result = jfc.showOpenDialog(window);
696
697 if (result == JFileChooser.APPROVE_OPTION) {
698 File inFile = jfc.getSelectedFile();
699 try {
700 dictionaryURL = Utility.toURL(inFile.toString());
701 }
702 catch (MalformedURLException ex) {
703
704 }
705 }
706 else return;
707
708
709 }
710 else if ((LTDTKeys.GETDICTIONARYFROMURL).equals(ae.getActionCommand())) {
711
712 dictionaryURL = getURL (window);
713
714 if (dictionaryURL==null) return;
715 }
716
717
718
719 window.setGlassPane(pw2);
720 pw2.setBackground( new Color(255, 255, 255, 255) );
721 pw2.setForeground( Color.LIGHT_GRAY);
722
723 pw2.activate("Importing Data Dictionary. Please wait ...");
724 Thread thread = new Thread()
725 {
726 public void run () {
727
728 addDictionary();
729 pw2.deactivate();
730 }
731 };
732 thread.start();
733
734 }
735
736 private void addDictionary() {
737
738
739
740 int dictionaryParsingStatus = window.dictionaryMap.addSingleDictionary (props, window, dictionaryURL);
741
742 if (dictionaryParsingStatus==LTDTKeys.SUCCESS) {
743
744
745
746 try {
747 window.mDictionary = DictionaryUtility.MergeDictionary(window.mDictionary, dictionaryURL);
748 }
749 catch ( MalformedURLException me) {
750 JOptionPane.showMessageDialog(window, "Error when construction runtime merged dictionary. "+me.getMessage());
751 }
752 catch (ParseException pe) {
753 JOptionPane.showMessageDialog(window,"Error when construction runtime merged dictionary. "+pe.getMessage());
754 }
755 catch (IOException ie) {
756 JOptionPane.showMessageDialog(window, "Error when construction runtime merged dictionary. "+ie.getMessage());
757 }
758
759 DictionaryUtility.populateDictionaryFullListingPane(window);
760
761 props.setProperty(LTDTKeys.PROJECTALTERED, "true");
762
763 window.dictListPane.jtfSearchString.setText("");
764
765 String currentDictionaryDef = props.getProperty(LTDTKeys.DICTIONARIES);
766
767
768 if (currentDictionaryDef.endsWith(LTDTKeys.DICTIONARY_DELIMITER) || currentDictionaryDef.length()==0) {
769 props.setProperty(LTDTKeys.DICTIONARIES, currentDictionaryDef+dictionaryURL.toString()+LTDTKeys.DICTIONARY_DELIMITER);
770 }
771 else {
772 props.setProperty(LTDTKeys.DICTIONARIES, currentDictionaryDef+LTDTKeys.DICTIONARY_DELIMITER+dictionaryURL.toString()+LTDTKeys.DICTIONARY_DELIMITER);
773 }
774
775 switch (window.requestedType) {
776 case LTDTKeys.OBJECT_TYPE:
777 DictionaryListPane.displaySingleTypeList(window, LTDTKeys.OBJECTONLY);
778 break;
779 case LTDTKeys.ELEMENT_TYPE:
780 DictionaryListPane.displaySingleTypeList(window, LTDTKeys.ELEMENTONLY);
781 break;
782 case LTDTKeys.ALL_TYPE:
783 DictionaryListPane.displaySingleTypeList(window, LTDTKeys.ALLTYPES);
784 break;
785
786 }
787
788
789
790 }
791 }
792 private URL getURL(MainWindow window ) {
793
794 String urlFilename;
795
796 URL url=null;
797
798 urlFilename = JOptionPane.showInputDialog
799 (window, "Please specify a URL.");
800
801 if (urlFilename==null) {
802 return null;
803 }
804 else if (urlFilename.length()==0) {
805
806 }
807
808 urlFilename = urlFilename.trim();
809 if (urlFilename.trim().length() ==0) {
810 urlFilename = JOptionPane.showInputDialog
811 (window, "Please specify a URL");
812 getURL(window);
813 }
814 else {
815 if (!(urlFilename.startsWith("http"))) {
816 JOptionPane.showMessageDialog(
817 window,
818 "Can not identify URL "+urlFilename+" \nPlease try again.");
819 getURL(window);
820 }
821 else {
822 try {
823 url = Utility.toURL(urlFilename);
824 }
825 catch (MalformedURLException e) {
826 JOptionPane.showMessageDialog(
827 window,
828 "Can not identify URL "+urlFilename+" \nPlease try again.");
829
830 }
831
832 }
833 }
834 return url;
835 }
836
837
838 private void modifyDictionaryKeyword() {
839 int panelIdx = this.window.dictListPane.jtp.getSelectedIndex();
840 int keywordIdx = -1;
841 String modifiedKeyword=null;
842 boolean noSelectionMade = false;
843
844 if (panelIdx > -1) {
845 if (panelIdx==LTDTKeys.OBJECTTABINDEX) {
846 keywordIdx = this.window.dictListPane.objectPanel.keywordList.getSelectedIndex();
847 if (keywordIdx > -1)
848 modifiedKeyword = window.keywordDisplayLong[keywordIdx];
849 }
850 else if (panelIdx==LTDTKeys.ELEMENTTABINDEX) {
851 keywordIdx = this.window.dictListPane.elementPanel.keywordList.getSelectedIndex();
852 if (keywordIdx > -1)
853 modifiedKeyword = window.keywordDisplayLong[keywordIdx];
854 }
855 else if (panelIdx==LTDTKeys.ALLTABINDEX) {
856 keywordIdx = this.window.dictListPane.fullPanel.keywordList.getSelectedIndex();
857 if (keywordIdx > -1)
858 modifiedKeyword = window.keywordSubLong[keywordIdx];
859 }
860
861 if (modifiedKeyword!=null) {
862
863 KeywordProperty kp = (KeywordProperty) window.dictionaryMap.get(modifiedKeyword);
864 if (kp.kwdDef instanceof ObjectDefinition) {
865 new ObjectDialog(props, window, LTDTKeys.MODIFYOBJECTTITLE, modifiedKeyword);
866
867 }
868 else if (kp.kwdDef instanceof ElementDefinition) {
869 new ElementDialog(props, window, LTDTKeys.MODIFYELEMENTTITLE, modifiedKeyword);
870 }
871 }
872 else noSelectionMade=true;
873 }
874 else noSelectionMade=true;
875
876 if (noSelectionMade) {
877 if (window.keywordSubShort!=null)
878 JOptionPane.showMessageDialog(window, "Please select an object or element from the data dictionary listing.",
879 "Modify Object/Element Not Selected", JOptionPane.WARNING_MESSAGE);
880 else
881 JOptionPane.showMessageDialog(window, "The data dictionary listing is empty. \n"+
882 "Please import a data dictionary to populate the data dictionary listing.",
883 "Modify Object/Element Not Selected", JOptionPane.WARNING_MESSAGE);
884 }
885
886 return;
887 }
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903 /***
904 * purge all edits inside the undo buffer
905 *
906 */
907 public void purgeUndos() {
908 undo.discardAllEdits();
909 undoAction.updateUndoState();
910 redoAction.updateRedoState();
911 }
912
913 class TemplateUndoableEditListener implements UndoableEditListener {
914 public void undoableEditHappened(UndoableEditEvent e) {
915
916 undo.addEdit(e.getEdit());
917 undoAction.updateUndoState();
918 redoAction.updateRedoState();
919 }
920 }
921
922
923 class UndoAction extends AbstractAction {
924 public UndoAction() {
925 super("Undo");
926 setEnabled(false);
927 }
928
929 public void actionPerformed(ActionEvent ae) {
930 try {
931 undo.undo();
932 }
933 catch (CannotUndoException ex) {
934 JOptionPane.showMessageDialog(window, "Unable to undo: "+ex.getMessage());
935 }
936 updateUndoState();
937 redoAction.updateRedoState();
938 }
939
940 void updateUndoState() {
941 if (undo.canUndo()) {
942 setEnabled(true);
943 putValue(Action.NAME, "Undo");
944 }
945 else {
946 setEnabled(false);
947 putValue(Action.NAME, "Undo");
948 }
949 }
950 }
951
952 class RedoAction extends AbstractAction {
953 public RedoAction() {
954 super("Redo");
955 setEnabled(false);
956 }
957
958 public void actionPerformed(ActionEvent ae) {
959 try {
960 undo.redo();
961 }
962 catch (CannotRedoException ex) {
963 JOptionPane.showMessageDialog(window, "Unable to redo: "+ex.getMessage());
964 }
965 updateRedoState();
966 undoAction.updateUndoState();
967 }
968
969 void updateRedoState() {
970 if (undo.canRedo()) {
971 setEnabled(true);
972 putValue (Action.NAME, "Redo");
973 }
974 else {
975 setEnabled(false);
976 putValue(Action.NAME, "Redo");
977 }
978 }
979 }
980 }