Search in sources :

Example 46 with IEntityPart

use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.

the class NotationStyling method getEmbeddingStyle.

public EmbeddingStyle getEmbeddingStyle(IStylingFactory stylingFactory, IEntityPart contextPart, IEntity entity) {
    if (!(contextPart instanceof IStyledPart))
        return EmbeddingStyle.NONE;
    IEntity parentEntity = stylingFactory.getParentEntity(entity);
    IEntityPart parentContextPart = stylingFactory.getParentPart(contextPart);
    IEntityStyling parentEntityStyling = getEntityStyling(stylingFactory, parentContextPart, parentEntity);
    boolean embedChild = parentEntityStyling.embedChild(entity.wGetParent().wIndexOf(entity));
    if (embedChild) {
        switch(parentEntityStyling.getLayoutStyle()) {
            case SIMPLE_TABLE:
                return EmbeddingStyle.TABLE_CELL;
            case COMPOSITE_TABLE:
                return EmbeddingStyle.TABLE_ROW;
            default:
                return EmbeddingStyle.NONE;
        }
    } else
        return EmbeddingStyle.NONE;
}
Also used : IEntity(org.whole.lang.model.IEntity) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 47 with IEntityPart

use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.

the class NotationStyling method isEmbedded.

public boolean isEmbedded(IStylingFactory stylingFactory, IEntityPart contextPart, IEntity entity) {
    if (!(contextPart instanceof IStyledPart))
        return false;
    IEntityStyling entityStyling = getEntityStyling(stylingFactory, contextPart, entity);
    LayoutStyle layoutStyle = entityStyling.getLayoutStyle();
    IEntity parentEntity = stylingFactory.getParentEntity(entity);
    IEntityPart parentContextPart = stylingFactory.getParentPart(contextPart);
    IEntityStyling parentEntityStyling = getEntityStyling(stylingFactory, parentContextPart, parentEntity);
    boolean embedChild = parentEntityStyling.embedChild(entity.wGetParent().wIndexOf(entity));
    if (embedChild)
        return true;
    else {
        LayoutStyle parentLayoutStyle = parentEntityStyling.getLayoutStyle();
        switch(parentLayoutStyle) {
            case COLUMN:
            case COMPOSITE_TABLE:
                return embedChild;
            case TABLE_CELL:
            case TABLE_ROW:
                return true;
            case TREE:
                return false;
            case SIMPLE_TABLE:
            default:
                return isEmbedded(stylingFactory, parentContextPart, parentEntity);
        }
    }
}
Also used : LayoutStyle(org.whole.lang.ui.notations.styledtree.styling.EntityStyling.LayoutStyle) IEntity(org.whole.lang.model.IEntity) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 48 with IEntityPart

use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.

the class TextTransferDropTargetListener method getCommand.

@Override
protected Command getCommand() {
    String text = (String) getCurrentEvent().data;
    Shell shell = getViewer().getControl().getShell();
    IImportAsModelDialog dialog = factory.createImplicitElementImportAsModelDialog(shell, "Drop As", false);
    if (!dialog.show())
        return null;
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    EntityDescriptor<?> stage = dialog.getStage();
    try {
        IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
        bm.wDefValue("parseFragments", true);
        IEntity entity = persistenceKit.readModel(new StringPersistenceProvider(text, bm));
        // FIXME workaround for selections with multiple entities
        if (EntityUtils.isTuple(entity))
            bm.wDef("syntheticRoot", entity);
        boolean hasSyntheticRoot = bm.wIsSet("syntheticRoot");
        IEntityIterator<IEntity> iterator;
        boolean needsCompositeTarget = false;
        if (hasSyntheticRoot) {
            IEntity syntheticRoot = bm.wGet("syntheticRoot");
            iterator = IteratorFactory.childIterator();
            iterator.reset(syntheticRoot);
            needsCompositeTarget = syntheticRoot.wSize() > 1;
        } else {
            iterator = IteratorFactory.selfIterator();
            iterator.reset(entity);
        }
        List<IEntityPart> editParts = new ArrayList<IEntityPart>();
        while (iterator.hasNext()) {
            IEntity stageEntity = EntityUtils.clone(iterator.next());
            stageEntity = ClipboardUtils.conditionalStageAdd(getTargetEditPart(), stage, stageEntity, needsCompositeTarget);
            editParts.add(ClipboardUtils.createEditPart(getViewer().getEditPartFactory(), stageEntity));
        }
        ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
        request.setEditParts(editParts);
        return super.getCommand();
    } catch (Exception e) {
        return null;
    }
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) IBindingManager(org.whole.lang.bindings.IBindingManager) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 49 with IEntityPart

use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.

the class TextTransferDragSourceListener method dragSetData.

public void dragSetData(DragSourceEvent event) {
    EditPartViewer viewer = getViewer();
    List<EditPart> selectedEditParts = getSelectedEditParts();
    IStructuredSelection selection = new StructuredSelection(selectedEditParts);
    if (ClipboardUtils.hasTextSeletion(viewer, selection))
        event.data = ClipboardUtils.getTextSelection(viewer, selection);
    else
        try {
            int length = selectedEditParts.size();
            IEntity[] values = new IEntity[length];
            for (int i = 0; i < length; i++) values[i] = EntityUtils.clone(((IEntityPart) selectedEditParts.get(i)).getModelEntity());
            event.data = ClipboardUtils.unparseEntity(BindingManagerFactory.instance.createTuple(true, values));
        } catch (Exception e) {
            event.data = "";
        }
}
Also used : EditPart(org.eclipse.gef.EditPart) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EditPartViewer(org.eclipse.gef.EditPartViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Aggregations

IEntityPart (org.whole.lang.ui.editparts.IEntityPart)49 IEntity (org.whole.lang.model.IEntity)21 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)12 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 ArrayList (java.util.ArrayList)6 EditPart (org.eclipse.gef.EditPart)6 Point (org.eclipse.draw2d.geometry.Point)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 FocusEvent (org.eclipse.swt.events.FocusEvent)4 FocusListener (org.eclipse.swt.events.FocusListener)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ActionRegistry (org.whole.lang.e4.ui.actions.ActionRegistry)4 E4KeyHandler (org.whole.lang.e4.ui.actions.E4KeyHandler)4 E4NavigationKeyHandler (org.whole.lang.e4.ui.actions.E4NavigationKeyHandler)4 IPartFocusListener (org.whole.lang.ui.editparts.IPartFocusListener)4 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)4 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)3