📄 flowexportwizard.java
字号:
}
classpathURLs.add(new File(Flow4JPlugin.getInstallFolderPath().toFile(), "/bin").toURL());
//pluginRuntimeLibs.add(new File(Flow4JPlugin.getPluginInstallFolderPath("net.orthanc.flow4j.flowdoc").toFile(), "/bin").toURL());
return classpathURLs;
}
/**
* Creates the ant build flowFile that generates the flow documentation.
* If a build file already exists, then it will be deleted before the new one is created.
* @param buildFile the build flowFile that is generated
* @param flowFiles the flow files from which documentation will be created
* @param destFolder the destination folder
* @throws IOException if the build flowFile cannot be written
*/
private void createBuildFile(
File buildFile,
List flowFiles,
File destFolder)
throws IOException, JavaModelException {
if (buildFile.exists()) {
buildFile.delete();
buildFile.createNewFile();
}
PrintWriter writer = new PrintWriter(new FileWriter(buildFile), true);
writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writer.println("<project name=\"Flowdoc\" default=\"flowdoc\" basedir=\".\">");
writer.println(" <property name=\"flow4jplugin.dir\" value=\"" + Flow4JPlugin.getInstallFolderPath().toFile().getAbsolutePath().replace('\\', '/') + "\"/>");
writer.println(" <property name=\"flow4jpluginjar.file\" value=\"${flow4jplugin.dir}/flow4jplugin.jar\"/>");
writer.println(" <property name=\"flowdocplugin.dir\" value=\"" + Flow4JPlugin.getPluginInstallFolderPath("net.orthanc.flow4j.flowdoc").toFile().getAbsolutePath().replace('\\', '/') + "\"/>");
writer.println(" <property name=\"flowdocpluginjar.file\" value=\"${flowdocplugin.dir}/flowdocplugin.jar\"/>");
writer.println(" <property name=\"dest.dir\" value=\"" + destFolder.getAbsolutePath().replace('\\', '/') + "/flowdoc\"/>");
//castor writer.println(" <property name=\"mapping.file\" value=\"" + Flow4JPlugin.getCastorMappingFile().getAbsolutePath().replace('\\', '/') + "\"/>");
writer.println(" <property name=\"prettysettings.file\" value=\"" + Flow4JPlugin.getPrettySettingsFile().getAbsolutePath().replace('\\', '/') + "\"/>");
writer.println(" <target name=\"flowdoc\" description=\"Creates Flow documentation\">");
writer.println(" <path id=\"flowdoc.class.path\">");
writer.println(" <fileset dir=\"${flow4jplugin.dir}/lib\">");
writer.println(" <include name=\"*.jar\"/>");
writer.println(" </fileset>");
writer.println(" <fileset dir=\"${flowdocplugin.dir}/lib\">");
writer.println(" <include name=\"*.jar\"/>");
writer.println(" </fileset>");
writer.println(" <pathelement location=\"${flow4jpluginjar.file}\"/>");
writer.println(" <pathelement location=\"${flowdocpluginjar.file}\"/>");
for (int i = 0; i < mainPage.getSelectedProjects().length; i++) {
IJavaProject javaProject = Flow4JPlugin.getJavaProject(mainPage.getSelectedProjects()[i]);
writer.println(" <!-- project: " + stripHtml(javaProject.getPath().toString()) + " -->");
List classpathList = new ArrayList();
Flow4JPlugin.getResolvedClasspath(Flow4JPlugin.getProject(javaProject), classpathList);
for (Iterator iter = classpathList.iterator(); iter.hasNext();) {
IPath path = (IPath) iter.next();
writer.println(" <pathelement location=\"" + path.toOSString() + "\"/>");
}
}
writer.println(" <pathelement location=\"${flow4jplugin.dir}/bin\"/><!-- for testing in runtime workbench -->");
writer.println(" <pathelement location=\"${flowdocplugin.dir}/bin\"/><!-- for testing in runtime workbench -->");
writer.println(" </path>");
writer.println(" <taskdef");
writer.println(" name=\"flow2java\"");
writer.println(" classname=\"net.orthanc.flow4j.tools.ant.FlowJavaSourceGenerator\"");
writer.println(" classpathref=\"flowdoc.class.path\"/>");
writer.println(" <taskdef");
writer.println(" name=\"flow2image\"");
writer.println(" classname=\"net.orthanc.flow4j.designer.tools.ant.DesignerFlowImageGenerator\"");
// writer.println(" classname=\"net.orthanc.flow4j.tools.ant.FlowImageGenerator\"");
writer.println(" classpathref=\"flowdoc.class.path\"/>");
writer.println(" <taskdef name=\"flow2html\"");
writer.println(" classname=\"net.orthanc.flow4j.tools.xdoclet.FlowHtmlGenerator\"");
writer.println(" classpathref=\"flowdoc.class.path\" />");
writer.println(" <mkdir dir=\"${dest.dir}\"/>");
writer.println(" <delete includeEmptyDirs=\"true\">");
writer.println(" <fileset dir=\"${dest.dir}\"/>");
writer.println(" </delete>");
writer.println(" <mkdir dir=\"${dest.dir}\"/>");
writer.println(" <copy todir=\"${dest.dir}\">");
for (Iterator iter = flowFiles.iterator(); iter.hasNext();) {
FileDesc fileDesc = (FileDesc)iter.next();
writer.println(" <fileset dir=\"" + fileDesc.getSourceFolderPath().toFile().getAbsolutePath() + "\">");
writer.println(" <include name=\"" + fileDesc.getRelFlowFilePath() + "\"/>");
writer.println(" </fileset>");
}
writer.println(" </copy>");
writer.println(" <flow2java destDir=\"${dest.dir}\"");
writer.println(" srcDir=\"${dest.dir}\"");
//castor writer.println(" mappingFile=\"${mapping.file}\"");
writer.println(" prettySettingsFile=\"${prettysettings.file}\"");
writer.println(" includes=\"**/*.f4j\">");
writer.println(" </flow2java>");
writer.println(" <flow2image");
writer.println(" destdir=\"${dest.dir}\"");
//castor writer.println(" mappingFile=\"${mapping.file}\"");
writer.println(" jpg=\"true\"");
writer.println(" pdf=\"false\">");
writer.println(" <fileset dir=\"${dest.dir}\">");
writer.println(" <include name=\"**/*.f4j\"/>");
writer.println(" </fileset>");
writer.println(" </flow2image>");
writer.println(" <flow2html destdir=\"${dest.dir}\">");
writer.println(" <fileset dir=\"${dest.dir}\">");
writer.println(" <include name=\"**/*.java\"/>");
writer.println(" </fileset>");
writer.println(" <html/>");
writer.println(" </flow2html>");
writer.println(" <delete includeEmptyDirs=\"true\">");
writer.println(" <fileset dir=\"${dest.dir}\">");
writer.println(" <include name=\"**/*.f4j\"/>");
writer.println(" <include name=\"**/*.java\"/>");
writer.println(" </fileset>");
writer.println(" </delete>");
writer.println(" </target>");
writer.println("</project>");
writer.close();
}
/**
*
* @param text
* @return
*/
private String stripHtml(String text) {
text = text.replace('<', '_');
text = text.replace('>', '_');
text = text.replace('&', '_');
text = text.replace('"', '_');
return text;
}
/**
* Returns the flow files which can be found in the given projects.
* @param jprojects flow4j projects
* @return flow files which can be found in the given projects.
* @throws JavaModelException
*/
private List getFlowFiles(IProject[] jprojects) throws JavaModelException {
List flowFiles = new ArrayList();
for (int i = 0; i < jprojects.length; i++) {
IJavaProject javaProject =
Flow4JPlugin.getJavaProject(jprojects[i]);
IPackageFragment[] els = javaProject.getPackageFragments();
for (int j = 0; j < els.length; j++) {
IPackageFragment packageFragment = (IPackageFragment) els[j];
packageFragment.toString();
Object[] nonJavaResources =
packageFragment.getNonJavaResources();
for (int k = 0; k < nonJavaResources.length; k++) {
Object obj = nonJavaResources[k];
if (!(obj instanceof IFile))
continue;
IFile nonJavaResource = (IFile) obj;
if (Flow4JPlugin.isFlowFile(nonJavaResource)) {
flowFiles.add(new FileDesc(packageFragment, nonJavaResource));
}
}
}
}
return flowFiles;
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizard#performCancel()
*/
public boolean performCancel() {
return mainPage.cancel();
}
/**
*
* @author greifa
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
private class FileDesc {
IPackageFragment packageFrament;
IFile flowFile;
FileDesc(IPackageFragment packageFrament, IFile file) {
this.packageFrament = packageFrament;
this.flowFile = file;
}
IPath getSourceFolderPath() {
List segments = new ArrayList();
IJavaElement elem = packageFrament.getParent();
while (elem.getElementType() != IJavaElement.JAVA_PROJECT) {
if (((IJavaProject)Flow4JPlugin.getJavaProject(flowFile.getProject())).getElementName().equals(elem.getPath().segment(0))) {
segments.add(elem.getPath().removeFirstSegments(1).makeRelative());
} else {
segments.add(elem.getPath());
}
elem = elem.getParent();
}
IPath folderPath = new Path(flowFile.getProject().getLocation().toString());
for (int i = segments.size(); i > 0 ; i--) {
folderPath = folderPath.append((IPath)segments.get(i-1));
}
//System.out.println("folderPath: "+folderPath);
return folderPath;
}
IPath getRelFlowFilePath() {
IPath folderPath = getSourceFolderPath();
int matchingFirstSgmnts = flowFile.getLocation().matchingFirstSegments(folderPath);
IPath filePath = flowFile.getLocation();
filePath = filePath.removeFirstSegments(matchingFirstSgmnts).makeRelative().setDevice(null);
//System.out.println("filePath: "+filePath);
return filePath;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -