Search in sources :

Example 6 with IArchimateModelObject

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

the class TreeStateHelper method saveStateOnApplicationClose.

/**
 * Save expanded state of tree elements on Application close
 * @param memento
 */
void saveStateOnApplicationClose(IMemento memento) {
    Hashtable<File, String> map = new Hashtable<File, String>();
    IMemento expandedMem = memento.createChild(MEMENTO_EXPANDED);
    for (Object element : fTreeViewer.getVisibleExpandedElements()) {
        if (element instanceof IIdentifier && element instanceof IArchimateModelObject) {
            // Only store if saved in a file
            File file = ((IArchimateModelObject) element).getArchimateModel().getFile();
            if (file != null) {
                String id = ((IIdentifier) element).getId();
                String string = map.get(file);
                if (string == null) {
                    string = id;
                } else {
                    string += ELEMENT_SEP_CHAR + id;
                }
                map.put(file, string);
            }
        }
    }
    for (File file : map.keySet()) {
        IMemento elementMem = expandedMem.createChild(MEMENTO_MODEL);
        elementMem.putString(MEMENTO_FILE, file.getAbsolutePath());
        elementMem.putString(MEMENTO_ELEMENTS, map.get(file));
    }
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) Hashtable(java.util.Hashtable) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) File(java.io.File) IMemento(org.eclipse.ui.IMemento)

Example 7 with IArchimateModelObject

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

the class NavigatorView 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().getActualInput();
        if (input instanceof IArchimateModelObject && ((IArchimateModelObject) input).getArchimateModel() == newValue) {
            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 8 with IArchimateModelObject

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

the class TreeModelViewerDragDropHandler method moveTreeObjects.

/**
 * Move Tree Objects
 */
void moveTreeObjects(IFolder newParent, Object[] objects) {
    final CompoundCommand compoundCommand = new NonNotifyingCompoundCommand() {

        @Override
        public String getLabel() {
            return getCommands().size() > 1 ? Messages.TreeModelViewerDragDropHandler_0 : super.getLabel();
        }
    };
    for (Object object : objects) {
        if (object instanceof IFolder) {
            // This first - folders go in folders
            if (!newParent.getFolders().contains(object)) {
                compoundCommand.add(new MoveFolderCommand(newParent, (IFolder) object));
            }
        } else if (object instanceof IArchimateModelObject) {
            if (!newParent.getElements().contains(object)) {
                compoundCommand.add(new MoveObjectCommand(newParent, (IArchimateModelObject) object));
            }
        }
    }
    CommandStack stack = (CommandStack) newParent.getAdapter(CommandStack.class);
    stack.execute(compoundCommand);
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) CommandStack(org.eclipse.gef.commands.CommandStack) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) MoveFolderCommand(com.archimatetool.editor.views.tree.commands.MoveFolderCommand) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IFolder(com.archimatetool.model.IFolder) MoveObjectCommand(com.archimatetool.editor.views.tree.commands.MoveObjectCommand)

Example 9 with IArchimateModelObject

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

the class GenerateViewAction method isSameModel.

/**
 * As this action is for the models tree, it's possible a user could select objects
 * from different models. We don't want this.
 */
private boolean isSameModel(IStructuredSelection selection) {
    IArchimateModel model = null;
    for (Object o : selection.toArray()) {
        if (o instanceof IArchimateModelObject) {
            IArchimateModel nextModel = ((IArchimateModelObject) o).getArchimateModel();
            if (model != null && model != nextModel) {
                return false;
            }
            model = nextModel;
        }
    }
    return true;
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) 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