use of com.archimatetool.templates.model.ITemplate in project archi by archimatetool.
the class NewArchimateModelFromTemplateWizard 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 {
// $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()) {
IArchimateModel model = IEditorModelManager.INSTANCE.openModel(file);
if (model != null) {
// New name
// $NON-NLS-1$
model.setName(Messages.NewArchimateModelFromTemplateWizard_1 + " " + model.getName());
// Set latest model version (need to do this in case we immediately save as Template)
model.setVersion(ModelVersion.VERSION);
// Set file to null
model.setFile(null);
// New IDs
model.setId(model.getIDAdapter().getNewID());
for (Iterator<EObject> iter = model.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IIdentifier) {
((IIdentifier) eObject).setId(model.getIDAdapter().getNewID());
}
}
// Edit in-place in Tree
UIRequestManager.INSTANCE.fireRequest(new TreeEditElementRequest(this, model));
} else {
fErrorMessage = Messages.NewArchimateModelFromTemplateWizard_2;
}
} else {
fErrorMessage = Messages.NewArchimateModelFromTemplateWizard_2;
}
tmp.delete();
} catch (IOException ex) {
ex.printStackTrace();
fErrorMessage = ex.getMessage();
}
}
});
}
if (fErrorMessage != null) {
MessageDialog.openError(getShell(), Messages.NewArchimateModelFromTemplateWizard_3, fErrorMessage);
getContainer().getShell().setVisible(true);
}
return fErrorMessage == null;
}
use of com.archimatetool.templates.model.ITemplate in project archi by archimatetool.
the class NewModelFromTemplateWizardPage method handleOpenAction.
/**
* User wants to open Template from file
*/
protected void handleOpenAction() {
getContainer().getShell().setVisible(false);
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
dialog.setText(Messages.NewModelFromTemplateWizardPage_4);
// $NON-NLS-1$ //$NON-NLS-2$
dialog.setFilterExtensions(new String[] { "*" + fTemplateManager.getTemplateFileExtension(), "*.*" });
String path = dialog.open();
if (path == null) {
selectFirstTableItem();
getContainer().getShell().setVisible(true);
return;
}
final File file = new File(path);
// Create template and Finish
BusyIndicator.showWhile(null, new Runnable() {
@Override
public void run() {
try {
ITemplate template = fTemplateManager.createTemplate(file);
template.setFile(file);
fSelectedTemplate = template;
((ExtendedWizardDialog) getContainer()).finishPressed();
} catch (IOException ex) {
MessageDialog.openError(getShell(), Messages.NewModelFromTemplateWizardPage_5, ex.getMessage());
selectFirstTableItem();
getContainer().getShell().setVisible(true);
}
}
});
}
use of com.archimatetool.templates.model.ITemplate in project archi by archimatetool.
the class NewModelFromTemplateWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout());
setControl(container);
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(container, getHelpID());
GridData gd;
SashForm sash1 = new SashForm(container, SWT.HORIZONTAL);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 800;
gd.heightHint = 500;
sash1.setLayoutData(gd);
Composite tableComposite = new Composite(sash1, SWT.BORDER);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.verticalSpacing = 0;
tableComposite.setLayout(layout);
// Inbuilt Templates
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
fInbuiltTableViewer = createGroupsTableViewer(tableComposite, Messages.NewModelFromTemplateWizardPage_2, gd);
fInbuiltTableViewer.setInput(new Object[] { fTemplateManager.getInbuiltTemplateGroup(), OPEN, MANAGE });
// Mouse UP actions...
fInbuiltTableViewer.getControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
Object o = ((IStructuredSelection) fInbuiltTableViewer.getSelection()).getFirstElement();
// Open...
if (o == OPEN) {
handleOpenAction();
} else // Manage...
if (o == MANAGE) {
handleManageTemplatesAction();
}
}
});
// My Templates
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
fUserTableViewer = createGroupsTableViewer(tableComposite, Messages.NewModelFromTemplateWizardPage_3, gd);
fUserTableViewer.setComparator(new ViewerComparator() {
@Override
public int category(Object element) {
if (element == fTemplateManager.AllUserTemplatesGroup) {
return 0;
}
return 1;
}
});
fUserTableViewer.setInput(fTemplateManager);
SashForm sash2 = new SashForm(sash1, SWT.VERTICAL);
Composite galleryComposite = new Composite(sash2, SWT.NULL);
layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.verticalSpacing = 0;
galleryComposite.setLayout(layout);
fGallery = new Gallery(galleryComposite, SWT.V_SCROLL | SWT.BORDER);
fGallery.setLayoutData(new GridData(GridData.FILL_BOTH));
// Renderers
final NoGroupRenderer groupRenderer = new NoGroupRenderer();
groupRenderer.setItemSize(DEFAULT_GALLERY_ITEM_SIZE, DEFAULT_GALLERY_ITEM_SIZE);
groupRenderer.setAutoMargin(true);
groupRenderer.setMinMargin(10);
fGallery.setGroupRenderer(groupRenderer);
final DefaultGalleryItemRenderer itemRenderer = new DefaultGalleryItemRenderer();
itemRenderer.setDropShadows(true);
itemRenderer.setDropShadowsSize(7);
itemRenderer.setShowRoundedSelectionCorners(false);
fGallery.setItemRenderer(itemRenderer);
// Root Group
fGalleryRoot = new GalleryItem(fGallery, SWT.NONE);
// Slider
final Scale scale = new Scale(galleryComposite, SWT.HORIZONTAL);
gd = new GridData(SWT.END, SWT.NONE, false, false);
gd.widthHint = 120;
if (PlatformUtils.isMac()) {
// Mac clips height of slider
gd.heightHint = 20;
}
scale.setLayoutData(gd);
scale.setMaximum(480);
scale.setMinimum(64);
scale.setIncrement(8);
scale.setPageIncrement(64);
scale.setSelection(DEFAULT_GALLERY_ITEM_SIZE);
scale.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int inc = scale.getSelection();
itemRenderer.setDropShadows(inc >= DEFAULT_GALLERY_ITEM_SIZE);
groupRenderer.setItemSize(inc, inc);
}
});
// Description
fDescriptionText = new StyledText(sash2, SWT.V_SCROLL | SWT.READ_ONLY | SWT.WRAP | SWT.BORDER);
fGallery.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.item instanceof GalleryItem) {
ITemplate template = (ITemplate) ((GalleryItem) e.item).getData();
updateWizard(template);
} else {
updateWizard(null);
}
}
});
// Double-clicks
fGallery.addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
GalleryItem item = fGallery.getItem(new Point(event.x, event.y));
if (item != null) {
((ExtendedWizardDialog) getContainer()).finishPressed();
}
}
});
// Dispose of the images in TemplateManager here not in the main dispose() method because if the help system is showing then
// the TrayDialog is resized and this control is asked to relayout.
fGallery.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
fTemplateManager.dispose();
}
});
// Mouse move shows thumbnails
registerMouseMoveHandler();
// Select first group on table
selectFirstTableItem();
sash1.setWeights(new int[] { 30, 70 });
sash2.setWeights(new int[] { 70, 30 });
// Yes it's OK
setPageComplete(true);
}
use of com.archimatetool.templates.model.ITemplate in project archi by archimatetool.
the class NewModelFromTemplateWizardPage method updateGallery.
/**
* Update the Gallery
* @param group
*/
protected void updateGallery(ITemplateGroup group) {
for (ITemplate template : group.getSortedTemplates()) {
GalleryItem item = new GalleryItem(fGalleryRoot, SWT.NONE);
item.setText(StringUtils.safeString(template.getName()));
item.setImage(template.getKeyThumbnail());
item.setData(template);
}
if (fGalleryRoot.getItem(0) != null) {
fGallery.setSelection(new GalleryItem[] { fGalleryRoot.getItem(0) });
updateWizard((ITemplate) fGalleryRoot.getItem(0).getData());
} else {
updateWizard(null);
}
}
use of com.archimatetool.templates.model.ITemplate 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();
}
}
Aggregations