use of com.archimatetool.templates.wizard.ModelViewsTreeViewer 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