001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.actions;
011:
012: import org.eclipse.core.runtime.IAdaptable;
013: import org.eclipse.jface.action.Action;
014: import org.eclipse.ui.IWorkbenchPage;
015: import org.eclipse.ui.IWorkbenchWindow;
016: import org.eclipse.ui.WorkbenchException;
017: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
018: import org.eclipse.ui.internal.Workbench;
019: import org.eclipse.ui.internal.WorkbenchMessages;
020: import org.eclipse.ui.internal.misc.StatusUtil;
021: import org.eclipse.ui.statushandlers.StatusManager;
022:
023: /**
024: * Opens a new window. The initial perspective
025: * for the new window will be the same type as
026: * the active perspective in the window which this
027: * action is running in. The default input for the
028: * new window's page is application-specific.
029: */
030: public class OpenInNewWindowAction extends Action implements
031: ActionFactory.IWorkbenchAction {
032:
033: /**
034: * The workbench window; or <code>null</code> if this
035: * action has been <code>dispose</code>d.
036: */
037: private IWorkbenchWindow workbenchWindow;
038:
039: private IAdaptable pageInput;
040:
041: /**
042: * Creates a new <code>OpenInNewWindowAction</code>. Sets
043: * the new window page's input to be an application-specific
044: * default.
045: *
046: * @param window the workbench window containing this action
047: */
048: public OpenInNewWindowAction(IWorkbenchWindow window) {
049: this (window, ((Workbench) window.getWorkbench())
050: .getDefaultPageInput());
051: setActionDefinitionId("org.eclipse.ui.window.newWindow"); //$NON-NLS-1$
052: }
053:
054: /**
055: * Creates a new <code>OpenInNewWindowAction</code>.
056: *
057: * @param window the workbench window containing this action
058: * @param input the input for the new window's page
059: */
060: public OpenInNewWindowAction(IWorkbenchWindow window,
061: IAdaptable input) {
062: super (WorkbenchMessages.OpenInNewWindowAction_text);
063: if (window == null) {
064: throw new IllegalArgumentException();
065: }
066: this .workbenchWindow = window;
067: // @issue missing action id
068: setToolTipText(WorkbenchMessages.OpenInNewWindowAction_toolTip);
069: pageInput = input;
070: window.getWorkbench().getHelpSystem().setHelp(this ,
071: IWorkbenchHelpContextIds.OPEN_NEW_WINDOW_ACTION);
072: }
073:
074: /**
075: * Set the input to use for the new window's page.
076: *
077: * @param input the input
078: */
079: public void setPageInput(IAdaptable input) {
080: pageInput = input;
081: }
082:
083: /**
084: * The implementation of this <code>IAction</code> method
085: * opens a new window. The initial perspective
086: * for the new window will be the same type as
087: * the active perspective in the window which this
088: * action is running in.
089: */
090: public void run() {
091: if (workbenchWindow == null) {
092: // action has been disposed
093: return;
094: }
095: try {
096: String perspId;
097:
098: IWorkbenchPage page = workbenchWindow.getActivePage();
099: if (page != null && page.getPerspective() != null) {
100: perspId = page.getPerspective().getId();
101: } else {
102: perspId = workbenchWindow.getWorkbench()
103: .getPerspectiveRegistry()
104: .getDefaultPerspective();
105: }
106:
107: workbenchWindow.getWorkbench().openWorkbenchWindow(perspId,
108: pageInput);
109: } catch (WorkbenchException e) {
110: StatusUtil.handleStatus(e.getStatus(),
111: WorkbenchMessages.OpenInNewWindowAction_errorTitle
112: + ": " + e.getMessage(), //$NON-NLS-1$
113: StatusManager.SHOW);
114: }
115: }
116:
117: /* (non-Javadoc)
118: * Method declared on ActionFactory.IWorkbenchAction.
119: * @since 3.0
120: */
121: public void dispose() {
122: workbenchWindow = null;
123: }
124: }
|