validationeditor.java

来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 186 行

JAVA
186
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/validation/ValidationEditor.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.validation;

import java.io.*;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.editor.IPDEEditorPage;


import com.webpump.ui.base.gui.*;
import com.webpump.ui.base.data.*;
import com.webpump.ui.perspective.MacroResource;
import com.webpump.ui.perspective.WebpumpIDEPlugin;

/**
 * Class for Defining the Validation Editor.
 * 
 * @author zhao_f
 * @version 2.0.0 2004-1-13
 */
public class ValidationEditor extends BaseEditor{
	//编辑器名称
	public static String EDITOR_NAME = WebpumpIDEPlugin.getResourceString(MacroResource.VALIDATIONEDITOR_EDITOR_NAME);
	
	//编辑器主页面名称
	public static String EDITOR_PAGE = WebpumpIDEPlugin.getResourceString(MacroResource.VALIDATIONEIDTOR_DEFAULT_PAGE_NAME);
	
	//编辑器源代?页面名称
	public static String EDITOR_SOURCE_PAGE = WebpumpIDEPlugin.getResourceString(MacroResource.EDITOR_SOURCE_PAGE_NAME);
	
	//工程对?
	private IProject m_objProject;
	private String m_strPrefix;
		
		
	/**
	 * The Constructor which initiate this editor using the constructor of its parent.
	 */
	public ValidationEditor() {
			super();
	}
	
	/**
	 * Create file system model
	 * @param file
	 */
	private ValidationModel createFileSystemModel(File file) {
		
		InputStream stream = null;
		//Open the input file stream
		try {
			stream = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			PDEPlugin.logException(e);
			return null;
		}
		//Indicate a new object of ValidationModel
		ValidationModel model = new ValidationModel();
		
		//Get the parent path of the input file
		String parentPath = file.getParentFile().getAbsolutePath();
		//Load the file stream to the model
		try {
			model.load(stream, false);
		} catch (CoreException e) {
			// Errors in the file
			return null;
		}
		//Close the input file stream
		try {
			stream.close();
		} catch (IOException e) {
		}
		return model;
	}
	
	/**
	 * Create the resource model for the file.
	 * @param file
	 */
	protected BaseModel createResourceModel(IFile file)
		throws CoreException
	{
		InputStream stream = null;
		//Return the contents of the file in the form of stream
		stream = file.getContents(false);
		//Retrun the project which contains the resource file
		m_objProject = file.getProject();

		
		ValidationModel objValidationModel = new ValidationModel(file);
		
		//Load the input stream to the validation model
		try
		{
			
			this.m_objFile = file;			
objValidationModel.setFile(file);
			objValidationModel.load(stream, false);
		}
		catch(Exception e)
		{

		}
		try
		{
			stream.close();
		}
		catch(IOException e)
		{
	
		}
		return objValidationModel;
	}
	
	/**
	 * Create the model for the input file
	 * @param input
	 */
	protected Object createModel(Object input) throws CoreException {
	
		//Create the resource model if the input is an instance of IFile
		if(input instanceof IFile)
			return createResourceModel((IFile)input);
		//Create the storage model if the input is an instance of IStorage
		if (input instanceof IStorage)
			return createStorageModel((IStorage) input);
		//Create the file system model if the input is an instance of File
		if (input instanceof File)
			return createFileSystemModel((File) input);				
		else
			return null;
			
	}
	
	/**
	 * Create pages on this editor
	 */	
	protected void createPages() {
		firstPageId = EDITOR_NAME;
		formWorkbook.setFirstPageSelected(false);
		ValidationPage objValidRulePage =
			new ValidationPage(this, EDITOR_NAME);			
		addPage(EDITOR_PAGE, objValidRulePage);
		addPage("EDITOR_SOURCE_PAGE", new BaseSourcePage(this,EDITOR_SOURCE_PAGE));		
	}
	
	/**
	 * Get the Page whose ID is EDITOR_PAGE
	 */	 
	public IPDEEditorPage getHomePage() {
		
		return getPage(EDITOR_PAGE);
	}
	
	/**
	 * Get the Source Page ID 
	 */	
	protected String getSourcePageId() {
		return "EDITOR_SOURCE_PAGE";
	}
		
}

⌨️ 快捷键说明

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