org.eclipse.equinox.p2.ui.sdk.scheduler_1.1.0.v20110815-1744

16:44:34.089 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.ui.sdk.scheduler_1.1.0.v20110815-1744.jar
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.osgi.util.NLS;

public class AutomaticUpdateMessages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.ui.sdk.scheduler.messages";
  public static String SchedulerStartup_day;
  public static String SchedulerStartup_Monday;
  public static String SchedulerStartup_Tuesday;
  public static String SchedulerStartup_Wednesday;
  public static String SchedulerStartup_Thursday;
  public static String SchedulerStartup_Friday;
  public static String SchedulerStartup_Saturday;
  public static String SchedulerStartup_Sunday;
  public static String SchedulerStartup_1AM;
  public static String SchedulerStartup_2AM;
  public static String SchedulerStartup_3AM;
  public static String SchedulerStartup_4AM;
  public static String SchedulerStartup_5AM;
  public static String SchedulerStartup_6AM;
  public static String SchedulerStartup_7AM;
  public static String SchedulerStartup_8AM;
  public static String SchedulerStartup_9AM;
  public static String SchedulerStartup_10AM;
  public static String SchedulerStartup_11AM;
  public static String SchedulerStartup_12PM;
  public static String SchedulerStartup_1PM;
  public static String SchedulerStartup_2PM;
  public static String SchedulerStartup_3PM;
  public static String SchedulerStartup_4PM;
  public static String SchedulerStartup_5PM;
  public static String SchedulerStartup_6PM;
  public static String SchedulerStartup_7PM;
  public static String SchedulerStartup_8PM;
  public static String SchedulerStartup_9PM;
  public static String SchedulerStartup_10PM;
  public static String SchedulerStartup_11PM;
  public static String SchedulerStartup_12AM;
  public static String AutomaticUpdatesPopup_PrefLinkOnly;
  public static String AutomaticUpdatesPopup_RemindAndPrefLink;
  public static String AutomaticUpdatesPopup_ReminderJobTitle;
  public static String AutomaticUpdatesPreferencePage_findUpdates;
  public static String AutomaticUpdateScheduler_30Minutes;
  public static String AutomaticUpdateScheduler_60Minutes;
  public static String AutomaticUpdateScheduler_240Minutes;
  public static String AutomaticUpdateScheduler_UpdateNotInitialized;
  public static String AutomaticUpdatesPopup_UpdatesAvailableTitle;
  public static String AutomaticUpdater_AutomaticDownloadOperationName;
  public static String AutomaticUpdater_ClickToReviewUpdates;
  public static String AutomaticUpdater_ClickToReviewUpdatesWithProblems;
  public static String AutomaticUpdatesPreferencePage_UpdateSchedule;
  public static String AutomaticUpdatesPreferencePage_findOnStart;
  public static String AutomaticUpdatesPreferencePage_findOnSchedule;
  public static String AutomaticUpdatesPreferencePage_downloadOptions;
  public static String AutomaticUpdatesPreferencePage_searchAndNotify;
  public static String AutomaticUpdatesPreferencePage_downloadAndNotify;
  public static String AutomaticUpdatesPreferencePage_at;
  public static String AutomaticUpdatesPreferencePage_GenericProductName;
  public static String AutomaticUpdatesPreferencePage_RemindGroup;
  public static String AutomaticUpdatesPreferencePage_RemindSchedule;
  public static String AutomaticUpdatesPreferencePage_RemindOnce;
  public static String AutomaticUpdatesPopup_ClickToReviewDownloaded;
  public static String AutomaticUpdatesPopup_ClickToReviewNotDownloaded;
  public static String ErrorSavingPreferences;
  public static String ErrorSavingClassicPreferences;
  public static String ErrorLoadingPreferenceKeys;
  
  static
  {
    NLS.initializeMessages("org.eclipse.equinox.internal.p2.ui.sdk.scheduler.messages", AutomaticUpdateMessages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdateMessages
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import java.io.IOException;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
import org.eclipse.equinox.p2.core.IAgentLocation;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.ProfileScope;
import org.eclipse.equinox.p2.operations.ProvisioningSession;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.eclipse.ui.statushandlers.StatusManager;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class AutomaticUpdatePlugin
  extends AbstractUIPlugin
{
  public static final String ICON_PATH = "$nl$/icons/";
  public static final String IMG_TOOL_UPDATE = "tool/update.gif";
  public static final String IMG_TOOL_UPDATE_PROBLEMS = "tool/update_problems.gif";
  public static final String IMG_TOOL_CLOSE = "tool/close.gif";
  public static final String IMG_TOOL_CLOSE_HOT = "tool/close_hot.gif";
  private static AutomaticUpdatePlugin plugin;
  private static BundleContext context;
  private AutomaticUpdateScheduler scheduler;
  private AutomaticUpdater updater;
  private ScopedPreferenceStore preferenceStore;
  private ProvisioningSession session;
  public static final String PLUGIN_ID = "org.eclipse.equinox.p2.ui.sdk.scheduler";
  
  public static BundleContext getContext()
  {
    return context;
  }
  
  public static AutomaticUpdatePlugin getDefault()
  {
    return plugin;
  }
  
  public void start(BundleContext bundleContext)
    throws Exception
  {
    super.start(bundleContext);
    plugin = this;
    context = bundleContext;
    IProvisioningAgent agent = (IProvisioningAgent)ServiceHelper.getService(getContext(), IProvisioningAgent.SERVICE_NAME);
    session = new ProvisioningSession(agent);
    
    PreferenceInitializer.migratePreferences();
  }
  
  public void stop(BundleContext bundleContext)
    throws Exception
  {
    if (scheduler != null)
    {
      scheduler.shutdown();
      scheduler = null;
    }
    if (updater != null)
    {
      updater.shutdown();
      updater = null;
    }
    plugin = null;
    super.stop(bundleContext);
    context = null;
  }
  
  public AutomaticUpdateScheduler getScheduler()
  {
    if (scheduler == null) {
      scheduler = new AutomaticUpdateScheduler();
    }
    return scheduler;
  }
  
  public AutomaticUpdater getAutomaticUpdater()
  {
    if (updater == null) {
      updater = new AutomaticUpdater();
    }
    return updater;
  }
  
  void setScheduler(AutomaticUpdateScheduler scheduler)
  {
    this.scheduler = scheduler;
  }
  
  public IProvisioningEventBus getProvisioningEventBus()
  {
    ServiceReference<?> busReference = context.getServiceReference(IProvisioningEventBus.SERVICE_NAME);
    if (busReference == null) {
      return null;
    }
    return (IProvisioningEventBus)context.getService(busReference);
  }
  
  public IPreferenceStore getPreferenceStore()
  {
    if (preferenceStore == null)
    {
      IAgentLocation agentLocation = getAgentLocation();
      if (agentLocation == null) {
        return super.getPreferenceStore();
      }
      preferenceStore = new ScopedPreferenceStore(new ProfileScope(agentLocation, "_SELF_"), "org.eclipse.equinox.p2.ui.sdk.scheduler");
    }
    return preferenceStore;
  }
  
  public IAgentLocation getAgentLocation()
  {
    ServiceReference<?> ref = getContext().getServiceReference(IAgentLocation.SERVICE_NAME);
    if (ref == null) {
      return null;
    }
    IAgentLocation location = (IAgentLocation)getContext().getService(ref);
    getContext().ungetService(ref);
    return location;
  }
  
  public void savePreferences()
  {
    if (preferenceStore != null) {
      try
      {
        preferenceStore.save();
      }
      catch (IOException e)
      {
        StatusManager.getManager().handle(new Status(4, "org.eclipse.equinox.p2.ui.sdk.scheduler", 0, AutomaticUpdateMessages.ErrorSavingPreferences, e), 3);
      }
    }
  }
  
  protected void initializeImageRegistry(ImageRegistry reg)
  {
    createImageDescriptor("tool/update.gif", reg);
    createImageDescriptor("tool/update_problems.gif", reg);
    createImageDescriptor("tool/close.gif", reg);
    createImageDescriptor("tool/close_hot.gif", reg);
  }
  
  private void createImageDescriptor(String id, ImageRegistry reg)
  {
    URL url = FileLocator.find(getBundle(), new Path("$nl$/icons/").append(id), null);
    ImageDescriptor desc = ImageDescriptor.createFromURL(url);
    reg.put(id, desc);
  }
  
  public ProvisioningSession getSession()
  {
    return session;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdatePlugin
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.equinox.internal.provisional.p2.updatechecker.IUpdateListener;
import org.eclipse.equinox.internal.provisional.p2.updatechecker.UpdateEvent;

class AutomaticUpdateScheduler$1
  implements IUpdateListener
{
  final AutomaticUpdateScheduler this$0;
  
  AutomaticUpdateScheduler$1(AutomaticUpdateScheduler paramAutomaticUpdateScheduler) {}
  
  public void updatesAvailable(UpdateEvent event)
  {
    AutomaticUpdatePlugin.getDefault().getAutomaticUpdater().updatesAvailable(event);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdateScheduler.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.ULocale;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector;
import org.eclipse.equinox.internal.provisional.p2.updatechecker.IUpdateChecker;
import org.eclipse.equinox.internal.provisional.p2.updatechecker.IUpdateListener;
import org.eclipse.equinox.internal.provisional.p2.updatechecker.UpdateEvent;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.statushandlers.StatusManager;

public class AutomaticUpdateScheduler
  implements IStartup
{
  public static final String P_DAY = "day";
  public static final String P_HOUR = "hour";
  public static final String[] DAYS;
  public static final String[] HOURS = { AutomaticUpdateMessages.SchedulerStartup_1AM, AutomaticUpdateMessages.SchedulerStartup_2AM, AutomaticUpdateMessages.SchedulerStartup_3AM, AutomaticUpdateMessages.SchedulerStartup_4AM, AutomaticUpdateMessages.SchedulerStartup_5AM, AutomaticUpdateMessages.SchedulerStartup_6AM, AutomaticUpdateMessages.SchedulerStartup_7AM, AutomaticUpdateMessages.SchedulerStartup_8AM, AutomaticUpdateMessages.SchedulerStartup_9AM, AutomaticUpdateMessages.SchedulerStartup_10AM, AutomaticUpdateMessages.SchedulerStartup_11AM, AutomaticUpdateMessages.SchedulerStartup_12PM, AutomaticUpdateMessages.SchedulerStartup_1PM, AutomaticUpdateMessages.SchedulerStartup_2PM, AutomaticUpdateMessages.SchedulerStartup_3PM, AutomaticUpdateMessages.SchedulerStartup_4PM, 
    AutomaticUpdateMessages.SchedulerStartup_5PM, AutomaticUpdateMessages.SchedulerStartup_6PM, AutomaticUpdateMessages.SchedulerStartup_7PM, AutomaticUpdateMessages.SchedulerStartup_8PM, AutomaticUpdateMessages.SchedulerStartup_9PM, AutomaticUpdateMessages.SchedulerStartup_10PM, AutomaticUpdateMessages.SchedulerStartup_11PM, AutomaticUpdateMessages.SchedulerStartup_12AM };
  private IUpdateListener listener = null;
  private IUpdateChecker checker = null;
  String profileId;
  
  static
  {
    Calendar calendar = Calendar.getInstance(new ULocale(Platform.getNL()));
    String[] daysAsStrings = { AutomaticUpdateMessages.SchedulerStartup_day, AutomaticUpdateMessages.SchedulerStartup_Sunday, AutomaticUpdateMessages.SchedulerStartup_Monday, AutomaticUpdateMessages.SchedulerStartup_Tuesday, AutomaticUpdateMessages.SchedulerStartup_Wednesday, AutomaticUpdateMessages.SchedulerStartup_Thursday, AutomaticUpdateMessages.SchedulerStartup_Friday, AutomaticUpdateMessages.SchedulerStartup_Saturday };
    int firstDay = calendar.getFirstDayOfWeek();
    DAYS = new String[8];
    DAYS[0] = daysAsStrings[0];
    int countDays = 0;
    for (int i = firstDay; i <= 7; i++) {
      DAYS[(++countDays)] = daysAsStrings[i];
    }
    for (int i = 1; i < firstDay; i++) {
      DAYS[(++countDays)] = daysAsStrings[i];
    }
  }
  
  public AutomaticUpdateScheduler()
  {
    AutomaticUpdatePlugin.getDefault().setScheduler(this);
    IProvisioningAgent agent = (IProvisioningAgent)ServiceHelper.getService(AutomaticUpdatePlugin.getContext(), IProvisioningAgent.SERVICE_NAME);
    checker = ((IUpdateChecker)agent.getService(IUpdateChecker.SERVICE_NAME));
    if (checker == null)
    {
      IStatus status = new Status(4, "org.eclipse.equinox.p2.ui.sdk.scheduler", AutomaticUpdateMessages.AutomaticUpdateScheduler_UpdateNotInitialized);
      StatusManager.getManager().handle(status, 1);
      return;
    }
    profileId = "_SELF_";
  }
  
  public void earlyStartup()
  {
    garbageCollect();
    scheduleUpdate();
  }
  
  private void garbageCollect()
  {
    if (profileId == null) {
      return;
    }
    IPreferenceStore pref = AutomaticUpdatePlugin.getDefault().getPreferenceStore();
    if (!pref.getBoolean("gcOnStartup")) {
      return;
    }
    IProvisioningAgent agent = (IProvisioningAgent)ServiceHelper.getService(AutomaticUpdatePlugin.getContext(), IProvisioningAgent.SERVICE_NAME);
    GarbageCollector collector = (GarbageCollector)agent.getService(GarbageCollector.SERVICE_NAME);
    if (collector == null) {
      return;
    }
    IProfileRegistry registry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    if (registry == null) {
      return;
    }
    IProfile profile = registry.getProfile(profileId);
    if (profile == null) {
      return;
    }
    collector.runGC(profile);
  }
  
  public void shutdown()
  {
    removeUpdateListener();
  }
  
  public void rescheduleUpdate()
  {
    removeUpdateListener();
    IPreferenceStore pref = AutomaticUpdatePlugin.getDefault().getPreferenceStore();
    String schedule = pref.getString("schedule");
    if (schedule.equals("on-startup")) {
      return;
    }
    scheduleUpdate();
  }
  
  private void scheduleUpdate()
  {
    if (profileId == null) {
      return;
    }
    IPreferenceStore pref = AutomaticUpdatePlugin.getDefault().getPreferenceStore();
    if (!pref.getBoolean("enabled")) {
      return;
    }
    String schedule = pref.getString("schedule");
    long delay = -1L;
    long poll = -1L;
    if (!schedule.equals("on-startup"))
    {
      delay = computeDelay(pref);
      poll = computePoll(pref);
    }
    listener = new IUpdateListener()
    {
      public void updatesAvailable(UpdateEvent event)
      {
        AutomaticUpdatePlugin.getDefault().getAutomaticUpdater().updatesAvailable(event);
      }
    };
    checker.addUpdateCheck(profileId, getProfileQuery(), delay, poll, listener);
  }
  
  private IQuery<IInstallableUnit> getProfileQuery()
  {
    return new IUProfilePropertyQuery("org.eclipse.equinox.p2.type.root", Boolean.TRUE.toString());
  }
  
  private int getDay(IPreferenceStore pref)
  {
    String day = pref.getString("day");
    for (int d = 0; d < DAYS.length; d++) {
      if (DAYS[d].equals(day)) {
        switch (d)
        {
        case 0: 
          return -1;
        case 1: 
          return 2;
        case 2: 
          return 3;
        case 3: 
          return 4;
        case 4: 
          return 5;
        case 5: 
          return 6;
        case 6: 
          return 7;
        case 7: 
          return 1;
        }
      }
    }
    return -1;
  }
  
  private int getHour(IPreferenceStore pref)
  {
    String hour = pref.getString("hour");
    for (int h = 0; h < HOURS.length; h++) {
      if (HOURS[h].equals(hour)) {
        return h + 1;
      }
    }
    return 1;
  }
  
  private long computeDelay(IPreferenceStore pref)
  {
    int target_d = getDay(pref);
    int target_h = getHour(pref);
    
    Calendar calendar = Calendar.getInstance();
    
    int current_d = calendar.get(7);
    
    int current_h = calendar.get(11);
    int current_m = calendar.get(12);
    int current_s = calendar.get(13);
    int current_ms = calendar.get(14);
    
    long delay = 0L;
    if (target_d == -1)
    {
      if ((target_h == current_h) && (current_m == 0) && (current_s == 0)) {
        return delay;
      }
      int delta_h = target_h - current_h;
      if (target_h <= current_h) {
        delta_h += 24;
      }
      delay = ((delta_h * 60 - current_m) * 60 - current_s) * 1000 - current_ms;
      return delay;
    }
    if ((target_d == current_d) && (target_h == current_h) && (current_m == 0) && (current_s == 0)) {
      return delay;
    }
    int delta_d = target_d - current_d;
    if ((target_d < current_d) || ((target_d == current_d) && ((target_h < current_h) || ((target_h == current_h) && (current_m > 0))))) {
      delta_d += 7;
    }
    delay = (((delta_d * 24 + target_h - current_h) * 60 - current_m) * 60 - current_s) * 1000 - current_ms;
    return delay;
  }
  
  private long computePoll(IPreferenceStore pref)
  {
    int target_d = getDay(pref);
    if (target_d == -1) {
      return 86400000L;
    }
    return 604800000L;
  }
  
  private void removeUpdateListener()
  {
    if ((listener != null) && (checker != null))
    {
      checker.removeUpdateCheck(listener);
      listener = null;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdateScheduler
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import java.util.EventObject;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener;
import org.eclipse.equinox.p2.engine.IProfileEvent;

class AutomaticUpdater$1
  implements ProvisioningListener
{
  final AutomaticUpdater this$0;
  
  AutomaticUpdater$1(AutomaticUpdater paramAutomaticUpdater) {}
  
  public void notify(EventObject o)
  {
    if ((o instanceof IProfileEvent))
    {
      IProfileEvent event = (IProfileEvent)o;
      if ((event.getReason() == 2) && (this$0.sameProfile(event.getProfileId()))) {
        this$0.triggerNewUpdateNotification();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdater.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

class AutomaticUpdater$2
  implements Runnable
{
  final AutomaticUpdater this$0;
  
  AutomaticUpdater$2(AutomaticUpdater paramAutomaticUpdater) {}
  
  public void run()
  {
    this$0.clearUpdateAffordances();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdater.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.operations.UpdateOperation;

class AutomaticUpdater$3$1
  implements Runnable
{
  final AutomaticUpdater.3 this$1;
  
  AutomaticUpdater$3$1(AutomaticUpdater.3 param3, boolean paramBoolean) {}
  
  public void run()
  {
    AutomaticUpdater.3.access$0(this$1).notifyUserOfUpdates(access$0this$1).operation.getResolutionResult().isOK(), val$notifyWithPopup);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdater.3.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.equinox.p2.operations.UpdateOperation;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.statushandlers.StatusManager;

class AutomaticUpdater$3
  extends JobChangeAdapter
{
  final AutomaticUpdater this$0;
  
  AutomaticUpdater$3(AutomaticUpdater paramAutomaticUpdater, boolean paramBoolean) {}
  
  public void done(IJobChangeEvent jobEvent)
  {
    IStatus jobStatus = jobEvent.getResult();
    if (jobStatus.isOK())
    {
      this$0.alreadyDownloaded = true;
      PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable()
      {
        public void run()
        {
          this$0.notifyUserOfUpdates(this$0.operation.getResolutionResult().isOK(), val$notifyWithPopup);
        }
      });
    }
    else if (jobStatus.getSeverity() != 8)
    {
      StatusManager.getManager().handle(jobStatus, 1);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdater.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.operations.UpdateOperation;

class AutomaticUpdater$4
  implements Runnable
{
  final AutomaticUpdater this$0;
  
  AutomaticUpdater$4(AutomaticUpdater paramAutomaticUpdater, boolean paramBoolean) {}
  
  public void run()
  {
    this$0.notifyUserOfUpdates(this$0.operation.getResolutionResult().isOK(), val$notifyWithPopup);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdater.4
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

class AutomaticUpdater$5
  implements Listener
{
  final AutomaticUpdater this$0;
  
  AutomaticUpdater$5(AutomaticUpdater paramAutomaticUpdater) {}
  
  public void handleEvent(Event event)
  {
    this$0.launchUpdate();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdater.5
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

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.eclipse.equinox.internal.provisional.p2.updatechecker.UpdateEvent;

class AutomaticUpdater$6
  extends Job
{
  final AutomaticUpdater this$0;
  
  AutomaticUpdater$6(AutomaticUpdater paramAutomaticUpdater, String $anonymous0)
  {
    super($anonymous0);
  }
  
  public IStatus run(IProgressMonitor monitor)
  {
    if (monitor.isCanceled()) {
      return Status.CANCEL_STATUS;
    }
    this$0.updatesAvailable(new UpdateEvent(this$0.profileId, this$0.getInstalledIUs()));
    return Status.OK_STATUS;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdater.6
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EventObject;
import java.util.Iterator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener;
import org.eclipse.equinox.internal.provisional.p2.updatechecker.IUpdateListener;
import org.eclipse.equinox.internal.provisional.p2.updatechecker.UpdateEvent;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileEvent;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.PhaseSetFactory;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.operations.ProfileModificationJob;
import org.eclipse.equinox.p2.operations.ProvisioningSession;
import org.eclipse.equinox.p2.operations.UpdateOperation;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.statushandlers.StatusManager;

public class AutomaticUpdater
  implements IUpdateListener
{
  StatusLineCLabelContribution updateAffordance;
  IStatusLineManager statusLineManager;
  Collection<IInstallableUnit> iusWithUpdates;
  String profileId;
  ProvisioningListener profileListener;
  AutomaticUpdatesPopup popup;
  boolean alreadyDownloaded = false;
  UpdateOperation operation;
  private static final String AUTO_UPDATE_STATUS_ITEM = "AutoUpdatesStatus";
  
  public AutomaticUpdater()
  {
    createProfileListener();
  }
  
  private void createProfileListener()
  {
    profileListener = new ProvisioningListener()
    {
      public void notify(EventObject o)
      {
        if ((o instanceof IProfileEvent))
        {
          IProfileEvent event = (IProfileEvent)o;
          if ((event.getReason() == 2) && (sameProfile(event.getProfileId()))) {
            triggerNewUpdateNotification();
          }
        }
      }
    };
    getProvisioningEventBus().addListener(profileListener);
  }
  
  boolean sameProfile(String another)
  {
    if (another.equals("_SELF_")) {
      another = getProfileRegistry().getProfile(another).getProfileId();
    }
    if (profileId.equals("_SELF_")) {
      profileId = getProfileRegistry().getProfile(profileId).getProfileId();
    }
    return profileId.equals(another);
  }
  
  public void updatesAvailable(UpdateEvent event)
  {
    updatesAvailable(event, true);
  }
  
  void updatesAvailable(UpdateEvent event, final boolean notifyWithPopup)
  {
    boolean download = getPreferenceStore().getBoolean("download");
    profileId = event.getProfileId();
    iusWithUpdates = event.getIUs();
    validateIusToUpdate();
    alreadyDownloaded = false;
    
    operation = new UpdateOperation(getSession(), iusWithUpdates);
    operation.setProfileId(event.getProfileId());
    IStatus status = operation.resolveModal(new NullProgressMonitor());
    if ((!status.isOK()) || (operation.getPossibleUpdates() == null) || (operation.getPossibleUpdates().length == 0))
    {
      if (PlatformUI.isWorkbenchRunning()) {
        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable()
        {
          public void run()
          {
            clearUpdateAffordances();
          }
        });
      }
      return;
    }
    if (download)
    {
      ProfileModificationJob job = new ProfileModificationJob(AutomaticUpdateMessages.AutomaticUpdater_AutomaticDownloadOperationName, getSession(), event.getProfileId(), operation.getProvisioningPlan(), new ProvisioningContext(getSession().getProvisioningAgent()));
      job.setPhaseSet(PhaseSetFactory.createPhaseSetIncluding(new String[] { PhaseSetFactory.PHASE_COLLECT }));
      job.setUser(false);
      job.setSystem(true);
      job.addJobChangeListener(new JobChangeAdapter()
      {
        public void done(IJobChangeEvent jobEvent)
        {
          IStatus jobStatus = jobEvent.getResult();
          if (jobStatus.isOK())
          {
            alreadyDownloaded = true;
            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable()
            {
              public void run()
              {
                notifyUserOfUpdates(operation.getResolutionResult().isOK(), val$notifyWithPopup);
              }
            });
          }
          else if (jobStatus.getSeverity() != 8)
          {
            StatusManager.getManager().handle(jobStatus, 1);
          }
        }
      });
      job.schedule();
    }
    else
    {
      PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable()
      {
        public void run()
        {
          notifyUserOfUpdates(operation.getResolutionResult().isOK(), notifyWithPopup);
        }
      });
    }
  }
  
  ProvisioningSession getSession()
  {
    return AutomaticUpdatePlugin.getDefault().getSession();
  }
  
  ProvisioningUI getProvisioningUI()
  {
    return ProvisioningUI.getDefaultUI();
  }
  
  void validateIusToUpdate()
  {
    ArrayList<IInstallableUnit> list = new ArrayList(iusWithUpdates.size());
    IProfile profile = getProfileRegistry().getProfile(profileId);
    for (Iterator localIterator = iusWithUpdates.iterator(); localIterator.hasNext();)
    {
      IInstallableUnit iuWithUpdate = (IInstallableUnit)localIterator.next();
      try
      {
        if (validToUpdate(profile, iuWithUpdate)) {
          list.add(iuWithUpdate);
        }
      }
      catch (OperationCanceledException localOperationCanceledException) {}
    }
    iusWithUpdates = list;
  }
  
  private boolean validToUpdate(IProfile profile, IInstallableUnit iu)
  {
    int lock = 0;
    boolean isRoot = false;
    try
    {
      String value = profile.getInstallableUnitProperty(iu, "org.eclipse.equinox.p2.type.lock");
      if (value != null) {
        lock = Integer.parseInt(value);
      }
      value = profile.getInstallableUnitProperty(iu, "org.eclipse.equinox.p2.type.root");
      isRoot = value == null ? false : Boolean.valueOf(value).booleanValue();
    }
    catch (NumberFormatException localNumberFormatException) {}
    return (isRoot) && ((lock & 0x2) == 0);
  }
  
  Shell getWorkbenchWindowShell()
  {
    IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    return activeWindow != null ? activeWindow.getShell() : null;
  }
  
  IStatusLineManager getStatusLineManager()
  {
    if (statusLineManager != null) {
      return statusLineManager;
    }
    IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWindow == null) {
      return null;
    }
    try
    {
      Method method = activeWindow.getClass().getDeclaredMethod("getStatusLineManager", new Class[0]);
      try
      {
        Object statusLine = method.invoke(activeWindow, new Object[0]);
        if ((statusLine instanceof IStatusLineManager))
        {
          statusLineManager = ((IStatusLineManager)statusLine);
          return statusLineManager;
        }
      }
      catch (InvocationTargetException localInvocationTargetException) {}catch (IllegalAccessException localIllegalAccessException) {}
      site = activeWindow.getActivePage().getActivePart().getSite();
    }
    catch (NoSuchMethodException localNoSuchMethodException) {}
    IWorkbenchPartSite site;
    if ((site instanceof IViewSite)) {
      statusLineManager = ((IViewSite)site).getActionBars().getStatusLineManager();
    } else if ((site instanceof IEditorSite)) {
      statusLineManager = ((IEditorSite)site).getActionBars().getStatusLineManager();
    }
    return statusLineManager;
  }
  
  void updateStatusLine()
  {
    IStatusLineManager manager = getStatusLineManager();
    if (manager != null) {
      manager.update(true);
    }
  }
  
  void createUpdateAffordance()
  {
    updateAffordance = new StatusLineCLabelContribution("AutoUpdatesStatus", 5);
    updateAffordance.addListener(3, new Listener()
    {
      public void handleEvent(Event event)
      {
        launchUpdate();
      }
    });
    IStatusLineManager manager = getStatusLineManager();
    if (manager != null)
    {
      manager.add(updateAffordance);
      manager.update(true);
    }
  }
  
  void notifyUserOfUpdates(boolean isValid, boolean showPopup)
  {
    if (updateAffordance == null) {
      createUpdateAffordance();
    }
    if (isValid)
    {
      if (showPopup) {
        openUpdatePopup();
      }
      updateAffordance.setTooltip(AutomaticUpdateMessages.AutomaticUpdater_ClickToReviewUpdates);
      updateAffordance.setImage(AutomaticUpdatePlugin.getDefault().getImageRegistry().get("tool/update.gif"));
    }
    else
    {
      updateAffordance.setTooltip(AutomaticUpdateMessages.AutomaticUpdater_ClickToReviewUpdatesWithProblems);
      updateAffordance.setImage(AutomaticUpdatePlugin.getDefault().getImageRegistry().get("tool/update_problems.gif"));
    }
    IStatusLineManager manager = getStatusLineManager();
    if (manager != null) {
      manager.update(true);
    }
  }
  
  void checkUpdateAffordanceEnablement()
  {
    if (updateAffordance == null) {
      return;
    }
    boolean shouldBeVisible = getProvisioningUI().hasScheduledOperations();
    if (updateAffordance.isVisible() != shouldBeVisible)
    {
      IStatusLineManager manager = getStatusLineManager();
      if (manager != null)
      {
        updateAffordance.setVisible(shouldBeVisible);
        manager.update(true);
      }
    }
  }
  
  void openUpdatePopup()
  {
    if (popup == null) {
      popup = new AutomaticUpdatesPopup(getWorkbenchWindowShell(), alreadyDownloaded, getPreferenceStore());
    }
    popup.open();
  }
  
  void clearUpdateAffordances()
  {
    if (updateAffordance != null)
    {
      IStatusLineManager manager = getStatusLineManager();
      if (manager != null)
      {
        manager.remove(updateAffordance);
        manager.update(true);
      }
      updateAffordance.dispose();
      updateAffordance = null;
    }
    if (popup != null)
    {
      popup.close(false);
      popup = null;
    }
  }
  
  public void launchUpdate()
  {
    getProvisioningUI().openUpdateWizard(false, operation, null);
  }
  
  void triggerNewUpdateNotification()
  {
    Job notifyJob = new Job("Update validate job")
    {
      public IStatus run(IProgressMonitor monitor)
      {
        if (monitor.isCanceled()) {
          return Status.CANCEL_STATUS;
        }
        updatesAvailable(new UpdateEvent(profileId, getInstalledIUs()));
        return Status.OK_STATUS;
      }
    };
    notifyJob.setSystem(true);
    notifyJob.setUser(false);
    notifyJob.setPriority(30);
    notifyJob.schedule();
  }
  
  public Collection<IInstallableUnit> getInstalledIUs()
  {
    IProfile profile = getProfileRegistry().getProfile(profileId);
    if (profile == null) {
      return CollectionUtils.emptyList();
    }
    IQuery<IInstallableUnit> query = new UserVisibleRootQuery();
    IQueryResult<IInstallableUnit> queryResult = profile.query(query, null);
    return queryResult.toUnmodifiableSet();
  }
  
  public void shutdown()
  {
    statusLineManager = null;
    if (profileListener != null)
    {
      getProvisioningEventBus().removeListener(profileListener);
      profileListener = null;
    }
  }
  
  IProfileRegistry getProfileRegistry()
  {
    return (IProfileRegistry)getSession().getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME);
  }
  
  IProvisioningEventBus getProvisioningEventBus()
  {
    return (IProvisioningEventBus)getSession().getProvisioningAgent().getService(IProvisioningEventBus.SERVICE_NAME);
  }
  
  IPreferenceStore getPreferenceStore()
  {
    return AutomaticUpdatePlugin.getDefault().getPreferenceStore();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdater
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

class AutomaticUpdatesPopup$1
  extends MouseAdapter
{
  final AutomaticUpdatesPopup this$0;
  
  AutomaticUpdatesPopup$1(AutomaticUpdatesPopup paramAutomaticUpdatesPopup) {}
  
  public void mouseDown(MouseEvent e)
  {
    AutomaticUpdatePlugin.getDefault().getAutomaticUpdater().launchUpdate();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdatesPopup.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.ui.dialogs.PreferencesUtil;

class AutomaticUpdatesPopup$2
  extends SelectionAdapter
{
  final AutomaticUpdatesPopup this$0;
  
  AutomaticUpdatesPopup$2(AutomaticUpdatesPopup paramAutomaticUpdatesPopup) {}
  
  public void widgetSelected(SelectionEvent e)
  {
    PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(this$0.getShell(), "org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdatesPreferencePage", null, null);
    dialog.open();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdatesPopup.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

class AutomaticUpdatesPopup$3
  implements IPropertyChangeListener
{
  final AutomaticUpdatesPopup this$0;
  
  AutomaticUpdatesPopup$3(AutomaticUpdatesPopup paramAutomaticUpdatesPopup) {}
  
  public void propertyChange(PropertyChangeEvent event)
  {
    this$0.handlePreferenceChange(event);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdatesPopup.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.progress.WorkbenchJob;

class AutomaticUpdatesPopup$4
  extends WorkbenchJob
{
  final AutomaticUpdatesPopup this$0;
  
  AutomaticUpdatesPopup$4(AutomaticUpdatesPopup paramAutomaticUpdatesPopup, String $anonymous0)
  {
    super($anonymous0);
  }
  
  public IStatus runInUIThread(IProgressMonitor monitor)
  {
    if (monitor.isCanceled()) {
      retu
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd