Where to change attributes from code? [message #161006] |
Fri, 16 November 2007 17:53 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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 #161100 is a reply to message #161006] |
Sun, 18 November 2007 18:01 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: martin.tauber.t-online.de
Hi Malte,
what do you mean by you would like to change attrbutes of your model out
of your program ...
Regards
Martin
Malte Koelling wrote:
> 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 #161876 is a reply to message #161100] |
Wed, 21 November 2007 16:06 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: malte.koelling.udo.edu
Hello Martin
thank you for your reply. I am sorry for my poor first mail, as it didnt
provide the needed information, I can see this now, so much more thinks
for answering. I solved the problem by myself and modifed one of the given
solution from here.
The code can be found below for anyone else who has the same problem. But
I have one more question. The attribute index of type int of the model
Task is now changed automatically after creation. But the next constrained
is that it must not happen that a nummber misses between a lower and a
higer number. For example, there are:
Task Task Task
1001 1002 1003
If the Task in the middle is deleted the index number 1003 should change
to 1002. How can I achieve that?
Regards
Malte
Source Code for Solution
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import
org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElem entCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequ est;
import zwei.Model;
import zwei.Task;
/**
* @generated NOT
*/
public class TaskEditHelper extends ZweiBaseEditHelper {
@Override
protected ICommand getConfigureCommand(ConfigureRequest req) {
final Task t = (Task) req.getElementToConfigure();
t.setIndex(33);
Model m = (Model) req.getEditingDomain().getParent(t);
int index = m.getTasks().size();
int nindex = 0;
if (index == 1) {
nindex = 1001;
} else {
List tasks = (List) m.getTasks();
Iterator it = tasks.iterator();
int indicies[] = new int[tasks.size() - 1];
int i = 0;
while (it.hasNext() && indicies.length > i) {
indicies[i] = ((Task) it.next()).getIndex();
i++;
}
java.util.Arrays.sort(indicies);
if (indicies[0] != 1001) {
nindex = 1001;
} else {
nindex = 1000 + index;
for (i = 0; i < index - 2; i++) {
if (indicies[i + 1] - indicies[i] > 1) {
nindex = indicies[i] + 1;
break;
}
}
}
}
t.setIndex(nindex);
ConfigureElementCommand operation = new ConfigureElementCommand(req) {
@Override
protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
return null;
}
};
return operation;
}
}
|
|
|
Re: Where to change attributes from code? [message #162576 is a reply to message #161876] |
Sun, 25 November 2007 02:42 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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.04505 seconds