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);
}
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();
}
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();
}
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;
}
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();
}
Aggregations