connectioncommand.java

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

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

import java.util.Vector;

import org.eclipse.gef.commands.Command;
import org.eclipse.jface.wizard.WizardDialog;

import com.webpump.ui.gefmodule.dialog.TaskDialog;
import com.webpump.ui.gefmodule.model.ModelSubpart;
import com.webpump.ui.gefmodule.model.Module;
import com.webpump.ui.gefmodule.model.Page;
import com.webpump.ui.gefmodule.model.Task;
import com.webpump.ui.perspective.MacroResource;
import com.webpump.ui.perspective.WebpumpIDEPlugin;

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

	/**old source*/
	protected ModelSubpart oldSource;

	/**old source terminal*/
	protected String oldSourceTerminal;

	/**old target*/
	protected ModelSubpart oldTarget;

	/**old target terminal*/
	protected String oldTargetTerminal;

	/**source*/
	protected ModelSubpart source;

	/**source terminal*/
	protected String sourceTerminal;

	/**terget*/
	protected ModelSubpart target;

	/**target terminal*/
	protected String targetTerminal;

	/**task*/
	protected Task task;

	/**module*/
	protected Module module;

	/**
	 * contructor
	 */
	public ConnectionCommand() {
		super("wire connection");
	}

	/**
	 * whether can execute
	 * @return true
	 */
	public boolean canExecute() {
		return true;
	}

	/**
	 * execute
	 */
	public void execute() {
		if (source != null) {
			task.detachSource();
			task.setSource(source);
			task.setSourceTerminal(sourceTerminal);
			task.attachSource();
		}
		if (target != null) {
			task.detachTarget();
			task.setTarget(target);
			task.setTargetTerminal(targetTerminal);
			task.attachTarget();
		}
		if (source == null && target == null) {
			task.detachSource();
			task.detachTarget();
			task.setTarget(null);
			task.setSource(null);
		}
	}

	/**
	 * execute create
	 * @return boolean
	 */
	public boolean executeCreate() {
		task.setSource(source);
		task.setSourceTerminal(sourceTerminal);
		task.setTarget(target);
		task.setTargetTerminal(targetTerminal);

		TaskDialog objWizard = new TaskDialog();

		//设置视图的模块信息
		objWizard.setTask(task);

		Vector taskVector = new Vector();
		for (int i = 0; i < module.getChildren().size(); i++) {
			Page page = (Page) module.getChildren().get(i);
			for (int j = 0; j < page.getSourceConnections().size(); j++) {
				taskVector.add(page.getSourceConnections().get(j));
			}
		}
		Task[] tasks = (Task[]) taskVector.toArray(new Task[taskVector.size()]);
		objWizard.setTasks(tasks);

		objWizard.init(WebpumpIDEPlugin.getDefault().getWorkbench(), null);

		WizardDialog objDialog =
			new WizardDialog(
				WebpumpIDEPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
				objWizard);
		objDialog.setPageSize(
			MacroResource.DIALOG_A_SIZE_WIDTH,
			MacroResource.DIALOG_A_SIZE_HEIGHT);
		// Open the wizard dialog
		if (objDialog.open() == WizardDialog.OK) {
			task.attachSource();
			task.attachTarget();
			return true;
		}
		return false;
	}

	/**
	 * get label
	 * @param String
	 */
	public String getLabel() {
		return "Connection change";
	}

	/**
	 * get source
	 * @return source ModelSubpart
	 */
	public ModelSubpart getSource() {
		return source;
	}

	/**
	 * get source terminal
	 * @return source terminal String
	 */
	public java.lang.String getSourceTerminal() {
		return sourceTerminal;
	}

	/**
	 * get target
	 * @return target ModelSubpart
	 */
	public ModelSubpart getTarget() {
		return target;
	}

	/**
	 * get target terminal
	 * @return target terminal String
	 */
	public String getTargetTerminal() {
		return targetTerminal;
	}

	/**
	 * get task
	 * @return task Task
	 */
	public Task getTask() {
		return task;
	}

	/**
	 * redo
	 */
	public void redo() {
		execute();
	}

	/**
	 * set source
	 * @param newSource ModelSubpart
	 */
	public void setSource(ModelSubpart newSource) {
		source = newSource;
	}

	/**
	 * set source terminal
	 * @param newSourceTerminal String
	 */
	public void setSourceTerminal(String newSourceTerminal) {
		sourceTerminal = newSourceTerminal;
	}

	/**
	 * set target
	 * @param newTarget ModelSubpart
	 */
	public void setTarget(ModelSubpart newTarget) {
		target = newTarget;
	}

	/**
	 * set target terminal
	 * @param newTargetTerminal String
	 */
	public void setTargetTerminal(String newTargetTerminal) {
		targetTerminal = newTargetTerminal;
	}

	/**
	 * set task
	 * @param w Task
	 */
	public void setTask(Task w) {
		task = w;
		oldSource = w.getSource();
		oldTarget = w.getTarget();
		oldSourceTerminal = w.getSourceTerminal();
		oldTargetTerminal = w.getTargetTerminal();
	}

	/**
	 * set module
	 * @param module Module
	 */
	public void setModule(Module module) {
		this.module = module;
	}

	/**
	 * undo
	 */
	public void undo() {
		source = task.getSource();
		target = task.getTarget();
		sourceTerminal = task.getSourceTerminal();
		targetTerminal = task.getTargetTerminal();

		task.detachSource();
		task.detachTarget();

		task.setSource(oldSource);
		task.setTarget(oldTarget);
		task.setSourceTerminal(oldSourceTerminal);
		task.setTargetTerminal(oldTargetTerminal);

		task.attachSource();
		task.attachTarget();
	}
}

⌨️ 快捷键说明

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