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 |
Rui Domingues 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 #1005401 is a reply to message #1005182] |
Fri, 25 January 2013 09:30 |
Rui Domingues 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;
}
}
|
|
| | | |
Goto Forum:
Current Time: Thu Mar 28 12:32:15 GMT 2024
Powered by FUDForum. Page generated in 0.32271 seconds
|