[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: how can I set the location of the view in the editor without opening it?

HI ;
	Check the SetBoundsCommand; it should give you an idea on how to do it

bobywolf wrote:
I use copyToImageUtil to add a view to diagram file without opening the file, and it works, but I can not set the location of the view in the editor without opening the editor, how can I set the location of the view in the editor without opening it?

((Diagram)objs[0]).insertChild(view); //add the view to the diagram file without opening it

==============the completed code I used:

final Resource modelResource = resourceSet.getResource(
        URI.createPlatformResourceURI(resourcePath
          .toString()), true);
      if(modelResource instanceof XMIResourceImpl){
       Object[] objs = getElements(modelResource);
EObjectAdapter objAdapter = new EObjectAdapter(data);

CopyToImageUtil copyToImageUtil = new CopyToImageUtil();
diagramEditPart = copyToImageUtil.createDiagramEditPart((Diagram) objs[0],shell,NewpmbeDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
}


CreateViewRequest.ViewDescriptor viewDescriptor = new CreateViewRequest.ViewDescriptor(
objAdapter, Node.class, null,
NewpmbeDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);



if(subDiagramEditPart != null){ //ÊÇsubDiagramµÄcmd¾ÍÔÚsubDiagramÖд´½¨£¬ÕâÊÇÔÚÄÄ´´½¨µÄΨһ±ê×¼£¡

CreateCommand command = new CreateCommand((TransactionalEditingDomain) myEditingDomain, viewDescriptor, (View)subDiagramEditPart.getModel()) {

protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
CommandResult result = super.doExecuteWithResult(monitor, info);
View view = (View) ((IAdaptable) result.getReturnValue())
.getAdapter(View.class);
Object[] objs = getElements(modelResource);
((Diagram)objs[0]).insertChild(view); //add the view to the diagram file without opening it
if( modelResource != null)
try {
modelResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}


};
try {
OperationHistoryFactory.getOperationHistory().execute(command,
new NullProgressMonitor(), null);
} catch (ExecutionException e) {
NewpmbeDiagramEditorPlugin.getInstance().logError(
"Unable to create shortcut", e); //$NON-NLS-1$
}
}