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

📄 extlibraryextendedactionbarcontributor.java

📁 EMF、GEF官方例子源代码
💻 JAVA
字号:
/**
 * <copyright>
 *
 * Copyright (c) 2005 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   IBM - Initial API and implementation
 *
 * </copyright>
 *
 * $Id: EXTLibraryExtendedActionBarContributor.java,v 1.1 2005/11/10 18:57:56 marcelop Exp $
 */
package org.eclipse.emf.examples.extlibrary.actions;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;

import org.eclipse.emf.examples.extlibrary.Library;
import org.eclipse.emf.examples.extlibrary.presentation.EXTLibraryActionBarContributor;

/**
 * Extension to the generated action bar contributor to handle creation of
 * multi-rooted resources.
 */
public class EXTLibraryExtendedActionBarContributor
	extends EXTLibraryActionBarContributor {

	/**
	 * Constructor
	 */
	public EXTLibraryExtendedActionBarContributor() {
		super();
	}

	/*
	 * @see org.eclipse.emf.examples.library.presentation.EXTLibraryActionBarContributor#generateCreateChildActions(java.util.Collection,
	 *      org.eclipse.jface.viewers.ISelection)
	 */
	protected Collection generateCreateChildActions(Collection descriptors,
			ISelection selection) {
		Collection actions = new ArrayList(super.generateCreateChildActions(
			descriptors, selection));
		if (selection instanceof IStructuredSelection
			&& ((IStructuredSelection) selection).size() == 1) {
			Object object = ((IStructuredSelection) selection)
				.getFirstElement();
			if (object instanceof Resource) {
				actions.add(generateResourceAction(((Resource) object)));
			}
		}

		return actions;
	}

	/*
	 * @see org.eclipse.emf.examples.extlibrary.presentation.EXTLibraryActionBarContributor#generateCreateSiblingActions(java.util.Collection,
	 *      org.eclipse.jface.viewers.ISelection)
	 */
	protected Collection generateCreateSiblingActions(Collection descriptors,
			ISelection selection) {
		Collection actions = new ArrayList(super.generateCreateSiblingActions(
			descriptors, selection));
		if (selection instanceof IStructuredSelection
			&& ((IStructuredSelection) selection).size() == 1) {
			Object object = ((IStructuredSelection) selection)
				.getFirstElement();
			if (object instanceof Library) {
				actions.add(generateResourceAction(((Library) object)
					.eResource()));
			}
		}

		return actions;
	}

	/**
	 * Generates a library action for a given resource
	 * 
	 * @param resource
	 *            the containing resource
	 * @return the action
	 */
	protected Action generateResourceAction(Resource resource) {
		return new CreateLibraryAction(activeEditorPart,
			new StructuredSelection(resource));
	}

	/*
	 * @see org.eclipse.ui.part.EditorActionBarContributor#init(org.eclipse.ui.IActionBars)
	 */
	public void init(IActionBars actionBars) {
		super.init(actionBars);

		ISharedImages sharedImages = PlatformUI.getWorkbench()
			.getSharedImages();
		this.deleteAction = new ExtendedDeleteAction();
		this.deleteAction.setImageDescriptor(sharedImages
			.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
		actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
			this.deleteAction);

		actionBars.updateActionBars();
	}
}

⌨️ 快捷键说明

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