01: /*******************************************************************************
02: * Copyright (c) 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.components.actions;
11:
12: import org.eclipse.jface.action.IAction;
13: import org.eclipse.jface.dialogs.MessageDialog;
14: import org.eclipse.jface.viewers.ISelection;
15: import org.eclipse.swt.SWT;
16: import org.eclipse.swt.layout.FillLayout;
17: import org.eclipse.swt.widgets.Display;
18: import org.eclipse.swt.widgets.Shell;
19: import org.eclipse.ui.IPageLayout;
20: import org.eclipse.ui.IWorkbenchPage;
21: import org.eclipse.ui.IWorkbenchWindow;
22: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
23: import org.eclipse.ui.internal.WorkbenchPage;
24: import org.eclipse.ui.internal.components.framework.ComponentException;
25: import org.eclipse.ui.internal.components.framework.FactoryMap;
26: import org.eclipse.ui.internal.part.components.services.IWorkbenchPartFactory;
27:
28: /**
29: * Demonstrate how to open a view by its ID from an IWorkbenchPage.
30: */
31: public class CreateViewByIdAction implements
32: IWorkbenchWindowActionDelegate {
33: private IWorkbenchWindow window;
34:
35: /**
36: * The constructor.
37: */
38: public CreateViewByIdAction() {
39: }
40:
41: public void run(IAction action) {
42: IWorkbenchPage page = window.getActivePage();
43:
44: if (page == null) {
45: MessageDialog.openInformation(window.getShell(),
46: "Open view", "No workbench page open");
47: return;
48: }
49:
50: final Shell tempShell = new Shell(window.getShell(),
51: SWT.DIALOG_TRIM | SWT.RESIZE);
52:
53: tempShell.setLayout(new FillLayout());
54: tempShell.setText("Problems");
55:
56: IWorkbenchPartFactory factory = ((WorkbenchPage) page)
57: .getPartFactory();
58: try {
59: factory.createView(IPageLayout.ID_PROBLEM_VIEW, tempShell,
60: null, new FactoryMap());
61: } catch (ComponentException e) {
62: tempShell.dispose();
63: MessageDialog.openError(window.getShell(),
64: "Error opening view", e.getMessage());
65: }
66:
67: // Open the dialog
68: tempShell.open();
69: Display d = tempShell.getDisplay();
70: while (!tempShell.isDisposed()) {
71: if (!d.readAndDispatch())
72: d.sleep();
73: }
74:
75: }
76:
77: public void selectionChanged(IAction action, ISelection selection) {
78: }
79:
80: public void dispose() {
81: }
82:
83: public void init(IWorkbenchWindow window) {
84: this.window = window;
85: }
86: }
|