コード例 #1
0
  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();
  }
コード例 #2
0
  @Override
  public void detach(MPartSashContainerElement element, int x, int y, int width, int height) {
    // If we're showing through a placehoilder then detach it...
    if (element.getCurSharedRef() != null) {
      element = element.getCurSharedRef();
    }

    // Determine the correct parent for the new window
    MWindow window = getTopLevelWindowFor(element);
    MPerspective thePersp = getPerspectiveFor(element);

    MTrimmedWindow newWindow = MBasicFactory.INSTANCE.createTrimmedWindow();

    newWindow.setX(x);
    newWindow.setY(y);
    newWindow.setWidth(width);
    newWindow.setHeight(height);

    element.getParent().getChildren().remove(element);
    MWindowElement uiRoot = wrapElementForWindow(element);
    newWindow.getChildren().add(uiRoot);

    if (thePersp != null) {
      thePersp.getWindows().add(newWindow);
    } else if (window != null) {
      window.getWindows().add(newWindow);
    }
  }
コード例 #3
0
 /**
  * Wraps an element in a PartStack if it's a MPart or an MPlaceholder that references an MPart
  *
  * @param element The element to be wrapped
  * @return The wrapper for the given element
  */
 private MWindowElement wrapElementForWindow(MPartSashContainerElement element) {
   if (element instanceof MPlaceholder) {
     MUIElement ref = ((MPlaceholder) element).getRef();
     if (ref instanceof MPart) {
       MPartStack newPS = MBasicFactory.INSTANCE.createPartStack();
       newPS.getChildren().add((MPlaceholder) element);
       return newPS;
     }
   } else if (element instanceof MPart) {
     MPartStack newPS = MBasicFactory.INSTANCE.createPartStack();
     newPS.getChildren().add((MPart) element);
     return newPS;
   } else if (element instanceof MWindowElement) {
     return (MWindowElement) element;
   }
   return null;
 }