Search in sources :

Example 46 with IArchimateModel

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);
    }
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 47 with IArchimateModel

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;
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder)

Example 48 with IArchimateModel

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();
            }
        }
    }
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 49 with IArchimateModel

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;
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) ArchiRepository(org.archicontribs.modelrepository.grafico.ArchiRepository) IArchimateModel(com.archimatetool.model.IArchimateModel) UpdatingTableColumnLayout(com.archimatetool.editor.ui.components.UpdatingTableColumnLayout)

Example 50 with IArchimateModel

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);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) RevertCommand(org.eclipse.jgit.api.RevertCommand) MergeResult(org.eclipse.jgit.api.MergeResult) IOException(java.io.IOException) MergeConflictHandler(org.archicontribs.modelrepository.grafico.MergeConflictHandler) IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

IArchimateModel (com.archimatetool.model.IArchimateModel)124 Test (org.junit.Test)51 File (java.io.File)35 IOException (java.io.IOException)22 IArchimateElement (com.archimatetool.model.IArchimateElement)14 EObject (org.eclipse.emf.ecore.EObject)14 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)13 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)13 IDiagramModel (com.archimatetool.model.IDiagramModel)12 CommandStack (org.eclipse.gef.commands.CommandStack)11 IFolder (com.archimatetool.model.IFolder)10 ArrayList (java.util.ArrayList)10 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)9 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)9 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)7 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)5 IIdentifier (com.archimatetool.model.IIdentifier)5 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)5