| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2000, 2007 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
| 11 | package org.eclipse.ui.internal.ide.model; |
| 12 | |
| 13 | import org.eclipse.core.runtime.IAdaptable; |
| 14 | import org.eclipse.core.runtime.IStatus; |
| 15 | |
| 16 | import org.eclipse.ui.model.IWorkbenchAdapter; |
| 17 | import org.eclipse.ui.model.WorkbenchAdapter; |
| 18 | |
| 19 | /** |
| 20 | * UI manifestation of a status object. |
| 21 | */ |
| 22 | public class WorkbenchStatus extends WorkbenchAdapter implements IAdaptable { |
| 23 | private IStatus status; |
| 24 | |
| 25 | private Object[] children; |
| 26 | |
| 27 | /** |
| 28 | * Creates a workbench status for the given status. |
| 29 | * |
| 30 | * @param status the status |
| 31 | */ |
| 32 | public WorkbenchStatus(IStatus status) { |
| 33 | this.status = status; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns an object which is an instance of the given class |
| 38 | * associated with this object. Returns <code>null</code> if |
| 39 | * no such object can be found. |
| 40 | */ |
| 41 | public Object getAdapter(Class adapter) { |
| 42 | if (adapter == IWorkbenchAdapter.class) { |
| 43 | return this; |
| 44 | } |
| 45 | return null; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns the children of this element. |
| 50 | */ |
| 51 | public Object[] getChildren(Object o) { |
| 52 | if (children == null) { |
| 53 | IStatus[] childStatii = status.getChildren(); |
| 54 | children = new Object[childStatii.length]; |
| 55 | for (int i = 0; i < childStatii.length; i++) { |
| 56 | children[i] = new WorkbenchStatus(childStatii[i]); |
| 57 | } |
| 58 | } |
| 59 | return children; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @see IWorkbenchAdapter#getLabel |
| 64 | */ |
| 65 | public String getLabel(Object o) { |
| 66 | return status.getMessage(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Returns the wrapped status object. |
| 71 | * |
| 72 | * @return the wrapped status object |
| 73 | */ |
| 74 | public IStatus getStatus() { |
| 75 | return status; |
| 76 | } |
| 77 | } |