webpumpprojectchangelistener.java

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

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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.eclipse.core.internal.resources.Folder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;

import com.webpump.ui.perspective.WebpumpIDEPlugin;
import com.webpump.ui.project.*;

public class WebpumpProjectChangeListener implements IResourceChangeListener,IResourceDeltaVisitor  {

	// this is for file save purpose
	public void resourceChanged(IResourceChangeEvent event) {
		IResource resource = event.getResource();
		
	  if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
		try {
		  event.getDelta().accept(this); // accept visitor

		}
		catch (CoreException e) {
		  e.printStackTrace();
		}
	  }
	}

	// this is used by the instance which implements IResourceDeltaVisitor.
	// In this case, EclipsePlugin instance itself
	public boolean visit(IResourceDelta delta) throws CoreException {
	  int kind = delta.getKind();
	  IResource  resource  = delta.getResource(); 
	  

	  if (kind == IResourceDelta.REMOVED && resource instanceof Folder) {
	  	
	  	Folder objFolder = (Folder)resource;
	  	
	  	IPath objPath = objFolder.getFullPath();
	  	
	  	if ((objPath.segmentCount()==3)&&(objPath.segment(1).equals("module")))
	  	{
			//重写工程文?
			//1、取工程文?
			IPath projectPath = objFolder.getLocation().removeLastSegments(2); 
			
			projectPath = projectPath.append("project.webpump");
			
			File objFile = new File(projectPath.toString());
			
			InputStream stream;
			try {
				
				stream = new FileInputStream(objFile);
	
						
				ProjectModel objProjectModel = new ProjectModel();
				
				objProjectModel.load(stream,true);
				
				ProjectInfo objProjectInfo = (ProjectInfo)objProjectModel.getDataObject();
				
				ModuleList objModuleList = (ModuleList)objProjectInfo.getChild()[0]; 
					
				Object[] objModuleArray = objModuleList.getChild(); 
				
				if (objModuleArray!=null)
				{
					for (int i = 0;i<objModuleArray.length;i++)
					{
						ModuleInfo objModuleInfo = (ModuleInfo)objModuleArray[i];
						if (objModuleInfo.getModelInfo()[1].equals(objPath.segment(2)) )
						{
							objModuleList.remove(objModuleArray[i]);
							break;
						}
					}
				}
								
				objProjectModel.save(objFile);
				
				objProjectModel = WebpumpIDEPlugin.getProjectModelEx(objFolder.getLocation().removeLastSegments(2),false);
				
				if (objProjectModel!=null)
				{
					objModuleList = (ModuleList)objProjectModel.getDataObject().getChild()[0];
					
					objModuleArray = objModuleList.getChild(); 
				
					if (objModuleArray!=null)
					{
						for (int i = 0;i<objModuleArray.length;i++)
						{
							ModuleInfo objModuleInfo = (ModuleInfo)objModuleArray[i];
							if (objModuleInfo.getModelInfo()[1].equals(objPath.segment(2)) )
							{
								objModuleList.remove(objModuleArray[i]);
								break;
							}
						}
					}					
					 
				}

			
				 
				objProjectModel.save(objFile);
			
				
			} catch (FileNotFoundException e) {
				
				e.printStackTrace();
			}
			
	  	}
  	
		// file is saved
		return false; // Don't need to visit the children
	  }
	  return true;  // visit the children
	}


}

⌨️ 快捷键说明

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