copyaction.java

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

JAVA
117
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/gefmodule/action/CopyAction.java,v 1.1.1.1 2004/07/01 09:07:46 wang_j Exp $
 * $Revision: 1.1.1.1 $
 * $Date: 2004/07/01 09:07:46 $
 *
 * ====================================================================
 *
 * 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.gefmodule.action;

import java.util.Iterator;
import java.util.Vector;

import org.eclipse.gef.internal.GEFMessages;
import org.eclipse.gef.ui.actions.CopyTemplateAction;
import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.ui.IEditorPart;

import com.webpump.ui.gefmodule.ModuleEditor;
import com.webpump.ui.gefmodule.edit.PageEditPart;
import com.webpump.ui.gefmodule.util.DataTransfer;

/**
 * Class for CopyAction
 * 
 * @author shi_l
 * @version 2.0.0 2004-5-30
 */
public class CopyAction extends CopyTemplateAction {

	private Vector template;
	/**
	 * Constructs a new CopyTemplateAction.  You must manually add this action to the palette
	 * viewer's list of selection listeners.  Otherwise, this action's enabled state won't be
	 * updated properly.
	 * 
	 * @see org.eclipse.gef.ui.actions.EditorPartAction#EditorPartAction(IEditorPart)
	 */
	public CopyAction(IEditorPart edit) {
		super(edit);
		template = new Vector();
	}

	/**
	 * Returns whether the selected EditPart is a TemplateEditPart.
	 * @return whether the selected EditPart is a TemplateEditPart
	 */
	protected boolean calculateEnabled() {
		if(template != null && template.size() > 0) {
			return true;
		}
		return false;
	}

	/**
	 * @see org.eclipse.gef.ui.actions.EditorPartAction#init()
	 */
	protected void init() {
		setId(GEFActionConstants.COPY);
		setText(GEFMessages.CopyAction_Label);
	}

	/**
	 * Sets the default {@link Clipboard Clipboard's} contents to be the currently selected
	 * template.
	 */
	public void run() {
		Object[] obj = template.toArray();
		Object[] objects = new Object[1];
		objects[0] = obj;
		Transfer[] tr = new DataTransfer[1];
		tr[0] = DataTransfer.getInstance();
		ModuleEditor.getClipBoard().setContents(objects, tr);
		PasteTemplateAction.TIMES = 1;
//		Clipboard.getDefault().setContents(template);
	}
	
	/**
	 * operation on selection changed
	 * @param event SelectionChangedEvent
	 */
	public void selectionChanged(SelectionChangedEvent event) {
		template.removeAllElements();
		ISelection s = event.getSelection();
		if (!(s instanceof IStructuredSelection))
			return;
		IStructuredSelection selection = (IStructuredSelection)s;
		if (selection != null) {
			Iterator obj = selection.iterator();
			while(obj.hasNext()) {
				Object page = obj.next();
				if(page instanceof PageEditPart) {
					Object model = ((PageEditPart) page).getModel();
					template.add(model);
				}
			}
		}
		refresh();
	}
}

⌨️ 快捷键说明

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