package tool.content;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
import tool.model.ToolClass;
public class CexContentProvider implements ITreeContentProvider{
private StructuredViewer viewer;
@Override
public void dispose() {
viewer = null;
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (oldInput != null && !oldInput.equals(newInput)){
this.viewer = (StructuredViewer) viewer;
}
}
@Override
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
@Override
public Object[] getChildren(Object parentElement) {
//parse the class resource and create a ToolClass
if (parentElement instanceof IFile &&
(((IFile)parentElement).getFileExtension().equalsIgnoreCase("CLA") ||
((IFile)parentElement).getFileExtension().equalsIgnoreCase("WCL"))){
ToolClass cls = ToolClass.parseUsingGrammar((IFile) parentElement);
// ToolClass cls = ToolClass.fetch((IFile) parentElement);
return new Object[] {cls};
} else if (parentElement instanceof ToolClass){
return ((ToolClass)parentElement).getComponents();
}
return null;
}
@Override
public Object getParent(Object element) {
if (element instanceof IResource)
return ((IResource)element).getParent();
else
return null;
}
@Override
public boolean hasChildren(Object element) {
if (element instanceof IFile &&
(((IFile)element).getFileExtension().equalsIgnoreCase("CLA") ||
((IFile)element).getFileExtension().equalsIgnoreCase("WCL"))){
return true;
} else if (element instanceof ToolClass){
return ((ToolClass)element).getComponents().length > 0;
}
return false;
}
}