use of com.archimatetool.model.IArchimateModel 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.IArchimateModel in project archi by archimatetool.
the class HTMLReportHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IArchimateModel model = getActiveArchimateModel();
if (model != null) {
try {
HTMLReportExporter exporter = new HTMLReportExporter(model);
exporter.export();
} catch (IOException ex) {
MessageDialog.openError(workbenchWindow.getShell(), Messages.HTMLReportAction_0, ex.getMessage());
ex.printStackTrace();
}
}
return null;
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class HTMLReportProvider method run.
@Override
public void run(CommandLine commandLine) throws Exception {
if (!hasCorrectOptions(commandLine)) {
return;
}
String sOutput = commandLine.getOptionValue(OPTION_CREATE_HTML_REPORT);
if (!StringUtils.isSet(sOutput)) {
logError(Messages.HTMLReportProvider_1);
return;
}
File folderOutput = new File(sOutput);
folderOutput.mkdirs();
if (!folderOutput.exists()) {
logError(NLS.bind(Messages.HTMLReportProvider_2, sOutput));
return;
}
IArchimateModel model = CommandLineState.getModel();
if (model == null) {
throw new IOException(Messages.HTMLReportProvider_3);
}
logMessage(NLS.bind(Messages.HTMLReportProvider_4, model.getName(), sOutput));
HTMLReportExporter ex = new HTMLReportExporter(model);
// $NON-NLS-1$
ex.createReport(folderOutput, "index.html");
logMessage(Messages.HTMLReportProvider_5);
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class UserPropertiesSection method getAllUniquePropertyKeysForModel.
/**
* @return All unique Property Keys for an entire model (sorted)
*/
private String[] getAllUniquePropertyKeysForModel() {
IArchimateModel model = getArchimateModel();
List<String> list = new ArrayList<String>();
for (Iterator<EObject> iter = model.eAllContents(); iter.hasNext(); ) {
EObject element = iter.next();
if (element instanceof IProperty) {
String key = ((IProperty) element).getKey();
if (StringUtils.isSetAfterTrim(key) && !list.contains(key)) {
list.add(key);
}
}
}
String[] items = list.toArray(new String[list.size()]);
Arrays.sort(items, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
return items;
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class TreeModelView method propertyChange.
// ======================================================================
// Listen to Property Changes from IEditorModelManager
// ======================================================================
@Override
public void propertyChange(PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
Object source = evt.getSource();
// New Model created or opened
if (propertyName == IEditorModelManager.PROPERTY_MODEL_CREATED || propertyName == IEditorModelManager.PROPERTY_MODEL_OPENED) {
getViewer().refresh();
IArchimateModel model = (IArchimateModel) evt.getNewValue();
// Expand and Select new node
getViewer().expandToLevel(model.getFolder(FolderType.DIAGRAMS), 1);
getViewer().setSelection(new StructuredSelection(model), true);
} else // Model removed
if (propertyName == IEditorModelManager.PROPERTY_MODEL_REMOVED) {
getViewer().refresh();
} else // Model dirty state, so update Actions and modified state of source (asterisk on model node)
if (propertyName == IEditorModelManager.COMMAND_STACK_CHANGED) {
updateActions();
getViewer().update(source, null);
} else // Ecore Events will come so turn tree refresh off
if (propertyName == IEditorModelManager.PROPERTY_ECORE_EVENTS_START) {
super.propertyChange(evt);
// Remove Syncing
TreeSelectionSynchroniser.INSTANCE.setSynchronise(false);
} else // Ecore Events have finished so turn tree refresh on
if (propertyName == IEditorModelManager.PROPERTY_ECORE_EVENTS_END) {
super.propertyChange(evt);
// Add Syncing
TreeSelectionSynchroniser.INSTANCE.setSynchronise(true);
} else {
super.propertyChange(evt);
}
}
Aggregations