protected Command computeCommand() { MUIElement selectedPart = model; if (selectedPart instanceof MPart) { MGenericStack<MUIElement> partStack = findParentStack(); if (partStack != null) { selectedPart = partStack; } } MElementContainer<MUIElement> parent = partStack.getParent(); List<MUIElement> children = parent.getChildren(); int index = children.indexOf(partStack); if (parent instanceof MGenericTile<?>) { MGenericTile<?> genericTile = (MGenericTile<?>) parent; int modelIndex = children.indexOf(selectedPart); if (modelIndex == 0 && index == 1 && children.size() == 2 && genericTile.isHorizontal()) { return UnexecutableCommand.INSTANCE; } } CompoundCommand result = new CompoundCommand(); MPartSashContainer newSash = MBasicFactory.INSTANCE.createPartSashContainer(); String preferData = partStack.getContainerData(); newSash.setContainerData(preferData); newSash.setHorizontal(true); if (selectedPart instanceof MPartStack) { if (selectedPart.getParent() == null) { selectedPart.setContainerData(preferData); result.add(CommandFactory.createAddChildCommand(newSash, selectedPart, 0)); } else { result.add(new ChangeParentCommand(newSash, selectedPart, 0)); if (!preferData.equals(selectedPart.getContainerData())) { result.add( new ApplyAttributeSettingCommand( (EObject) selectedPart, "containerData", preferData)); } } } else if (selectedPart instanceof MPart) { MPart part = (MPart) selectedPart; MPartStack createPartStack = MBasicFactory.INSTANCE.createPartStack(); createPartStack.setContainerData(preferData); if (part.getParent() != null) { result.add(new ChangeParentCommand(createPartStack, part, 0)); } else { result.add(CommandFactory.createAddChildCommand(createPartStack, part, 0)); } result.add(CommandFactory.createAddChildCommand(newSash, createPartStack, 0)); } result.add(new ChangeParentCommand(newSash, partStack, 1)); result.add(CommandFactory.createAddChildCommand(parent, newSash, index)); return result.unwrap(); }
@Override public void insert( MPartSashContainerElement toInsert, MPartSashContainerElement relTo, int where, float ratio) { assert (toInsert != null && relTo != null); if (ratio >= 1) { warn("EModelService#insert() expects the ratio to be between (0,100)"); // $NON-NLS-1$ ratio = ratio / 100; // reduce it } assert (ratio > 0 && ratio < 1); // determine insertion order boolean insertBefore = where == ABOVE || where == LEFT_OF; boolean horizontal = where == LEFT_OF || where == RIGHT_OF; MPartSashContainer newSash = BasicFactoryImpl.eINSTANCE.createPartSashContainer(); newSash.setHorizontal(horizontal); // Maintain the existing weight in the new sash newSash.setContainerData(relTo.getContainerData()); combine(toInsert, relTo, newSash, insertBefore, ratio); }