use of com.archimatetool.editor.views.tree.commands.NewDiagramCommand in project archi by archimatetool.
the class TreeModelViewActionFactory method createNewSketchAction.
private IAction createNewSketchAction(final IFolder folder) {
IAction action = new Action(Messages.TreeModelViewActionFactory_2) {
@Override
public void run() {
// Create a new Diagram Model, set its name
ISketchModel sketchModel = IArchimateFactory.eINSTANCE.createSketchModel();
sketchModel.setName(Messages.TreeModelViewActionFactory_3);
// Defaults
int defaultBackground = Preferences.STORE.getInt(IPreferenceConstants.SKETCH_DEFAULT_BACKGROUND);
sketchModel.setBackground(defaultBackground);
// Execute Command
Command cmd = new NewDiagramCommand(folder, sketchModel, Messages.TreeModelViewActionFactory_3);
CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
};
action.setImageDescriptor(IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_SKETCH));
return action;
}
use of com.archimatetool.editor.views.tree.commands.NewDiagramCommand in project archi by archimatetool.
the class NewCanvasFromTemplateWizard method createNewCanvasFromTemplate.
private void createNewCanvasFromTemplate(File file) throws IncompatibleModelException, IOException {
// Ascertain if this is a zip file
boolean isArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file);
Resource resource = ArchimateResourceFactory.createNewResource(isArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath()));
// Check model compatibility
ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
// Wrap in try/catch to load as much as possible
try {
resource.load(null);
} catch (IOException ex) {
// Error occured loading model. Was it a disaster?
try {
modelCompatibility.checkErrors();
}// Incompatible
catch (IncompatibleModelException ex1) {
fErrorMessage = NLS.bind(Messages.NewCanvasFromTemplateWizard_4, file) + "\n" + // $NON-NLS-1$
ex1.getMessage();
throw ex1;
}
}
// And then fix any backward compatibility issues
try {
modelCompatibility.fixCompatibility();
} catch (CompatibilityHandlerException ex) {
}
// Pull out the Canvas model
IArchimateModel templateModel = (IArchimateModel) resource.getContents().get(0);
IFolder folderViews = templateModel.getFolder(FolderType.DIAGRAMS);
ICanvasModel canvasModel = (ICanvasModel) folderViews.getElements().get(0);
// Create New UUIDs for elements...
TemplateUtils.generateNewUUIDs(canvasModel);
// Load the images from the template model's file now
if (isArchiveFormat) {
IArchiveManager archiveManager = (IArchiveManager) fFolder.getAdapter(IArchiveManager.class);
archiveManager.loadImagesFromModelFile(file);
}
Command cmd = new NewDiagramCommand(fFolder, canvasModel, Messages.NewCanvasFromTemplateWizard_5);
CommandStack commandStack = (CommandStack) fFolder.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
use of com.archimatetool.editor.views.tree.commands.NewDiagramCommand in project archi by archimatetool.
the class TreeModelViewActionFactory method createNewArchimateDiagramAction.
private IAction createNewArchimateDiagramAction(final IFolder folder) {
IAction action = new Action(Messages.TreeModelViewActionFactory_0) {
@Override
public void run() {
// Create a new Diagram Model, set its name
IDiagramModel diagramModel = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
diagramModel.setName(Messages.TreeModelViewActionFactory_1);
// Execute Command
Command cmd = new NewDiagramCommand(folder, diagramModel, Messages.TreeModelViewActionFactory_1);
CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
};
action.setImageDescriptor(IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_DIAGRAM));
return action;
}
Aggregations