Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
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 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1927
Registered: July 2009
Location: Walldorf, Germany
Senior Member
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
Re: Select pictogram element in editor on add [message #1842336 is a reply to message #1842290] Wed, 16 June 2021 16:43 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
Or do you override IToolBehaviorProvider.getSelections method and somehow unselect shape?
Re: Select pictogram element in editor on add [message #1843226 is a reply to message #1842255] Tue, 20 July 2021 18:27 Go to previous message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
I don't select border in tool behavior, nor do I override getSelection(), to see if my implementation of tool behavior is at fault, I removed reference to it, but still see the same behavior.
Previous Topic:Image doesn't load in editor
Goto Forum:
  


Current Time: Wed Dec 01 22:27:56 GMT 2021

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

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

Back to the top