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

📄 addbuilderaction.java

📁 基于eclipse的工具开发代码
💻 JAVA
字号:
package com.cownew.uidesigner.builder;import java.util.Iterator;import org.eclipse.core.resources.ICommand;import org.eclipse.core.resources.IProject;import org.eclipse.core.resources.IProjectDescription;import org.eclipse.core.runtime.CoreException;import org.eclipse.core.runtime.IAdaptable;import org.eclipse.jface.action.IAction;import org.eclipse.jface.viewers.ISelection;import org.eclipse.jface.viewers.IStructuredSelection;import org.eclipse.ui.IObjectActionDelegate;import org.eclipse.ui.IWorkbenchPart;import com.cownew.uidesigner.Activator;public class AddBuilderAction implements IObjectActionDelegate{	private ISelection selection;	public void run(IAction action)	{		if (selection instanceof IStructuredSelection)		{			for (Iterator it = ((IStructuredSelection) selection).iterator(); it					.hasNext();)			{				Object element = it.next();				IProject project = null;				if (element instanceof IProject)				{					project = (IProject) element;				} else if (element instanceof IAdaptable)				{					project = (IProject) ((IAdaptable) element)							.getAdapter(IProject.class);				}				if (project != null)				{					addUIBuilder(project);				}			}		}	}	public void selectionChanged(IAction action, ISelection selection)	{		this.selection = selection;	}	public void setActivePart(IAction action, IWorkbenchPart targetPart)	{	}	private void addUIBuilder(IProject project)	{		try		{			//得到项目描述			IProjectDescription desc = project.getDescription();			//得到项目所有的构建器			ICommand[] commands = desc.getBuildSpec();			for (int i = 0; i < commands.length; ++i)			{				if (commands[i].getBuilderName().equals(UIBuilder.BUILDER_ID))				{					return;				}			}			ICommand[] newCommands = new ICommand[commands.length + 1];			System.arraycopy(commands, 0, newCommands, 0, commands.length);			//新建一个构建器			ICommand command = desc.newCommand();			command.setBuilderName(UIBuilder.BUILDER_ID);			newCommands[newCommands.length - 1] = command;			//将新设置的构建器添加进去			desc.setBuildSpec(newCommands);			project.setDescription(desc, null);		} catch (CoreException e)		{			Activator.logException(e);		}	}}

⌨️ 快捷键说明

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