Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » invoke addifpossible after creating diagram is not showing shapes
invoke addifpossible after creating diagram is not showing shapes [message #1001281] Wed, 16 January 2013 11:43 Go to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Hi. After creating diagram and model resources, I open my custom editor. Something like this:
	final Diagram diagram = Graphiti.getPeCreateService().createDiagram(DynamicFormEditor.DIAGRAM_TYPE_ID, diagramURI.trimFileExtension().lastSegment(), false);
		//Create model resource with a form
		URI modelURI = diagramURI.trimFileExtension().appendFileExtension(DFD_MODEL_EXTENSION);
		Resource resourceModel = rset.createResource(modelURI);
		Form form = DynamicformFactory.eINSTANCE.createForm();
		resourceModel.getContents().add(form);
		resourceModel.setTrackingModification(true);
		resourceModel.save(Collections.emptyMap());
		
		
		//Create diagram resource
		Resource resourceDiagram = rset.createResource(diagramURI);
		resourceDiagram.getContents().add(diagram);
		resourceDiagram.setTrackingModification(true);
		resourceDiagram.save(Collections.emptyMap());
		
		//Create custom editor input
		String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
		final DynamicFormDiagramEditorInput editorInput = new DynamicFormDiagramEditorInput( diagramURI, modelURI, resourceDiagram, resourceModel,providerId);
		//Open editor
		if (diagramEditor==null) {
			if (initNotEmpty) {
				openEditor(editorInput, form, diagram);
			} else {
				openEditor(editorInput, null, null);
			}
		}		


However, after opening editor and call addIfpossible nothing is drawn in diagram.
What am I doing wrong?

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
							.openEditor(editorInput, DynamicFormEditor.DIAGRAM_EDITOR_ID);
					if (form!=null && diagram!=null) {
						IFeatureProvider featProvider = editor.getDiagramTypeProvider().getFeatureProvider();
						AddContext context = new AddContext();
						context.setNewObject(form);
						context.setSize(100, 100);
						context.setLocation(0,0);
						context.setTargetContainer(diagram);
						featProvider.addIfPossible(context);
					}


Thanks in advance
Rui
Re: invoke addifpossible after creating diagram is not showing shapes [message #1001785 is a reply to message #1001281] Thu, 17 January 2013 11:17 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Rui,

does your feature provide deliver an AddFeature for your form object? If yes
does the add feature return true on canAdd?

Michael
Re: invoke addifpossible after creating diagram is not showing shapes [message #1001815 is a reply to message #1001785] Thu, 17 January 2013 12:13 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Yes it returns true, and it executes create method, but in diagram nothing happens.

Thanks
Re: invoke addifpossible after creating diagram is not showing shapes [message #1004601 is a reply to message #1001815] Wed, 23 January 2013 14:26 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Any further ideas?
Re: invoke addifpossible after creating diagram is not showing shapes [message #1005182 is a reply to message #1004601] Thu, 24 January 2013 15:40 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Sorry, not really. Can you share the coding of your add feature as well?

Michael
Re: invoke addifpossible after creating diagram is not showing shapes [message #1005401 is a reply to message #1005182] Fri, 25 January 2013 09:30 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Yes, here it is. Thanks again.
public class AddFormFeature extends AbstractAddFeature implements IAddFeature {


	private static final IColorConstant TEXT_FOREGROUND = IColorConstant.WHITE;

	private static final IColorConstant BACKGROUND_HEADER_RED = new ColorConstant(216, 25, 33);	 
	private static final IColorConstant BACKGROUND_HEADER_GRAY = new ColorConstant(231, 232, 233);
	private static final int MINHEIGHT = 300;
	private static final int MINWIDTH = 500;

	public AddFormFeature(IFeatureProvider fp) {
		super(fp);
	}

	@Override
	public boolean canAdd(IAddContext context) {
		if (context.getNewObject() instanceof Form) {
			if (context.getTargetContainer() instanceof Diagram) {
				return true;
			}
		}
		return false;
	}

	@Override
	public PictogramElement add(IAddContext context) {
		Form addedForm = (Form) context.getNewObject();
	
		ContainerShape targetDiagram = context.getTargetContainer();

		// CONTAINER SHAPE WITH ROUNDED RECTANGLE
		IPeCreateService peCreateService = Graphiti.getPeCreateService();
		ContainerShape containerShape =
				peCreateService.createContainerShape(targetDiagram, true);

		IGaService gaService = Graphiti.getGaService();

		int height = Math.max(context.getHeight(), MINHEIGHT);
		int width = Math.max(context.getWidth(), MINWIDTH);

		Rectangle rectangle; // need to access it later
		{
			// create and set graphics algorithm
			rectangle = gaService.createRectangle(containerShape);
			rectangle.setForeground(manageColor(ColorConstant.GRAY));
			rectangle.setBackground(manageColor(ColorConstant.WHITE));
			rectangle.setLineWidth(1);
			rectangle.setLineStyle(LineStyle.DASH);
			gaService.setLocationAndSize(rectangle, 0,  0, width,  height);

			// if added Browser has no resource we add it to the resource 
			// of the diagram
			// in a real scenario the business model would have its own resource
			if (addedForm.eResource() == null) {
				getDiagram().eResource().getContents().add(addedForm);
			}
			// create link and wire it
			link(containerShape, addedForm);
		}
		
		// create and set graphics algorithm
		ContainerShape redHeaderShape =
				peCreateService.createContainerShape(containerShape, false);

		Rectangle redRectangle = gaService.createRectangle(redHeaderShape);
		redRectangle.setForeground(manageColor(BACKGROUND_HEADER_RED));
		redRectangle.setBackground(manageColor(BACKGROUND_HEADER_RED));
		redRectangle.setLineWidth(0);
		redRectangle.setLineVisible(false);
		gaService.setLocationAndSize(redRectangle,
				ConstantUtils.RELATIVE_MARGIN, 
				ConstantUtils.RELATIVE_MARGIN,width-(ConstantUtils.RELATIVE_MARGIN*2), ConstantUtils.Y_LINE_HEADER);
		
		// if added Browser has no resource we add it to the resource 
		// of the diagram
		// in a real scenario the business model would have its own resource
		if (addedForm.eResource() == null) {
			getDiagram().eResource().getContents().add(addedForm);
		}
		// create link and wire it	
		link(redHeaderShape, addedForm);
		PropertiesUtil.setFormRectangleProperty(redRectangle, PropertiesUtil.FORM_RED_HEADER);

		// create and set graphics algorithm
		ContainerShape grayHeaderShape =
				peCreateService.createContainerShape(containerShape, false);

		Rectangle grayRectangle = gaService.createRectangle(grayHeaderShape);
		grayRectangle.setForeground(manageColor(BACKGROUND_HEADER_GRAY));
		grayRectangle.setBackground(manageColor(BACKGROUND_HEADER_GRAY));
		grayRectangle.setLineWidth(0);
		grayRectangle.setLineVisible(false);
		gaService.setLocationAndSize(grayRectangle,
				ConstantUtils.RELATIVE_MARGIN, 
				ConstantUtils.RELATIVE_MARGIN*2+ConstantUtils.Y_LINE_HEADER,width-(ConstantUtils.RELATIVE_MARGIN*2), ConstantUtils.Y_LINE_HEADER);

		if (addedForm.eResource() == null) {
			getDiagram().eResource().getContents().add(addedForm);
		}
		link(grayHeaderShape, addedForm);
		PropertiesUtil.setFormRectangleProperty(grayRectangle, PropertiesUtil.FORM_GRAY_HEADER);


		Font diagFont = gaService.manageDefaultFont(getDiagram());
		// SHAPE WITH TEXT
		{
			Shape shape = peCreateService.createShape(redHeaderShape, false);
			Text text = gaService.createText(shape, Messages.addform_create_form);
			text.setForeground(manageColor(TEXT_FOREGROUND));
			text.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT ); 
			text.setLineVisible(false);
			text.setBackground(manageColor(IColorConstant.RED));
			text.setFont(gaService.manageFont(getDiagram(), diagFont.getName(), utils.ConstantUtils.FONT_SIZE, false, false));
			gaService.setLocationAndSize(text, ConstantUtils.RELATIVE_MARGIN, 0, width, ConstantUtils.Y_LINE_HEADER);

		}
		
		{
			Shape shape = peCreateService.createShape(grayHeaderShape, false);
			Text text = gaService.createText(shape, Messages.addform_preview_form);
			text.setForeground(manageColor(ColorConstant.BLACK));
			text.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT ); 
			text.setLineVisible(false);
			text.setFont(gaService.manageFont(getDiagram(), diagFont.getName(), utils.ConstantUtils.FONT_SIZE, false, false));

			gaService.setLocationAndSize(text, ConstantUtils.RELATIVE_MARGIN, 0, width, ConstantUtils.Y_LINE_HEADER);

		}
		//layoutPictogramElement(containerShape);
		return containerShape;
	}
}



Re: invoke addifpossible after creating diagram is not showing shapes [message #1005465 is a reply to message #1005401] Fri, 25 January 2013 14:39 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Rui,

it seems as if there are two instances of diagram involved here: one you are
adding to and one that's shown inside the editor. You should open the editor
using a diagram URL only, the editor itself is resposnible for loading the
diagram using its own editing domain.

Michael
Re: invoke addifpossible after creating diagram is not showing shapes [message #1005476 is a reply to message #1005465] Fri, 25 January 2013 15:37 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Thanks for your time.


If I use URL how can tell my editor that input is my IeditorInput implementation?
Sorry there's something missin to me to put this together.

I suppose you are also talking about using IDE.openEditor instead of
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor

Rui
Re: invoke addifpossible after creating diagram is not showing shapes [message #1005710 is a reply to message #1005476] Mon, 28 January 2013 11:15 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
The open editor method does take an IEditorInput parameter, you would just
need to pass your instance holding the url there.

Michael
Previous Topic:Providing a correct MoveShapeFeature
Next Topic:Accessing the modified objects after feature is executed
Goto Forum:
  


Current Time: Mon Dec 22 15:40:26 GMT 2014

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

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