Search in sources :

Example 1 with IArchimateDiagramModel

use of com.archimatetool.model.IArchimateDiagramModel in project archi by archimatetool.

the class Validator method validate.

/**
 * @return The list of Issue Categories and Issues
 */
public List<Object> validate() {
    if (fModel == null) {
        return null;
    }
    // Collect interesting objects
    fElements = new ArrayList<IArchimateElement>();
    fRelations = new ArrayList<IArchimateRelationship>();
    fViews = new ArrayList<IArchimateDiagramModel>();
    for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IArchimateRelationship) {
            fRelations.add((IArchimateRelationship) eObject);
        } else if (eObject instanceof IArchimateElement) {
            fElements.add((IArchimateElement) eObject);
        } else if (eObject instanceof IArchimateDiagramModel) {
            fViews.add((IArchimateDiagramModel) eObject);
        }
    }
    // Analyse
    List<Object> result = new ArrayList<Object>();
    fErrorList = new ArrayList<ErrorType>();
    fWarningList = new ArrayList<WarningType>();
    fAdviceList = new ArrayList<AdviceType>();
    // ------------------ Checkers -----------------------------
    IPreferenceStore store = ArchiHammerPlugin.INSTANCE.getPreferenceStore();
    // Invalid Relations
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_INVALID_RELATIONS)) {
        collectIssues(new InvalidRelationsChecker(getArchimateRelationships()));
    }
    // Unused Elements
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_UNUSED_ELEMENTS)) {
        collectIssues(new UnusedElementsChecker(getArchimateElements()));
    }
    // Unused Relations
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_UNUSED_RELATIONS)) {
        collectIssues(new UnusedRelationsChecker(getArchimateRelationships()));
    }
    // Empty Views
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_EMPTY_VIEWS)) {
        collectIssues(new EmptyViewsChecker(getArchimateViews()));
    }
    // Components in wrong Viewpoints
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_VIEWPOINT)) {
        collectIssues(new ViewpointChecker(getArchimateViews()));
    }
    // Nested elements
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_NESTING)) {
        collectIssues(new NestedElementsChecker(getArchimateViews()));
    }
    // Possible Duplicates
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_DUPLICATE_ELEMENTS)) {
        collectIssues(new DuplicateElementChecker(getArchimateElements()));
    }
    // Junctions
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_JUNCTIONS)) {
        collectIssues(new JunctionsChecker(getArchimateElements()));
    }
    if (!fErrorList.isEmpty()) {
        IIssueCategory category = new ErrorsCategory(fErrorList);
        result.add(category);
    }
    if (!fWarningList.isEmpty()) {
        IIssueCategory category = new WarningsCategory(fWarningList);
        result.add(category);
    }
    if (!fAdviceList.isEmpty()) {
        IIssueCategory category = new AdviceCategory(fAdviceList);
        result.add(category);
    }
    if (result.isEmpty()) {
        result.add(new OKType());
    }
    return result;
}
Also used : UnusedElementsChecker(com.archimatetool.hammer.validation.checkers.UnusedElementsChecker) EmptyViewsChecker(com.archimatetool.hammer.validation.checkers.EmptyViewsChecker) AdviceCategory(com.archimatetool.hammer.validation.issues.AdviceCategory) ArrayList(java.util.ArrayList) DuplicateElementChecker(com.archimatetool.hammer.validation.checkers.DuplicateElementChecker) ErrorType(com.archimatetool.hammer.validation.issues.ErrorType) EObject(org.eclipse.emf.ecore.EObject) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) ViewpointChecker(com.archimatetool.hammer.validation.checkers.ViewpointChecker) WarningsCategory(com.archimatetool.hammer.validation.issues.WarningsCategory) ErrorsCategory(com.archimatetool.hammer.validation.issues.ErrorsCategory) InvalidRelationsChecker(com.archimatetool.hammer.validation.checkers.InvalidRelationsChecker) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) UnusedRelationsChecker(com.archimatetool.hammer.validation.checkers.UnusedRelationsChecker) OKType(com.archimatetool.hammer.validation.issues.OKType) JunctionsChecker(com.archimatetool.hammer.validation.checkers.JunctionsChecker) WarningType(com.archimatetool.hammer.validation.issues.WarningType) NestedElementsChecker(com.archimatetool.hammer.validation.checkers.NestedElementsChecker) AdviceType(com.archimatetool.hammer.validation.issues.AdviceType) EObject(org.eclipse.emf.ecore.EObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IIssueCategory(com.archimatetool.hammer.validation.issues.IIssueCategory)

Example 2 with IArchimateDiagramModel

use of com.archimatetool.model.IArchimateDiagramModel in project archi by archimatetool.

the class TreeViewpointFilterProvider method partActivated.

@Override
public void partActivated(IWorkbenchPart part) {
    /*
         * Refresh Tree only if an IEditorPart is activated.
         * 
         * If we call refresh() when a ViewPart is activated then a problem occurs when:
         * 1. User adds a new Diagram View to the Tree
         * 2. Element is added to model - refresh() is called on Tree
         * 3. Diagram Editor is opened and activated
         * 4. This is notified of Diagram Editor Part activation and calls refresh() on Tree
         * 5. NewDiagramCommand.execute() calls TreeModelViewer.editElement() to edit the cell name
         * 6. The Tree is then activated and This is notified of Diagram Editor Part activation and calls refresh() on Tree
         * 7. TreeModelViewer.refresh(element) then cancels editing
         */
    if (part instanceof IEditorPart) {
        IArchimateDiagramModel previous = fActiveDiagramModel;
        // Archimate editor
        if (part instanceof IArchimateDiagramEditor) {
            IArchimateDiagramModel dm = (IArchimateDiagramModel) ((IArchimateDiagramEditor) part).getModel();
            if (previous == dm) {
                return;
            }
            fActiveDiagramModel = dm;
        } else // Other type of editor (sketch, canvas)
        {
            fActiveDiagramModel = null;
        }
        // Refresh previous model
        refreshTreeModel(previous);
        // Refresh selected model
        refreshTreeModel(fActiveDiagramModel);
    }
}
Also used : IArchimateDiagramEditor(com.archimatetool.editor.diagram.IArchimateDiagramEditor) IEditorPart(org.eclipse.ui.IEditorPart) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 3 with IArchimateDiagramModel

use of com.archimatetool.model.IArchimateDiagramModel in project archi by archimatetool.

the class HintsView method selectionChanged.

public void selectionChanged(Object source, Object selected) {
    if (fActionPinContent.isChecked()) {
        return;
    }
    Object object = null;
    String key = null;
    // EClass (selected from Diagram Palette) so get Java class
    if (selected instanceof EClass) {
        EClass eClass = (EClass) selected;
        object = eClass.getInstanceClass();
    } else // Adaptable, dig in to get to get Element...
    if (selected instanceof IAdaptable) {
        // This first
        object = ((IAdaptable) selected).getAdapter(IHelpHintProvider.class);
        if (object == null) {
            object = ((IAdaptable) selected).getAdapter(IArchimateConcept.class);
        }
        if (object == null) {
            object = ((IAdaptable) selected).getAdapter(IDiagramModelObject.class);
        }
        if (object == null) {
            object = ((IAdaptable) selected).getAdapter(IDiagramModelConnection.class);
        }
        if (object == null) {
            object = ((IAdaptable) selected).getAdapter(IDiagramModel.class);
        }
    } else // Default
    {
        object = selected;
    }
    // Hint Provider, if set
    if (object instanceof IHelpHintProvider) {
        String title = ((IHelpHintProvider) object).getHelpHintTitle();
        String text = ((IHelpHintProvider) object).getHelpHintContent();
        if (StringUtils.isSet(title) || StringUtils.isSet(text)) {
            fTitleLabel.setText(title);
            Color color = getTitleColor(object);
            fTitleLabel.setBackground(new Color[] { color, ColorConstants.white }, new int[] { 80 }, false);
            text = makeHTMLEntry(text);
            fBrowser.setText(text);
            // $NON-NLS-1$
            fLastPath = "";
            return;
        }
    }
    // Archimate Diagram Model use Viewpoint as key
    if (object instanceof IArchimateDiagramModel) {
        key = ((IArchimateDiagramModel) object).getViewpoint();
    }
    Hint hint = getHintFromObject(object, key);
    if (hint != null) {
        if (fLastPath != hint.path) {
            // Title and Color
            Color color = getTitleColor(object);
            fTitleLabel.setBackground(new Color[] { color, ColorConstants.white }, new int[] { 80 }, false);
            fTitleLabel.setText(hint.title);
            // Load page
            fPageLoaded = false;
            fBrowser.setUrl(hint.path);
            fLastPath = hint.path;
            // Kludge for Mac/Safari when displaying hint on mouse rollover menu item in MagicConnectionCreationTool
            if (PlatformUtils.isMac() && source instanceof MenuItem) {
                _doMacWaitKludge();
            }
        }
    } else {
        // $NON-NLS-1$
        fBrowser.setText("");
        // $NON-NLS-1$
        fLastPath = "";
        // $NON-NLS-1$
        fTitleLabel.setText("");
        fTitleLabel.setBackground(ColorConstants.white);
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) EClass(org.eclipse.emf.ecore.EClass) Color(org.eclipse.swt.graphics.Color) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) MenuItem(org.eclipse.swt.widgets.MenuItem) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 4 with IArchimateDiagramModel

use of com.archimatetool.model.IArchimateDiagramModel in project archi by archimatetool.

the class ViewpointChecker method findComponentsInWrongViewpoints.

List<IIssue> findComponentsInWrongViewpoints() {
    List<IIssue> issues = new ArrayList<IIssue>();
    for (IArchimateDiagramModel dm : fViews) {
        String id = dm.getViewpoint();
        IViewpoint viewPoint = ViewpointManager.INSTANCE.getViewpoint(id);
        for (Iterator<EObject> iter = dm.eAllContents(); iter.hasNext(); ) {
            EObject eObject = iter.next();
            if (eObject instanceof IDiagramModelArchimateObject) {
                IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) eObject;
                IArchimateElement element = dmo.getArchimateElement();
                if (!viewPoint.isAllowedConcept(element.eClass())) {
                    IIssue issue = createIssue(dmo, dm.getName(), viewPoint.getName());
                    issues.add(issue);
                }
            }
        }
    }
    return issues;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IIssue(com.archimatetool.hammer.validation.issues.IIssue) IViewpoint(com.archimatetool.model.viewpoints.IViewpoint) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 5 with IArchimateDiagramModel

use of com.archimatetool.model.IArchimateDiagramModel in project archi by archimatetool.

the class ViewpointManagerTests method testIsAllowedDiagramModelComponent.

@Test
public void testIsAllowedDiagramModelComponent() {
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    dm.setViewpoint("organization");
    IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo1.setArchimateElement(IArchimateFactory.eINSTANCE.createBusinessActor());
    dm.getChildren().add(dmo1);
    assertTrue(ViewpointManager.INSTANCE.isAllowedDiagramModelComponent(dmo1));
    IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo2.setArchimateElement(IArchimateFactory.eINSTANCE.createNode());
    dm.getChildren().add(dmo2);
    assertFalse(ViewpointManager.INSTANCE.isAllowedDiagramModelComponent(dmo2));
    IDiagramModelArchimateConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    conn.setArchimateRelationship(IArchimateFactory.eINSTANCE.createAssociationRelationship());
    conn.connect(dmo1, dmo2);
    assertFalse(ViewpointManager.INSTANCE.isAllowedDiagramModelComponent(conn));
    IDiagramModelArchimateObject dmo3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo3.setArchimateElement(IArchimateFactory.eINSTANCE.createBusinessRole());
    dm.getChildren().add(dmo3);
    conn.connect(dmo1, dmo3);
    assertTrue(ViewpointManager.INSTANCE.isAllowedDiagramModelComponent(conn));
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) Test(org.junit.Test)

Aggregations

IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)29 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)8 IIssue (com.archimatetool.hammer.validation.issues.IIssue)6 IArchimateModel (com.archimatetool.model.IArchimateModel)6 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)6 IViewpoint (com.archimatetool.model.viewpoints.IViewpoint)5 EObject (org.eclipse.emf.ecore.EObject)5 AdviceType (com.archimatetool.hammer.validation.issues.AdviceType)4 ISketchModel (com.archimatetool.model.ISketchModel)4 IArchimateElement (com.archimatetool.model.IArchimateElement)3 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)3 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)3 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)3 IDiagramEditorFactory (com.archimatetool.editor.diagram.IDiagramEditorFactory)2 ArchimateDiagramEditPartFactory (com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory)2 IFolder (com.archimatetool.model.IFolder)2 FreeformGraphicalRootEditPart (org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)2 GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2