/******************************************************************************* * Copyright (c) 2011, 2012 Wind River Systems, Inc. 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: * Wind River Systems - initial API and implementation *******************************************************************************/ package org.eclipse.tcf.te.tcf.filesystem.ui.internal.wizards; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; import org.eclipse.tcf.te.tcf.locator.model.Model; import org.eclipse.tcf.te.ui.views.interfaces.IRoot; /** * The content provider used by TargetSelectionPage to provide the current * target list. */ public class TargetContentProvider implements ITreeContentProvider { private final static Object[] NO_ELEMENTS = new Object[0]; /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) */ @Override public Object[] getChildren(Object parentElement) { Object[] children = NO_ELEMENTS; // If it is the locator model, get the peers if (parentElement instanceof ILocatorModel) { children = ((ILocatorModel)parentElement).getPeers(); } return children; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) */ @Override public Object getParent(Object element) { // If it is a peer model node, return the parent locator model if (element instanceof IPeerModel) { return ((IPeerModel)element).getModel(); } return null; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) */ @Override public boolean hasChildren(Object element) { boolean hasChildren = false; if (element instanceof ILocatorModel) { hasChildren = ((ILocatorModel)element).getPeers().length > 0; } return hasChildren; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) */ @Override public Object[] getElements(Object inputElement) { return getChildren(inputElement); } /* (non-Javadoc) * @see org.eclipse.jface.viewers.IContentProvider#dispose() */ @Override public void dispose() { } /* (non-Javadoc) * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) */ @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { final ILocatorModel model = Model.getModel(); if (model != null && newInput instanceof IRoot) { // Refresh the model asynchronously Protocol.invokeLater(new Runnable() { @Override public void run() { model.getService(ILocatorModelRefreshService.class).refresh(); } }); } } }