Search in sources :

Example 41 with IDiagramModel

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

the class DiagramUtilsTests method testGetDiagramExtents.

@Test
public void testGetDiagramExtents() {
    IDiagramModel dm = model.getDiagramModels().get(2);
    // x of furthest object in diagram, and its width
    int width = 720 + 193;
    // x of furthest object in diagram, and its height
    int height = 468 + 85;
    Shell shell = new Shell();
    GraphicalViewerImpl viewer = DiagramUtils.createViewer(dm, shell);
    shell.dispose();
    org.eclipse.draw2d.geometry.Rectangle rect = DiagramUtils.getDiagramExtents(viewer);
    assertEquals(new org.eclipse.draw2d.geometry.Rectangle(0, 0, width, height), rect);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IDiagramModel(com.archimatetool.model.IDiagramModel) GraphicalViewerImpl(org.eclipse.gef.ui.parts.GraphicalViewerImpl) Test(org.junit.Test)

Example 42 with IDiagramModel

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

the class DiagramUtilsTests method testCreateViewer_ArchimateModel.

@Test
public void testCreateViewer_ArchimateModel() {
    IDiagramModel dm = model.getDiagramModels().get(0);
    assertTrue(dm instanceof IArchimateDiagramModel);
    Shell shell = new Shell();
    GraphicalViewerImpl viewer = DiagramUtils.createViewer(dm, shell);
    assertNotNull(viewer);
    assertTrue(viewer.getEditPartFactory() instanceof ArchimateDiagramEditPartFactory);
    assertTrue(viewer.getRootEditPart() instanceof FreeformGraphicalRootEditPart);
    assertSame(dm, viewer.getContents().getModel());
    assertSame(shell, viewer.getControl().getShell());
    shell.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ArchimateDiagramEditPartFactory(com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory) IDiagramModel(com.archimatetool.model.IDiagramModel) GraphicalViewerImpl(org.eclipse.gef.ui.parts.GraphicalViewerImpl) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) Test(org.junit.Test)

Example 43 with IDiagramModel

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

the class DiagramUtilsTests method testCreateImage_Model_NoChildren_Scaled.

@Test
public void testCreateImage_Model_NoChildren_Scaled() {
    IDiagramModel dm = model.getDiagramModels().get(0);
    // Blank View is minimum 100 x 100
    Image img = DiagramUtils.createImage(dm, 1, 0);
    assertEquals(new Rectangle(0, 0, 100, 100), img.getBounds());
    img.dispose();
    img = DiagramUtils.createImage(dm, 2, 0);
    assertEquals(new Rectangle(0, 0, 200, 200), img.getBounds());
    img.dispose();
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) Test(org.junit.Test)

Example 44 with IDiagramModel

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

the class MyImporter method createAndAddView.

protected IDiagramModel createAndAddView(IArchimateModel model, String name, String id) {
    IDiagramModel diagramModel = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    diagramModel.setName(name);
    diagramModel.setId(id);
    IFolder folder = model.getDefaultFolderForObject(diagramModel);
    folder.getElements().add(diagramModel);
    idLookup.put(diagramModel.getId(), diagramModel);
    return diagramModel;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IFolder(com.archimatetool.model.IFolder)

Example 45 with IDiagramModel

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

the class SaveArchimateModelAsTemplateWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    GridData gd;
    Label label;
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout());
    setControl(container);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID);
    Group fileComposite = new Group(container, SWT.NULL);
    fileComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout layout = new GridLayout(3, false);
    fileComposite.setLayout(layout);
    label = new Label(fileComposite, SWT.NULL);
    label.setText(Messages.SaveArchimateModelAsTemplateWizardPage_4);
    fFileTextField = new Text(fileComposite, SWT.BORDER | SWT.SINGLE);
    fFileTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    File newFile = new File(CURRENT_FOLDER, Messages.SaveArchimateModelAsTemplateWizardPage_5 + ArchimateTemplateManager.ARCHIMATE_TEMPLATE_FILE_EXTENSION);
    fFileTextField.setText(newFile.getPath());
    // Single text control so strip CRLFs
    UIUtils.conformSingleTextControl(fFileTextField);
    fFileTextField.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            validateFields();
        }
    });
    Button fileButton = new Button(fileComposite, SWT.PUSH);
    fileButton.setText(Messages.SaveArchimateModelAsTemplateWizardPage_6);
    fileButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            File file = chooseFile();
            if (file != null) {
                fFileTextField.setText(file.getPath());
                CURRENT_FOLDER = file.getParentFile();
            }
        }
    });
    Group fieldGroup = new Group(container, SWT.NULL);
    fieldGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    layout = new GridLayout(2, false);
    fieldGroup.setLayout(layout);
    label = new Label(fieldGroup, SWT.NULL);
    label.setText(Messages.SaveArchimateModelAsTemplateWizardPage_7);
    fNameTextField = new Text(fieldGroup, SWT.BORDER | SWT.SINGLE);
    fNameTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (StringUtils.isSet(fModel.getName())) {
        fNameTextField.setText(fModel.getName());
    }
    // Single text control so strip CRLFs
    UIUtils.conformSingleTextControl(fNameTextField);
    fNameTextField.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            validateFields();
        }
    });
    label = new Label(fieldGroup, SWT.NULL);
    label.setText(Messages.SaveArchimateModelAsTemplateWizardPage_8);
    gd = new GridData(SWT.NULL, SWT.TOP, false, false);
    label.setLayoutData(gd);
    fDescriptionTextField = new Text(fieldGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 120;
    // Stop overstretch
    gd.widthHint = 550;
    fDescriptionTextField.setLayoutData(gd);
    if (StringUtils.isSet(fModel.getPurpose())) {
        fDescriptionTextField.setText(fModel.getPurpose());
    }
    // Thumbnails
    boolean thumbsEnabled = !fModel.getDiagramModels().isEmpty();
    Group thumbsGroup = new Group(container, SWT.NULL);
    thumbsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    layout = new GridLayout();
    thumbsGroup.setLayout(layout);
    fButtonIncludeThumbs = new Button(thumbsGroup, SWT.CHECK);
    fButtonIncludeThumbs.setText(Messages.SaveArchimateModelAsTemplateWizardPage_9);
    fButtonIncludeThumbs.setSelection(thumbsEnabled);
    fButtonIncludeThumbs.setEnabled(thumbsEnabled);
    fButtonIncludeThumbs.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fModelViewsTreeViewer.getControl().setEnabled(fButtonIncludeThumbs.getSelection());
            fPreviewLabel.setEnabled(fButtonIncludeThumbs.getSelection());
        }
    });
    label = new Label(thumbsGroup, SWT.NULL);
    label.setText(Messages.SaveArchimateModelAsTemplateWizardPage_10);
    label.setEnabled(thumbsEnabled);
    Composite thumbContainer = new Composite(thumbsGroup, SWT.NULL);
    thumbContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
    layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    thumbContainer.setLayout(layout);
    fModelViewsTreeViewer = new ModelViewsTreeViewer(thumbContainer, SWT.NONE);
    fModelViewsTreeViewer.setInput(fModel.getFolder(FolderType.DIAGRAMS));
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 120;
    // gd.widthHint = 140;
    fModelViewsTreeViewer.getControl().setLayoutData(gd);
    fModelViewsTreeViewer.getControl().setEnabled(thumbsEnabled);
    fPreviewLabel = new Label(thumbContainer, SWT.BORDER);
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 120;
    gd.widthHint = 150;
    fPreviewLabel.setLayoutData(gd);
    // Dispose of the image here not in the main dispose() method because if the help system is showing then
    // the TrayDialog is resized and this label is asked to relayout.
    fPreviewLabel.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            disposePreviewImage();
        }
    });
    fModelViewsTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            disposePreviewImage();
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (o instanceof IDiagramModel) {
                TemplateUtils.createThumbnailPreviewImage((IDiagramModel) o, fPreviewLabel);
            } else {
                fPreviewLabel.setImage(null);
            }
        }
    });
    // Select first Template item on tree (on a thread so that thumbnail preview is right size)
    fModelViewsTreeViewer.expandAll();
    Display.getCurrent().asyncExec(new Runnable() {

        @Override
        public void run() {
            for (TreeItem item : fModelViewsTreeViewer.getTree().getItems()) {
                Object o = item.getData();
                if (o instanceof IDiagramModel) {
                    fModelViewsTreeViewer.setSelection(new StructuredSelection(o));
                    break;
                }
            }
        }
    });
    validateFields();
}
Also used : Group(org.eclipse.swt.widgets.Group) DisposeListener(org.eclipse.swt.events.DisposeListener) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Text(org.eclipse.swt.widgets.Text) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ModelViewsTreeViewer(com.archimatetool.templates.wizard.ModelViewsTreeViewer) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) IDiagramModel(com.archimatetool.model.IDiagramModel) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) File(java.io.File)

Aggregations

IDiagramModel (com.archimatetool.model.IDiagramModel)68 Test (org.junit.Test)28 IArchimateElement (com.archimatetool.model.IArchimateElement)16 IArchimateModel (com.archimatetool.model.IArchimateModel)12 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)12 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)11 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)9 File (java.io.File)8 EObject (org.eclipse.emf.ecore.EObject)8 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)8 Image (org.eclipse.swt.graphics.Image)8 IArchimateConcept (com.archimatetool.model.IArchimateConcept)7 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)7 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)6 Command (org.eclipse.gef.commands.Command)6 GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)6 Shell (org.eclipse.swt.widgets.Shell)6