⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basemodel.java

📁 一个eclipse插件源代码。用于web开发
💻 JAVA
字号:
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/base/data/BaseModel.java,v 1.2 2004/12/29 09:45:30 wang_j Exp $
 * $Revision: 1.2 $
 * $Date: 2004/12/29 09:45:30 $
 *
 * ====================================================================
 *
 * 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.base.data;

import java.io.*;
import java.util.Hashtable;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.core.*;
import org.eclipse.pde.internal.core.*;
import org.w3c.dom.*;
import org.xml.sax.*;

import com.webpump.ui.perspective.WebpumpIDEPlugin;
import com.webpump.ui.project.ProjectInfo;
import com.webpump.ui.project.ProjectModel;


// Referenced classes of package org.easystruts.eclipse.editor:
//			  AbstractStrutsConfigModel

public class BaseModel extends AbstractModel
implements IModel, IModelChangeProvider,IEditable 
{
	protected boolean dirty;
	protected boolean editable;
	protected IFile file;	
	protected BaseDataObject m_objDataObject;
		
	public BaseModel(IFile objFile)
	{
		file = objFile;
		dirty = false;
		editable = true;
	}
	
	public BaseModel()
	{
		dirty = false;
		editable = true;
	}

	public void fireModelChanged(IModelChangedEvent event) {
		if (event.getChangeType()!=IModelChangedEvent.WORLD_CHANGED)
			dirty = true;
		super.fireModelChanged(event);
	}
		
	public BaseObject[] getBaseObjectArray()
	{
		BaseObject[] objBaseObjectArray = new BaseObject[1];
		objBaseObjectArray[0] = m_objDataObject;
		return objBaseObjectArray;
	}
	
	public BaseDataObject getDataObject()
	{
		return m_objDataObject;
	}

	public void setDataObject(BaseDataObject objBaseDataObject)
	{
		m_objDataObject = objBaseDataObject;
	}

	public boolean isDirty()
	{
		return dirty;
	}

	public void refresh()
	{

	}
	public void load()
	{
		if (file == null)
			return;
		if (file.exists()) {
			boolean outOfSync = false;
			InputStream stream = null;
			try {
				stream = file.getContents(false);
			} catch (CoreException e) {
				outOfSync = true;
				try {
					stream = file.getContents(true);
				} catch (CoreException ex) {
					return;
				}
			}
			try {
				load(stream, outOfSync);
				stream.close();
			} catch (CoreException e) {
			} catch (IOException e) {
				PDECore.logException(e);
			}
		} else {
			this.m_objDataObject = new BaseDataObject();
			m_objDataObject.model = this;
			loaded = true;
		}
	}	
	public void load(InputStream stream, boolean outOfSync)
		throws CoreException
	{
		SourceDOMParser parser = new SourceDOMParser();
 
		  try {
		   InputSource source = new InputSource(stream);

		   		   
		   parser.parse(source);
		   processDocument(parser.getDocument(), parser.getLineTable());
		   loaded = true;

		  } catch (SAXException e) {
		  } catch (IOException e) {
		//   PDECore.logException(e);
		  }
	}

	public void setDirty(boolean dirty)
	{
		this.dirty = dirty;
		if(dirty)
			refresh();
	}

	public boolean isEditable()
	{
		return editable;
	}

	public void setEditable(boolean editable)
	{
		this.editable = editable;
	}
	
	protected void processDocument(Document doc, Hashtable lineTable) 
	{

	}


	public void reload(InputStream stream, boolean outOfSync)
		throws CoreException {
		load(stream, outOfSync);
		fireModelChanged(
			new ModelChangedEvent(
				IModelChangedEvent.WORLD_CHANGED,
				new Object[] { m_objDataObject },
				null));
	}
	
	protected void updateTimeStamp() {
		updateTimeStamp(file.getLocation().toFile());
	}
	
	public boolean isInSync() {
		return isInSync(file.getLocation().toFile());
	}	
	
	public void dispose() {

		disposed = true;
	}	

	public String getContents() {
		StringWriter swriter = new StringWriter();
				
		PrintWriter writer = new PrintWriter(swriter);
		save(writer);
		writer.flush();
		try {
			swriter.close();
		} catch (IOException e) {
		}
		return swriter.toString();
	}
	
	public void save() {
		if (file == null)
			return;
		try {
			ProjectModel objProjectModel = WebpumpIDEPlugin.getProjectModel(file,false);
			String strCharset = ((ProjectInfo)objProjectModel.getDataObject()).getProjectInfo()[5];
						
			String contents = getContents();
			ByteArrayInputStream stream =
				new ByteArrayInputStream(contents.getBytes(strCharset));
			if (file.exists()) {
				file.setContents(stream, false, false, null);
			} else {
				file.create(stream, false, null);
			}
			stream.close();
		} catch (CoreException e) {
			PDECore.logException(e);
		} catch (IOException e) {
		}
	}
	
	
	public void save(File objFile) {
		if (objFile == null)
			return;
		try {
				
			ProjectModel objProjectModel = WebpumpIDEPlugin.getProjectModel(file,false);
			String strCharset = ((ProjectInfo)objProjectModel.getDataObject()).getProjectInfo()[5];
							
			String contents = getContents();
		
			FileOutputStream objFileOutputStream = new FileOutputStream(objFile);
			
			objFileOutputStream.write(contents.getBytes(strCharset));
			objFileOutputStream.close(); 	
			
			
		} catch (IOException e) {
		}
	}
		
	public void save(PrintWriter writer) 
	{
		
		ProjectModel objProjectModel = WebpumpIDEPlugin.getProjectModel(file,false);
		String strCharset = ((ProjectInfo)objProjectModel.getDataObject()).getProjectInfo()[5];
		if (isLoaded()) 
		{
			writer.println("<?xml version=\"1.0\" encoding=\""+strCharset+"\"?>");
			m_objDataObject.write("", writer);
		}
		dirty = false;
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -