Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Update element after duplicate
Update element after duplicate [message #109490] Wed, 07 March 2007 08:37 Go to next message
Hugues Rerolle is currently offline Hugues RerolleFriend
Messages: 16
Registered: July 2009
Junior Member
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 #112933 is a reply to message #109490] Mon, 19 March 2007 19:09 Go to previous messageGo to next message
Hugues Rerolle is currently offline Hugues RerolleFriend
Messages: 16
Registered: July 2009
Junior Member
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 #113200 is a reply to message #112933] Tue, 20 March 2007 15:04 Go to previous messageGo to next message
Eclipse UserFriend
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 #113538 is a reply to message #112933] Wed, 21 March 2007 17:33 Go to previous messageGo to next message
Cherie Revells is currently offline Cherie RevellsFriend
Messages: 299
Registered: July 2009
Senior Member
Hugues,

I think you can write after advice for the duplicate command to handle
this. See the bottom of the Element Types tutorial here:
http://help.eclipse.org/help32/topic/org.eclipse.gmf.doc/pro g-guide/runtime/Developers%20Guide%20to%20the%20Extensible%2 0Type%20Registry/Developers%20Guide%20to%20the%20Extensible% 20Type%20Registry.html

Regards,
Cherie

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 Go to previous message
Hugues Rerolle is currently offline Hugues RerolleFriend
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
>
Previous Topic:Validation Decoration in RCP
Next Topic:unwanted re-formatting of manually written and of generated code
Goto Forum:
  


Current Time: Thu Dec 26 14:56:19 GMT 2024

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

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

Back to the top