www.pudn.com > talk-plugins.rar > LoadIPPassMapAction.java


package talkServer;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;

/**
 * @author Xiang Zhou
 * @date 2006-4-28
 */

public class LoadIPPassMapAction extends Action {

	private final IWorkbenchWindow window;

	private final String viewId;

	public LoadIPPassMapAction(IWorkbenchWindow window, String label,
			String viewId) {
		this.window = window;
		this.viewId = viewId;
		setText(label);
		// The id is used to refer to the action in a menu or toolbar
		setId(ICommandIds.CMD_LOAD_IP_PASSWORD_MAP);
		// Associate the action with a pre-defined command, to allow key
		// bindings.
		setActionDefinitionId(ICommandIds.CMD_LOAD_IP_PASSWORD_MAP);
		setImageDescriptor(talkServer.TalkServerPlugin
				.getImageDescriptor("/icons/sample2.gif"));
	}

	public void run() {
		if (window != null) {
			try {
				window.getActivePage().showView(viewId, null,
						IWorkbenchPage.VIEW_ACTIVATE);
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "Error",
						"Error opening view:" + e.getMessage());
			}
		}
	}
}