use of com.archimatetool.model.IIdentifier 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.IIdentifier in project archi by archimatetool.
the class ModelChecker method checkHasIdentifiers.
List<String> checkHasIdentifiers() {
List<String> messages = new ArrayList<String>();
for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IIdentifier && !StringUtils.isSet(((IIdentifier) eObject).getId())) {
// $NON-NLS-1$
String message = Messages.ModelChecker_10 + " " + ArchiLabelProvider.INSTANCE.getLabel(eObject);
messages.add(message);
}
}
return messages;
}
use of com.archimatetool.model.IIdentifier in project archi by archimatetool.
the class CopySnapshotTests method testCopiedObjectsHaveIdentifiersAndParents.
private void testCopiedObjectsHaveIdentifiersAndParents(IDiagramModel newTargetDiagramModel) {
List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
selected.addAll(getAllDiagramComponents(sourceDiagramModel));
CopySnapshot snapshot = new CopySnapshot(selected);
Command cmd = snapshot.getPasteCommand(newTargetDiagramModel, mock(GraphicalViewer.class), null, false);
cmd.execute();
for (TreeIterator<EObject> iter = newTargetDiagramModel.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
assertNotNull(eObject.eContainer());
if (eObject instanceof IIdentifier) {
assertNotNull(((IIdentifier) eObject).getId());
}
if (eObject instanceof IDiagramModelArchimateComponent) {
assertNotNull(((IDiagramModelArchimateComponent) eObject).getArchimateConcept());
assertNotNull(((IDiagramModelArchimateComponent) eObject).getArchimateConcept().eContainer());
}
}
}
use of com.archimatetool.model.IIdentifier 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.model.IIdentifier in project archi by archimatetool.
the class IDAdapter method notifyChanged.
@Override
public void notifyChanged(Notification msg) {
super.notifyChanged(msg);
if (msg.getEventType() == Notification.ADD) {
if (msg.getNewValue() instanceof IIdentifier) {
IIdentifier element = (IIdentifier) msg.getNewValue();
String id = element.getId();
// Element has no ID so allocate one
if (id == null) {
element.setId(getNewID());
} else // Register the ID to the list when loading in from file
{
registerID(id);
}
}
}
}
Aggregations