⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 migrateto150support.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/**
 * Copyright (c) 2003-2006 Craig Setera
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 */
package eclipseme.ui.internal.migration;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IStartup;

import eclipseme.core.IEclipseMECoreConstants;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.migration.OldPlatformComponentsAccess;
import eclipseme.core.model.device.DeviceRegistry;
import eclipseme.core.persistence.PersistenceException;

/**
 * Provides support for migrating from pre-1.5 version to
 * version 1.5 of EclipseME.
 * <p />
 * Copyright (c) 2003-2006 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.1 $
 * <br>
 * $Date: 2006/03/06 00:55:27 $
 * <br>
 * @author Craig Setera
 */
public class MigrateTo150Support implements IStartup {
	private static final String PREF_150_MIGRATED = "migrated_150";
	
	// A job that will launch the migration support for
	// pre-1.5 EclipseME jobs
	private class MigrationJob extends Job {
		public MigrationJob() {
			super("EclipseME Migration UI");
			setPriority(LONG);
			setSystem(false);
		}

		protected IStatus run(IProgressMonitor monitor) {
			Preferences prefs = EclipseMECorePlugin.getDefault().getPluginPreferences();
			boolean autoLaunch = prefs.getBoolean(IEclipseMECoreConstants.PREF_AUTO_LAUNCH_MIGRATION);
			if (autoLaunch) {
				Display display = Display.getDefault();
				LaunchMigration runnable = new LaunchMigration(display);
				display.asyncExec(runnable);
				prefs.setValue(IEclipseMECoreConstants.PREF_AUTO_LAUNCH_MIGRATION, false);
				EclipseMECorePlugin.getDefault().savePluginPreferences();
			}
			
			return EclipseMECorePlugin.newStatus(IStatus.OK, 0, "Migration Launched");
		}
	}

	// Runnable for the actual migration processing
	private class LaunchMigration implements Runnable {
		private Display display;
		private IStatus status;
		
		public LaunchMigration(Display display) {
			this.display = display;
			status = EclipseMECorePlugin.newStatus(IStatus.OK, 0, "Migration Complete");
		}

		/**
		 * @return Returns the status.
		 */
		public IStatus getStatus() {
			return status;
		}
		
		public void run() {
			Shell shell = display.getActiveShell();
			
			try {
				if (shouldDoMigration()) {
					WizardDialog dialog = new WizardDialog(shell, new MigrationWizard());
					dialog.open();
				}
			} catch (Exception e) {
				status = EclipseMECorePlugin.newStatus(IStatus.ERROR, -999, "Migration Failed", e);
			}
		}
	}
	
	/**
	 * Construct a new migration object.
	 */
	public MigrateTo150Support() {
		super();
	}

	/**
	 * @see org.eclipse.ui.IStartup#earlyStartup()
	 */
	public void earlyStartup() {
		// Do version to version migration
		(new MigrationJob()).schedule(10000L);
	}
	
	/**
	 * Return a boolean indicating whether migration should
	 * be done or not.
	 * 
	 * @return
	 * @throws PersistenceException 
	 */
	private boolean shouldDoMigration() 
		throws PersistenceException 
	{
		Preferences prefs = EclipseMECorePlugin.getDefault().getPluginPreferences();
		boolean previouslyMigrated = prefs.getBoolean(PREF_150_MIGRATED);
		boolean hasComponentsFile = new OldPlatformComponentsAccess().storeFileExists();
		boolean hasDefinedDevices = (DeviceRegistry.singleton.getDeviceCount() > 0);
		
		return !previouslyMigrated && !hasDefinedDevices && hasComponentsFile;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -