Search in sources :

Example 6 with ITemplate

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

the class TemplateManagerDialog method openTemplate.

/**
 * Add a Template file
 */
protected void openTemplate() {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
    dialog.setText(Messages.TemplateManagerDialog_13);
    // $NON-NLS-1$ //$NON-NLS-2$
    dialog.setFilterExtensions(new String[] { "*" + fTemplateManager.getTemplateFileExtension(), "*.*" });
    String path = dialog.open();
    if (path == null) {
        return;
    }
    final File file = new File(path);
    if (hasUserTemplate(file)) {
        MessageDialog.openInformation(getShell(), Messages.TemplateManagerDialog_16, Messages.TemplateManagerDialog_17);
        return;
    }
    BusyIndicator.showWhile(null, new Runnable() {

        @Override
        public void run() {
            try {
                ITemplate template = fTemplateManager.createTemplate(file);
                template.setFile(file);
                fTemplateManager.addUserTemplate(template);
                fTableViewer.refresh();
            } catch (IOException ex) {
                MessageDialog.openError(getShell(), Messages.TemplateManagerDialog_18, ex.getMessage());
            }
        }
    });
}
Also used : ITemplate(com.archimatetool.templates.model.ITemplate) IOException(java.io.IOException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 7 with ITemplate

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

the class TemplateManagerDialogDragDropHandler method copy.

private void copy(ITemplateGroup parent) {
    IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
    // From Table to Tree
    for (Object o : selection.toArray()) {
        if (o instanceof ITemplate) {
            if (!parent.getTemplates().contains(o)) {
                parent.addTemplate((ITemplate) o);
            }
        }
    }
    fTreeViewer.refresh();
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITemplate(com.archimatetool.templates.model.ITemplate)

Example 8 with ITemplate

use of com.archimatetool.templates.model.ITemplate 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)

Example 9 with ITemplate

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

the class NewCanvasFromTemplateWizard method performFinish.

@Override
public boolean performFinish() {
    // Get template
    ITemplate template = fMainPage.getSelectedTemplate();
    if (template == null) {
        return false;
    }
    getContainer().getShell().setVisible(false);
    fErrorMessage = null;
    final File zipFile = template.getFile();
    if (zipFile != null && zipFile.exists()) {
        BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

            @Override
            public void run() {
                try {
                    fErrorMessage = null;
                    // $NON-NLS-1$
                    File tmp = File.createTempFile("~architemplate", null);
                    tmp.deleteOnExit();
                    File file = ZipUtils.extractZipEntry(zipFile, TemplateManager.ZIP_ENTRY_MODEL, tmp);
                    if (file != null && file.exists()) {
                        createNewCanvasFromTemplate(file);
                    } else {
                        fErrorMessage = Messages.NewCanvasFromTemplateWizard_1;
                    }
                    tmp.delete();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    // $NON-NLS-1$
                    fErrorMessage = Messages.NewCanvasFromTemplateWizard_2 + " " + ex.getMessage();
                }
            }
        });
    }
    if (fErrorMessage != null) {
        MessageDialog.openError(getShell(), Messages.NewCanvasFromTemplateWizard_3, fErrorMessage);
        getContainer().getShell().setVisible(true);
    }
    return fErrorMessage == null;
}
Also used : ITemplate(com.archimatetool.templates.model.ITemplate) File(java.io.File) CompatibilityHandlerException(com.archimatetool.editor.model.compatibility.CompatibilityHandlerException) IncompatibleModelException(com.archimatetool.editor.model.compatibility.IncompatibleModelException) IOException(java.io.IOException)

Example 10 with ITemplate

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

the class CanvasTemplateManager method loadInbuiltTemplates.

@Override
protected ITemplateGroup loadInbuiltTemplates() {
    ITemplateGroup group = new TemplateGroup(Messages.CanvasTemplateManager_0);
    File folder = CanvasEditorPlugin.INSTANCE.getTemplatesFolder();
    if (folder.exists()) {
        for (File file : folder.listFiles()) {
            if (file.getName().toLowerCase().endsWith(CANVAS_TEMPLATE_FILE_EXTENSION)) {
                ITemplate template = new CanvasModelTemplate();
                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

ITemplate (com.archimatetool.templates.model.ITemplate)10 File (java.io.File)6 IOException (java.io.IOException)4 ITemplateGroup (com.archimatetool.templates.model.ITemplateGroup)3 TemplateGroup (com.archimatetool.templates.model.TemplateGroup)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 GalleryItem (org.eclipse.nebula.widgets.gallery.GalleryItem)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 CompatibilityHandlerException (com.archimatetool.editor.model.compatibility.CompatibilityHandlerException)1 IncompatibleModelException (com.archimatetool.editor.model.compatibility.IncompatibleModelException)1 TreeEditElementRequest (com.archimatetool.editor.views.tree.TreeEditElementRequest)1 IArchimateModel (com.archimatetool.model.IArchimateModel)1 IIdentifier (com.archimatetool.model.IIdentifier)1 Iterator (java.util.Iterator)1 EObject (org.eclipse.emf.ecore.EObject)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 DefaultGalleryItemRenderer (org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer)1 Gallery (org.eclipse.nebula.widgets.gallery.Gallery)1