|
|
Re: Update element after duplicate [message #113200 is a reply to message #112933] |
Tue, 20 March 2007 15:04 |
Eclipse User |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
You can execute a command in the canonical policy. I do something similar
to correct copy pasted connections. Execute a command whenever a certain
event occurs, see code below.
vlad
public class B2CanonicalConnectionEditPolicy extends
CanonicalConnectionEditPolicy {
private static class FixCopyPastedConnectionsCommand extends
AbstractTransactionalCommand {
private List connections;
private static String label = "Fix Copy Pasted Connections Command";
public FixCopyPastedConnectionsCommand(
TransactionalEditingDomain domain, List connections) {
super(domain, label, getWorkspaceFiles(connections));
this.connections = connections;
// TODO Auto-generated constructor stub
}
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {
for (Object c : connections) {
Connection conn = (Connection) c;
End src = conn.getSrc();
End dst = conn.getDst();
if (src.getOutgoingConnections().contains(conn) == false) {
conn.setSrc(null);
conn.setSrc(src);
}
if (dst.getIncomingConnections().contains(conn) == false) {
conn.setDst(null);
conn.setDst(dst);
}
}
return CommandResult.newOKCommandResult();
}
}
......
protected void handleNotificationEvent(Notification event) {
/*
* fix some copy & paste issues
*/
if (event.getFeature().equals(
Bluenose2Package.eINSTANCE.getPipeline_Connections())) {
List connections = null;
if (event.getEventType() == Notification.ADD) {
connections = Collections.singletonList(event.getNewValue());
} else if (event.getEventType() == Notification.ADD_MANY) {
connections = (List) event.getNewValue();
}
if (connections != null) {
TransactionalEditingDomain domain = TransactionUtil
.getEditingDomain(connections.get(0));
AbstractTransactionalCommand command = new FixCopyPastedConnectionsCommand(
domain, connections);
executeCommand(new ICommandProxy(command));
}
}
super.handleNotificationEvent(event);
}
}
On Mon, 19 Mar 2007 20:09:54 +0100, Hugues wrote:
>
>
> Sorry to insist, but is an important subject for me. I just need to
> access the duplicated object just after the duplication, In order to
> modify the new created object updating some attributes (for example : id
> attribute with a unique value).
>
> Anybody can help me ?
>
> Thanks
>
>
>
>
>
>
> Hugues a écrit :
>>
>> Hi all,
>>
>> I want to automatically update element created by duplication.
>>
>> I try to use getDuplication() in XXXEditHelper but this method is call
>> before duplication.
>>
>> Anybody has a solution?
>>
>>
>> Thanks in advance
>>
>>
>> Hugues
|
|
|
|
Re: Update element after duplicate [message #113941 is a reply to message #113200] |
Fri, 23 March 2007 11:38 |
Hugues Rerolle Messages: 16 Registered: July 2009 |
Junior Member |
|
|
Thanks Vlad, it's working.
Hugues
Vlad Ciubotariu a écrit :
> You can execute a command in the canonical policy. I do something similar
> to correct copy pasted connections. Execute a command whenever a certain
> event occurs, see code below.
>
> vlad
>
> public class B2CanonicalConnectionEditPolicy extends
> CanonicalConnectionEditPolicy {
>
> private static class FixCopyPastedConnectionsCommand extends
> AbstractTransactionalCommand {
>
> private List connections;
>
> private static String label = "Fix Copy Pasted Connections Command";
>
> public FixCopyPastedConnectionsCommand(
> TransactionalEditingDomain domain, List connections) {
> super(domain, label, getWorkspaceFiles(connections));
> this.connections = connections;
> // TODO Auto-generated constructor stub
> }
>
> @Override
> protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
> IAdaptable info) throws ExecutionException {
> for (Object c : connections) {
> Connection conn = (Connection) c;
> End src = conn.getSrc();
> End dst = conn.getDst();
>
> if (src.getOutgoingConnections().contains(conn) == false) {
> conn.setSrc(null);
> conn.setSrc(src);
> }
>
> if (dst.getIncomingConnections().contains(conn) == false) {
> conn.setDst(null);
> conn.setDst(dst);
> }
> }
> return CommandResult.newOKCommandResult();
> }
>
> }
> .....
>
> protected void handleNotificationEvent(Notification event) {
> /*
> * fix some copy & paste issues
> */
>
> if (event.getFeature().equals(
> Bluenose2Package.eINSTANCE.getPipeline_Connections())) {
>
> List connections = null;
>
> if (event.getEventType() == Notification.ADD) {
> connections = Collections.singletonList(event.getNewValue());
> } else if (event.getEventType() == Notification.ADD_MANY) {
> connections = (List) event.getNewValue();
> }
>
> if (connections != null) {
> TransactionalEditingDomain domain = TransactionUtil
> .getEditingDomain(connections.get(0));
> AbstractTransactionalCommand command = new FixCopyPastedConnectionsCommand(
> domain, connections);
> executeCommand(new ICommandProxy(command));
> }
>
> }
>
>
> super.handleNotificationEvent(event);
> }
>
> }
>
> On Mon, 19 Mar 2007 20:09:54 +0100, Hugues wrote:
>
>>
>> Sorry to insist, but is an important subject for me. I just need to
>> access the duplicated object just after the duplication, In order to
>> modify the new created object updating some attributes (for example : id
>> attribute with a unique value).
>>
>> Anybody can help me ?
>>
>> Thanks
>>
>>
>>
>>
>>
>>
>> Hugues a écrit :
>>> Hi all,
>>>
>>> I want to automatically update element created by duplication.
>>>
>>> I try to use getDuplication() in XXXEditHelper but this method is call
>>> before duplication.
>>>
>>> Anybody has a solution?
>>>
>>>
>>> Thanks in advance
>>>
>>>
>>> Hugues
>
|
|
|
Powered by
FUDForum. Page generated in 0.04332 seconds