Package org.jampa.net.version

Source Code of org.jampa.net.version.VersionCheckerJob

/*
* 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.net.version;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.jampa.controllers.Controller;
import org.jampa.gui.components.osd.NewVersionOSD;
import org.jampa.gui.translations.Messages;
import org.jampa.logging.Log;
import org.jampa.preferences.PreferenceConstants;

public class VersionCheckerJob extends Job {
 
 
  private boolean manualCheck;

  public VersionCheckerJob() {
    super(Messages.getString("VersionCheckerJob.JobTitle"));
    this.manualCheck = false;
  }
 
  public VersionCheckerJob(boolean manualCheck) {
    super(Messages.getString("VersionCheckerJob.JobTitle"));
    this.manualCheck = manualCheck;
  }
 
  @Override
  protected IStatus run(IProgressMonitor monitor) {
                 
    monitor.beginTask(Messages.getString("VersionCheckerJob.MainTask"), 2);

    VersionChecker versionChecker = new VersionChecker();       

    monitor.subTask(Messages.getString("VersionCheckerJob.ConnectingTo") + " " + versionChecker.getCheckUrl());
   
    if (versionChecker.checkLastVersionNumber()) { 
     
      monitor.worked(1);           
     
      monitor.subTask(Messages.getString("VersionCheckerJob.CheckingVersion"));

      if (versionChecker.isNewerVersionAvailable()) {
        monitor.worked(1);     
       
        Log.getInstance(VersionCheckerJob.class).info("New version available: " + versionChecker.getNewVersionAsString() + " (current: " + versionChecker.getCurrentVersionAsString() + ")."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        new NewVersionOSD(String.format(Messages.getString("VersionCheckerJob.NewVersionAvailable"), versionChecker.getNewVersionAsString()), //$NON-NLS-1$
            Messages.getString("VersionCheckerJob.NewVersionWebSite"),
            Controller.getInstance().getPreferenceStore().getString(PreferenceConstants.VERSION_UPDATE_URL)).start();

      } else {
        monitor.worked(1);
        Log.getInstance(VersionCheckerJob.class).info("No new version available."); //$NON-NLS-1$

        // Manuel check, user wait for an answer.
        if (manualCheck) {
          new NewVersionOSD(String.format(Messages.getString("VersionCheckerJob.NoNewVersionAvailable"), versionChecker.getNewVersionAsString()), //$NON-NLS-1$
              Messages.getString("VersionCheckerJob.NoNewVersionAvailableStayTuned"),
              "").start(); //$NON-NLS-1$
        }
      }

    } else {
      monitor.worked(1);
      Log.getInstance(VersionCheckerJob.class).info("Unable to check for new version (not connected to Internet or website unreachable)."); //$NON-NLS-1$
      // Manuel check, user wait for an answer.
      if (manualCheck) {
        new NewVersionOSD(String.format(Messages.getString("VersionCheckerJob.CheckVersionError"), versionChecker.getNewVersionAsString()), //$NON-NLS-1$
            Messages.getString("VersionCheckerJob.CheckVersionErrorExplanation"),
            "").start(); //$NON-NLS-1$
      }
    }

 
    monitor.done();
    return Status.OK_STATUS;
  }

}
TOP

Related Classes of org.jampa.net.version.VersionCheckerJob

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.