01: /*******************************************************************************
02: * Copyright (c) 2003, 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.rcp.browser;
11:
12: import java.util.ArrayList;
13: import java.util.Arrays;
14: import java.util.Iterator;
15: import java.util.List;
16:
17: import org.eclipse.core.runtime.IStatus;
18: import org.eclipse.core.runtime.Status;
19: import org.eclipse.ui.IWorkbenchPage;
20: import org.eclipse.ui.IWorkbenchPartReference;
21: import org.eclipse.ui.plugin.AbstractUIPlugin;
22:
23: /**
24: * Plug-in class for the browser example.
25: */
26: public class BrowserPlugin extends AbstractUIPlugin {
27: private static BrowserPlugin DEFAULT;
28:
29: public BrowserPlugin() {
30: DEFAULT = this ;
31: }
32:
33: public static BrowserPlugin getDefault() {
34: return DEFAULT;
35: }
36:
37: /**
38: * Logs the given throwable.
39: *
40: * @param t the throwable to log
41: */
42: public void log(Throwable t) {
43: String msg = t.getMessage();
44: if (msg == null)
45: msg = t.toString();
46: IStatus status = new Status(IStatus.ERROR, getBundle()
47: .getSymbolicName(), 0, msg, t);
48: getLog().log(status);
49: }
50:
51: /**
52: * Returns a list of all views and editors in the given page,
53: * excluding any secondary views like the History view.
54: *
55: * @param page the workbench page
56: * @return a list of all non-secondary parts in the page
57: */
58: public static List getNonSecondaryParts(IWorkbenchPage page) {
59: ArrayList list = new ArrayList();
60: list.addAll(Arrays.asList(page.getViewReferences()));
61: list.addAll(Arrays.asList(page.getEditorReferences()));
62: for (Iterator i = list.iterator(); i.hasNext();) {
63: IWorkbenchPartReference ref = (IWorkbenchPartReference) i
64: .next();
65: if (ref instanceof ISecondaryPart) {
66: i.remove();
67: }
68: }
69: return list;
70: }
71:
72: }
|