📄 jadfilemoveparticipant.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 org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.MoveParticipant;
import eclipseme.core.model.IMidletSuiteProject;
import eclipseme.core.model.MidletSuiteFactory;
/**
* EclipseME participant in move refactoring operations
* for a project's 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.4 $
* <br>
* $Date: 2006/02/11 21:26:57 $
* <br>
* @author Craig Setera
*/
public class JadFileMoveParticipant extends MoveParticipant {
private IFile jadFile;
/**
* @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object)
*/
protected boolean initialize(Object element) {
boolean enable = false;
jadFile = (IFile) element;
if (jadFile.getProjectRelativePath().getFileExtension().equals("jad")) {
IMidletSuiteProject suite = getMidletSuite(jadFile);
enable =
suite.getJadFile().equals(jadFile) &&
(getNewFilePath() != null);
}
return enable;
}
/**
* @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName()
*/
public String getName() {
return "Update JAD file reference";
}
/**
* @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
*/
public RefactoringStatus checkConditions(
IProgressMonitor pm,
CheckConditionsContext context)
throws OperationCanceledException
{
return new RefactoringStatus();
}
/**
* @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor)
*/
public Change createChange(IProgressMonitor pm)
throws CoreException, OperationCanceledException
{
IPath oldPath = jadFile.getProjectRelativePath();
IPath newPath = getNewFilePath();
return new JadFileProjectMetadataChange(getMidletSuite(jadFile), oldPath, newPath);
}
/**
* Return the midlet suite in which the file is located or
* <code>null</code> if not in a midlet project.
*
* @param file
* @return
*/
private IMidletSuiteProject getMidletSuite(IFile file)
{
IMidletSuiteProject suite = null;
IProject project = jadFile.getProject();
IJavaProject javaProject = JavaCore.create(project);
if (javaProject != null) {
suite = MidletSuiteFactory.getMidletSuiteProject(javaProject);
}
return suite;
}
/**
* Return the new name to be used for the updates.
* @return
*/
private IPath getNewFilePath() {
IPath path = null;
IContainer destination = getNewContainer();
if (destination != null) {
String filename = jadFile.getName();
path = destination.getProjectRelativePath().append(filename);
}
return path;
}
/**
* Return the path that will hold the jad file after the
* refactoring operation.
*
* @return
*/
private IContainer getNewContainer() {
IContainer container = null;
Object destination = getArguments().getDestination();
if (destination instanceof IContainer) {
container = (IContainer) destination;
} else if (destination instanceof IAdaptable) {
container = (IContainer) ((IAdaptable) destination).getAdapter(IContainer.class);
}
return container;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -