Multiple view for the same semantic model [message #521723] |
Thu, 18 March 2010 11:14  |
Eclipse User |
|
|
|
Hi everybody,
I am trying to create multiple view (on the same diagram) for the same semantic model.
On GMF tips website, we have "Creating New Elements And Corresponding Views ", but this is to create a new view + semantic model at the same time. I already have a semantic model (EObject) and its notation view on the diagram. I want to create one more notation view on the same diagram. Any ideas how to do it ?
Thanks very much in advance !!!!
|
|
|
|
|
|
|
|
|
|
Re: Multiple view for the same semantic model [message #522743 is a reply to message #522675] |
Tue, 23 March 2010 15:35   |
Eclipse User |
|
|
|
According to related documentation:
"This edit policy handles double click (open) gestures on shapes. When
the user double clicks on an edit part, GEF creates a REQ_OPEN request
and subclasses of this edit policy should handle that request. This
policy should be installed with the policy role OPEN_ROLE. Normally, the
corresponding edit policy role would be defined in EditPolicy, but no
such role currently exists."
I guess you know what you are doing. See below. You will probably have
to adapt the code presented since I never used this policy and I don't
know which kind of request is sent to controller.
Le 23/03/2010 16:04, cuong a écrit :
> Hi Ali,
>
> Thanks for replying. Based on your suggestion I create a new edit policy
> ActorDuplicateViewPolicy which extends OpenEditPolicy
>
> public class ActorDuplicateViewPolicy extends OpenEditPolicy{
>
> @Override
> protected Command getOpenCommand(Request request) {
//retrieve the view targeted by the request
Object element = request.getObjects().get(0);
List<CreateViewRequest.ViewDescriptor> descriptors =
new ArrayList<CreateViewRequest.ViewDescriptor>();
CreateViewRequest.ViewDescriptor viewDescriptor =
new CreateViewRequest.ViewDescriptor(
new EObjectAdapter((EObject) element),
Node.class,
((IHintedType)
XXXElementTypes.getElementType(XXXEditPart.VISUAL_ID)).getSe manticHint(),
getDiagramPreferencesHint());
viewDescriptor.setPersisted(true);
descriptors.add(viewDescriptor);
Command res = null;
if (!descriptors.isEmpty()) {
res = createViews(request, descriptors);
}
if (res == null)
return UnexecutableCommand.INSTANCE;
return res;
> }
private Command createViews(
Request request, List<CreateViewRequest.ViewDescriptor> viewDescriptors)
{
CreateViewRequest createViewRequest =
new CreateViewRequest(viewDescriptors);
//FIXME: set location of new view next to current location
createViewRequest.setLocation(request.getLocation());
Command createCommand = getHost().getCommand(createViewRequest);
if (createCommand != null) {
List result = (List) createViewRequest.getNewObject();
dropRequest.setResult(result);
ArrangeRequest arrangeRequest = new ArrangeRequest(
RequestConstants.REQ_ARRANGE_DEFERRED);
arrangeRequest.setViewAdaptersToArrange(result);
createCommand.chain(getHost().getCommand(arrangeRequest));
}
return createCommand;
}
private View getHostView() {
return (View) (getHost().getModel());
}
private PreferencesHint getDiagramPreferencesHint() {
return ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint();
}
Hope it will help.
Cheers.
>
> }
>
> My idea is to double click on an Actor to duplicate them on the diagram
> view. So inside getOpenCommand function, I use CreateCommand to create a
> new view for Actor. But I have no idea how to create a correct
> viewDescriptor. Or maybe CreateCommand is not the right command to
> duplicate a view ?
> Waiting for your reply :)...
>
>
|
|
|
Re: Multiple view for the same semantic model [message #522744 is a reply to message #522743] |
Tue, 23 March 2010 15:39  |
Eclipse User |
|
|
|
Le 23/03/2010 20:35, exquisitus a écrit :
> According to related documentation:
>
> "This edit policy handles double click (open) gestures on shapes. When
> the user double clicks on an edit part, GEF creates a REQ_OPEN request
> and subclasses of this edit policy should handle that request. This
> policy should be installed with the policy role OPEN_ROLE. Normally, the
> corresponding edit policy role would be defined in EditPolicy, but no
> such role currently exists."
>
> I guess you know what you are doing. See below. You will probably have
> to adapt the code presented since I never used this policy and I don't
> know which kind of request is sent to controller.
>
> Le 23/03/2010 16:04, cuong a écrit :
>> Hi Ali,
>>
>> Thanks for replying. Based on your suggestion I create a new edit policy
>> ActorDuplicateViewPolicy which extends OpenEditPolicy
>>
>> public class ActorDuplicateViewPolicy extends OpenEditPolicy{
>>
>> @Override
>> protected Command getOpenCommand(Request request) {
> //retrieve the view targeted by the request
> Object element = request.getObjects().get(0);
> List<CreateViewRequest.ViewDescriptor> descriptors =
> new ArrayList<CreateViewRequest.ViewDescriptor>();
> CreateViewRequest.ViewDescriptor viewDescriptor =
> new CreateViewRequest.ViewDescriptor(
> new EObjectAdapter((EObject) element),
> Node.class,
> ((IHintedType)
> XXXElementTypes.getElementType(XXXEditPart.VISUAL_ID)).getSe manticHint(), getDiagramPreferencesHint());
>
> viewDescriptor.setPersisted(true);
> descriptors.add(viewDescriptor);
> Command res = null;
> if (!descriptors.isEmpty()) {
> res = createViews(request, descriptors);
> }
> if (res == null)
> return UnexecutableCommand.INSTANCE;
> return res;
>
>> }
>
> private Command createViews(
> Request request, List<CreateViewRequest.ViewDescriptor> viewDescriptors)
> {
> CreateViewRequest createViewRequest =
> new CreateViewRequest(viewDescriptors);
> //FIXME: set location of new view next to current location
> createViewRequest.setLocation(request.getLocation());
> Command createCommand = getHost().getCommand(createViewRequest);
> if (createCommand != null) {
> List result = (List) createViewRequest.getNewObject();
> dropRequest.setResult(result);
sorry: request.setResult(result); (this method has been adapted from my
DnD policy)
> ArrangeRequest arrangeRequest = new ArrangeRequest(
> RequestConstants.REQ_ARRANGE_DEFERRED);
> arrangeRequest.setViewAdaptersToArrange(result);
> createCommand.chain(getHost().getCommand(arrangeRequest));
> }
> return createCommand;
> }
>
> private View getHostView() {
> return (View) (getHost().getModel());
> }
>
> private PreferencesHint getDiagramPreferencesHint() {
> return ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint();
> }
>
> Hope it will help.
> Cheers.
>
>>
>> }
>>
>> My idea is to double click on an Actor to duplicate them on the diagram
>> view. So inside getOpenCommand function, I use CreateCommand to create a
>> new view for Actor. But I have no idea how to create a correct
>> viewDescriptor. Or maybe CreateCommand is not the right command to
>> duplicate a view ?
>> Waiting for your reply :)...
>>
>>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04740 seconds