Home » Modeling » Graphiti » Select pictogram element in editor on add
Select pictogram element in editor on add [message #1842255] |
Mon, 14 June 2021 14:59  |
Eclipse User |
|
|
|
When I add PE form palette, it's not being selected. This is not behavior I am seeing in tutorial examples where when Class is created, it's selected in the editor - source.
Is there anything I need to define in order for PE to be selected when it's created?
This is my add() method:
@Override
public PictogramElement add(IAddContext context) {
IPeCreateService peCreateService = Graphiti.getPeCreateService();
IGaService gaService = Graphiti.getGaService();
ObjectType object = (ObjectType) context.getNewObject();
Font font = gaService.manageFont(getDiagram(), "Arial", 9);
IDimension dimensions = GraphitiUtil.calculateContainerWidth(object.getName(), font);
int containerWidth = calculateContainerWidth(dimensions);
// main container
ContainerShape containerShape = createMainContainer(context);
// rounded rectangle
createRoundedRectangle(context, gaService, containerWidth, containerShape);
// icon
createObjectIcon(peCreateService, gaService, object, containerWidth, containerShape);
IwayType root = ((DesignerDiagramBehavior)getDiagramBehavior()).getModelRoot();
root.getServer().getProcessflow().getObjects().getObject().add(object);
final ChopboxAnchor newAnchor = peCreateService.createChopboxAnchor(containerShape);
link(containerShape, object);
// line
createHorizontalLine(peCreateService, gaService, containerWidth, containerShape);
// label
createObjectLabel(peCreateService, gaService, object, font, containerWidth, containerShape);
int width = context.getWidth() < MIN_SIZE ? MIN_SIZE : context.getWidth();
int height = context.getHeight() < MIN_SIZE ? MIN_SIZE : context.getHeight();
final Connection targetConnection = context.getTargetConnection();
if (targetConnection != null) {
gaService.setLocation(containerShape.getGraphicsAlgorithm(), context.getX() - (width / 2),
context.getY() - (height / 2));
Anchor oldEndAnchor = targetConnection.getEnd();
Anchor oldStartAnchor = targetConnection.getStart();
targetConnection.setEnd(newAnchor);
createConnection(peCreateService, gaService, oldStartAnchor, targetConnection, newAnchor, true);
createConnection(peCreateService, gaService, newAnchor, targetConnection, oldEndAnchor, false);
}
gaService.manageFont(getDiagram(), IGaService.DEFAULT_FONT, IGaService.DEFAULT_FONT_SIZE, true, false);
// trigger object add event
try {
if (ModelHelper.isAdapterObject(object.getType())) {
DesignerDiagramBehavior designerDiagramBehavior = (DesignerDiagramBehavior)getDiagramBehavior();
LocalDescriptorProvider localDescriptorProvider = designerDiagramBehavior.getLocalDescriptorProvider();
com.ibi.configsm.xml.server.ObjectTypeDocument.ObjectType[] flowObjectCategory = localDescriptorProvider.getObjectTypes(object.getType());
if(flowObjectCategory.length > 0){
com.ibi.configsm.xml.server.ObjectTypeDocument.ObjectType beanObjectType = flowObjectCategory[0];
ComponentDescriptor serviceDescriptor = localDescriptorProvider.findServiceDescriptor(beanObjectType);
designerDiagramBehavior.getEventBus().post(new ObjectActionChangeEvent(null, serviceDescriptor));
}
}
} catch (CoreServicesException e) {
DesignerUIPlugin.getDefault().logError(e.getLocalizedMessage(), e);
}
DiagramEditor editor = (DiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
editor.setPictogramElementForSelection(containerShape);
layoutPictogramElement(containerShape);
return containerShape;
}
Thanks,
Alex
|
|
|
Re: Select pictogram element in editor on add [message #1842290 is a reply to message #1842255] |
Tue, 15 June 2021 14:44   |
Eclipse User |
|
|
|
Alex,
setting the editor selection from within the add feature should not be required. The graphical element you return in the add feature is used in DiagramBehavior.executeFeature() to select it. The only thing that I could think that prevents this, is the method getSelectionBorder() in the tool behavior provider that can be used to adapt the selected shape.
- Michael
|
|
| | |
Goto Forum:
Current Time: Mon Feb 10 04:58:30 GMT 2025
Powered by FUDForum. Page generated in 0.05214 seconds
|