Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Using Pipelined Content Providers w/ CNF
Using Pipelined Content Providers w/ CNF [message #495650] Thu, 05 November 2009 16:03 Go to next message
Terran Gilman is currently offline Terran GilmanFriend
Messages: 67
Registered: July 2009
Member
Hello again,

I'm still working on migrating the Voice Tools Project file navigator view to the Common Navigator Framework. Specifically, this will be a contribution to the existing Project Explorer view instead of a new Common Navigator based view.

We have a custom data model that is partially backed by real file system resources. I have created an implementation of IPipelinedTreeContentProvider that is registered via the navigatorContent extension point as overriding the standard resource content provider. The current edition of that file is attached to this message for reference.

The data model is transient in that each request for an object's children produces a list of new object instances. However, all objects in the model implement a proper .equals(Object) method. The view displays the model content perfectly when opened. The problem is when adding items to the model.

The interceptAdd method is called on my pipelined content provider which swaps the IResource objects out for our model representations as well as ensures the parent object is replaced. The structural changes are not reflected in the view. I explicitly attempted to refresh the view's content at that element and it's children but nothing happens.

A call to the no argument refresh method on the view successfully synchs the structure. Another interesting thing i found is that I cannot successfully use the expand/collapse functions using my object model instances. I have added some debug statements to the equals of my model classes and they are being executed by the view when locating the proper widget, but no changes are made.

Does anyone have any ideas what is going on here? Do the objects contained in the view structure have to be the same object and not just through the .equals(Object) method?

From looking at the JDT and CDT implementations, it appears that they don't use this mechanism and handle the resource change events internally and just clear the add set in the pipeline function. What is the recommended why of using this mechanism?

Any insight would be a great help. Thanks.

Trip Gilman
Project Lead Voice Tools Project

--------------------------------------------------
WorkflowProjectContentProvider.java
--------------------------------------------------

/*---------------------------------------------------------- ----------------
* Copyright (c) 2009 OpenMethods, LLC
* 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:
* Trip Gilman (OpenMethods)
* - initial API and implementation
------------------------------------------------------------ -------------*/
package org.eclipse.vtp.desktop.projects.core.view;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
import org.eclipse.ui.navigator.IPipelinedTreeContentProvider;
import org.eclipse.ui.navigator.PipelinedShapeModification;
import org.eclipse.ui.navigator.PipelinedViewerUpdate;
import org.eclipse.vtp.desktop.model.core.IDesignDocument;
import org.eclipse.vtp.desktop.model.core.IWorkflowProject;
import org.eclipse.vtp.desktop.model.core.IWorkflowResource;
import org.eclipse.vtp.desktop.model.core.IWorkflowResourceContaine r;
import org.eclipse.vtp.desktop.model.core.WorkflowCore;
import org.eclipse.vtp.desktop.model.core.natures.WorkflowProjectNa ture;

/**
* @author trip
*
*/
public class WorkflowProjectContentProvider implements IPipelinedTreeContentProvider, IDoubleClickListener
{
private Viewer viewer = null;

public WorkflowProjectContentProvider()
{
}

/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(j ava.lang.Object)
*/
@Override
public Object[] getChildren(Object parentElement)
{
System.out.println("in getChildren");
if(parentElement instanceof IProject)
{
IWorkflowProject workflowProject = WorkflowCore.getDefault().getWorkflowModel().convertToWorkfl owProject((IProject)parentElement);
return workflowProject.getChildren().toArray();
}
else if(parentElement instanceof IWorkflowResourceContainer)
return ((IWorkflowResourceContainer)parentElement).getChildren().to Array();
return null;
}

/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(jav a.lang.Object)
*/
@Override
public Object getParent(Object element)
{
if(element instanceof IProject)
return null;
else if(element instanceof IWorkflowResource)
return ((IWorkflowResource)element).getParent();
return null;
}

/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(j ava.lang.Object)
*/
@Override
public boolean hasChildren(Object element)
{
if(element instanceof IProject)
return true;
if(element instanceof IDesignDocument)
return false;
if(element instanceof IWorkflowResourceContainer)
return true;
return false;
}

/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElem ents(java.lang.Object)
*/
@Override
public Object[] getElements(Object inputElement)
{
System.err.println("in get elements: " + inputElement.getClass().getName());
if(inputElement instanceof IWorkspaceRoot)
return ((IWorkspaceRoot)inputElement).getProjects();
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)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
{
if(this.viewer != null)
((CommonViewer)this.viewer).removeDoubleClickListener(this);
this.viewer = viewer;
if(viewer != null)
((CommonViewer)this.viewer).addDoubleClickListener(this);
}

public void getPipelinedChildren(Object aParent, Set theCurrentChildren)
{
System.out.println("in getPipelinedChildren: " + aParent.getClass().getName());
List newChildren = new LinkedList();
if(aParent instanceof IProject)
{
IProject project = (IProject)aParent;
try
{
if(project.hasNature(WorkflowProjectNature.NATURE_ID))
{
IWorkflowProject workflowProject = WorkflowCore.getDefault().getWorkflowModel().convertToWorkfl owProject(project);
List<IWorkflowResource> workflowResources = workflowProject.getChildren();
Iterator iterator = theCurrentChildren.iterator();
while(iterator.hasNext())
{
Object child = iterator.next();
if(child instanceof IResource)
{
IResource resource = (IResource)child;
for(IWorkflowResource workflowResource : workflowResources)
{
if(workflowResource.getName().equals(resource.getName()))
{
iterator.remove();
newChildren.add(workflowResource);
break;
}
}
}
}
}
}
catch (CoreException e)
{
e.printStackTrace();
}
}
theCurrentChildren.addAll(newChildren);
}

@Override
public void getPipelinedElements(Object anInput, Set theCurrentElements)
{
System.out.println("in getPipelinedElements: " + anInput.getClass().getName());
getPipelinedChildren(anInput, theCurrentElements);
}

@Override
public Object getPipelinedParent(Object anObject, Object aSuggestedParent)
{
System.out.println("in getPipelinedParent: " + anObject + " " + aSuggestedParent);
if(aSuggestedParent instanceof IResource)
{
IResource resource = (IResource)aSuggestedParent;
IWorkflowResource workflowResource = WorkflowCore.getDefault().getWorkflowModel().convertToWorkfl owResource(resource);
if(workflowResource != null)
{
if(!(workflowResource instanceof IWorkflowProject))
{
return workflowResource;
}
}
}
return aSuggestedParent;
}

public PipelinedShapeModification interceptAdd(
final PipelinedShapeModification anAddModification)
{
Object parentObj = anAddModification.getParent();
if(parentObj instanceof IResource)
{
IResource parent = (IResource)parentObj;
IWorkflowResource workflowParent = WorkflowCore.getDefault().getWorkflowModel().convertToWorkfl owResource(parent);
System.out.println(workflowParent);
if(workflowParent != null)
{
anAddModification.setParent(workflowParent);
}
Set children = anAddModification.getChildren();
List newChildren = new LinkedList();
Iterator iterator = children.iterator();
while(iterator.hasNext())
{
Object childObj = iterator.next();
if(childObj instanceof IResource)
{
IResource childResource = (IResource)childObj;
IWorkflowResource workflowChild = WorkflowCore.getDefault().getWorkflowModel().convertToWorkfl owResource(childResource);
System.out.println(workflowChild);
if(workflowChild != null)
{
iterator.remove();
newChildren.add(workflowChild);
}
}
}
children.addAll(newChildren);
}
final Object parent = anAddModification.getParent();
// viewer.getControl().getDisplay().timerExec(3000, new Runnable(){
// public void run()
// {
// System.out.println(parent);
TreeViewer viewer2 = (TreeViewer)viewer;
viewer2.refresh(parent, true);
// viewer2.collapseToLevel(parent, TreeViewer.ALL_LEVELS);
// viewer2.expandToLevel(parent, 1);
// }
// });
return anAddModification;
}

public boolean interceptRefresh(
PipelinedViewerUpdate aRefreshSynchronization)
{
System.out.println("in interceptRefresh: " + aRefreshSynchronization);
boolean changed = false;
Set children = aRefreshSynchronization.getRefreshTargets();
List newTargets = new LinkedList();
Iterator iterator = children.iterator();
while(iterator.hasNext())
{
Object childObj = iterator.next();
if(childObj instanceof IResource)
{
IResource childResource = (IResource)childObj;
IWorkflowResource workflowChild = WorkflowCore.getDefault().getWorkflowModel().convertToWorkfl owResource(childResource);
System.out.println(workflowChild);
if(workflowChild != null)
{
iterator.remove();
newTargets.add(workflowChild);
changed = true;
}
}
}
children.addAll(newTargets);
return changed;
}

public PipelinedShapeModification interceptRemove(
PipelinedShapeModification aRemoveModification)
{
System.out.println("in interceptRemove: " + aRemoveModification);
return aRemoveModification;
}

public boolean interceptUpdate(PipelinedViewerUpdate anUpdateSynchronization)
{
System.out.println("in interceptUpdate: " + anUpdateSynchronization);
return false;
}

public void init(ICommonContentExtensionSite aConfig)
{
}

public void restoreState(IMemento aMemento)
{
}

public void saveState(IMemento aMemento)
{
}

@Override
public void doubleClick(DoubleClickEvent event)
{
IStructuredSelection selection = (IStructuredSelection)event.getSelection();
Object sel = selection.getFirstElement();
if(sel instanceof IDesignDocument)
{
try
{
IDE.openEditor(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage(), ((IDesignDocument)sel).getUnderlyingFile());
}
catch (PartInitException e)
{
e.printStackTrace();
}
}
}

}

[Updated on: Thu, 05 November 2009 16:06]

Report message to a moderator

Re: Using Pipelined Content Providers w/ CNF [message #495761 is a reply to message #495650] Thu, 05 November 2009 22:51 Go to previous message
Terran Gilman is currently offline Terran GilmanFriend
Messages: 67
Registered: July 2009
Member
Your object model must override the Object.hashCode() method to provide identity comparison when using the Common Navigator Framework if your model is loaded on demand.
Previous Topic:Make Use of Rename Events With Resource Change Events
Next Topic:To display secondary views under Eclipse menu Window -> Show VIew
Goto Forum:
  


Current Time: Tue Mar 19 08:53:11 GMT 2024

Powered by FUDForum. Page generated in 0.02475 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top