bindeditor.java
来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 1,701 行 · 第 1/5 页
JAVA
1,701 行
*
*/
void createPage3() {
Composite composite = new Composite(getContainer(), SWT.NONE);
FillLayout layout = new FillLayout();
composite.setLayout(layout);
formbeantext = new Text(composite, SWT.BORDER | SWT.MULTI|SWT.V_SCROLL|SWT.FLAT);
int index = addPage(composite);
setPageText(index, WebpumpIDEPlugin.getResourceString(MacroResource.BINDEDITOR_PAGE3_NAME));
}
/**
* Creates the pages of the multi-page editor.
*/
protected void createPages() {
createPage0();
createPage1();
createPage2();
createPage3();
setHtmlPage();
this.setTitle(editor.getTitle());
this.getControl(0).addKeyListener(new DelKeyListener(this));
}
/**
* get the name of the recent project,
* return the name it geted for method user.
*
* @param the html file of the page 0's editor
* @return the name of project which contains the file
*/
public String getProjectName(IFile file){
String projectname = "";
String Path = file.getFullPath().toString();
int pathindex = 0;
int folderbegin = 0;
int folderend = 0;
for(int i = 0;i < Path.length();i++){
if(Path.substring(i,i+1).compareTo("/") == 0){
pathindex++;
if(pathindex == 1){
folderbegin = i+1;
}
if(pathindex == 2){
pathindex = 1;
folderend = i;
projectname = Path.substring(folderbegin,folderend);
break;
}
}
}
return projectname;
}
/**
* Saves the multi-page editor's document.
* It also update the documents of the jsp files and formbean.java files.
*/
public void doSave(IProgressMonitor monitor) {
/** save the page 0's document */
getEditor(0).doSave(monitor);
/** sort the file of the page0 and create the six parts which will be contributed to the jsp files */
sortJSPWords();
/** the jsp file */
IFile jspfile;
/** the formbean file */
IFile formbeanfile;
/** the content of the jsp file */
String jspcontent = "";
/** the content of the formbean file */
String formcontent = "";
try{
try {
createJspFile();
createFormFile();
} catch (CoreException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}catch(NullPointerException e){
MessageDialog.openInformation(
this.getEditorSite().getPage().getWorkbenchWindow().getShell(),
(WebpumpIDEPlugin.getResourceString(MacroResource.BINDEDITOR_NULLJSPFILEMESNOTE)),
(WebpumpIDEPlugin.getResourceString(MacroResource.BINDEDITOR_NULLJSPFILEMES)));
}
catch(Exception e){
e.printStackTrace();
}
}
/**
* Saves the multi-page editor's document as another file.
* Also updates the text for page 0's tab, and updates this multi-page editor's input
* to correspond to the nested editor's.
*/
public void doSaveAs() {
IEditorPart editor = getEditor(0);
editor.doSaveAs();
setPageText(0, editor.getTitle());
setInput(editor.getEditorInput());
}
/**
* We will initialize file contents with the parameter "contents".
*
* @param the content with which this function to create the stream
*/
private InputStream openContentStream(String contents) {
InputStream inputstream = null;
try
{
//find jsp chaset
int nIndex = contents.indexOf("text/html;charset=");
String strCharset = "";
if (nIndex > 0)
{
int nRIndex = contents.indexOf("\"",nIndex);
if (nRIndex >nIndex +18)
{
strCharset = contents.substring(nIndex+18,nRIndex);
}
}
if (strCharset.length() > 0 )
{
inputstream = new ByteArrayInputStream(contents.getBytes(strCharset));
}
else
{
inputstream = new ByteArrayInputStream(contents.getBytes());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return inputstream;
}
/* (non-Javadoc)
* Method declared on IEditorPart
*/
public void gotoMarker(IMarker marker) {
setActivePage(0);
getEditor(0).gotoMarker(marker);
}
/**
* The <code>BindEditor</code> implementation of this method
* checks that the input is an instance of <code>IFileEditorInput</code>
* and get the conten of the BindParameters.xml.
*/
public void init(IEditorSite site, IEditorInput editorInput)
throws PartInitException {
/** checks that the input is an instance of <code>IFileEditorInput</code> */
if (!(editorInput instanceof IFileEditorInput))
throw new PartInitException("Invalid Input: Must be IFileEditorInput");
/** get the html file */
m_objhtmlfile = (IFile) editorInput.getAdapter(IFile.class);
m_strModuleFolder = m_objhtmlfile.getFullPath().segment(1);
/** to get the file of BindParameters.xml */
IFile file = (IFile)editorInput.getAdapter(IFile.class);
IPath filePath = file.getRawLocation();
IPath projectPath = file.getFullPath();
m_objProjectPath = projectPath;
filePath = filePath.removeLastSegments(projectPath.segmentCount()-3);
filePath = filePath.append("/config/bindparameters.xml");
m_objxmlfile = new File(filePath.toString());
m_objBindParaModel = WebpumpIDEPlugin.getBindParaModel(file,false);
super.init(site, editorInput);
}
/* (non-Javadoc)
* Method declared on IEditorPart.
*/
public boolean isSaveAsAllowed() {
return true;
}
/**
* Calculates the contents of page 1 to page 3 when the it is activated.
*
* @param newPageIndex the page number of the current page change target
*/
protected void pageChange(int newPageIndex) {
super.pageChange(newPageIndex);
/** to get the document of the xmleditor */
IDocumentProvider provider= ((ITextEditor) editor).getDocumentProvider();
IEditorInput input = editor.getEditorInput();
IDocument document = provider.getDocument(input);
/** to get the cursorposition in the xmleditor */
TextSelection selectedText =
(TextSelection)editor.getEditorSite().getSelectionProvider().getSelection();
String strSelectedText = selectedText.getText();
/** Calculates the contents of page 1 when the it is activated */
if (newPageIndex == 1) {
m_objTable.removeAll();
DocumentChanged documentchanged = new DocumentChanged(this);
ArrayList arraylist=documentchanged.takeAllParas();
//documentadapter.showAllParas(arraylist);
documentchanged.changeModel(arraylist);
int t = 0;
}
/** Calculates the contents of page 1 when the it is activated */
if (newPageIndex == 2) {
m_objTable.removeAll();
DocumentChanged documentchanged = new DocumentChanged(this);
ArrayList arraylist=documentchanged.takeAllParas();
//documentadapter.showAllParas(arraylist);
documentchanged.changeModel(arraylist);
jspPreview();
}
/** Calculates the contents of page 1 when the it is activated */
if (newPageIndex == 3) {
m_objTable.removeAll();
DocumentChanged documentchanged = new DocumentChanged(this);
ArrayList arraylist=documentchanged.takeAllParas();
//documentadapter.showAllParas(arraylist);
documentchanged.changeModel(arraylist);
formbeanPreview();
}
}
/**
* Sorts the words in page 0,
* and shows them in page 2 to finish the function of JSP Preview.
*/
void jspPreview() {
/** sort the file of the page0 and create the six parts which will be contributed to the jsp files */
sortJSPWords();
/** the content of the new jspfile we want to use as preview contents */
String jspcontent = "";
/** the jsp file corresponding to the html file we edit */
IFile jspfile;
/** the path of the jsp file */
IPath Path = null;
/** the full path of the jsp file */
IPath FullPath = null;
/** get the path of the jsp file */
Path = createPath(m_objhtmlfile,"/jsp/",".jsp")[0];
/** get the full path of the jsp file */
FullPath = createPath(m_objhtmlfile,"/jsp/",".jsp")[1];
/** to get the jsp file with it's path */
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(Path);
jspfile = (IFile) resource;
/** to get the jsp file content with it's full path */
jspcontent = getcontent(FullPath,m_strModuleFolder);
//System.out.println("jspcontent = " + jspcontent );
/** to set the parameter m_strJSPFileContent so that we can preview the newest JSP file content */
StringWriter displayText = new StringWriter();
if(!(jspcontent == null || jspcontent.equals("")))
{
setjspcontent(jspcontent);
displayText.write(m_strJSPFileContent);
}
else
{
displayText.write("Error:The JSP File in the path of \"" + FullPath.toOSString() + "\" is not avaliable!");
}
/** to preview the jsp file content */
jsptext.setText(displayText.toString());
}
/**
* Sorts the content in BindParameters.xml for each bind parameter in page0,
* and to create String of get/set method for them,
* then join these Strings together to create a Formbean.java content,
* which will finish the function of FORMBEAN Preview.
*/
void formbeanPreview(){
/** to get the bind parameters of this html page */
Vector vParameterInfo = m_objHtmlPage.getvParameterInfo();
/** sort the file of the page0 and create the four parts which will be contributed to the frombean files */
sortFORMWords(vParameterInfo);
/** the content of the newest formbean file that we want to use as the formbean preview content */
String formcontent = "";
/** the formbean file */
IFile formfile;
/** the path of the formbean file */
IPath Path = null;
/** the full path of the formbean file */
IPath FullPath = null;
/** get the path of the formbean file */
Path = createPath(m_objhtmlfile,"/src/","Form.java")[0];
/** get the full path of the formbean file */
FullPath = createPath(m_objhtmlfile,"/src/","Form.java")[1];
/** to get the formbean file with it's path */
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(Path);
formfile = (IFile) resource;
/** to get the formbean file content with it's full path */
formcontent = getcontent(FullPath,m_strModuleFolder);
//System.out.println("formcontent = " + formcontent);
/** to set the parameter m_strFORMFileContent so that we can preview the newest FORM file content */
setformcontent(formcontent);
/** to preview the newest formbean file content */
StringWriter displayText = new StringWriter();
displayText.write(m_strFORMFileContent);
formbeantext.setText(displayText.toString());
}
/**
* Sorts the words in page 0,
* and then create a newcontent which can be used in the jsp files
* for the function of JSPPreview and the update of jsp files.
*/
public void sortJSPWords(){
/** the content of the html bind editor */
String editorText =
editor.getDocumentProvider().getDocument(editor.getEditorInput()).get();
m_strJSP_htmlscript = createBodyContent(getStringByFlag(editorText,MacroResource.BINDEDITOR_ACTION_SCRIPTHEAD,MacroResource.BINDEDITOR_ACTION_SCRIPTTAIL),2);
m_strJSP_htmlstyle = createBodyContent(getStringByFlag(editorText,MacroResource.BINDEDITOR_ACTION_STYLEHEAD,MacroResource.BINDEDITOR_ACTION_STYLETAIL),3);
m_strJSP_htmlheader = createBodyContent(getStringByFlag(editorText,MacroResource.BINDEDITOR_ACTION_HEADERHEAD,MacroResource.BINDEDITOR_ACTION_HEADERTAIL),4);
m_strJSP_htmlbody = createBodyContent(getStringByFlag(editorText,MacroResource.BINDEDITOR_ACTION_BODYHEAD,MacroResource.BINDEDITOR_ACTION_BODYTAIL),1);
m_strJSP_htmltail = createBodyContent(getStringByFlag(editorText,MacroResource.BINDEDITOR_ACTION_TAILHEAD,MacroResource.BINDEDITOR_ACTION_TAILTAIL),5);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?