Search in sources :

Example 36 with IArchimateConcept

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

the class UsedInViewsSection method createTableControl.

private void createTableControl(Composite parent) {
    createLabel(parent, Messages.UsedInViewsSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
    // Table
    Composite tableComp = createTableComposite(parent, SWT.NONE);
    TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
    fTableViewer = new TableViewer(tableComp, SWT.BORDER | SWT.FULL_SELECTION);
    // Column
    TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
    // On Mac shows alternate table row colours
    fTableViewer.getTable().setLinesVisible(true);
    // Help ID
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }

        public Object[] getElements(Object inputElement) {
            return DiagramModelUtils.findReferencedDiagramsForArchimateConcept((IArchimateConcept) inputElement).toArray();
        }
    });
    fTableViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((IDiagramModel) element).getName();
        }

        @Override
        public Image getImage(Object element) {
            return IArchiImages.ImageFactory.getImage(IArchiImages.ICON_DIAGRAM);
        }
    });
    fTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            if (!isAlive(fArchimateConcept)) {
                return;
            }
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (o instanceof IDiagramModel) {
                IDiagramModel diagramModel = (IDiagramModel) o;
                IDiagramModelEditor editor = EditorManager.openDiagramEditor(diagramModel);
                if (editor instanceof IArchimateDiagramEditor) {
                    ((IArchimateDiagramEditor) editor).selectArchimateConcepts(new IArchimateConcept[] { fArchimateConcept });
                }
            }
        }
    });
    fTableViewer.setComparator(new ViewerComparator());
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Image(org.eclipse.swt.graphics.Image) IDiagramModelEditor(com.archimatetool.editor.diagram.IDiagramModelEditor) IArchimateDiagramEditor(com.archimatetool.editor.diagram.IArchimateDiagramEditor) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IDiagramModel(com.archimatetool.model.IDiagramModel) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IArchimateConcept(com.archimatetool.model.IArchimateConcept) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 37 with IArchimateConcept

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

the class CSVImporter method importRelations.

// -------------------------------- Import Relations --------------------------------
/**
 * Import Relations from CSV file
 * @param file The file to import
 * @throws IOException
 * @throws CSVParseException
 */
void importRelations(File file) throws IOException, CSVParseException {
    for (CSVRecord csvRecord : getRecords(file)) {
        if (!isRelationsRecordCorrectSize(csvRecord)) {
            throw new CSVParseException(Messages.CSVImporter_2);
        }
        // Header
        if (isHeaderRecord(csvRecord, RELATIONSHIPS_HEADER)) {
            continue;
        } else // Relation
        {
            createRelationFromRecord(csvRecord);
        }
    }
    // Now connect the relations
    for (Entry<String, IArchimateConcept> entry : newConcepts.entrySet()) {
        if (entry.getValue() instanceof IArchimateRelationship) {
            IArchimateRelationship relation = (IArchimateRelationship) entry.getValue();
            // Get the ids from the temporary stores
            // $NON-NLS-1$
            IArchimateConcept source = findReferencedConcept((String) relation.getAdapter("sourceID"));
            // $NON-NLS-1$
            IArchimateConcept target = findReferencedConcept((String) relation.getAdapter("targetID"));
            // Is it a valid relationship?
            if (!ArchimateModelUtils.isValidRelationship(source.eClass(), target.eClass(), relation.eClass())) {
                throw new CSVParseException(Messages.CSVImporter_5 + relation.getId());
            }
            // Connect
            relation.connect(source, target);
        }
    }
}
Also used : IArchimateConcept(com.archimatetool.model.IArchimateConcept) CSVRecord(org.apache.commons.csv.CSVRecord) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) CSVParseException(com.archimatetool.csv.CSVParseException)

Example 38 with IArchimateConcept

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

the class TreeSelectionSynchroniser method selectionChanged.

@Override
public void selectionChanged(SelectionChangedEvent event) {
    if (isDispatching) {
        return;
    }
    fLastEvent = event;
    if (!Preferences.doLinkView() || !fDoSync) {
        return;
    }
    isDispatching = true;
    ISelection selection = event.getSelection();
    Object source = event.getSource();
    // Selection from Diagram Editor, so update the Tree if it is showing
    if (source instanceof GraphicalViewer && fTreeView != null) {
        List<Object> list = new ArrayList<Object>();
        for (Object o : ((IStructuredSelection) selection).toArray()) {
            if (o instanceof EditPart) {
                Object model = ((EditPart) o).getModel();
                // Archimate concept
                if (model instanceof IDiagramModelArchimateComponent) {
                    model = ((IDiagramModelArchimateComponent) model).getArchimateConcept();
                    list.add(model);
                } else // Diagram model
                if (model instanceof IDiagramModel) {
                    list.add(model);
                }
            }
        }
        // Select in tree
        fTreeView.getViewer().setSelection(new StructuredSelection(list), true);
    } else // Archimate objects selection from Tree View, so update any Archimate Diagram Editors
    if (source instanceof TreeViewer) {
        List<IArchimateConcept> list = new ArrayList<IArchimateConcept>();
        // Archimate elements
        for (Object o : ((IStructuredSelection) selection).toArray()) {
            if (o instanceof IArchimateConcept) {
                list.add((IArchimateConcept) o);
            }
        }
        // Select these in the Diagram Editors
        for (IDiagramModelEditor diagramEditor : fDiagramEditors) {
            if (diagramEditor instanceof IArchimateDiagramEditor) {
                ((IArchimateDiagramEditor) diagramEditor).selectArchimateConcepts(list.toArray(new IArchimateConcept[list.size()]));
            }
        }
    }
    isDispatching = false;
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) EditPart(org.eclipse.gef.EditPart) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDiagramModelEditor(com.archimatetool.editor.diagram.IDiagramModelEditor) IArchimateDiagramEditor(com.archimatetool.editor.diagram.IArchimateDiagramEditor) IDiagramModel(com.archimatetool.model.IDiagramModel) ISelection(org.eclipse.jface.viewers.ISelection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

IArchimateConcept (com.archimatetool.model.IArchimateConcept)38 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)14 ArrayList (java.util.ArrayList)9 IDiagramModel (com.archimatetool.model.IDiagramModel)7 EObject (org.eclipse.emf.ecore.EObject)7 IArchimateElement (com.archimatetool.model.IArchimateElement)6 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)6 Test (org.junit.Test)6 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)5 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IArchimateDiagramEditor (com.archimatetool.editor.diagram.IArchimateDiagramEditor)3 IDiagramModelEditor (com.archimatetool.editor.diagram.IDiagramModelEditor)3 IArchimateModel (com.archimatetool.model.IArchimateModel)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 CSVParseException (com.archimatetool.csv.CSVParseException)2 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)2 IConnectable (com.archimatetool.model.IConnectable)2 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)2