| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2007 IBM Corporation and others. |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.library.ui.views; |
| |
| import java.util.ArrayList; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.epf.library.edit.LibraryEditPlugin; |
| import org.eclipse.epf.library.edit.util.TngUtil; |
| import org.eclipse.epf.library.ui.LibraryUIResources; |
| import org.eclipse.epf.uma.CapabilityPattern; |
| import org.eclipse.epf.uma.DeliveryProcess; |
| import org.eclipse.epf.uma.MethodLibrary; |
| import org.eclipse.epf.uma.MethodPlugin; |
| import org.eclipse.jface.viewers.ITreeContentProvider; |
| import org.eclipse.jface.viewers.Viewer; |
| |
| /** |
| * The content provider for the process tree viewer. |
| * |
| * @author Kelvin Low |
| * @since 1.2 |
| */ |
| public class ProcessTreeContentProvider implements ITreeContentProvider { |
| |
| private static final String CAPABILITY_PATTERNS = LibraryUIResources.capabilityPattern_text_plural; |
| |
| private static final String DELIVERY_PROCESSES = LibraryUIResources.deliveryProcess_text_plural; |
| |
| private static final Object[] EMPTY_LIST = new Object[0]; |
| |
| /** |
| * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(Object) |
| */ |
| public Object[] getChildren(Object parentElement) { |
| if (parentElement instanceof MethodLibrary) { |
| List children = new ArrayList(); |
| List plugins = ((MethodLibrary) parentElement).getMethodPlugins(); |
| for (Iterator it = plugins.iterator(); it.hasNext();) { |
| MethodPlugin plugin = (MethodPlugin) it.next(); |
| List processes = TngUtil.getAllProcesses(plugin); |
| if (processes.size() > 0) { |
| children.add(plugin); |
| } |
| } |
| return children.toArray(); |
| } else if (parentElement instanceof MethodPlugin) { |
| return new Object[] { |
| new ProcessTreeUIFolder( |
| CAPABILITY_PATTERNS, |
| LibraryEditPlugin.INSTANCE |
| .getImage("full/obj16/CapabilityPatterns"), parentElement), //$NON-NLS-1$ |
| new ProcessTreeUIFolder( |
| DELIVERY_PROCESSES, |
| LibraryEditPlugin.INSTANCE |
| .getImage("full/obj16/DeliveryProcesses"), parentElement) //$NON-NLS-1$ |
| }; |
| } else if (parentElement instanceof ProcessTreeUIFolder) { |
| ProcessTreeUIFolder uiFolder = (ProcessTreeUIFolder) parentElement; |
| MethodPlugin plugin = (MethodPlugin) uiFolder.getParent(); |
| if (uiFolder.getName() == CAPABILITY_PATTERNS) { |
| return getCapabilityPatterns(plugin).toArray(); |
| } else { |
| return getDeliveryProcesses(plugin).toArray(); |
| } |
| } |
| return EMPTY_LIST; |
| } |
| |
| /** |
| * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(Object) |
| */ |
| public Object getParent(Object element) { |
| return null; |
| } |
| |
| /** |
| * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(Object) |
| */ |
| public boolean hasChildren(Object element) { |
| return getChildren(element).length > 0; |
| } |
| |
| /** |
| * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object) |
| */ |
| public Object[] getElements(Object inputElement) { |
| return getChildren(inputElement); |
| } |
| |
| public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
| } |
| |
| public void dispose() { |
| } |
| |
| private List getCapabilityPatterns(MethodPlugin plugin) { |
| List capabilityPatterns = new ArrayList(); |
| List items = TngUtil.getAllProcesses(plugin); |
| for (Iterator it = items.iterator(); it.hasNext();) { |
| org.eclipse.epf.uma.Process p = (org.eclipse.epf.uma.Process) it |
| .next(); |
| if (p instanceof CapabilityPattern) { |
| capabilityPatterns.add(p); |
| } |
| } |
| return capabilityPatterns; |
| } |
| |
| private List getDeliveryProcesses(MethodPlugin plugin) { |
| List deliveryProcesses = new ArrayList(); |
| List items = TngUtil.getAllProcesses(plugin); |
| for (Iterator it = items.iterator(); it.hasNext();) { |
| org.eclipse.epf.uma.Process p = (org.eclipse.epf.uma.Process) it |
| .next(); |
| if (p instanceof DeliveryProcess) { |
| deliveryProcesses.add(p); |
| } |
| } |
| return deliveryProcesses; |
| } |
| |
| } |