htmldocumentadapter.java
来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 217 行
JAVA
217 行
/*
* $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/bind/listeners/HTMLDocumentAdapter.java,v 1.1.1.1 2004/07/01 09:07:42 wang_j Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/07/01 09:07:42 $
*
* ====================================================================
*
* The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
*
* Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
* IT Forest Corporation
* All rights reserved.
*
* This software is the confidential and proprietary information of
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
* You shall not disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into with
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
*/
package com.webpump.ui.bind.listeners;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import com.webpump.ui.perspective.MacroResource;
import com.webpump.ui.bind.editors.BindEditor;
import com.webpump.ui.bind.editors.XMLEditor;
import com.webpump.ui.bind.action.BindHtmlBody;
import com.webpump.ui.bind.action.BindHtmlHeader;
import com.webpump.ui.bind.action.BindHtmlScript;
import com.webpump.ui.bind.action.BindHtmlStyle;
import com.webpump.ui.bind.action.BindHtmlTail;
/**
* Class to monitor the DocumentEvent so that it can
* update the state of 5 necessory bind action,
* when the document changed in the editor .
*
* @author zhang_tx
* @version 2.0.0 2004-2-13
*/
public class HTMLDocumentAdapter implements IDocumentListener {
/** the HTML Bind Editor */
private BindEditor bigeditor;
/** the action object of the Bind Html Body action */
private IAction bodyact;
/** the action object of the Bind Html Header action */
private IAction headeract;
/** the action object of the Bind Html Script action */
private IAction scriptact;
/** the action object of the Bind Html Style action */
private IAction styleact;
/** the action object of the Bind Html Tail Script action */
private IAction tailact;
/** the constructor of the HTMLDocumentAdapter
*
* @param BindEditor editor the editor whose document is monitor by this Adapter
*/
public HTMLDocumentAdapter(BindEditor editor) {
this.bigeditor = editor;
}
/** the function which will be called when the document about to be changed
*
* @param DocumentEvent event the document change event
*/
public void documentAboutToBeChanged(DocumentEvent event) {
}
/** the function which will be called when the document is changed
*
* @param DocumentEvent event the document change event
*/
public void documentChanged(DocumentEvent event) {
XMLEditor xmleditor = null;
xmleditor = bigeditor.getXMLEditor();
int f = 0;
if (bigeditor!=null){
/** get the action object of the Bind Html Body action */
bodyact = BindHtmlBody.m_objaction;
/** get the action object of the Bind Html Header action */
headeract = BindHtmlHeader.m_objaction;
/** get the action object of the Bind Html Script action */
scriptact = BindHtmlScript.m_objaction;
/** get the action object of the Bind Html Style action */
styleact = BindHtmlStyle.m_objaction;
/** get the action object of the Bind Html Tail Script action */
tailact = BindHtmlTail.m_objaction;
}
if(xmleditor!=null){
/** update the state of action object of the Bind Html Body action */
doDocumentChanged(xmleditor,bodyact,"<!--WebPumpTools[DrawScene] -->","<!--End of WebPumpTools[DrawScene] -->");
/** update the state of action object of the Bind Html Header action */
doDocumentChanged(xmleditor,headeract,"<!--WebPumpTools[BodyHeader] -->","<!--End of WebPumpTools[BodyHeader] -->");
/** update the state of action object of the Bind Html Script action */
doDocumentChanged(xmleditor,scriptact,"<!--WebPumpTools[Script] -->","<!--End of WebPumpTools[Script] -->");
/** update the state of action object of the Bind Html Style action */
doDocumentChanged(xmleditor,styleact,"<!--WebPumpTools[Style] -->","<!--End of WebPumpTools[Style] -->");
/** update the state of action object of the Bind Html TailScript action */
doDocumentChanged(xmleditor,tailact,"<!--WebPumpTools[TailScript] -->","<!--End of WebPumpTools[TailScript] -->");
}
}
/** the function to update the parameter action's state
*
* @param XMLEditor editor the editor which contain the document
* @param IAction action the action whose state is to be updated
* @param String actionheader the headtarget of the bind tag
* @param String actiontail the tailtarget of the bind tag
*/
public void doDocumentChanged(XMLEditor editor,IAction action,String actionheader,String actiontail){
/** to get the document of the editor */
IDocumentProvider provider= ((ITextEditor) editor).getDocumentProvider();
IEditorInput input = editor.getEditorInput();
IDocument document = provider.getDocument(input);
/** to search for the headtarget in the document
* if finded, then search for the tailtarget
* if not, then activate the action
*/
int tag = -1;
try {
tag = document.search(0,actionheader,true,false,false);
int t = 0;
} catch (BadLocationException e) {
e.printStackTrace();
}
if(tag != -1){
/** to search for the tailtarget of in the tailtarget
* if finded, then set the action cannot be trigered
* if not, then activate the action
*/
int tag1 = 0;
try
{
tag1 = document.search(0,actiontail,true,false,false);
int t = 0;
}
catch (BadLocationException e1)
{
e1.printStackTrace();
}
if(tag1 != -1){
/** set the action cannot be trigered*/
action.setEnabled(false);
}else{
/** activate the action */
action.setEnabled(true);
}
}else{
/** activate the action */
action.setEnabled(true);
}
}
public void BindTagSearch(DocumentEvent event) throws BadLocationException{
IDocument document = event.getDocument();
String ChangedText = document.get();
int offset = event.getOffset();
int starttag = 0;
String type = "";
boolean tagdestory = false;
boolean endTag = false;
for(int i = offset;i>=0;i--){
if(ChangedText.substring(i-4,i).equals("]-->")){
int t = 0;
while(!ChangedText.substring(i-4-t-1,i-4-t).equals("[")){
t++;
}
type = ChangedText.substring(i-4-t,i-4);
int z = 0;
while(!ChangedText.substring(i-4-z-4,i-4-z).equals("<!--")){
z++;
}
if(type.equals("ERRORS")){
}
if(type.equals("LOOP")){
}
if(type.equals("CUSTOMER")){
}
if(type.equals("DrawScene")){
int searchforTag = document.search(0,MacroResource.BINDEDITOR_ACTION_BODYHEAD,true,false,false);
searchforTag += document.search(0,MacroResource.BINDEDITOR_ACTION_BODYTAIL,true,false,false);
if(searchforTag!= -1){
tagdestory = true;
}
}
if(type.equals("BodyHeader")){
int searchforTag = document.search(0,MacroResource.BINDEDITOR_ACTION_HEADERHEAD,true,false,false);
searchforTag += document.search(0,MacroResource.BINDEDITOR_ACTION_HEADERTAIL,true,false,false);
if(searchforTag!= -1){
tagdestory = true;
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?