Search in sources :

Example 1 with IDiagramModelObjectFigure

use of com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure in project archi by archimatetool.

the class AbstractBaseEditPart method createFigure.

@Override
protected IFigure createFigure() {
    /*
         * Create a Figure from the given class
         */
    IDiagramModelObjectFigure figure = null;
    if (figureClass != null) {
        try {
            figure = (IDiagramModelObjectFigure) figureClass.newInstance();
            figure.setDiagramModelObject(getModel());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return figure;
}
Also used : IDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure)

Example 2 with IDiagramModelObjectFigure

use of com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure in project archi by archimatetool.

the class DefaultEditPartSizeAction method createDefaultSizeCommand.

private Command createDefaultSizeCommand(List<?> objects) {
    CompoundCommand command = new CompoundCommand();
    for (Object object : objects) {
        if (object instanceof GraphicalEditPart) {
            GraphicalEditPart part = (GraphicalEditPart) object;
            if (part.getModel() instanceof IDiagramModelObject) {
                IDiagramModelObject model = (IDiagramModelObject) part.getModel();
                if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                    continue;
                }
                IFigure figure = part.getFigure();
                if (figure instanceof IDiagramModelObjectFigure) {
                    Dimension defaultSize = ((IDiagramModelObjectFigure) figure).getDefaultSize();
                    IBounds bounds = model.getBounds().getCopy();
                    if (bounds.getWidth() != defaultSize.width || bounds.getHeight() != defaultSize.height) {
                        bounds.setWidth(defaultSize.width);
                        bounds.setHeight(defaultSize.height);
                        Command cmd = new SetConstraintObjectCommand(model, bounds);
                        command.add(cmd);
                    }
                }
            }
        }
    }
    return command.unwrap();
}
Also used : SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IBounds(com.archimatetool.model.IBounds) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure) Dimension(org.eclipse.draw2d.geometry.Dimension) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable) IFigure(org.eclipse.draw2d.IFigure)

Example 3 with IDiagramModelObjectFigure

use of com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure in project archi by archimatetool.

the class FigureImagePreviewFactory method getPreviewImage.

private static Image getPreviewImage(IArchimateElementUIProvider provider, int type) {
    EClass eClass = provider.providerFor();
    String key = eClass.getName() + type;
    Image image = imageRegistry.get(key);
    if (image == null) {
        IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
        dmo.setArchimateElement((IArchimateElement) IArchimateFactory.eINSTANCE.create(eClass));
        dmo.setName(provider.getDefaultName());
        dmo.setTextPosition(ITextPosition.TEXT_POSITION_TOP);
        ColorFactory.setDefaultColors(dmo);
        dmo.setType(type);
        provider.setInstance(dmo);
        GraphicalEditPart editPart = (GraphicalEditPart) provider.createEditPart();
        editPart.setModel(dmo);
        IDiagramModelObjectFigure figure = (IDiagramModelObjectFigure) editPart.getFigure();
        figure.setSize(provider.getDefaultSize());
        figure.refreshVisuals();
        figure.validate();
        image = DiagramUtils.createImage(figure, 1, 0);
        imageRegistry.put(key, image);
    }
    return image;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure) Image(org.eclipse.swt.graphics.Image) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart)

Aggregations

IDiagramModelObjectFigure (com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure)3 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 SetConstraintObjectCommand (com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand)1 IBounds (com.archimatetool.model.IBounds)1 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)1 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)1 ILockable (com.archimatetool.model.ILockable)1 IFigure (org.eclipse.draw2d.IFigure)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 EClass (org.eclipse.emf.ecore.EClass)1 Command (org.eclipse.gef.commands.Command)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 Image (org.eclipse.swt.graphics.Image)1