/*******************************************************************************
- * Copyright (c) 2010, 2011 Ericsson
- *
+ * Copyright (c) 2010, 2012 Ericsson
+ *
* 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:
* Francois Chouinard - Initial API and implementation
+ * Bernd Hufmann - Implement getParent()
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
-import org.eclipse.ui.navigator.ICommonContentProvider;
import org.eclipse.ui.navigator.IPipelinedTreeContentProvider;
import org.eclipse.ui.navigator.PipelinedShapeModification;
import org.eclipse.ui.navigator.PipelinedViewerUpdate;
/**
- * <b><u>TmfNavigatorContentProvider</u></b>
+ * The TMF project content provider for the tree viewer in the project explorer view.
* <p>
+ * @version 1.0
+ * @author Francois Chouinard
*/
-public class TmfNavigatorContentProvider implements ICommonContentProvider, IPipelinedTreeContentProvider {
+public class TmfNavigatorContentProvider implements IPipelinedTreeContentProvider {
// ------------------------------------------------------------------------
// ICommonContentProvider
// ------------------------------------------------------------------------
-
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ */
@Override
public Object[] getElements(Object inputElement) {
return null;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
@Override
public Object getParent(Object element) {
+ if (element instanceof IProject) {
+ IProject project = (IProject) element;
+ return project.getParent();
+ }
+
+ if (element instanceof TmfTraceFolder) {
+ TmfTraceFolder folder = (TmfTraceFolder) element;
+ // Return the corresponding IProject as parent because from CNF point of view the IProject is the parent.
+ // The IProject is needed e.g. for link with Editor to work correctly.
+ return folder.getParent().getResource();
+ }
+
+ if (element instanceof TmfTraceElement) {
+ TmfTraceElement traceElement = (TmfTraceElement) element;
+ return traceElement.getParent();
+ }
+
+ if (element instanceof TmfExperimentFolder) {
+ TmfExperimentFolder folder = (TmfExperimentFolder) element;
+ // Return the corresponding IProject as parent because from CNF point of view the IProject is the parent.
+ // The IProject is needed e.g. for link with Editor to work correctly.
+ return folder.getParent().getResource();
+ }
+
+ if (element instanceof TmfExperimentElement) {
+ TmfExperimentElement expElement = (TmfExperimentElement) element;
+ return expElement.getParent();
+ }
return null;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
@Override
public boolean hasChildren(Object element) {
if (element instanceof IProject) {
return false;
}
+ /*
+ * (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) {
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento)
+ */
@Override
public void restoreState(IMemento aMemento) {
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento)
+ */
@Override
public void saveState(IMemento aMemento) {
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.ICommonContentProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite)
+ */
@Override
public void init(ICommonContentExtensionSite aConfig) {
}
// ------------------------------------------------------------------------
// ICommonContentProvider - getChildren()
// ------------------------------------------------------------------------
-
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
@Override
public synchronized Object[] getChildren(Object parentElement) {
return new Object[0];
}
+ // ------------------------------------------------------------------------
+ // Helper method
+ // ------------------------------------------------------------------------
private Object[] getProjectChildren(IProject project) {
// The children structure
List<Object> children = new ArrayList<Object>();
for (IResource resource : members) {
String name = resource.getName();
ITmfProjectModelElement trace = childrenMap.get(name);
- if (!name.startsWith(TmfTraceElement.SUPPLEMENATARY_FILES_PREFIX)) {
- if (trace == null) {
- trace = new TmfTraceElement(name, resource, tmfTraceFolder);
- }
- children.add(trace);
+ if (trace == null) {
+ trace = new TmfTraceElement(name, resource, tmfTraceFolder);
}
+ children.add(trace);
childrenMap.remove(name);
}
} catch (CoreException e) {
// IPipelinedTreeContentProvider
// ------------------------------------------------------------------------
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedChildren(java.lang.Object, java.util.Set)
+ */
@Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
public void getPipelinedChildren(Object parent, Set currentChildren) {
customizeTmfElements(getChildren(parent), currentChildren);
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedElements(java.lang.Object, java.util.Set)
+ */
@Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
public void getPipelinedElements(Object input, Set currentElements) {
customizeTmfElements(getElements(input), currentElements);
}
/**
* Add/replace the ITmfProjectElement to the list of children
- *
+ *
* @param elements
* the list returned by getChildren()
* @param children
* the current children
*/
- private void customizeTmfElements(Object[] elements, Set<Object> children) {
+ private static void customizeTmfElements(Object[] elements,
+ Set<Object> children) {
if (elements != null && children != null) {
for (Object element : elements) {
if (element instanceof ITmfProjectModelElement) {
}
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedParent(java.lang.Object, java.lang.Object)
+ */
@Override
public Object getPipelinedParent(Object anObject, Object aSuggestedParent) {
return aSuggestedParent;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptAdd(org.eclipse.ui.navigator.PipelinedShapeModification)
+ */
@Override
public PipelinedShapeModification interceptAdd(PipelinedShapeModification anAddModification) {
return anAddModification;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRemove(org.eclipse.ui.navigator.PipelinedShapeModification)
+ */
@Override
public PipelinedShapeModification interceptRemove(PipelinedShapeModification aRemoveModification) {
return null;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRefresh(org.eclipse.ui.navigator.PipelinedViewerUpdate)
+ */
@Override
public boolean interceptRefresh(PipelinedViewerUpdate aRefreshSynchronization) {
return false;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptUpdate(org.eclipse.ui.navigator.PipelinedViewerUpdate)
+ */
@Override
public boolean interceptUpdate(PipelinedViewerUpdate anUpdateSynchronization) {
return false;
}
-
}