| 
| Where to change attributes from code? [message #161006] | Fri, 16 November 2007 12:53  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: malte.koelling.udo.edu 
 Hello,
 
 as many people I would like to chance attributes of my model out of my
 program. The plan is to set an index number according to the number of
 already existing elements of this type. So for example if there already 2
 models of type "Task" and I make a new one its index should be "3".
 
 I read the Newsgroup Q&A about this topic and this post.
 
 http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg03870.html
 
 But I did not get it, where to put this code? Shall I put it in the
 "TaskEditHelperClass" in my diagram plugin? But this class seems never to
 be called if create a new element. Do I have to register this class
 somewhere, so that it is called everytime a new object "Task" was created?
 
 Best Regards and thanks
 
 Malte
 |  |  |  | 
|  | 
|  | 
| 
| Re: Where to change attributes from code? [message #162576 is a reply to message #161876] | Sat, 24 November 2007 21:42  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: Sam.sam.org 
 private class ChangeAttrCommand extends Command {
 
 
 public ChangeAttrCommand (Element element, Attribute attr, value) {
 
 setLabel("set attr");
 
 
 this.element = element;
 
 ....
 
 }
 
 
 public boolean canExecute() {
 
 return true;
 
 }
 
 public boolean canUndo() {
 
 return false;
 
 }
 
 
 public void execute() {
 
 IUndoableOperation op = new AbstractEMFOperation(getEditingDomain(), "") {
 
 
 protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
 throws ExecutionException {
 
 
 attr.setValue(value);
 
 return Status.OK_STATUS;
 
 }
 
 };
 
 
 try {
 
 op.execute(new NullProgressMonitor(), null);
 
 } catch (ExecutionException e) {
 
 ....}
 
 }
 
 }
 
 
 }
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.04523 seconds