org.eclipse.update.scheduler_3.2.300.v20100512

16:48:46.031 INFO  jd.cli.Main - Decompiling org.eclipse.update.scheduler_3.2.300.v20100512.jar
package org.eclipse.update.internal.scheduler;

import org.eclipse.update.search.UpdateSearchRequest;
import org.eclipse.update.ui.UpdateJob;

class AutomaticUpdateJob
  extends UpdateJob
{
  public AutomaticUpdateJob(String name, boolean isAutomatic, boolean download)
  {
    super(name, isAutomatic, download);
  }
  
  public AutomaticUpdateJob(String name, UpdateSearchRequest searchRequest)
  {
    super(name, searchRequest);
  }
  
  public boolean belongsTo(Object family)
  {
    return SchedulerStartup.automaticJobFamily == family;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.AutomaticUpdateJob
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IStartup;
import org.eclipse.update.configuration.IConfiguredSite;
import org.eclipse.update.configuration.IInstallConfiguration;
import org.eclipse.update.configuration.ILocalSite;
import org.eclipse.update.configurator.ConfiguratorUtils;
import org.eclipse.update.configurator.IPlatformConfiguration;
import org.eclipse.update.core.IFeature;
import org.eclipse.update.core.IFeatureReference;
import org.eclipse.update.core.ISite;
import org.eclipse.update.core.SiteManager;
import org.eclipse.update.core.VersionedIdentifier;
import org.eclipse.update.internal.operations.OperationFactory;
import org.eclipse.update.operations.IOperation;
import org.eclipse.update.operations.OperationsManager;

public class ScheduledPluginUninstall
  implements IStartup
{
  public void earlyStartup()
  {
    URL platformXML = ConfiguratorUtils.getCurrentPlatformConfiguration().getConfigurationLocation();
    
    File f = new File(platformXML.getFile());
    
    f = new File(f.getParentFile(), "toBeUninstalled");
    try
    {
      if (!f.exists()) {
        return;
      }
      FileInputStream fis = new FileInputStream(f);
      Properties toBeUninstalled = new Properties();
      toBeUninstalled.load(fis);
      fis.close();
      
      IFeature[] features = new IFeature[toBeUninstalled.size()];
      IConfiguredSite[] configuredSites = new IConfiguredSite[toBeUninstalled.size()];
      
      IConfiguredSite[] sites = SiteManager.getLocalSite().getCurrentConfiguration().getConfiguredSites();
      
      Enumeration featuresToBeDeleted = toBeUninstalled.elements();
      int i = 0;
      while (featuresToBeDeleted.hasMoreElements())
      {
        String temp = (String)featuresToBeDeleted.nextElement();
        StringTokenizer stk = new StringTokenizer(temp, ";");
        String targetSite = stk.nextToken();
        String featureName = stk.nextToken();
        for (int j = 0; j < sites.length; j++) {
          if (sites[j].getSite().getURL().toString().equals(targetSite))
          {
            configuredSites[i] = sites[j];
            IFeatureReference[] siteFeatures = configuredSites[i].getFeatureReferences();
            for (int k = 0; k < siteFeatures.length; k++) {
              if (siteFeatures[k].getVersionedIdentifier().toString().equals(featureName))
              {
                features[i] = siteFeatures[k].getFeature(null);
                
                break;
              }
            }
          }
        }
        i++;
      }
      IOperation uninstallFeaturesOperation = 
        ((OperationFactory)OperationsManager.getOperationFactory()).createUninstallFeaturesOperation(configuredSites, features);
      
      uninstallFeaturesOperation.execute(null, null);
      
      f.delete();
    }
    catch (IOException localIOException) {}catch (CoreException e)
    {
      e.printStackTrace();
    }
    catch (InvocationTargetException e)
    {
      e.printStackTrace();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.ScheduledPluginUninstall
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler;

import java.lang.reflect.Constructor;
import java.util.Calendar;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.IStartup;

public class SchedulerStartup
  implements IStartup
{
  public static final String P_ENABLED = "enabled";
  public static final String P_SCHEDULE = "schedule";
  public static final String VALUE_ON_STARTUP = "on-startup";
  public static final String VALUE_ON_SCHEDULE = "on-schedule";
  public static final String P_DOWNLOAD = "download";
  public static final String P_DAY = "day";
  public static final String P_HOUR = "hour";
  private Job job;
  static final Object automaticJobFamily = new Object();
  private IJobChangeListener jobListener;
  public static final String[] DAYS = {
    UpdateSchedulerMessages.SchedulerStartup_day, 
    UpdateSchedulerMessages.SchedulerStartup_Monday, 
    UpdateSchedulerMessages.SchedulerStartup_Tuesday, 
    UpdateSchedulerMessages.SchedulerStartup_Wednesday, 
    UpdateSchedulerMessages.SchedulerStartup_Thursday, 
    UpdateSchedulerMessages.SchedulerStartup_Friday, 
    UpdateSchedulerMessages.SchedulerStartup_Saturday, 
    UpdateSchedulerMessages.SchedulerStartup_Sunday };
  public static final String[] HOURS = {
    UpdateSchedulerMessages.SchedulerStartup_1AM, 
    UpdateSchedulerMessages.SchedulerStartup_2AM, 
    UpdateSchedulerMessages.SchedulerStartup_3AM, 
    UpdateSchedulerMessages.SchedulerStartup_4AM, 
    UpdateSchedulerMessages.SchedulerStartup_5AM, 
    UpdateSchedulerMessages.SchedulerStartup_6AM, 
    UpdateSchedulerMessages.SchedulerStartup_7AM, 
    UpdateSchedulerMessages.SchedulerStartup_8AM, 
    UpdateSchedulerMessages.SchedulerStartup_9AM, 
    UpdateSchedulerMessages.SchedulerStartup_10AM, 
    UpdateSchedulerMessages.SchedulerStartup_11AM, 
    UpdateSchedulerMessages.SchedulerStartup_12PM, 
    UpdateSchedulerMessages.SchedulerStartup_1PM, 
    UpdateSchedulerMessages.SchedulerStartup_2PM, 
    UpdateSchedulerMessages.SchedulerStartup_3PM, 
    UpdateSchedulerMessages.SchedulerStartup_4PM, 
    UpdateSchedulerMessages.SchedulerStartup_5PM, 
    UpdateSchedulerMessages.SchedulerStartup_6PM, 
    UpdateSchedulerMessages.SchedulerStartup_7PM, 
    UpdateSchedulerMessages.SchedulerStartup_8PM, 
    UpdateSchedulerMessages.SchedulerStartup_9PM, 
    UpdateSchedulerMessages.SchedulerStartup_10PM, 
    UpdateSchedulerMessages.SchedulerStartup_11PM, 
    UpdateSchedulerMessages.SchedulerStartup_12AM };
  
  public SchedulerStartup()
  {
    UpdateSchedulerPlugin.setScheduler(this);
  }
  
  public void earlyStartup()
  {
    scheduleUpdateJob();
  }
  
  public void scheduleUpdateJob()
  {
    Preferences pref = UpdateSchedulerPlugin.getDefault()
      .getPluginPreferences();
    if (!pref.getBoolean("enabled")) {
      return;
    }
    String schedule = pref.getString("schedule");
    long delay = -1L;
    if (schedule.equals("on-startup"))
    {
      if (job == null) {
        delay = 0L;
      } else {
        delay = -1L;
      }
    }
    else {
      delay = computeDelay(pref);
    }
    if (delay == -1L) {
      return;
    }
    startSearch(delay);
  }
  
  private int getDay(Preferences 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(Preferences 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(Preferences 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 void startSearch(long delay)
  {
    if (job != null)
    {
      if (jobListener != null) {
        Job.getJobManager().removeJobChangeListener(jobListener);
      }
      Job.getJobManager().cancel(automaticJobFamily);
    }
    if (jobListener == null)
    {
      jobListener = createJobChangeAdapter();
      if (jobListener == null) {
        return;
      }
    }
    Job.getJobManager().addJobChangeListener(jobListener);
    String jobName = UpdateSchedulerMessages.AutomaticUpdatesJob_AutomaticUpdateSearch;
    boolean download = UpdateSchedulerPlugin.getDefault()
      .getPluginPreferences().getBoolean(
      "download");
    job = createUpdateJob(jobName, download);
    if (job != null) {
      job.schedule(delay);
    }
  }
  
  private Job createUpdateJob(String name, boolean download)
  {
    try
    {
      Class theClass = 
        Class.forName("org.eclipse.update.internal.scheduler.AutomaticUpdateJob");
      Constructor constructor = theClass.getConstructor(new Class[] {
        String.class, Boolean.TYPE, Boolean.TYPE });
      return (Job)constructor.newInstance(new Object[] { name, 
        Boolean.TRUE, new Boolean(download) });
    }
    catch (Exception e)
    {
      UpdateSchedulerPlugin.logException(e, false);
    }
    return null;
  }
  
  private IJobChangeListener createJobChangeAdapter()
  {
    try
    {
      Class theClass = 
        Class.forName("org.eclipse.update.internal.scheduler.UpdateJobChangeAdapter");
      Constructor constructor = theClass
        .getConstructor(new Class[] { SchedulerStartup.class });
      return (IJobChangeListener)constructor
        .newInstance(new Object[] { this });
    }
    catch (Exception e)
    {
      UpdateSchedulerPlugin.logException(e, false);
    }
    return null;
  }
  
  Job getJob()
  {
    return job;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.SchedulerStartup
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler;

class UpdateJobChangeAdapter$1
  implements Runnable
{
  final UpdateJobChangeAdapter this$0;
  
  UpdateJobChangeAdapter$1(UpdateJobChangeAdapter paramUpdateJobChangeAdapter)
  {
    this$0 = paramUpdateJobChangeAdapter;
  }
  
  public void run()
  {
    UpdateJobChangeAdapter.access$0(this$0);
    UpdateJobChangeAdapter.access$1(this$0).scheduleUpdateJob();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.UpdateJobChangeAdapter.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler;

class UpdateJobChangeAdapter$2
  implements Runnable
{
  final UpdateJobChangeAdapter this$0;
  
  UpdateJobChangeAdapter$2(UpdateJobChangeAdapter paramUpdateJobChangeAdapter)
  {
    this$0 = paramUpdateJobChangeAdapter;
  }
  
  public void run()
  {
    UpdateJobChangeAdapter.access$2(this$0);
    UpdateJobChangeAdapter.access$1(this$0).scheduleUpdateJob();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.UpdateJobChangeAdapter.2
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler;

class UpdateJobChangeAdapter$3
  implements Runnable
{
  final UpdateJobChangeAdapter this$0;
  
  UpdateJobChangeAdapter$3(UpdateJobChangeAdapter paramUpdateJobChangeAdapter)
  {
    this$0 = paramUpdateJobChangeAdapter;
  }
  
  public void run()
  {
    UpdateJobChangeAdapter.access$3(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.UpdateJobChangeAdapter.3
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler;

class UpdateJobChangeAdapter$4
  implements Runnable
{
  final UpdateJobChangeAdapter this$0;
  
  UpdateJobChangeAdapter$4(UpdateJobChangeAdapter paramUpdateJobChangeAdapter)
  {
    this$0 = paramUpdateJobChangeAdapter;
  }
  
  public void run()
  {
    UpdateJobChangeAdapter.access$3(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.UpdateJobChangeAdapter.4
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler;

import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.update.internal.ui.UpdateUI;
import org.eclipse.update.internal.ui.UpdateUIMessages;
import org.eclipse.update.internal.ui.wizards.InstallWizard;
import org.eclipse.update.internal.ui.wizards.InstallWizard2;
import org.eclipse.update.internal.ui.wizards.ResizableInstallWizardDialog;
import org.eclipse.update.ui.UpdateJob;

class UpdateJobChangeAdapter
  extends JobChangeAdapter
{
  private SchedulerStartup startup;
  
  public UpdateJobChangeAdapter(SchedulerStartup startup)
  {
    this.startup = startup;
  }
  
  public void done(IJobChangeEvent event)
  {
    if (event.getJob() == startup.getJob()) {
      if ((((AutomaticUpdateJob)startup.getJob()).getUpdates().length > 0) && 
        (!InstallWizard.isRunning())) {
        if (UpdateSchedulerPlugin.getDefault().getPluginPreferences().getBoolean("download")) {
          UpdateUI.getStandardDisplay().asyncExec(new Runnable()
          {
            public void run()
            {
              UpdateJobChangeAdapter.this.asyncNotifyDownloadUser();
              startup.scheduleUpdateJob();
            }
          });
        } else {
          UpdateUI.getStandardDisplay().asyncExec(new Runnable()
          {
            public void run()
            {
              UpdateJobChangeAdapter.this.asyncNotifyUser();
              startup.scheduleUpdateJob();
            }
          });
        }
      }
    }
  }
  
  private void asyncNotifyUser()
  {
    UpdateUI.getStandardDisplay().beep();
    if (MessageDialog.openQuestion(UpdateUI.getActiveWorkbenchShell(), 
      UpdateUIMessages.AutomaticUpdatesJob_EclipseUpdates1, 
      UpdateUIMessages.AutomaticUpdatesJob_UpdatesAvailable)) {
      BusyIndicator.showWhile(UpdateUI.getStandardDisplay(), 
        new Runnable()
        {
          public void run()
          {
            UpdateJobChangeAdapter.this.openInstallWizard2();
          }
        });
    }
  }
  
  private void asyncNotifyDownloadUser()
  {
    UpdateUI.getStandardDisplay().beep();
    if (MessageDialog.openQuestion(UpdateUI.getActiveWorkbenchShell(), 
      UpdateUIMessages.AutomaticUpdatesJob_EclipseUpdates2, 
      UpdateUIMessages.AutomaticUpdatesJob_UpdatesDownloaded)) {
      BusyIndicator.showWhile(UpdateUI.getStandardDisplay(), 
        new Runnable()
        {
          public void run()
          {
            UpdateJobChangeAdapter.this.openInstallWizard2();
          }
        });
    }
  }
  
  private void openInstallWizard2()
  {
    if (InstallWizard.isRunning()) {
      return;
    }
    AutomaticUpdateJob ujob = (AutomaticUpdateJob)startup.getJob();
    InstallWizard2 wizard = new InstallWizard2(ujob.getSearchRequest(), 
      ujob.getUpdates(), true);
    WizardDialog dialog = new ResizableInstallWizardDialog(
      UpdateUI.getActiveWorkbenchShell(), wizard, 
      UpdateUIMessages.AutomaticUpdatesJob_Updates);
    dialog.create();
    dialog.open();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.UpdateJobChangeAdapter
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler;

import org.eclipse.osgi.util.NLS;

public final class UpdateSchedulerMessages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.update.internal.scheduler.UpdateSchedulerResources";
  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 AutomaticUpdatesJob_AutomaticUpdateSearch;
  public static String AutomaticUpdatesPreferencePage_findUpdates;
  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;
  
  static
  {
    NLS.initializeMessages("org.eclipse.update.internal.scheduler.UpdateSchedulerResources", UpdateSchedulerMessages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.UpdateSchedulerMessages
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler;

import java.lang.reflect.InvocationTargetException;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

public class UpdateSchedulerPlugin
  extends AbstractUIPlugin
{
  public static final String P_ENABLED = "enabled";
  public static final String P_SCHEDULE = "schedule";
  public static final String VALUE_ON_STARTUP = "on-startup";
  public static final String VALUE_ON_SCHEDULE = "on-schedule";
  public static final String P_DOWNLOAD = "download";
  private static UpdateSchedulerPlugin plugin;
  private ResourceBundle resourceBundle;
  private static SchedulerStartup scheduler;
  
  public UpdateSchedulerPlugin()
  {
    plugin = this;
  }
  
  public ResourceBundle getResourceBundle()
  {
    if (resourceBundle == null) {
      try
      {
        resourceBundle = ResourceBundle.getBundle("org.eclipse.update.internal.scheduler.UpdateSchedulerResources");
      }
      catch (MissingResourceException localMissingResourceException)
      {
        resourceBundle = null;
      }
    }
    return resourceBundle;
  }
  
  public static UpdateSchedulerPlugin getDefault()
  {
    return plugin;
  }
  
  public static String getPluginId()
  {
    return getDefault().getBundle().getSymbolicName();
  }
  
  public static void logException(Throwable e)
  {
    logException(e, true);
  }
  
  public static void logException(Throwable e, boolean showErrorDialog)
  {
    if ((e instanceof InvocationTargetException)) {
      e = ((InvocationTargetException)e).getTargetException();
    }
    IStatus status = null;
    if ((e instanceof CoreException))
    {
      status = ((CoreException)e).getStatus();
    }
    else
    {
      String message = e.getMessage();
      if (message == null) {
        message = e.toString();
      }
      status = 
        new Status(
        4, 
        getPluginId(), 
        0, 
        message, 
        e);
    }
    log(status, showErrorDialog);
  }
  
  public static void log(IStatus status, boolean showErrorDialog)
  {
    if (status.getSeverity() != 1)
    {
      if (showErrorDialog) {
        ErrorDialog.openError(
          getActiveWorkbenchShell(), 
          null, 
          null, 
          status);
      }
      Bundle bundle = Platform.getBundle("org.eclipse.update.scheduler");
      Platform.getLog(bundle).log(status);
    }
    else
    {
      MessageDialog.openInformation(
        getActiveWorkbenchShell(), 
        null, 
        status.getMessage());
    }
  }
  
  public static IWorkbenchPage getActivePage()
  {
    UpdateSchedulerPlugin plugin = getDefault();
    IWorkbenchWindow window = 
      plugin.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
      return window.getActivePage();
    }
    return null;
  }
  
  public static Shell getActiveWorkbenchShell()
  {
    IWorkbenchWindow window = getActiveWorkbenchWindow();
    return window != null ? window.getShell() : null;
  }
  
  public static IWorkbenchWindow getActiveWorkbenchWindow()
  {
    return getDefault().getWorkbench().getActiveWorkbenchWindow();
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
  }
  
  public static SchedulerStartup getScheduler()
  {
    if (scheduler == null) {
      scheduler = new SchedulerStartup();
    }
    return scheduler;
  }
  
  static void setScheduler(SchedulerStartup scheduler)
  {
    scheduler = scheduler;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.UpdateSchedulerPlugin
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler.preferences;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class AutomaticUpdatesPreferencePage$1
  extends SelectionAdapter
{
  final AutomaticUpdatesPreferencePage this$0;
  
  AutomaticUpdatesPreferencePage$1(AutomaticUpdatesPreferencePage paramAutomaticUpdatesPreferencePage)
  {
    this$0 = paramAutomaticUpdatesPreferencePage;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    AutomaticUpdatesPreferencePage.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.preferences.AutomaticUpdatesPreferencePage.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler.preferences;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class AutomaticUpdatesPreferencePage$2
  extends SelectionAdapter
{
  final AutomaticUpdatesPreferencePage this$0;
  
  AutomaticUpdatesPreferencePage$2(AutomaticUpdatesPreferencePage paramAutomaticUpdatesPreferencePage)
  {
    this$0 = paramAutomaticUpdatesPreferencePage;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    AutomaticUpdatesPreferencePage.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.preferences.AutomaticUpdatesPreferencePage.2
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler.preferences;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class AutomaticUpdatesPreferencePage$3
  extends SelectionAdapter
{
  final AutomaticUpdatesPreferencePage this$0;
  
  AutomaticUpdatesPreferencePage$3(AutomaticUpdatesPreferencePage paramAutomaticUpdatesPreferencePage)
  {
    this$0 = paramAutomaticUpdatesPreferencePage;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    AutomaticUpdatesPreferencePage.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.preferences.AutomaticUpdatesPreferencePage.3
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler.preferences;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class AutomaticUpdatesPreferencePage$4
  extends SelectionAdapter
{
  final AutomaticUpdatesPreferencePage this$0;
  
  AutomaticUpdatesPreferencePage$4(AutomaticUpdatesPreferencePage paramAutomaticUpdatesPreferencePage)
  {
    this$0 = paramAutomaticUpdatesPreferencePage;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    AutomaticUpdatesPreferencePage.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.preferences.AutomaticUpdatesPreferencePage.4
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler.preferences;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class AutomaticUpdatesPreferencePage$5
  extends SelectionAdapter
{
  final AutomaticUpdatesPreferencePage this$0;
  
  AutomaticUpdatesPreferencePage$5(AutomaticUpdatesPreferencePage paramAutomaticUpdatesPreferencePage)
  {
    this$0 = paramAutomaticUpdatesPreferencePage;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    AutomaticUpdatesPreferencePage.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.preferences.AutomaticUpdatesPreferencePage.5
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler.preferences;

import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.update.internal.scheduler.SchedulerStartup;
import org.eclipse.update.internal.scheduler.UpdateSchedulerMessages;
import org.eclipse.update.internal.scheduler.UpdateSchedulerPlugin;

public class AutomaticUpdatesPreferencePage
  extends PreferencePage
  implements IWorkbenchPreferencePage
{
  private Button enabledCheck;
  private Button onStartupRadio;
  private Button onScheduleRadio;
  private Combo dayCombo;
  private Label atLabel;
  private Combo hourCombo;
  private Button searchOnlyRadio;
  private Button searchAndDownloadRadio;
  private Group updateScheduleGroup;
  private Group downloadGroup;
  
  public void init(IWorkbench workbench) {}
  
  protected Control createContents(Composite parent)
  {
    Composite container = new Composite(parent, 0);
    GridLayout layout = new GridLayout();
    marginWidth = (marginHeight = 0);
    container.setLayout(layout);
    
    enabledCheck = new Button(container, 32);
    enabledCheck.setText(UpdateSchedulerMessages.AutomaticUpdatesPreferencePage_findUpdates);
    
    createSpacer(container, 1);
    
    updateScheduleGroup = new Group(container, 0);
    updateScheduleGroup.setText(UpdateSchedulerMessages.AutomaticUpdatesPreferencePage_UpdateSchedule);
    layout = new GridLayout();
    numColumns = 3;
    updateScheduleGroup.setLayout(layout);
    GridData gd = new GridData(768);
    updateScheduleGroup.setLayoutData(gd);
    
    onStartupRadio = new Button(updateScheduleGroup, 16);
    onStartupRadio.setText(
      UpdateSchedulerMessages.AutomaticUpdatesPreferencePage_findOnStart);
    gd = new GridData();
    horizontalSpan = 3;
    onStartupRadio.setLayoutData(gd);
    onStartupRadio.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        AutomaticUpdatesPreferencePage.this.pageChanged();
      }
    });
    onScheduleRadio = new Button(updateScheduleGroup, 16);
    onScheduleRadio.setText(UpdateSchedulerMessages.AutomaticUpdatesPreferencePage_findOnSchedule);
    gd = new GridData();
    horizontalSpan = 3;
    onScheduleRadio.setLayoutData(gd);
    onScheduleRadio.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        AutomaticUpdatesPreferencePage.this.pageChanged();
      }
    });
    dayCombo = new Combo(updateScheduleGroup, 8);
    dayCombo.setItems(SchedulerStartup.DAYS);
    gd = new GridData();
    widthHint = 200;
    horizontalIndent = 30;
    dayCombo.setLayoutData(gd);
    
    atLabel = new Label(updateScheduleGroup, 0);
    atLabel.setText(UpdateSchedulerMessages.AutomaticUpdatesPreferencePage_at);
    
    hourCombo = new Combo(updateScheduleGroup, 8);
    hourCombo.setItems(SchedulerStartup.HOURS);
    gd = new GridData();
    
    hourCombo.setLayoutData(gd);
    
    createSpacer(container, 1);
    
    downloadGroup = new Group(container, 0);
    downloadGroup.setText(UpdateSchedulerMessages.AutomaticUpdatesPreferencePage_downloadOptions);
    layout = new GridLayout();
    numColumns = 3;
    downloadGroup.setLayout(layout);
    gd = new GridData(768);
    downloadGroup.setLayoutData(gd);
    
    searchOnlyRadio = new Button(downloadGroup, 16);
    searchOnlyRadio.setText(
      UpdateSchedulerMessages.AutomaticUpdatesPreferencePage_searchAndNotify);
    gd = new GridData();
    horizontalSpan = 3;
    searchOnlyRadio.setLayoutData(gd);
    searchOnlyRadio.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        AutomaticUpdatesPreferencePage.this.pageChanged();
      }
    });
    searchAndDownloadRadio = new Button(downloadGroup, 16);
    searchAndDownloadRadio.setText(UpdateSchedulerMessages.AutomaticUpdatesPreferencePage_downloadAndNotify);
    gd = new GridData();
    horizontalSpan = 3;
    searchAndDownloadRadio.setLayoutData(gd);
    searchAndDownloadRadio.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        AutomaticUpdatesPreferencePage.this.pageChanged();
      }
    });
    initialize();
    
    enabledCheck.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        AutomaticUpdatesPreferencePage.this.pageChanged();
      }
    });
    Dialog.applyDialogFont(container);
    return container;
  }
  
  protected void createSpacer(Composite composite, int columnSpan)
  {
    Label label = new Label(composite, 0);
    GridData gd = new GridData();
    horizontalSpan = columnSpan;
    label.setLayoutData(gd);
  }
  
  private void initialize()
  {
    Preferences pref = UpdateSchedulerPlugin.getDefault().getPluginPreferences();
    enabledCheck.setSelection(pref.getBoolean("enabled"));
    setSchedule(pref.getString("schedule"));
    
    dayCombo.setText(SchedulerStartup.DAYS[getDay(pref, false)]);
    hourCombo.setText(SchedulerStartup.HOURS[getHour(pref, false)]);
    
    searchOnlyRadio.setSelection(!pref.getBoolean("download"));
    searchAndDownloadRadio.setSelection(pref.getBoolean("download"));
    
    pageChanged();
  }
  
  private void setSchedule(String value)
  {
    if (value.equals("on-startup")) {
      onStartupRadio.setSelection(true);
    } else {
      onScheduleRadio.setSelection(true);
    }
  }
  
  private void pageChanged()
  {
    boolean master = enabledCheck.getSelection();
    updateScheduleGroup.setEnabled(master);
    onStartupRadio.setEnabled(master);
    onScheduleRadio.setEnabled(master);
    dayCombo.setEnabled((master) && (onScheduleRadio.getSelection()));
    atLabel.setEnabled((master) && (onScheduleRadio.getSelection()));
    hourCombo.setEnabled((master) && (onScheduleRadio.getSelection()));
    downloadGroup.setEnabled(master);
    searchOnlyRadio.setEnabled(master);
    searchAndDownloadRadio.setEnabled(master);
  }
  
  protected void performDefaults()
  {
    super.performDefaults();
    Preferences pref = UpdateSchedulerPlugin.getDefault().getPluginPreferences();
    enabledCheck.setSelection(pref.getDefaultBoolean("enabled"));
    
    setSchedule(pref.getDefaultString("schedule"));
    onScheduleRadio.setSelection(pref.getDefaultBoolean("schedule"));
    
    dayCombo.setText(SchedulerStartup.DAYS[getDay(pref, true)]);
    hourCombo.setText(SchedulerStartup.HOURS[getHour(pref, true)]);
    
    searchOnlyRadio.setSelection(!pref.getDefaultBoolean("download"));
    searchAndDownloadRadio.setSelection(pref.getDefaultBoolean("download"));
    pageChanged();
  }
  
  public boolean performOk()
  {
    Preferences pref = UpdateSchedulerPlugin.getDefault().getPluginPreferences();
    pref.setValue("enabled", enabledCheck.getSelection());
    if (onStartupRadio.getSelection()) {
      pref.setValue("schedule", "on-startup");
    } else {
      pref.setValue("schedule", "on-schedule");
    }
    pref.setValue("day", dayCombo.getText());
    pref.setValue("hour", hourCombo.getText());
    
    pref.setValue("download", searchAndDownloadRadio.getSelection());
    
    UpdateSchedulerPlugin.getDefault().savePluginPreferences();
    
    UpdateSchedulerPlugin.getScheduler().scheduleUpdateJob();
    return true;
  }
  
  private int getDay(Preferences pref, boolean useDefault)
  {
    String day = useDefault ? pref.getDefaultString("day") : pref.getString("day");
    for (int i = 0; i < SchedulerStartup.DAYS.length; i++) {
      if (SchedulerStartup.DAYS[i].equals(day)) {
        return i;
      }
    }
    return 0;
  }
  
  private int getHour(Preferences pref, boolean useDefault)
  {
    String hour = useDefault ? pref.getDefaultString("hour") : pref.getString("hour");
    for (int i = 0; i < SchedulerStartup.HOURS.length; i++) {
      if (SchedulerStartup.HOURS[i].equals(hour)) {
        return i;
      }
    }
    return 0;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.preferences.AutomaticUpdatesPreferencePage
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.update.internal.scheduler.preferences;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.osgi.service.prefs.Preferences;

public class PreferenceInitializer
  extends AbstractPreferenceInitializer
{
  public void initializeDefaultPreferences()
  {
    Preferences node = new DefaultScope().getNode("org.eclipse.update.scheduler");
    node.putBoolean("enabled", false);
    node.put("schedule", "on-startup");
    node.putBoolean("download", false);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.update.internal.scheduler.preferences.PreferenceInitializer
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
1

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-2019. Infinite Loop Ltd