webpumpideplugin.java

来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 672 行 · 第 1/2 页

JAVA
672
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/perspective/WebpumpIDEPlugin.java,v 1.2 2004/12/29 09:45:31 wang_j Exp $
 * $Revision: 1.2 $
 * $Date: 2004/12/29 09:45:31 $
 *
 * ====================================================================
 *
 * 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.perspective;

import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.plugin.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.resources.*;
import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.ConnectionCreationToolEntry;
import org.eclipse.gef.palette.MarqueeToolEntry;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteEntry;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PaletteSeparator;
import org.eclipse.gef.palette.SelectionToolEntry;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gef.requests.SimpleFactory;
import org.eclipse.jface.resource.ImageDescriptor;

import com.webpump.ui.base.data.BaseObject;
import com.webpump.ui.bind.data.BindParaModel;
import com.webpump.ui.datasource.data.DataSourceModel;
import com.webpump.ui.gefmodule.ModuleEditor;
import com.webpump.ui.gefmodule.model.Page;
import com.webpump.ui.module.model.Model;
import com.webpump.ui.project.ProjectModel;
import com.webpump.ui.validationrule.ValidRuleModel;
import com.webpump.ui.wizard.WebpumpProjectChangeListener;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;

/**
 * this is  main plugin class to be used in the desktop.
 * there hava some common Function
 * 
 * @author wang_j
 * @version 2.0 2004-02-11
 */
public class WebpumpIDEPlugin extends AbstractUIPlugin {

	public static final String PLUGIN_ID = "WebPumpIDE";
	public static final String NATURE_ID = PLUGIN_ID + ".webpumpnature";

	
	/** The shared instance*/
	private static WebpumpIDEPlugin plugin;

	/**Resource bundle*/
	private ResourceBundle resourceBundle;

	private static HashMap projectMap = new HashMap();

	public static Model getModel(IFile file,boolean bRefresh) {
        
		HashMap hmModule = getModuleData(file);
        
		Model model = (Model) hmModule.get("model");
		
		if ((model == null)||(bRefresh)) {
			try {
				IPath path = file.getRawLocation();
				path = path.removeLastSegments(1).append("/module.xml");
				File xmlFile = new File(path.toString());
                InputStream stream = new FileInputStream(xmlFile);
				model = new Model(file);
				model.load(stream, false);
				hmModule.put("model", model);
			} catch (FileNotFoundException e) {
				log(e);
			} catch (CoreException e) {
				log(e);
			}
		}
        return model;
    }
    
	public static Model getModelFromHtml(IFile file,boolean bRefresh) {
        
		HashMap hmModule = getModuleData(file);
        
		Model model = (Model) hmModule.get("model");
		
		if ((model == null)||(bRefresh)) {
			try {
				IPath filePath = file.getRawLocation();
				IPath projectPath = file.getFullPath(); 
				 
				filePath = filePath.removeLastSegments(projectPath.segmentCount()-3);
				filePath = filePath.append("/module.xml");
				File xmlFile = new File(filePath.toString());
				InputStream stream = new FileInputStream(xmlFile);
				model = new Model();
				model.load(stream, false);
				hmModule.put("model", model);
			} catch (FileNotFoundException e) {
				log(e);
			} catch (CoreException e) {
				log(e);
			}
		}
		return model;
	}    
    
	public static ProjectModel getProjectModelEx(IPath projectPath,boolean bRefresh) {
        
		HashMap hmProject = (HashMap)projectMap.get(projectPath.segment(projectPath.segmentCount()-1));
        
        if (hmProject == null)
        {
			hmProject = new HashMap();
			projectMap.put(projectPath.segment(projectPath.segmentCount()-1),hmProject);
        }
        
		ProjectModel model = (ProjectModel) hmProject.get("/project.webpump");
		
		if ((model == null)||(bRefresh)) {
			try {
				IPath path = projectPath;
				path = path.append("/project.webpump");
				File xmlFile = new File(path.toString());
				InputStream stream = new FileInputStream(xmlFile);
				model = new ProjectModel();
				model.load(stream, false);
				hmProject.put("/project.webpump", model);
			} catch (FileNotFoundException e) {
				log(e);
			} catch (CoreException e) {
				log(e);
			}
		}
		return model;
	}
	      
	public static ProjectModel getProjectModel(IFile file,boolean bRefresh) {
		
		HashMap hmProject = (HashMap)projectMap.get(file.getFullPath().segment(0));
        
        if (hmProject == null)
        {
			hmProject = new HashMap();
			projectMap.put(file.getFullPath().segment(0),hmProject);
        }
        
		ProjectModel model = (ProjectModel) hmProject.get("/project.webpump");
		
		if ((model == null)||(bRefresh)) {
			try {
				IPath path = file.getLocation().removeLastSegments(file.getFullPath().segmentCount() - 1);
				path = path.append("/project.webpump");
				File xmlFile = new File(path.toString());
				InputStream stream = new FileInputStream(xmlFile);
				model = new ProjectModel(file);
				model.load(stream, false);
				hmProject.put("/project.webpump", model);
			} catch (FileNotFoundException e) {
				log(e);
			} catch (CoreException e) {
				log(e);
			}
		}
		return model;
	}
	      
    public static BindParaModel getBindParaModel(IFile file,boolean bRefresh)
    {
		HashMap hmModule = getModuleData(file);
        
		BindParaModel model = (BindParaModel) hmModule.get("Bind");
		if ((model == null)||(bRefresh)) {
			try {
				
				IPath filePath = file.getRawLocation();
				IPath projectPath = file.getFullPath(); 
				 
				filePath = filePath.removeLastSegments(projectPath.segmentCount()-3);
				
				filePath = filePath.append("/config/bindparameters.xml");
				//File xmlFile = new File(filePath.toString());
				//InputStream stream = new FileInputStream(xmlFile);
                File BindParametersXMLFile = new File(filePath.toString());
                InputStream stream = new FileInputStream(BindParametersXMLFile);
				model = new BindParaModel(file);
				model.load(stream, false);
				hmModule.put("Bind", model);
			} catch (FileNotFoundException e) {
				log(e);
			} catch (CoreException e) {
				log(e);
			}
		}
		return model;
    }
    

	public static ValidRuleModel getValidRuleModel(IFile file,boolean bRefresh)
	{
		//HashMap hmModule = getModuleData(file);
		String projectName = getProjectName(file); 
		ValidRuleModel model = (ValidRuleModel) projectMap.get(projectName+"_ValidRule");
		if ((model == null)||(bRefresh)) {
			try {
				IPath path = file.getRawLocation();
				IPath fullPath = file.getFullPath(); 
				path = path.removeLastSegments(fullPath.segmentCount()-1).append("/project-config/ValidationRule.xml");
				File xmlFile = new File(path.toString());
				InputStream stream = new FileInputStream(xmlFile);
				model = new ValidRuleModel();
				model.setFile(xmlFile);
				model.load(stream, false);
				projectMap.put("ValidRule", model);
			} catch (FileNotFoundException e) {
				log(e);
			} catch (CoreException e) {
				log(e);
			}
		}
		return model;
	}
	

	public static DataSourceModel getDataSourceModel(IFile file,boolean bRefresh)
	{
		String projectName = getProjectName(file); 		      
		DataSourceModel model = (DataSourceModel) projectMap.get(projectName+"_DataSource");
		if ((model == null)||(bRefresh)) {
			try {
				
				IPath filePath = file.getRawLocation();
				IPath fullPath = file.getFullPath();  
				filePath = filePath.removeLastSegments(fullPath.segmentCount()-1);
				
				filePath = filePath.append("/project-config/datasource.xml");
				File xmlFile = new File(filePath.toString());
				InputStream stream = new FileInputStream(xmlFile);
				model = new DataSourceModel();
				model.load(stream, false);
				projectMap.put("DataSource", model);
			} catch (FileNotFoundException e) {
				log(e);
			} catch (CoreException e) {
				log(e);
			}
		}
		return model;
	}
    
    
    public static DataSourceModel getDataSourceModelToSQL (IFile file,boolean bRefresh)
    {
		String projectName = getProjectName(file);      
        DataSourceModel model = (DataSourceModel) projectMap.get(projectName+"_DataSource");
        if ((model == null)||(bRefresh)) {
            try {
                
				IPath filePath = file.getRawLocation();
				IPath fullPath = file.getFullPath();  
				filePath = filePath.removeLastSegments(fullPath.segmentCount()-1);
                
                filePath = filePath.append("/project-config/datasource.xml");
                File xmlFile = new File(filePath.toString());
                InputStream stream = new FileInputStream(xmlFile);
                model = new DataSourceModel(file);
                model.load(stream, false);
				projectMap.put("DataSource", model);
            } catch (FileNotFoundException e) {
                log(e);
            } catch (CoreException e) {
                log(e);
            }
        }
        return model;
    }
		
	public static HashMap getModuleData(IFile file)
	{
		String projectName = getProjectName(file);
		String foldName = getFoldName(file);
		
		HashMap hmProject  = (HashMap) projectMap.get(projectName);
		if (hmProject == null) {
			hmProject = new HashMap();
			projectMap.put(projectName, hmProject);
		}
	        
		HashMap hmModule = (HashMap) hmProject.get(foldName);
		if (hmModule == null) {
			hmModule = new HashMap();
			hmProject.put(foldName, hmModule);
		}	 
		
		return hmModule;
	}
/**
 * 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
 */
private static String getProjectName(IFile file) {
	String projectname = "";
	String path = file.getFullPath().toString();
    int secondindex = path.indexOf("/", 2);
    projectname = path.substring(1, secondindex);
    return projectname;
}

⌨️ 快捷键说明

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