use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class TreeModelView method eCoreChanged.
// =================================================================================
// React to ECore Model Changes
// =================================================================================
@Override
protected void eCoreChanged(Notification msg) {
int type = msg.getEventType();
Object notifier = msg.getNotifier();
Object feature = msg.getFeature();
// Attribute set
if (type == Notification.SET) {
// Viewpoint changed
if (feature == IArchimatePackage.Literals.ARCHIMATE_DIAGRAM_MODEL__VIEWPOINT) {
if (Preferences.STORE.getBoolean(IPreferenceConstants.VIEWPOINTS_FILTER_MODEL_TREE)) {
if (notifier instanceof IDiagramModel) {
IArchimateModel model = ((IDiagramModel) notifier).getArchimateModel();
getViewer().refreshInBackground(model);
}
}
} else {
super.eCoreChanged(msg);
}
} else {
super.eCoreChanged(msg);
}
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class TreeModelViewerDragDropHandler method isValidTreeSelection.
/**
* Determine whether we have a valid selection of objects dragged from the Tree
* Do it at the start of the drag operation for optimal speed.
*/
boolean isValidTreeSelection(IStructuredSelection selection) {
if (selection == null || selection.isEmpty()) {
return false;
}
IArchimateModel model = null;
for (Object object : selection.toArray()) {
// Can't drag Models
if (object instanceof IArchimateModel) {
return false;
}
// Can only drag user folders
if (object instanceof IFolder && ((IFolder) object).getType() != FolderType.USER) {
return false;
}
// Don't allow mixed parent models
if (object instanceof IArchimateModelObject) {
IArchimateModel m = ((IArchimateModelObject) object).getArchimateModel();
if (model != null && m != model) {
return false;
}
model = m;
}
}
return true;
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class TreeStateHelper method restoreExpandedTreeElements.
/**
* Restore expanded elements on TreeView creation
*/
void restoreExpandedTreeElements(TreeViewer viewer) {
fTreeViewer = viewer;
addDisposeListener();
if (fExpandedElements.isEmpty()) {
return;
}
for (Object o : fExpandedElements) {
// Actual object
if (o instanceof IArchimateModelObject) {
fTreeViewer.expandToLevel(o, 1);
}
// String ids
if (o instanceof FileMap) {
try {
File file = ((FileMap) o).file;
String[] elements = ((FileMap) o).elements;
for (IArchimateModel model : IEditorModelManager.INSTANCE.getModels()) {
if (file.equals(model.getFile())) {
for (String id : elements) {
EObject element = ArchimateModelUtils.getObjectByID(model, id);
if (element != null) {
fTreeViewer.expandToLevel(element, 1);
}
}
// found model
break;
}
}
} catch (Exception ex) {
// We don't want to fail just for some stupid string operation
ex.printStackTrace();
}
}
}
}
use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.
the class HistoryView method selectionChanged.
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part == this) {
return;
}
Object selected = ((IStructuredSelection) selection).getFirstElement();
IArchiRepository selectedRepository = null;
// Repository selected
if (selected instanceof IArchiRepository) {
selectedRepository = (IArchiRepository) selected;
} else // Model selected, but is it in a git repo?
{
IArchimateModel model = part.getAdapter(IArchimateModel.class);
if (GraficoUtils.isModelInLocalRepository(model)) {
selectedRepository = new ArchiRepository(GraficoUtils.getLocalRepositoryFolderForModel(model));
}
}
// Update if selectedRepository is different
if (selectedRepository != null && !selectedRepository.equals(fSelectedRepository)) {
// Set label text
// $NON-NLS-1$
fRepoLabel.setText(Messages.HistoryView_0 + " " + selectedRepository.getName());
getViewer().setInput(selectedRepository);
// Do the table kludge
((UpdatingTableColumnLayout) getViewer().getTable().getParent().getLayout()).doRelayout();
// Update actions
fActionExtractCommit.setRepository(selectedRepository);
// fActionRevertSingleCommit.setRepository(selectedRepository);
fActionRevertUptoCommit.setRepository(selectedRepository);
fActionRestoreCommit.setRepository(selectedRepository);
fActionUndoLastCommit.setRepository(selectedRepository);
fActionResetToRemoteCommit.setRepository(selectedRepository);
// Select first row
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!getViewer().getTable().isDisposed()) {
Object element = getViewer().getElementAt(0);
if (element != null) {
getViewer().setSelection(new StructuredSelection(element));
}
}
}
});
// Store last selected
fSelectedRepository = selectedRepository;
}
}
use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.
the class RevertCommitAction method run.
@Override
public void run() {
// Offer to save the model if open and dirty
// We need to do this to keep grafico and temp files in sync
IArchimateModel model = getRepository().locateModel();
if (model != null && IEditorModelManager.INSTANCE.isModelDirty(model)) {
if (!offerToSaveModel(model)) {
return;
}
}
// Do the Grafico Export first
try {
getRepository().exportModelToGraficoFiles();
} catch (IOException ex) {
displayErrorDialog(Messages.RevertCommitAction_0, ex);
return;
}
// Then offer to Commit
try {
if (getRepository().hasChangesToCommit()) {
if (!offerToCommitChanges()) {
return;
}
}
} catch (IOException | GitAPIException ex) {
displayErrorDialog(Messages.RevertCommitAction_3, ex);
return;
}
// Revert
try (Git git = Git.open(getRepository().getLocalRepositoryFolder())) {
RevertCommand revertCommand = doRevertCommand(git);
MergeResult failingResult = revertCommand.getFailingResult();
if (failingResult != null) {
MergeConflictHandler handler = new MergeConflictHandler(failingResult, getRepository(), fWindow.getShell());
boolean result = handler.checkForMergeConflicts();
if (result) {
handler.mergeAndCommit(Messages.RevertCommitAction_4, false);
} else {
// User cancelled - we assume user has committed all changes so we can reset
handler.resetToLocalState();
}
} else {
new GraficoModelLoader(getRepository()).loadModel();
}
// Save the checksum
getRepository().saveChecksum();
notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
} catch (IOException | GitAPIException ex) {
displayErrorDialog(Messages.RevertCommitAction_1, ex);
}
}
Aggregations