📄 flow4jplugin.java
字号:
for (int i = 0; i < scPaths.length; i++) {
IPath scPath = scPaths[i];
// remove project segment at the beginning
scPath = scPath.removeFirstSegments(1);
if (scPath.isPrefixOf(filePath)) {
return filePath.removeFirstSegments(scPath.segmentCount());
}
}
return null;
}
/**
* TODO
* @param flowEditor
* @param pathEntries
*/
public static void getResolvedClasspath(
FlowEditor flowEditor,
List pathEntries) {
getResolvedClasspath(
((FileEditorInput) flowEditor.getEditorInput()).getFile(),
pathEntries);
}
/**
* TODO
* @param file
* @param pathEntries
*/
public static void getResolvedClasspath(IFile file, List pathEntries) {
getResolvedClasspath(file.getProject(), pathEntries);
}
/**
* TODO
* @param project
* @param pathEntries
*/
public static void getResolvedClasspath(
IProject project,
List pathEntries) {
getResolvedClasspath(project.getName(), pathEntries);
}
/**
* Adds classpath entries to the supported list.
* @param projectName
* @param pathEntries
*/
public static void getResolvedClasspath(
String projectName,
List pathEntries) {
IJavaProject javaProject = Flow4JPlugin.getJavaProject(projectName);
IPath path = null;
try {
IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
for (int i = 0; i < entries.length; i++) {
IClasspathEntry entry = entries[i];
path = null;
if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
path =
getWorkspaceRoot().getLocation().append(
JavaCore
.getResolvedClasspathEntry(entry)
.getPath());
} else if (
entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
path = JavaCore.getResolvedClasspathEntry(entry).getPath();
} else if (
entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
path = entry.getPath().makeAbsolute();
if (!path.toFile().getAbsoluteFile().exists()) {
IPath location =
getWorkspaceRoot()
.getProject(entry.getPath().segment(0))
.getFile(entry.getPath().removeFirstSegments(1))
.getLocation();
if (location != null) {
File tmpFile = location.toFile();
if (tmpFile.exists())
path = location;
}
}
}
if (path != null && !pathEntries.contains(path))
pathEntries.add(path);
if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
IProject requiredProject =
getWorkspaceProject(entry.getPath());
// recurse into projects
if (requiredProject != null)
getResolvedClasspath(requiredProject, pathEntries);
}
}
IPath outputPath = javaProject.getOutputLocation();
if (outputPath.segmentCount() == 1)
outputPath = javaProject.getResource().getLocation();
else
outputPath =
javaProject
.getProject()
.getFile(outputPath.removeFirstSegments(1))
.getLocation();
if (outputPath != null && !pathEntries.contains(outputPath))
pathEntries.add(outputPath);
} catch (JavaModelException e) {
Flow4JPlugin.log(e);
}
}
/**
* Returns true if the given project is accessible and it has
* a java nature, otherwise false.
*/
public static boolean hasJavaNature(IProject project) {
try {
return project.hasNature(JavaCore.NATURE_ID);
} catch (CoreException e) {
// project does not exist or is not open
}
return false;
}
/**
* Returns the active editor open in this page.
* <p>
* This is the visible editor on the page, or, if there is more than one
* visible editor, this is the one most recently brought to top.
* </p>
* @return the active editor, or <code>null</code> if no editor is active
*/
public static IEditorPart getActiveEditor() {
Flow4JPlugin plugin = Flow4JPlugin.getDefault();
IWorkbench wb = plugin.getWorkbench();
IWorkbenchWindow ww = wb.getActiveWorkbenchWindow();
IWorkbenchPage wp = ww.getActivePage();
IEditorPart ep = wp.getActiveEditor();
return ep;
}
/**
* Returns the active FlowEditor open in this page or <code>null</code>
* if the active editor is not of type FlowEditor.
* @return the active FlowEditor open in this page or <code>null</code>
* if the active editor is not of type FlowEditor.
*/
public static FlowEditor getActiveFlowEditor() {
IEditorPart editor = getActiveEditor();
return (editor instanceof FlowEditor) ? (FlowEditor) editor : null;
}
/**
* Adds the flow4j nature to the given project.
* Automatically adds the flow builder to the project
* @param project the project which will have the flow4j nature
* @param monitor the progress monitor
* @throws CoreException if something goes wrong
*/
static public void addFlow4JNature(
IProject project,
IProgressMonitor monitor)
throws CoreException {
if (!project.hasNature(Flow4JPlugin.FLOW4J_NATURE_ID)) {
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 1, prevNatures.length);
newNatures[0] = Flow4JPlugin.FLOW4J_NATURE_ID;
description.setNatureIds(newNatures);
project.setDescription(description, monitor);
} else {
monitor.worked(1);
}
}
/**
* Removes the flow4j nature to the given project.
* Automatically removes the flow builder to the project
* @param project the project which will get rid of its flow4j nature
* @param monitor the progress monitor
* @throws CoreException if something goes wrong
*/
static public void removeFlow4JNature(
IProject project,
IProgressMonitor monitor)
throws CoreException {
if (project.hasNature(Flow4JPlugin.FLOW4J_NATURE_ID)) {
IProjectDescription description = project.getDescription();
List natures = Arrays.asList(description.getNatureIds());
List newNatures = new ArrayList(natures.size() - 1);
for (ListIterator iter = natures.listIterator(); iter.hasNext();) {
String nature = (String) iter.next();
if (!nature.equals(Flow4JPlugin.FLOW4J_NATURE_ID)) {
newNatures.add(nature);
}
}
description.setNatureIds(
(String[]) newNatures.toArray(new String[newNatures.size()]));
project.setDescription(description, monitor);
}
}
static public void addFlow4jRuntimeLibrary(IJavaProject javaProject) {
IPath flow4jProjectPath =
new Path("ECLIPSE_HOME").append("plugins").append(
new Path(
Flow4JPlugin
.getDefault()
.getDescriptor()
.getInstallURL()
.getPath())
.lastSegment());
IClasspathEntry variableEntry =
JavaCore.newVariableEntry(
flow4jProjectPath.append("flow4jruntime.jar"),
flow4jProjectPath.append("src.zip"),
null,
true);
try {
IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
IClasspathEntry[] newEntries =
new IClasspathEntry[classpathEntries.length + 1];
System.arraycopy(
classpathEntries,
0,
newEntries,
0,
classpathEntries.length);
newEntries[newEntries.length - 1] = variableEntry;
javaProject.setRawClasspath(newEntries, null);
} catch (JavaModelException e) {
//Flow4JPlugin.log(e);
}
}
static public String getInstallFolderPathStr() throws IOException {
return Platform
.resolve(Flow4JPlugin.getDefault().getDescriptor().getInstallURL())
.getPath();
}
static public URL getInstallFolderPathURL() throws IOException {
return Platform
.resolve(Flow4JPlugin.getDefault().getDescriptor().getInstallURL());
}
static public IPath getInstallFolderPath() throws IOException {
return new Path(getInstallFolderPathStr());
}
static public String getPluginInstallFolderPathStr(String pluginId)
throws IOException {
return Platform
.resolve(
Platform.getPlugin(pluginId).getDescriptor().getInstallURL())
.getPath();
}
static public URL getPluginInstallFolderPathURL(String pluginId)
throws IOException {
return Platform
.resolve(
Platform.getPlugin(pluginId).getDescriptor().getInstallURL());
}
static public IPath getPluginInstallFolderPath(String pluginId)
throws IOException {
return new Path(getPluginInstallFolderPathStr(pluginId));
}
/**
* Returns the string from the plugin's resource bundle,
* or 'key' if not found.
*/
public static String getResourceString(String key) {
ResourceBundle bundle = Flow4JPlugin.getDefault().getResourceBundle();
try {
return (bundle != null ? bundle.getString(key) : key);
} catch (MissingResourceException e) {
return key;
}
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
/**
* TODO
* @param ex
*/
static public void log(CoreException ex) {
ex.printStackTrace();
IStatus cause = ex.getStatus();
if (cause.getException() != null) {
System.out.println("cause: " + cause.getMessage());
cause.getException().printStackTrace();
}
}
/**
* TODO
* @param ex
*/
static public void log(Throwable ex) {
ex.printStackTrace();
}
/**
* TODO
* @param message
*/
static public void log(String message) {
System.out.println(message);
}
/**
* TODO
* @param message
*/
static public void log(String message, Exception e) {
log(message);
log(e);
}
/*
public static void log(IStatus status) {
ResourcesPlugin.getPlugin().getLog().log(status);
}
public static void logErrorMessage(String message) {
log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, null));
}
public static void logException(
Throwable e,
final String title,
String message) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
IStatus status = null;
if (e instanceof CoreException)
status = ((CoreException) e).getStatus();
else {
if (message == null)
message = e.getMessage();
if (message == null)
message = e.toString();
status = new Status(IStatus.ERROR, getPluginId(), IStatus.OK, message, e);
}
ResourcesPlugin.getPlugin().getLog().log(status);
}
public static void logException(Throwable e) {
logException(e, null, null);
}
public static void log(Throwable e) {
if (e instanceof InvocationTargetException)
e = ((InvocationTargetException) e).getTargetException();
IStatus status = null;
if (e instanceof CoreException)
status = ((CoreException) e).getStatus();
else
status =
new Status(IStatus.ERROR, getPluginId(), IStatus.OK, e.getMessage(), e);
log(status);
}
*/
/**
* Opens a message Dialog window with the given messge.
* @param message the message
*/
static public void message(String message) {
MessageDialog.openInformation(new Shell(), "Flow4J Plug-in", message);
}
/**
* Returns the pretty printer Settings
* @return the pretty printer Settings
*/
public static FileSettings getPrettySettings() {
return prettySettings;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -