Search in sources :

Example 11 with IDiagramModel

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

the class DiagramModelConnectionSection method createRouterTypeControl.

private void createRouterTypeControl(Composite parent) {
    // Label
    createLabel(parent, Messages.DiagramModelConnectionSection_0, ITabbedLayoutConstants.BIG_LABEL_WIDTH, SWT.CENTER);
    // Combo
    fComboRouterType = new Combo(parent, SWT.READ_ONLY);
    fComboRouterType.setItems(comboItems);
    fComboRouterType.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CompoundCommand result = new CompoundCommand();
            for (EObject dm : getEObjects()) {
                if (isAlive(dm)) {
                    Command cmd = new ConnectionRouterTypeCommand((IDiagramModel) dm, ConnectionRouterAction.CONNECTION_ROUTER_TYPES.get(fComboRouterType.getSelectionIndex()));
                    if (cmd.canExecute()) {
                        result.add(cmd);
                    }
                }
            }
            executeCommand(result.unwrap());
        }
    });
    GridData gd = new GridData(SWT.NONE, SWT.NONE, true, false);
    gd.minimumWidth = ITabbedLayoutConstants.COMBO_WIDTH;
    fComboRouterType.setLayoutData(gd);
}
Also used : ConnectionRouterTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionRouterTypeCommand) ConnectionRouterTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionRouterTypeCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IDiagramModel(com.archimatetool.model.IDiagramModel) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EObject(org.eclipse.emf.ecore.EObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) Combo(org.eclipse.swt.widgets.Combo) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 12 with IDiagramModel

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

the class CopySnapshot method translateToAbsolute.

/**
 * Translate an objects x,y position to absolute co-ordinates
 * @param object
 * @param pt
 */
private void translateToAbsolute(IDiagramModelObject object, Point pt) {
    if (object.eContainer() instanceof IDiagramModelContainer && !(object.eContainer() instanceof IDiagramModel)) {
        IDiagramModelObject parent = (IDiagramModelObject) object.eContainer();
        pt.performTranslate(parent.getBounds().getX(), parent.getBounds().getY());
        translateToAbsolute(parent, pt);
    }
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 13 with IDiagramModel

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

the class DeleteFromModelAction method run.

@Override
public void run() {
    List<?> selection = getSelectedObjects();
    List<IArchimateConcept> archimateConcepts = new ArrayList<IArchimateConcept>();
    List<IDiagramModelComponent> diagramObjects = new ArrayList<IDiagramModelComponent>();
    // Gather Model elements, relations
    for (Object object : selection) {
        if (object instanceof EditPart) {
            Object model = ((EditPart) object).getModel();
            if (model instanceof IDiagramModelArchimateObject) {
                IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
                if (!archimateConcepts.contains(element)) {
                    archimateConcepts.add(element);
                }
                // Element's relationships
                for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
                    if (!archimateConcepts.contains(relation)) {
                        archimateConcepts.add(relation);
                    }
                    // Relation's relationships
                    for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
                        if (!archimateConcepts.contains(r)) {
                            archimateConcepts.add(r);
                        }
                    }
                }
            } else if (model instanceof IDiagramModelArchimateConnection) {
                IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
                if (!archimateConcepts.contains(relation)) {
                    archimateConcepts.add(relation);
                }
                // Relation's relationships
                for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
                    if (!archimateConcepts.contains(r)) {
                        archimateConcepts.add(r);
                    }
                }
            }
        }
    }
    // Gather referenced diagram objects
    for (IArchimateConcept archimateConcept : archimateConcepts) {
        for (IDiagramModel diagramModel : archimateConcept.getArchimateModel().getDiagramModels()) {
            for (IDiagramModelComponent dc : DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, archimateConcept)) {
                diagramObjects.add(dc);
            }
        }
    }
    // Check whether any of these concepts are referenced in other diagrams
    if (hasMoreThanOneReference(archimateConcepts, diagramObjects)) {
        if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.DeleteFromModelAction_0, Messages.DeleteFromModelAction_1 + // $NON-NLS-1$
        "\n\n" + Messages.DeleteFromModelAction_2)) {
            return;
        }
    }
    // Create commands
    CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(TEXT);
    for (IArchimateConcept archimateConcept : archimateConcepts) {
        if (archimateConcept instanceof IArchimateElement) {
            Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
            compoundCommand.add(cmd);
        } else if (archimateConcept instanceof IArchimateRelationship) {
            Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
            compoundCommand.add(cmd);
        }
    }
    for (IDiagramModelComponent dc : diagramObjects) {
        if (dc instanceof IDiagramModelObject) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) dc);
            compoundCommand.add(cmd);
        } else if (dc instanceof IDiagramModelConnection) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) dc);
            compoundCommand.add(cmd);
        }
    }
    execute(compoundCommand);
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) EditPart(org.eclipse.gef.EditPart) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) Command(org.eclipse.gef.commands.Command) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 14 with IDiagramModel

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

the class DiagramEditorInputFactory method saveState.

/**
 * Saves the state of the given diagram editor input into the given memento.
 *
 * @param memento the storage area for element state
 * @param input the diagram editor input
 */
public static void saveState(IMemento memento, DiagramEditorInput input) {
    IDiagramModel diagramModel = input.getDiagramModel();
    if (diagramModel != null && diagramModel.getArchimateModel() != null) {
        memento.putString(TAG_VIEW_ID, diagramModel.getId());
        String name = diagramModel.getName();
        if (name != null) {
            memento.putString(TAG_VIEW_NAME, name);
        }
        File file = diagramModel.getArchimateModel().getFile();
        if (file != null) {
            memento.putString(TAG_VIEW_FILE, file.getAbsolutePath());
        }
    }
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) File(java.io.File)

Example 15 with IDiagramModel

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

the class DiagramEditorInputFactory method createElement.

@Override
public IAdaptable createElement(IMemento memento) {
    String viewID = memento.getString(TAG_VIEW_ID);
    String fileName = memento.getString(TAG_VIEW_FILE);
    String viewName = memento.getString(TAG_VIEW_NAME);
    if (viewID != null && fileName != null) {
        File file = new File(fileName);
        for (IArchimateModel model : IEditorModelManager.INSTANCE.getModels()) {
            if (file.equals(model.getFile())) {
                for (IDiagramModel diagramModel : model.getDiagramModels()) {
                    if (viewID.equals(diagramModel.getId())) {
                        return new DiagramEditorInput(diagramModel);
                    }
                }
            }
        }
    }
    // Cannot find it, must have been removed from file
    return new NullDiagramEditorInput(fileName, viewName);
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

IDiagramModel (com.archimatetool.model.IDiagramModel)68 Test (org.junit.Test)28 IArchimateElement (com.archimatetool.model.IArchimateElement)16 IArchimateModel (com.archimatetool.model.IArchimateModel)12 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)12 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)11 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)9 File (java.io.File)8 EObject (org.eclipse.emf.ecore.EObject)8 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)8 Image (org.eclipse.swt.graphics.Image)8 IArchimateConcept (com.archimatetool.model.IArchimateConcept)7 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)7 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)6 Command (org.eclipse.gef.commands.Command)6 GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)6 Shell (org.eclipse.swt.widgets.Shell)6