Search in sources :

Example 1 with ITemplateGroup

use of com.archimatetool.templates.model.ITemplateGroup in project archi by archimatetool.

the class TemplateManagerDialog method newGroup.

/**
 * Add a new group
 */
protected void newGroup() {
    IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String newText) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return "".equals(newText) ? "" : hasGroup(newText) ? Messages.TemplateManagerDialog_21 : null;
        }

        boolean hasGroup(String name) {
            for (ITemplateGroup group : fTemplateManager.getUserTemplateGroups()) {
                if (name.equals(group.getName())) {
                    return true;
                }
            }
            return false;
        }
    };
    InputDialog dialog = new InputDialog(getShell(), Messages.TemplateManagerDialog_22, Messages.TemplateManagerDialog_23, // $NON-NLS-1$
    "", validator);
    if (dialog.open() == Window.OK) {
        String name = dialog.getValue();
        if (StringUtils.isSetAfterTrim(name)) {
            ITemplateGroup group = new TemplateGroup(name);
            fTemplateManager.getUserTemplateGroups().add(group);
            fTreeViewer.refresh();
            fTreeViewer.setSelection(new StructuredSelection(group), true);
        }
    }
}
Also used : ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) InputDialog(org.eclipse.jface.dialogs.InputDialog) TemplateGroup(com.archimatetool.templates.model.TemplateGroup) ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 2 with ITemplateGroup

use of com.archimatetool.templates.model.ITemplateGroup in project archi by archimatetool.

the class TemplateManagerDialogDragDropHandler method isValidDropTarget.

/**
 * @return True if target is valid
 */
private boolean isValidDropTarget(DropTargetEvent event) {
    Object parent = getTargetParent(event);
    if (parent instanceof ITemplateGroup) {
        ITemplateGroup targetGroup = (ITemplateGroup) parent;
        IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
        for (Object object : selection.toList()) {
            if (targetGroup.getTemplates().contains(object)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with ITemplateGroup

use of com.archimatetool.templates.model.ITemplateGroup in project archi by archimatetool.

the class SaveModelAsTemplateToCollectionWizardPage 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, getHelpID());
    fDoStoreInCollectionButton = new Button(container, SWT.CHECK);
    fDoStoreInCollectionButton.setText(Messages.SaveModelAsTemplateToCollectionWizardPage_0);
    fDoStoreInCollectionButton.setSelection(true);
    fDoStoreInCollectionButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean enabled = fDoStoreInCollectionButton.getSelection();
            fCategoriesTableViewer.getControl().setEnabled(enabled);
            fNewGroupButton.setEnabled(enabled);
            // Select first group, or none
            if (enabled) {
                Object o = fCategoriesTableViewer.getElementAt(0);
                if (o != null) {
                    fCategoriesTableViewer.setSelection(new StructuredSelection(o));
                }
            } else {
                fCategoriesTableViewer.setSelection(new StructuredSelection());
            }
        }
    });
    label = new Label(container, SWT.NULL);
    label.setText(Messages.SaveModelAsTemplateToCollectionWizardPage_1);
    Composite fieldContainer = new Composite(container, SWT.NULL);
    fieldContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    fieldContainer.setLayout(layout);
    Composite tableComp = new Composite(fieldContainer, SWT.NULL);
    tableComp.setLayout(new TableColumnLayout());
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 120;
    tableComp.setLayoutData(gd);
    fCategoriesTableViewer = new TemplateGroupsTableViewer(tableComp, SWT.BORDER | SWT.MULTI);
    fCategoriesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            fSelectedTemplateGroup = (ITemplateGroup) ((IStructuredSelection) event.getSelection()).getFirstElement();
        }
    });
    fCategoriesTableViewer.setInput(fTemplateManager.getUserTemplateGroups());
    fNewGroupButton = new Button(fieldContainer, SWT.NULL);
    fNewGroupButton.setText(Messages.SaveModelAsTemplateToCollectionWizardPage_2);
    gd = new GridData(SWT.TOP, SWT.TOP, false, false);
    fNewGroupButton.setLayoutData(gd);
    fNewGroupButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IInputValidator validator = new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return "".equals(newText) ? "" : hasGroup(newText) ? Messages.SaveModelAsTemplateToCollectionWizardPage_3 : null;
                }

                boolean hasGroup(String name) {
                    for (ITemplateGroup group : fTemplateManager.getUserTemplateGroups()) {
                        if (name.equals(group.getName())) {
                            return true;
                        }
                    }
                    return false;
                }
            };
            InputDialog dialog = new InputDialog(getShell(), Messages.SaveModelAsTemplateToCollectionWizardPage_4, Messages.SaveModelAsTemplateToCollectionWizardPage_5, // $NON-NLS-1$
            "", validator);
            if (dialog.open() == Window.OK) {
                String name = dialog.getValue();
                if (StringUtils.isSetAfterTrim(name)) {
                    ITemplateGroup group = new TemplateGroup(name);
                    fTemplateManager.getUserTemplateGroups().add(group);
                    fCategoriesTableViewer.refresh();
                    fCategoriesTableViewer.setSelection(new StructuredSelection(group), true);
                }
            }
        }
    });
    setPageComplete(true);
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) 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) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TemplateGroup(com.archimatetool.templates.model.TemplateGroup) ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 4 with ITemplateGroup

use of com.archimatetool.templates.model.ITemplateGroup in project archi by archimatetool.

the class TemplateManagerDialog method deleteSelectedObjects.

/**
 * Remove selected object
 */
protected void deleteSelectedObjects() {
    // Table
    if (fSelectedControl == fTableViewer) {
        for (Object o : ((IStructuredSelection) fTableViewer.getSelection()).toArray()) {
            if (o instanceof ITemplate) {
                fTemplateManager.getUserTemplates().remove(o);
                for (ITemplateGroup group : fTemplateManager.getUserTemplateGroups()) {
                    group.removeTemplate((ITemplate) o);
                }
            }
        }
        fTableViewer.refresh();
        fTreeViewer.refresh();
    } else // Tree
    if (fSelectedControl == fTreeViewer) {
        // Do it this way because we can't get template parents
        for (TreeItem item : fTreeViewer.getTree().getSelection()) {
            if (item.getData() instanceof ITemplate) {
                ITemplate template = (ITemplate) item.getData();
                TreeItem parent = item.getParentItem();
                if (parent.getData() instanceof ITemplateGroup) {
                    ((ITemplateGroup) parent.getData()).removeTemplate(template);
                }
            } else if (item.getData() instanceof ITemplateGroup) {
                fTemplateManager.getUserTemplateGroups().remove(item.getData());
            }
        }
        fTreeViewer.refresh();
    }
}
Also used : ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) TreeItem(org.eclipse.swt.widgets.TreeItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITemplate(com.archimatetool.templates.model.ITemplate)

Example 5 with ITemplateGroup

use of com.archimatetool.templates.model.ITemplateGroup in project archi by archimatetool.

the class ArchimateTemplateManager method loadInbuiltTemplates.

@Override
protected ITemplateGroup loadInbuiltTemplates() {
    ITemplateGroup group = new TemplateGroup(Messages.ArchimateTemplateManager_2);
    File folder = ArchiTemplatesPlugin.INSTANCE.getTemplatesFolder();
    if (folder.exists()) {
        for (File file : folder.listFiles()) {
            if (file.getName().toLowerCase().endsWith(ARCHIMATE_TEMPLATE_FILE_EXTENSION)) {
                ITemplate template = new ArchimateModelTemplate();
                template.setFile(file);
                group.addTemplate(template);
            }
        }
    }
    return group;
}
Also used : ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) TemplateGroup(com.archimatetool.templates.model.TemplateGroup) ITemplateGroup(com.archimatetool.templates.model.ITemplateGroup) ITemplate(com.archimatetool.templates.model.ITemplate) File(java.io.File)

Aggregations

ITemplateGroup (com.archimatetool.templates.model.ITemplateGroup)6 TemplateGroup (com.archimatetool.templates.model.TemplateGroup)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 ITemplate (com.archimatetool.templates.model.ITemplate)3 File (java.io.File)2 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)2 InputDialog (org.eclipse.jface.dialogs.InputDialog)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)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 Label (org.eclipse.swt.widgets.Label)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1