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

📄 jadfileprojectmetadatachange.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/**
 * Copyright (c) 2003-2005 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.core.internal.refactoring;

import java.io.File;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;

import eclipseme.core.model.IMidletSuiteProject;
import eclipseme.core.model.impl.MetaData;

/**
 * A refactoring change operation that updates the midlet 
 * suite information to point to the JAD file.
 * <p />
 * Copyright (c) 2003-2005 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.2 $
 * <br>
 * $Date: 2006/11/12 01:11:03 $
 * <br>
 * @author Craig Setera
 */
public class JadFileProjectMetadataChange extends Change {
	private IMidletSuiteProject midletSuite;
	private IPath oldPath;
	private IPath newPath;
	private IFile metadataFile;
	private long startTimestamp;
	
	/**
	 * Construct a new change object
	 * @param midletSuite
	 * @param oldPath
	 * @param newPath
	 */
	public JadFileProjectMetadataChange(
		IMidletSuiteProject midletSuite, 
		IPath oldPath, 
		IPath newPath) 
	{
		super();
		this.midletSuite = midletSuite;
		this.oldPath = oldPath;
		this.newPath = newPath;
		
		metadataFile = midletSuite.getProject().getFile(MetaData.METADATA_FILE);
	}

	/**
	 * @see org.eclipse.ltk.core.refactoring.Change#getName()
	 */
	public String getName() {
		return "Project JAD file update";
	}

	/**
	 * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor)
	 */
	public void initializeValidationData(IProgressMonitor pm) {
		startTimestamp = System.currentTimeMillis();
		
		File localFile = metadataFile.getLocation().toFile(); 
		if (localFile != null) {
			startTimestamp = localFile.lastModified();
		}
	}

	/**
	 * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
	 */
	public RefactoringStatus isValid(IProgressMonitor pm) 
		throws CoreException, OperationCanceledException 
	{
		RefactoringStatus status = new RefactoringStatus();
		
		File localFile = metadataFile.getLocation().toFile(); 
		if (localFile != null) {
			if (localFile.lastModified() != startTimestamp) {
				RefactoringStatus syncStatus = 
					RefactoringStatus.createErrorStatus(metadataFile + " has changed");
				status.merge(syncStatus);
			}
		}
		
		if (!metadataFile.isSynchronized(IResource.DEPTH_ONE)) {
			RefactoringStatus syncStatus = 
				RefactoringStatus.createErrorStatus(metadataFile + " is out of sync");
			status.merge(syncStatus);
		}
		
		return status;
	}

	/**
	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
	 */
	public Change perform(IProgressMonitor pm) 
		throws CoreException 
	{
		midletSuite.setJadFileLocation(newPath);
		return new JadFileProjectMetadataChange(midletSuite, newPath, oldPath);
	}

	/**
	 * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement()
	 */
	public Object getModifiedElement() {
		return metadataFile;
	}
}

⌨️ 快捷键说明

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