Search in sources :

Example 1 with ModelViewsTreeViewer

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();
}
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)1 ModelViewsTreeViewer (com.archimatetool.templates.wizard.ModelViewsTreeViewer)1 File (java.io.File)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1