Package net.sf.abproject.addressbook.ab

Source Code of net.sf.abproject.addressbook.ab.abImpl

package net.sf.abproject.addressbook.ab;


import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import net.sf.abproject.AB;
import net.sf.abproject.addressbook.ab.datamodel.AddressBook;
import net.sf.abproject.addressbook.ab.shepherd.Shepherd;
import net.sf.abproject.addressbook.ab.ui.pane.AddressBookPane;
import net.sf.abproject.i18n.m.M;
import net.sf.abproject.sachok.PreferencesForABProject;
import net.sf.egphilippovoss.product.ProductMetaData;
import net.sf.egphilippovoss.util.ExceptionUtil;
import net.sf.egphilippovoss.util.LookAndFeelUtil;
import net.sf.egphilippovoss.util.NamedCaller;
import net.sf.egphilippovoss.util.swing.MsgBoxUtil;

class abImpl extends ab {
    public static void main(String[] args){
      new abImpl().applicationLifecycle(args);
    }
    private void leavingApplicationLifecycle(NamedCaller nc, AddressBook addressBook) throws Throwable{//GTD Throwable is a wolf, work around this
      Shepherd.moveAddressbookToHDD(nc, abImpl.this,addressBook);
        System.exit(0);
    }
    /**
     * abImpl life cycle.
     * If uninstall option given, uninstall and leave user data which is commanded to be left.
     * Otherwise: if not installed, install. If installed, live. 9.
     * @param args command line arguments
     */
    private void applicationLifecycle(String[] args){
      final NamedCaller nc=new NamedCaller() {
      @Override
      public String getName() {
        try {
          return abImplConstants.APP_NAME;
        } catch (Throwable e) {
          e.printStackTrace();
          return M.UNNAMED_CALLER;
        }
      }

      @Override
      public ProductMetaData getProductMetaData() {
        return AB.PRODUCT_META_DATA;
      }
    };
      while(true){
          try {
//            try{
//              M.staticinit(nc);
//            }catch(Throwable tr){
//              tr.printStackTrace();
//              return;
//            }
            PreferencesForABProject.initLibrary(nc);
              LookAndFeelUtil.initLAF();
              final AddressBook addressBook = abPersistence.load(nc);
              AddressBookPane.showNewABFrame(nc, abImpl.this, addressBook,M.CONTACTS,"net.sf.abproject",new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      try {
                        leavingApplicationLifecycle(nc, addressBook);
                      } catch (Throwable throwable) {
                          ExceptionUtil.handleException(nc, throwable);
                          switch(MsgBoxUtil.askYesNo(nc, (JFrame)e.getSource(),"Cannot save address book---exit now and discard changes?","Error occured while saving.\r\nExit application now and discard your addressbook changes?",new String[]{"Yes","No"}, 1)){//GTD get rid of such messages
                              case 0:System.exit(1);break;
                              case 1:
                              default:throw new RuntimeException(throwable);
                          }
                      }
                  }
              });
              return;
          } catch (Throwable throwable) {
              ExceptionUtil.handleException(nc, throwable);
          }
      }
    }

}
TOP

Related Classes of net.sf.abproject.addressbook.ab.abImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.