Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

DocumentListController.java

Go to the documentation of this file.
00001 
00066 package com.arcle.rmt.superwaba.vc;
00067 
00068 import waba.ui.Window;
00069 import waba.ui.InputDialog;
00070 
00071 import com.arcle.rmt.superwaba.vc.DocumentList;
00072 import com.arcle.rmt.superwaba.vc.DocumentWindow;
00073 import com.arcle.rmt.superwaba.vc.DocumentWindowController;
00074 import com.arcle.rmt.superwaba.model.DocumentManager;
00075 import com.arcle.rmt.superwaba.model.Document;
00076 import com.arcle.rmt.superwaba.framework.Controller;
00077 import com.arcle.rmt.superwaba.framework.View;
00078 import com.arcle.rmt.superwaba.framework.Model;
00079 
00087 public class DocumentListController extends ControllerBase {
00088     protected DocumentListController() {
00089 
00090     }
00091 
00095     public static DocumentListController getInstance() {
00096         if (_instance == null) {
00097             _instance = new DocumentListController();
00098         }
00099         return _instance;
00100     }
00101 
00102     //-----------------------------------------------------------------------
00103     // Controller implementation
00104 
00105     public void viewInitialized(View v) {
00106 
00107     }
00108 
00109     //-----------------------------------------------------------------------
00110     // Command-Handling methods
00111 
00119     public void cmdNewDocument() {
00120         Document doc = DocumentManager.getInstance().createDocument();
00121         Window topMost = Window.getTopMost();
00122         InputDialog dlg = createInputDialog("New Document",
00123             "Enter Document Title:", "", null);
00124         topMost.popupBlockingModal(dlg);
00125 
00126         if (dlg.getPressedButtonIndex() == 0) {
00127             String docTitle = dlg.getValue();
00128             doc.setTitle(docTitle);
00129             doEditDocument(doc);
00130         }
00131     }
00132 
00140     public void cmdEditDocument(String docName) {
00141         Document doc = DocumentManager.getInstance().loadDocument(docName);
00142         if (doc != null ) {
00143             doEditDocument(doc);
00144         } else {
00145             Window.getTopMost().popupBlockingModal(createMessageBox(
00146                 "Edit Document", "Cannot open document: " + docName));
00147         }
00148     }
00149 
00150     //-----------------------------------------------------------------------
00151 
00158     protected void doEditDocument(Document doc) {
00159         DocumentWindowController ctrl = createDocumentWindowController(doc);
00160         DocumentWindow win = createDocumentWindow(ctrl);
00161         DocumentList.getInstance().popupBlockingModal(win);
00162         DocumentManager.getInstance().saveDocument(doc.getTitle(), doc);
00163         DocumentList.getInstance().modelUpdated();
00164     }
00165 
00166     //-----------------------------------------------------------------------
00167     // Factory Methods
00168 
00176     protected InputDialog createInputDialog(
00177             String title,
00178             String text,
00179             String defaultValue,
00180             String[] buttonCaptions) {
00181         InputDialog dlg;
00182         if (buttonCaptions == null) {
00183             dlg = new InputDialog(title, text, defaultValue);
00184         } else {
00185             dlg = new InputDialog(title, text, defaultValue, buttonCaptions);
00186         }
00187 
00197         /*
00198         // these doesn't work right yet.
00199         System.out.println(dlg.getPreferredHeight());
00200         dlg.setRect(InputDialog.LEFT, InputDialog.TOP, InputDialog.FILL,
00201             50);
00202         dlg.makeUnmovable();
00203         */
00204         return dlg;
00205     }
00206 
00210     protected DocumentWindowController createDocumentWindowController(Document doc) {
00211         return new DocumentWindowController(doc);
00212     }
00213 
00217     protected DocumentWindow createDocumentWindow(DocumentWindowController ctrl) {
00218         return new DocumentWindow(ctrl);
00219     }
00220 
00221     //-----------------------------------------------------------------------
00222     // Member variables.
00223 
00227     private static DocumentListController _instance = null;
00228 }

Generated on Fri Jun 18 19:51:19 2004 for Arcle Rambutan by doxygen 1.3.5