Search in sources :

Example 1 with ISketchModel

use of com.archimatetool.model.ISketchModel in project archi by archimatetool.

the class TreeModelViewActionFactory method createNewSketchAction.

private IAction createNewSketchAction(final IFolder folder) {
    IAction action = new Action(Messages.TreeModelViewActionFactory_2) {

        @Override
        public void run() {
            // Create a new Diagram Model, set its name
            ISketchModel sketchModel = IArchimateFactory.eINSTANCE.createSketchModel();
            sketchModel.setName(Messages.TreeModelViewActionFactory_3);
            // Defaults
            int defaultBackground = Preferences.STORE.getInt(IPreferenceConstants.SKETCH_DEFAULT_BACKGROUND);
            sketchModel.setBackground(defaultBackground);
            // Execute Command
            Command cmd = new NewDiagramCommand(folder, sketchModel, Messages.TreeModelViewActionFactory_3);
            CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
            commandStack.execute(cmd);
        }
    };
    action.setImageDescriptor(IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_SKETCH));
    return action;
}
Also used : NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) CommandStack(org.eclipse.gef.commands.CommandStack) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) Command(org.eclipse.gef.commands.Command) NewElementCommand(com.archimatetool.editor.views.tree.commands.NewElementCommand) ISketchModel(com.archimatetool.model.ISketchModel)

Example 2 with ISketchModel

use of com.archimatetool.model.ISketchModel in project archi by archimatetool.

the class ArchiLabelProviderTests method testGetLabel.

@Test
public void testGetLabel() {
    // Null object
    assertEquals("", ArchiLabelProvider.INSTANCE.getLabel(null));
    // Any object
    assertEquals("", ArchiLabelProvider.INSTANCE.getLabel(""));
    // Nameable
    INameable nameable = IArchimateFactory.eINSTANCE.createBusinessActor();
    nameable.setName("Hello");
    assertEquals("Hello", ArchiLabelProvider.INSTANCE.getLabel(nameable));
    // View
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    assertEquals("View", ArchiLabelProvider.INSTANCE.getLabel(dm));
    // Sketch
    ISketchModel sm = IArchimateFactory.eINSTANCE.createSketchModel();
    assertEquals("Sketch", ArchiLabelProvider.INSTANCE.getLabel(sm));
    // Image
    IDiagramModelImage di = IArchimateFactory.eINSTANCE.createDiagramModelImage();
    assertEquals("Image", ArchiLabelProvider.INSTANCE.getLabel(di));
}
Also used : INameable(com.archimatetool.model.INameable) IDiagramModelImage(com.archimatetool.model.IDiagramModelImage) ISketchModel(com.archimatetool.model.ISketchModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) Test(org.junit.Test)

Example 3 with ISketchModel

use of com.archimatetool.model.ISketchModel in project archi by archimatetool.

the class SketchEditor method updateBackgroundImage.

public void updateBackgroundImage() {
    ISketchModel model = getModel();
    if (fBackgroundImageLayer == null) {
        fBackgroundImageLayer = new BackgroundImageLayer();
        fScalableFreeformLayeredPane.add(fBackgroundImageLayer, BackgroundImageLayer.NAME, 0);
    }
    switch(model.getBackground()) {
        case 0:
            fBackgroundImageLayer.setImage(null);
            break;
        case 1:
            Image img = IArchiImages.ImageFactory.getImage(IArchiImages.BROWN_PAPER_BACKGROUND);
            fBackgroundImageLayer.setImage(img);
            break;
        case 2:
            img = IArchiImages.ImageFactory.getImage(IArchiImages.CORK_BACKGROUND);
            fBackgroundImageLayer.setImage(img);
            break;
        default:
            break;
    }
}
Also used : Image(org.eclipse.swt.graphics.Image) ISketchModel(com.archimatetool.model.ISketchModel)

Example 4 with ISketchModel

use of com.archimatetool.model.ISketchModel in project archi by archimatetool.

the class EditorManager method openDiagramEditor.

/**
 * Open the Diagram Editor for a given DiagramModel Model
 * @param name
 */
public static IDiagramModelEditor openDiagramEditor(IDiagramModel model) {
    if (model == null || model.eContainer() == null || !PlatformUI.isWorkbenchRunning()) {
        return null;
    }
    String id = null;
    IEditorInput editorInput = null;
    if (model instanceof IArchimateDiagramModel) {
        id = IArchimateDiagramEditor.ID;
        editorInput = new DiagramEditorInput(model);
    } else if (model instanceof ISketchModel) {
        id = ISketchEditor.ID;
        editorInput = new DiagramEditorInput(model);
    } else {
        IDiagramEditorFactory factory = DiagramEditorFactoryExtensionHandler.INSTANCE.getFactory(model);
        if (factory != null) {
            id = factory.getEditorID();
            editorInput = factory.createEditorInput(model);
        }
    }
    if (id == null || editorInput == null) {
        // $NON-NLS-1$
        throw new RuntimeException("Unsupported model type");
    }
    IEditorPart part = openEditor(editorInput, id);
    // Check it actually is IDiagramModelEditor, it could be an org.eclipse.ui.internal.ErrorEditorPart if an error occurs
    return part instanceof IDiagramModelEditor ? (IDiagramModelEditor) part : null;
}
Also used : IDiagramEditorFactory(com.archimatetool.editor.diagram.IDiagramEditorFactory) DiagramEditorInput(com.archimatetool.editor.diagram.DiagramEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IDiagramModelEditor(com.archimatetool.editor.diagram.IDiagramModelEditor) IEditorInput(org.eclipse.ui.IEditorInput) ISketchModel(com.archimatetool.model.ISketchModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 5 with ISketchModel

use of com.archimatetool.model.ISketchModel in project archi by archimatetool.

the class DiagramUtils method createViewer.

/**
 * Create a GraphicalViewerImpl to show the model. The Viewer has no Scroll Bars
 * @param model
 * @return A Graphical Viewer
 */
public static GraphicalViewerImpl createViewer(IDiagramModel model, Composite parent) {
    EditPartFactory editPartFactory = null;
    if (model instanceof IArchimateDiagramModel) {
        editPartFactory = new ArchimateDiagramEditPartFactory();
    } else if (model instanceof ISketchModel) {
        editPartFactory = new SketchEditPartFactory();
    } else {
        // Extensions
        IDiagramEditorFactory factory = DiagramEditorFactoryExtensionHandler.INSTANCE.getFactory(model);
        if (factory != null) {
            editPartFactory = factory.createEditPartFactory();
        }
    }
    if (editPartFactory == null) {
        // $NON-NLS-1$
        throw new RuntimeException("Unsupported model type");
    }
    GraphicalViewerImpl viewer = new GraphicalViewerImpl();
    viewer.createControl(parent);
    viewer.setEditPartFactory(editPartFactory);
    RootEditPart rootPart = new FreeformGraphicalRootEditPart();
    viewer.setRootEditPart(rootPart);
    viewer.setContents(model);
    viewer.flush();
    return viewer;
}
Also used : IDiagramEditorFactory(com.archimatetool.editor.diagram.IDiagramEditorFactory) ArchimateDiagramEditPartFactory(com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory) GraphicalViewerImpl(org.eclipse.gef.ui.parts.GraphicalViewerImpl) SketchEditPartFactory(com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory) SketchEditPartFactory(com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory) EditPartFactory(org.eclipse.gef.EditPartFactory) ArchimateDiagramEditPartFactory(com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart) ISketchModel(com.archimatetool.model.ISketchModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) RootEditPart(org.eclipse.gef.RootEditPart) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)

Aggregations

ISketchModel (com.archimatetool.model.ISketchModel)8 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)4 Test (org.junit.Test)4 IDiagramEditorFactory (com.archimatetool.editor.diagram.IDiagramEditorFactory)2 SketchEditPartFactory (com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory)2 FreeformGraphicalRootEditPart (org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)2 GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)2 DiagramEditorInput (com.archimatetool.editor.diagram.DiagramEditorInput)1 IDiagramModelEditor (com.archimatetool.editor.diagram.IDiagramModelEditor)1 ArchimateDiagramEditPartFactory (com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory)1 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)1 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)1 NewDiagramCommand (com.archimatetool.editor.views.tree.commands.NewDiagramCommand)1 NewElementCommand (com.archimatetool.editor.views.tree.commands.NewElementCommand)1 IDiagramModel (com.archimatetool.model.IDiagramModel)1 IDiagramModelImage (com.archimatetool.model.IDiagramModelImage)1 INameable (com.archimatetool.model.INameable)1 EditPart (org.eclipse.gef.EditPart)1 EditPartFactory (org.eclipse.gef.EditPartFactory)1 RootEditPart (org.eclipse.gef.RootEditPart)1