Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Palette drop aware TreeEditor
Palette drop aware TreeEditor [message #204959] Fri, 09 December 2005 07:19 Go to next message
Eclipse UserFriend
Originally posted by: prashanto.chatterjee.softwareag.com

Hi,
My team is working towards creating a TreeViewer instead of the normal
graphical viewer.

After a lot of slug-fest we were able to create a TreeViewer inside an
editor. My editpart for the viewer as a whole works fine and I am able to
drag-n-drop items from the palette onto the TreeViewer.

Now incidentally even the children have the same treeeditpart. However, I
am not able to drag-n-drop a palette item onto the first level children.
One possible reason is my editpart does not listen to palette drop as
opposed to my editor(with a TreeViewer). I tried to plug an implemented
TransferDropTargetListener into my editpart but did not succeed.

Where am I going wrong??? How do I make my editpart listen to drops from
the palette??

Below is the editpart code I am using:
------------------------------------------------------------ ------------------
public class ComplexTreeNodeEditPart extends AbstractTreeEditPart
implements
PropertyChangeListener {

protected String getText() {
return getCastedModel().getName();
}

ComplexTreeNodeEditPart(ComplexTreeNode model) {
super(model);
}

protected Image getImage() {
return getCastedModel().getIcon();
}

/**
* Upon activation, attach to the model element as a property change
listener.
*/
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
}
}


protected void createEditPolicies() {
// If this editpart is the root content of the viewer, then disallow
removal
if (getParent() instanceof RootEditPart) {
installEditPolicy(EditPolicy.COMPONENT_ROLE, new
RootComponentEditPolicy());

}

if(getParent() instanceof RootTreeEditPart){
//TreeContainerEditPolicy

installEditPolicy(EditPolicy.CONTAINER_ROLE, new
TreeContainerEditPolicy(){

protected Command getAddCommand(ChangeBoundsRequest request) {
// TODO Auto-generated method stub
return null;
}

protected Command getCreateCommand(CreateRequest request) {
Object childClass = request.getNewObjectType();
if (childClass == ComplexTreeNode.class || childClass ==
SimpleTreeNode.class || childClass == TreeNode.class) {

return new TreeNodeCreateCommand((TreeNode)request.getNewObject(),
(ComplexTreeNode)getHost().getModel());
}
return null;
}

protected Command getMoveChildrenCommand(ChangeBoundsRequest request) {
// TODO Auto-generated method stub
return null;
}

});
}
}

/**
* Upon deactivation, detach from the model element as a property change
listener.
*/
public void deactivate() {
if (isActive()) {
super.deactivate();
((ModelElement) getModel()).removePropertyChangeListener(this);
}
}

private ComplexTreeNode getCastedModel() {
return (ComplexTreeNode) getModel();
}

/**
* Convenience method that returns the EditPart corresponding to a given
child.
* @param child a model element instance
* @return the corresponding EditPart or null
*/
private EditPart getEditPartForChild(Object child) {
return (EditPart) getViewer().getEditPartRegistry().get(child);
}

/* (non-Javadoc)
* @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren( )
*/
protected List getModelChildren() {
List childList = new ArrayList();
TreeNode[] childArray = getCastedModel().getChildren();
for(int i=0; i<childArray.length; i++){
childList.add(childArray[i]);
}

return childList; // a list of shapes
}

/* (non-Javadoc)
* @see
java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt) {
String prop = evt.getPropertyName();
if (ComplexTreeNode.PROP_CHILD_ADDED.equals(prop)) {
// add a child to this edit part
// causes an additional entry to appear in the tree of the outline view
addChild(createChild(evt.getNewValue()), -1);
} else if (ComplexTreeNode.PROP_CHILD_REMOVED.equals(prop)) {
// remove a child from this edit part
// causes the corresponding edit part to disappear from the tree in the
outline view
removeChild(getEditPartForChild(evt.getNewValue()));
}
refreshVisuals();
}
}
------------------------------------------------------------ ------------------

Thanks in advance.

Hoping for a positive response,
Prashanto Chatterjee
Re: Palette drop aware TreeEditor - Success;But :( [message #205112 is a reply to message #204959] Mon, 12 December 2005 14:54 Go to previous message
Eclipse UserFriend
Originally posted by: prashanto.chatterjee.softwareag.com

Hi GEF geeks,
I was disappointed at not getting an answer last time. But it proved to be
a blessing in disguise. I tried hard and was able to accomplish this by
having a different associated edit-part for the root and the other tree
items.

However, I am now facing a different problem and I just cant find a clue.

As told previosly, we have substituted the graphical-viewer of the editor
by a TreeViewer. The following lines of code did the trick:

============================================================ ==================
public abstract class GraphicalEditorTree extends GraphicalEditor {

protected void createGraphicalViewer(Composite parent) {
GraphicalViewer viewer = new ObjectTreeViewer();
viewer.createControl(parent);
setGraphicalViewer(viewer);
configureGraphicalViewer();
hookGraphicalViewer();
initializeGraphicalViewer();
}
}
============================================================ ==================

where:

============================================================ ==================
public class ObjectTreeViewer extends TreeViewer implements
GraphicalViewer{

public Handle findHandleAt(Point p) {
// TODO Auto-generated method stub
return null;
}
============================================================ ==================

The effect of this has been such that the context menu associated with the
tree-viewer does not enable the delete option when I selct an edit part. I
have specified the ComponentEditPolicy in my TreeEditPart too. From my
understanding this should enable the delete in my context menu. But it
does not. I am lost. Please help.

Regards,
Prashanto
Previous Topic:how to draw a combobox control using draw2d
Next Topic:ScalableFreeformRootEditPart extremely slow
Goto Forum:
  


Current Time: Fri Apr 26 13:20:36 GMT 2024

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

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

Back to the top