use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class CreateEmptyModelProvider method createEmptyModelFromTemplate.
// Code taken from com.archimatetool.templates.impl.wizard.NewArchimateModelFromTemplateWizard
private IArchimateModel createEmptyModelFromTemplate(String template) throws IOException {
File fileTemplate = new File(template);
if (!fileTemplate.exists()) {
throw new IOException(NLS.bind(Messages.CreateEmptyModelProvider_3, template));
}
// $NON-NLS-1$
File tmp = File.createTempFile("~architemplate", null);
tmp.deleteOnExit();
// $NON-NLS-1$
File file = ZipUtils.extractZipEntry(fileTemplate, "model.archimate", tmp);
IArchimateModel model = LoadModelFromFileProvider.loadModel(file);
if (model == null) {
logError(Messages.CreateEmptyModelProvider_4);
return null;
}
// New name
// $NON-NLS-1$
model.setName(Messages.CreateEmptyModelProvider_5 + " " + model.getName());
// Set latest model version
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());
}
}
logMessage(NLS.bind(Messages.CreateEmptyModelProvider_6, fileTemplate));
return model;
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class ExportCSVProvider method run.
@Override
public void run(CommandLine commandLine) throws Exception {
if (!hasCorrectOptions(commandLine)) {
return;
}
IArchimateModel model = CommandLineState.getModel();
if (model == null) {
throw new IOException(Messages.ExportCSVProvider_1);
}
// Folder
String value = commandLine.getOptionValue(OPTION_EXPORT_CSV);
if (!StringUtils.isSet(value)) {
logError(Messages.ExportCSVProvider_2);
return;
}
File folderOutput = new File(value);
folderOutput.mkdirs();
if (!folderOutput.exists()) {
logError(NLS.bind(Messages.ExportCSVProvider_3, value));
return;
}
CSVExporter exporter = new CSVExporter(model);
// Delimiter
value = commandLine.getOptionValue(OPTION_DELIMITER);
if (StringUtils.isSet(value)) {
switch(value) {
case // $NON-NLS-1$
"\\t":
exporter.setDelimiter('\t');
break;
case // $NON-NLS-1$
";":
exporter.setDelimiter(';');
break;
default:
exporter.setDelimiter(',');
break;
}
}
// File prefix
value = commandLine.getOptionValue(OPTION_FILE_PREFIX);
if (StringUtils.isSet(value)) {
exporter.setFilePrefix(value);
}
// Encoding
value = commandLine.getOptionValue(OPTION_ENCODING);
if (StringUtils.isSet(value)) {
exporter.setEncoding(value);
}
// Use leading
exporter.setUseLeadingCharsHack(commandLine.hasOption(OPTION_LEADING_CHARS_HACK));
// Strip newlines
exporter.setStripNewLines(commandLine.hasOption(OPTION_STRIP_NEW_LINES));
logMessage(NLS.bind(Messages.ExportCSVProvider_4, model.getName(), folderOutput.getPath()));
exporter.export(folderOutput);
logMessage(Messages.ExportCSVProvider_5);
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class SaveAction method updateState.
@Override
public void updateState() {
IArchimateModel model = getActiveArchimateModel();
setEnabled(IEditorModelManager.INSTANCE.isModelDirty(model));
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class EditorModelManager method createNewModel.
@Override
public IArchimateModel createNewModel() {
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setName(Messages.EditorModelManager_0);
model.setDefaults();
// Add one default diagram
IDiagramModel diagramModel = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
diagramModel.setName(Messages.EditorModelManager_1);
model.getFolder(FolderType.DIAGRAMS).getElements().add(diagramModel);
// Register
registerModel(model);
return model;
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class EditorModelManager method askSaveModel.
/**
* Ask user for file name to save model
* @return the file or null
*/
private File askSaveModel() {
// On Mac if the app is minimised in the dock Display.getCurrent().getActiveShell() will return null
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
// Get focus on Mac
shell.setActive();
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
// $NON-NLS-1$
dialog.setFilterExtensions(new String[] { ARCHIMATE_FILE_WILDCARD, "*.*" });
String path = dialog.open();
if (path == null) {
return null;
}
// Only Windows adds the extension by default
if (dialog.getFilterIndex() == 0 && !path.endsWith(ARCHIMATE_FILE_EXTENSION)) {
path += ARCHIMATE_FILE_EXTENSION;
}
File file = new File(path);
// Make sure we don't already have it open
for (IArchimateModel m : getModels()) {
if (file.equals(m.getFile())) {
MessageDialog.openWarning(shell, Messages.EditorModelManager_8, NLS.bind(Messages.EditorModelManager_9, file));
return null;
}
}
// Make sure the file does not already exist
if (file.exists()) {
boolean result = MessageDialog.openQuestion(shell, Messages.EditorModelManager_10, NLS.bind(Messages.EditorModelManager_11, file));
if (!result) {
return null;
}
}
return file;
}
Aggregations