Package org.jampa

Source Code of org.jampa.ApplicationWorkbenchAdvisor

/*
* Jampa
* Copyright (C) 2008-2009 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*/

package org.jampa;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.application.IWorkbenchConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.jampa.controllers.Controller;
import org.jampa.gui.runnables.ApplicationCloser;
import org.jampa.logging.Log;
import org.jampa.preferences.PreferenceConstants;
import org.jampa.utils.Constants;


public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

  private static final String PERSPECTIVE_ID = "Jampa.MainPerspective"; //$NON-NLS-1$

  public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
      IWorkbenchWindowConfigurer configurer) { 
    return new ApplicationWorkbenchWindowAdvisor(configurer);
  }

  public String getInitialWindowPerspectiveId() {
    return PERSPECTIVE_ID;
  }
 
 
  public void initialize(IWorkbenchConfigurer configurer) {
    Log.getInstance(ApplicationWorkbenchAdvisor.class).info("Initializing application."); //$NON-NLS-1$
   
    configurer.setSaveAndRestore(true);
   
    Controller.getInstance().initialize();
   
    if (Controller.getInstance().getPreferenceStore().getString(PreferenceConstants.P_LIBRARY_PATH).isEmpty()) {
      Controller.getInstance().runWizard();
    }           
         
    Controller.getInstance().getPlaylistController().loadPlaylists();
    Controller.getInstance().getPlaylistController().loadPodcasts();
  }
 
  public void postStartup() {
    Controller.getInstance().onApplicationStarted();
    Log.getInstance(ApplicationWorkbenchAdvisor.class).info(Constants.APP_NAME + " initialized."); //$NON-NLS-1$
  }
 
  public boolean preShutdown() {
    Log.getInstance(ApplicationWorkbenchAdvisor.class).debug("Shutting down."); //$NON-NLS-1$
   
    Controller.getInstance().setApplicationStopping(true);
   
    ApplicationCloser applicationCloser = new ApplicationCloser();
   
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getDefault().getActiveShell());
   
    try {
      dialog.run(false, false, applicationCloser);
    } catch (InvocationTargetException e) {
      Log.getInstance(ApplicationWorkbenchAdvisor.class).error(e.getMessage());
    } catch (InterruptedException e) {
      Log.getInstance(ApplicationWorkbenchAdvisor.class).error(e.getMessage());     
    }
   
    /*
    Controller.getInstance().getEventController().setEventsPropagationEnabled(false);
    Controller.getInstance().getPlaylistController().onApplicationClose();   
    Controller.getInstance().getPlaylistController().writePlaylists();
    Controller.getInstance().getStatisticsController().saveStatistics();
   
    Controller.getInstance().getEqualizerController().writePresets();
   
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    if (store.getBoolean(PreferenceConstants.TRAY_SHOW_IN_TRAY)) {
      Controller.getInstance().getTrayController().hideTrayItems();
    }
   
    Controller.getInstance().getHSQLController().closeDatabase();
    */
   
    return true;
  }
 
  public String getMainPreferencePageId() {
    return "Jampa.preferences.GeneralPage"; //$NON-NLS-1$
  }
   
}
TOP

Related Classes of org.jampa.ApplicationWorkbenchAdvisor

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.