Search in sources :

Example 1 with IArchimateModelObject

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

the class AbstractECorePropertySection method getFilteredObjects.

/**
 * Filter selected objects.
 * Also ensure that selected objects are from only one model.
 * We don't support selections from more than one model due to each model having its own command stack.
 *
 * @return A list of filtered adaptable objects according to type
 */
private List<EObject> getFilteredObjects(List<?> objects) {
    ArrayList<EObject> list = new ArrayList<EObject>();
    IObjectFilter filter = getFilter();
    // Get underlying object if a Filter is applied
    for (Object object : objects) {
        if (filter != null) {
            object = filter.adaptObject(object);
        }
        if (object instanceof EObject) {
            list.add((EObject) object);
        }
    }
    // Only use the objects that are in *one* model - the model in the first selected object
    if (!list.isEmpty()) {
        IArchimateModel firstModel = ((IArchimateModelObject) list.get(0)).getArchimateModel();
        // Remove objects with different parent models
        for (int i = list.size() - 1; i >= 1; i--) {
            IArchimateModelObject eObject = (IArchimateModelObject) list.get(i);
            if (eObject.getArchimateModel() != firstModel) {
                list.remove(eObject);
            }
        }
    }
    return list;
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 2 with IArchimateModelObject

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

the class ZestView method propertyChange.

// =================================================================================
// Listen to Editor Model Changes
// =================================================================================
@Override
public void propertyChange(PropertyChangeEvent evt) {
    String propertyName = evt.getPropertyName();
    Object newValue = evt.getNewValue();
    // Model Closed
    if (propertyName == IEditorModelManager.PROPERTY_MODEL_REMOVED) {
        Object input = getViewer().getInput();
        if (input instanceof IArchimateModelObject && ((IArchimateModelObject) input).getArchimateModel() == newValue) {
            fDrillDownManager.reset();
        }
    } else // Command Stack - update Actions
    if (propertyName == IEditorModelManager.COMMAND_STACK_CHANGED) {
        updateActions();
    } else {
        super.propertyChange(evt);
    }
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject)

Example 3 with IArchimateModelObject

use of com.archimatetool.model.IArchimateModelObject 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 4 with IArchimateModelObject

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

the class TreeModelViewerFindReplaceProvider method getModelInScope.

/**
 * @return The model in scope of the selected element
 */
private IArchimateModel getModelInScope() {
    IStructuredSelection selection = (IStructuredSelection) fTreeModelViewer.getSelection();
    Object o = selection.getFirstElement();
    if (o instanceof IArchimateModelObject) {
        return ((IArchimateModelObject) o).getArchimateModel();
    }
    return null;
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 5 with IArchimateModelObject

use of com.archimatetool.model.IArchimateModelObject 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)

Aggregations

IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)9 EObject (org.eclipse.emf.ecore.EObject)5 IArchimateModel (com.archimatetool.model.IArchimateModel)4 IFolder (com.archimatetool.model.IFolder)2 File (java.io.File)2 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)1 MoveFolderCommand (com.archimatetool.editor.views.tree.commands.MoveFolderCommand)1 MoveObjectCommand (com.archimatetool.editor.views.tree.commands.MoveObjectCommand)1 IIdentifier (com.archimatetool.model.IIdentifier)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IMemento (org.eclipse.ui.IMemento)1