Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Starting nested Command from ViewProvider
Starting nested Command from ViewProvider [message #512334] Thu, 04 February 2010 17:18 Go to next message
Johannes Michler is currently offline Johannes MichlerFriend
Messages: 21
Registered: July 2009
Junior Member
Hi,

I've create some GMF-functionality to add images to my diagram. I created a new Image-Node that gets stored in the notation-model (no entry in the metamodel). This works fine so far. During the createNode() Method in my ViewProvider I ask the user to select an image and afterwards the image gets copied to some special folder. The editpart afterwards reads the image from this folder. This is all working fine. But when undoing my Image-Creation, the image copied to my special folder doesn't get deleted. Well of cause, this cannot be tracked by the TransactionChangeRecorder.

Is there a way to start a sub-command in my createNode-Method. Unfortunately I don't have the CreateCommand itself at this place. Any hints how I could start my subcommand (with a execute and undo-method doing the copy to my folder and the deletion on undo?)

-orgler
Re: Starting nested Command from ViewProvider [message #512875 is a reply to message #512334] Mon, 08 February 2010 09:34 Go to previous messageGo to next message
Johannes Michler is currently offline Johannes MichlerFriend
Messages: 21
Registered: July 2009
Junior Member
Well, I did some future experiments: I tried to manually start a new Command from within my createNode-Method in my Viewprovider using the following code. My execute()-method gets executed, but the undo() or canUndo() method is never executed. The command doesn't seem to be on the right command stack, since when clicking undo only the "Create View" Command gets executed.

Any ideas on how to get the right Command-Stack? My way seems to be wrong Sad


-orgler

InternalTransactionalEditingDomain edd = null;

EList<Adapter> o = (( DiagramImpl) containerView).eAdapters();
for ( Adapter adapter : o) {

if ( adapter instanceof TransactionChangeRecorder) {
TransactionChangeRecorder tcr = ( TransactionChangeRecorder) adapter;
edd = tcr.getEditingDomain();

}
}
if ( edd == null )
System.out.println( "very strange");

final Node node = NotationFactory.eINSTANCE.createNode();
node.setLayoutConstraint( NotationFactory.eINSTANCE.createBounds());
node.setType( semanticHint);
ImageBufferStyle ibs = NotationFactory.eINSTANCE.createImageBufferStyle();
final DescriptionStyle descStyle = NotationFactory.eINSTANCE.createDescriptionStyle();
EList styles = node.getStyles();
styles.add( ibs);
styles.add( descStyle);

AbstractCommand comm = new AbstractCommand() {

@Override
protected boolean prepare() {
return true;
}

public boolean canUndo() {
return true;
};

@Override
public void undo() {

System.out.println("never executed :-(");

}

@Override
public void execute() {
System.out.println("this gets executed");
}

@Override
public void redo() {
// TODO Auto-generated method stub

}

};

edd.getCommandStack().execute( comm);
Command c= edd.getCommandStack().getUndoCommand();
ViewUtil.insertChildView( containerView, node, index, persisted);
node.setElement( getSemanticElement( semanticAdapter));

return node;
Re: Starting nested Command from ViewProvider [message #519855 is a reply to message #512334] Wed, 10 March 2010 09:15 Go to previous message
Matthias M. is currently offline Matthias M.Friend
Messages: 27
Registered: July 2009
Junior Member

Hi,

got a similar problem here...
Have you solved this problem yet or does anybody else have any suggestions?

Regards,
Matthias


Previous Topic:get the length of an arrow (association connector)
Next Topic:Keep Tool on Double-Click
Goto Forum:
  


Current Time: Tue Mar 19 05:57:52 GMT 2024

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

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

Back to the top