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

📄 emfnewwizard.java

📁 基于eclipse的工具开发代码
💻 JAVA
字号:
package com.cownew.studio.modelDev.wizards;import java.lang.reflect.InvocationTargetException;import org.eclipse.core.resources.IContainer;import org.eclipse.core.resources.IFile;import org.eclipse.core.resources.IResource;import org.eclipse.core.resources.IWorkspaceRoot;import org.eclipse.core.resources.ResourcesPlugin;import org.eclipse.core.runtime.CoreException;import org.eclipse.core.runtime.IPath;import org.eclipse.core.runtime.IProgressMonitor;import org.eclipse.core.runtime.Path;import org.eclipse.jface.operation.IRunnableWithProgress;import org.eclipse.jface.viewers.ISelection;import org.eclipse.jface.viewers.IStructuredSelection;import org.eclipse.jface.wizard.Wizard;import org.eclipse.ui.INewWizard;import org.eclipse.ui.IWorkbench;import org.eclipse.ui.IWorkbenchPage;import org.eclipse.ui.IWorkbenchWindow;import org.eclipse.ui.PartInitException;import org.eclipse.ui.PlatformUI;import org.eclipse.ui.ide.IDE;import com.cownew.studio.Activator;import com.cownew.studio.modelDev.common.CommonUtils;public class EMFNewWizard extends Wizard implements INewWizard{	private EMFNewWizardPage page;	private ISelection selection;	public EMFNewWizard()	{		super();		setNeedsProgressMonitor(true);	}	public void addPages()	{		page = new EMFNewWizardPage((IStructuredSelection) selection);		addPage(page);	}	public boolean performFinish()	{		final IPath containerName = page.getContainerFullPath();		final String fileName = page.getFileName();		IRunnableWithProgress op = new IRunnableWithProgress() {			public void run(IProgressMonitor monitor)					throws InvocationTargetException			{				try				{					doFinish(containerName, fileName, monitor);				} catch (CoreException e)				{					Activator.logException(e);				} finally				{					monitor.done();				}			}		};		try		{			getContainer().run(true, false, op);		} catch (InterruptedException e)		{			return false;		} catch (InvocationTargetException e)		{			CommonUtils.handleExceptionAndAbort(e);			return false;		}		return true;	}	private void doFinish(IPath containerName, String fileName,			IProgressMonitor monitor) throws CoreException	{		monitor.beginTask("Creating " + fileName, 2);				//得到工作空间的根		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();				//得到文件存放的容器		IResource resource = root.findMember(containerName);		IContainer container = (IContainer) resource;				//得到代表欲创建文件的IFile对象		final IFile file = container.getFile(new Path(fileName));						String emf = EMFNewWizardPage.EMFFILEEXT;		int emflen = emf.length();		int namelen = fileName.length() - emflen;				//取得文件名的主文件名部分(比如Person.emf的主文件名为Person)		String entityName = fileName.substring(0, namelen);						//得到文件的初始内容		String content = getInitContent(entityName);				//保存生成的文件		CommonUtils.saveToFile(file, content, monitor);		monitor.worked(1);		monitor.setTaskName("Opening file for editing...");		getShell().getDisplay().asyncExec(new Runnable() {			public void run()			{				IWorkbench workbench = PlatformUI.getWorkbench();				IWorkbenchWindow win = workbench										.getActiveWorkbenchWindow();				IWorkbenchPage page = win.getActivePage();				try				{					//在编辑器中打开刚才创建的实体模型文件					IDE.openEditor(page, file, true);				} catch (PartInitException e)				{					CommonUtils.handleExceptionAndAbort(e);				}			}		});		monitor.worked(1);	}	public void init(IWorkbench workbench, IStructuredSelection selection)	{		this.selection = selection;	}		private static String getInitContent(String name)	{		StringBuffer sb = new StringBuffer();		sb.append("<EnityModel>").append(CommonUtils.LINESEPARATOR);		sb.append("    <Name>").append(name).append("</Name>")		  .append(CommonUtils.LINESEPARATOR);		sb.append("</EnityModel>");		return sb.toString();			}}

⌨️ 快捷键说明

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