📄 flow4jplugin.java
字号:
/**
* Creates a folder in the outputFolder
* @param outputFolder the root folder
* @param folderPath the relative path of the folder to create
* @return the created folder
* @throws CoreException if the creation fails
*/
public static IContainer createFolder(IContainer outputFolder, IPath folderPath, boolean derived) throws CoreException {
if (folderPath.isEmpty()) return outputFolder;
IFolder folder = outputFolder.getFolder(folderPath);
if (!folder.exists()) {
createFolder(outputFolder, folderPath.removeLastSegments(1), derived);
folder.create(true, true, null);
// if set to "true" then deleting the package only deletes
// the last path element
// "false" -> on deletion of the package the complete folder tree is deleted
folder.setDerived(derived);
}
return folder;
}
/**
* Registers task flowlets at the FlowManager which are used by the Plug-in itself
*/
/* private static void registerTaskFlowlets() {
// update flow file - tasks
FlowManager.registerTaskFlowlet(FutureVersionTask.class);
FlowManager.registerTaskFlowlet(GetDOMDocTask.class);
FlowManager.registerTaskFlowlet(GetVersionTask.class);
FlowManager.registerTaskFlowlet(SaveUpdatedFileTask.class);
FlowManager.registerTaskFlowlet(TooOldTask.class);
FlowManager.registerTaskFlowlet(V2ToV3Task.class);
}
*/
/**
* Registers the flows which are needed by the Flow4J Plug-in
*/
static private void registerFlows() {
FlowManager.registerFlow(
net.orthanc.flow4j.flows.updateflowfile.UpdateFlowFileFlow.class);
}
/**
* Returns whether a project has a Flow4J nature.
* @param project
* @return
*/
public static boolean hasFlow4JNature(IProject project) {
// Be flexible with 1.0 IDs - check all combinations
if (! project.isOpen())
return false;
try {
return project.hasNature(FLOW4J_NATURE_ID);
} catch (CoreException e) {
log(e);
}
return false;
}
/**
* Returns true if the file is a flow file.
* @param file the file to check
* @return true if the file is a flow file.
*/
public static boolean isFlowFile(IFile file) {
String extension = file.getProjectRelativePath().getFileExtension();
return extension == null
? false
: FLOW4J_FILE_EXTENSION.equalsIgnoreCase(extension);
}
/**
* Returns <code>true</code> if the file is a java file.
* @param file the file to check
* @return <code>true</code> if the file is a java file.
*/
public static boolean isJavaFile(IFile file) {
String extension = file.getProjectRelativePath().getFileExtension();
return extension == null
? false
: JAVA_FILE_EXTENSION.equalsIgnoreCase(extension);
}
/**
* Returns <code>true</code> if the file is a java file.
* @param file the file to check
* @return <code>true</code> if the file is a java file.
*/
public static boolean isScriptFile(IFile file) {
String extension = file.getProjectRelativePath().getFileExtension();
return Flow4JBSFManager.isScriptExtension(extension);
}
/**
* Convenience method to get the java model.
*/
public static IJavaModel getJavaModel() {
return JavaCore.create(getWorkspaceRoot());
}
/**
* Returns the workspace instance.
*/
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
/**
* Convenience method to get the workspace root.
*/
public static IWorkspaceRoot getWorkspaceRoot() {
return Flow4JPlugin.getWorkspace().getRoot();
}
/**
* Convenience method to get the active workbench window.
* @return the active workbench window.
*/
public static IWorkbenchWindow getActiveWorkbenchWindow() {
return getDefault().getWorkbench().getActiveWorkbenchWindow();
}
/**
* Returns the active workbench page.
* @return the active workbench page.
*/
public static IWorkbenchPage getActivePage() {
Flow4JPlugin plugin = getDefault();
IWorkbenchWindow window =
plugin.getWorkbench().getActiveWorkbenchWindow();
if (window == null)
return null;
return plugin.getWorkbench().getActiveWorkbenchWindow().getActivePage();
}
/**
* Convenience method to retrieve the Java project containing file in the
* currently opened editor.
*
* @return The active Java project.
* @author Peter Friese
*/
/* public static IJavaProject getActiveJavaProject() {
FlowEditor editor = Flow4JPlugin.getActiveFlowEditor();
if (editor != null) {
IEditorInput input = editor.getEditorInput();
if (input != null) {
Object adapter = input.getAdapter(IResource.class);
if ((adapter != null) && (adapter instanceof IResource)) {
IResource resource = (IResource) adapter;
IProject project = resource.getProject();
IJavaProject javaProject = JavaCore.create(project);
return javaProject;
}
}
}
return null;
}
*/
/**
* Convenience method to retrieve the Java project containing file in the
* currently opened editor.
*
* @return The active Java project.
*/
public static IJavaProject getActiveJavaProject() {
return Flow4JPlugin.getJavaProject(Flow4JPlugin.getActiveProject());
}
/**
* Convenience method to retrieve the project containing file in the
* currently opened editor.
* @return The active project.
*/
public static IProject getActiveProject() {
return Flow4JPlugin.getActiveFlowEditor().getFlowFile().getProject();
}
/**
* Retrieves the source type of the ITaskFlowlet interface.
*
* @return The source type of the ITaskFlowlet interface.
* @author Peter Friese
*/
public static IType getTaskFlowletBaseType() {
double start = System.currentTimeMillis();
if (Flow4JPlugin.taskFlowletBaseType == null) {
try {
Flow4JPlugin.taskFlowletBaseType =
Flow4JPlugin.getActiveJavaProject().findType(
"net.orthanc.flow4j.runtime.ITaskFlowlet");
}
catch (JavaModelException e) {
e.printStackTrace();
}
}
System.out.println(
"Looking up base type took "
+ (System.currentTimeMillis() - start)
+ "ms");
return Flow4JPlugin.taskFlowletBaseType;
}
/**
* Returns the java project with the given name
* @param projectName project name
* @return the java project with the given name
*/
public static IJavaProject getJavaProject(String projectName) {
return getJavaModel().getJavaProject(projectName);
}
/**
* Returns the java project with the name of the given project
* @param project project taht is maybe a java project
* @return the java project with the name of the given project
*/
public static IJavaProject getJavaProject(IProject project) {
return getJavaProject(project.getName());
}
/**
* TODO
* @param project
* @return
* @throws CoreException
*/
public static Flow4JProject getFlow4JProject(IProject project) throws CoreException {
return (Flow4JProject) (project.getNature(Flow4JPlugin.FLOW4J_NATURE_ID));
}
/**
* TODO
* @param javaProject
* @return
*/
public static IProject getProject(IJavaProject javaProject) {
return getWorkspaceProject(javaProject.getPath());
}
/**
* Returns a sorted list of projects.
* Sorted means that the longer comes first if
* two project names have the same prefix.
* The projects can be open or closed.
* @return a sorted list of projects.
*/
private static IProject[] getWorkspaceProjects() {
IProject[] result;
result = getWorkspaceRoot().getProjects();
// We have to sort the list of project names to make sure that we cut of the longest
// project from the path, if two projects with the same prefix exist. For example
// org.eclipse.jdt.ui and org.eclipse.jdt.ui.tests.
Arrays.sort(result, new Comparator() {
public int compare(Object o1, Object o2) {
int l1 = ((IProject) o1).getName().length();
int l2 = ((IProject) o2).getName().length();
if (l1 < l2)
return 1;
if (l2 < l1)
return -1;
return 0;
}
public boolean equals(Object obj) {
return super.equals(obj);
}
});
return result;
}
/**
* Returns a project which has the given path or
* <code>null</code> if none found.
* @param path the path of the project
* @return a project which has the given path or
* <code>null</code>
*/
private static IProject getWorkspaceProject(IPath path) {
IProject[] projects = getWorkspaceProjects();
for (int i = 0; i < projects.length; i++) {
IProject project = projects[i];
if (project.getFullPath().equals(path))
return project;
}
return null;
}
/**
* Returns a list of <code>IPath</code> classpath entries of the java project.
* @param project the java project
* @return list of <code>IPath</code> classpath entries of the java project.
* @throws JavaModelException
*/
/* public static List getClasspathEntryLocations(IJavaProject project)
throws JavaModelException {
List locations = new ArrayList();
for (int j = 0; j < project.getAllPackageFragmentRoots().length; j++) {
IPackageFragmentRoot frag = project.getAllPackageFragmentRoots()[j];
IClasspathEntry cp = frag.getRawClasspathEntry();
IPath path = cp.getPath();
if (cp.getEntryKind() == IClasspathEntry.CPE_SOURCE
|| cp.getEntryKind() == IClasspathEntry.CPE_CONTAINER)
continue;
if (cp.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
cp = JavaCore.getResolvedClasspathEntry(cp);
path = cp.getPath();
}
if (cp.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IResource resource =
Flow4JPlugin.getWorkspaceRoot().findMember(path);
if (resource != null)
path = resource.getLocation();
}
locations.add(path);
}
return locations;
}
*/
/**
* Returns the editor id for the given file.
*/
public static String getEditorID(String file) {
IEditorRegistry registry =
PlatformUI.getWorkbench().getEditorRegistry();
IEditorDescriptor descriptor = registry.getDefaultEditor(file);
if (descriptor != null)
return descriptor.getId();
return null;
}
/**
* TODO
* @param project
* @return
* @throws JavaModelException
*/
public static IPath[] getClasspathSourceContainers(IProject project) throws JavaModelException {
IJavaProject javaProject = Flow4JPlugin.getJavaProject(project);
List folders = new ArrayList();
IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
for (int i = 0; i < entries.length; i++) {
IClasspathEntry entry = entries[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
folders.add(entry.getPath());
}
}
return (IPath[])folders.toArray(new Path[folders.size()]);
}
/**
* Returns the classpath of the java file.
* @param file the java file
* @return the classpath of the java file or <code>null</code> if it cannot determined.
* @throws JavaModelException if the classpath cannot be determined
*/
static public IPath getClassPath(IFile file) throws JavaModelException {
IPath filePath = file.getProjectRelativePath();
IPath[] scPaths =
Flow4JPlugin.getClasspathSourceContainers(file.getProject());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -