/**
  * @see org.eclipse.ui.dialogs.CheckedTreeSelectionDialog#setInput(java.lang.Object)
  * @param input
  */
 @Override
 public void setInput(Object input) {
   super.setInput(input);
   if (input instanceof List<?> && !((List<?>) input).isEmpty()) {
     Object obj = ((List<?>) input).get(0);
     if (obj instanceof EditPart) {
       diagramEP = DiagramEditPartsUtil.getDiagramEditPart((EditPart) obj);
     }
   }
   Assert.isNotNull(diagramEP);
 }
 /** @generated */
 protected Image getLabelIcon() {
   EObject parserElement = getParserElement();
   if (parserElement == null) {
     return null;
   }
   List<View> views = DiagramEditPartsUtil.findViews(parserElement, getViewer());
   for (View view : views) {
     if (NameLabelIconHelper.showLabelIcon(view)) {
       return UMLElementTypes.getImage(parserElement.eClass());
     }
   }
   return null;
 }
 /**
  * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
  * @param element
  * @return
  */
 public String getText(Object element) {
   EditPart dummyEP = DiagramEditPartsUtil.getEditPartFromView((View) element, diagramEP);
   String text = "[No Text To Display]";
   if (dummyEP instanceof GraphicalEditPart) {
     IFigure figure = ((GraphicalEditPart) dummyEP).getFigure();
     if (figure instanceof WrappingLabel) {
       String str = ((WrappingLabel) figure).getText();
       if (str != null && str.length() != 0) {
         text = str;
       }
     }
   }
   return text;
 }
示例#4
0
 /**
  * Tests if the compartment is a compartment list
  *
  * @param node the node on which we want add an Overlay
  * @return <code>true</code> if the compartment is managed by an {@link XYLayoutEditPolicy}
  */
 protected boolean isInCompartmentList(Node node) {
   IGraphicalEditPart gep =
       (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class);
   if (gep != null && gep.getRoot() != null) {
     EObject container = node.eContainer();
     if (container instanceof View) {
       EditPart EP = DiagramEditPartsUtil.getEditPartFromView((View) container, gep);
       EditPolicy editPolicy = EP.getEditPolicy(EditPolicy.LAYOUT_ROLE);
       if (!(editPolicy instanceof XYLayoutEditPolicy)) { // we are in a
         // compartment
         // list
         return true;
       }
     }
   }
   return false;
 }
 private Float getPosition(InteractionFragment fragment) {
   if (fragment == null) {
     return null;
   }
   View view = getGraphicalView(fragment);
   if (view == null) {
     return null;
   }
   Float[] preferPosition = cachePositions != null ? cachePositions.get(view) : null;
   EObject hostElement = ViewUtil.resolveSemanticElement(view);
   EditPart editPart = DiagramEditPartsUtil.getEditPartFromView(view, fragmentRootEditPart);
   if (fragment instanceof MessageOccurrenceSpecification
       && hostElement instanceof Message
       && editPart instanceof ConnectionNodeEditPart) {
     boolean isStart = fragment == ((Message) hostElement).getSendEvent();
     Point location =
         getAbsoluteEdgeExtremity((ConnectionNodeEditPart) editPart, isStart, preferPosition);
     if (location != null) {
       return isStart ? location.y - HALF_UNIT : location.y + HALF_UNIT;
     }
   } else if (fragment instanceof ExecutionOccurrenceSpecification
       && hostElement instanceof ExecutionSpecification
       && editPart instanceof IGraphicalEditPart) {
     Rectangle bounds = getAbsoluteBounds((IGraphicalEditPart) editPart, preferPosition);
     if (bounds != null) {
       if (bounds.height <= 0) {
         bounds.height = 50; // LifelineXYLayoutEditPolicy.EXECUTION_INIT_HEIGHT;
       }
       if (fragment == ((ExecutionSpecification) hostElement).getStart()) {
         return bounds.y - HALF_UNIT;
       } else {
         return bounds.bottom() + HALF_UNIT;
       }
     }
   } else if (view instanceof Shape && editPart instanceof IGraphicalEditPart) {
     Rectangle bounds = getAbsoluteBounds((IGraphicalEditPart) editPart, preferPosition);
     if (bounds != null) {
       return bounds.y * CONVERT_UNIT;
     }
   }
   return null;
 }
 private View getGraphicalView(EObject eObj) {
   if (eObj instanceof ExecutionOccurrenceSpecification) {
     ExecutionSpecification execution = ((ExecutionOccurrenceSpecification) eObj).getExecution();
     return getGraphicalView(execution);
   } else if (eObj instanceof MessageOccurrenceSpecification) {
     return getGraphicalView(((MessageOccurrenceSpecification) eObj).getMessage());
   } else if (eObj instanceof PartDecomposition) {
     EList<Lifeline> covereds = ((PartDecomposition) eObj).getCovereds();
     if (covereds.size() == 1) {
       return getGraphicalView(covereds.get(0));
     }
   } else if (eObj != null) {
     List<?> views = DiagramEditPartsUtil.getEObjectViews(eObj);
     if (views.size() == 1) {
       return (View) views.get(0);
     }
     return null;
   }
   return null;
 }
  /** {@inheritDoc} */
  @Override
  protected Command getActionCommand() {
    /* for further information, see bug 302555 */
    ViewServiceUtil.forceLoad();

    ShowHideCompartmentRequest req = null;
    CompoundCommand completeCmd =
        new CompoundCommand("Destroy and Create Compartment Command"); // $NON-NLS-1$

    // the commands to hide compartment
    for (EditPartRepresentation current : this.viewsToDestroy) {
      if (current instanceof CompartmentEditPartRepresentation) {
        CompartmentEditPartRepresentation currentRepresentation =
            (CompartmentEditPartRepresentation) current;
        View currentView = currentRepresentation.getCompartmentView();
        EditPart currentEditPart =
            currentRepresentation
                .getRepresentedEditPart(); // should not be null, because a view to  delete should
                                           // be visible, and so have an existing associated edit
                                           // part.
        // if null, try to find it using gmf methods from the view

        if (currentEditPart == null) {
          Activator.log.debug(
              "Warning! An edit part representation wished to destroy a view, but no edit part exists currently!"
                  + current);
          currentEditPart =
              DiagramEditPartsUtil.getEditPartFromView(currentView, selectedElements.get(0))
                  .getParent();
        }

        if (currentEditPart != null) {
          req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.HIDE, currentView);
          req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
          Command tmp = currentEditPart.getCommand(req);
          if (tmp != null && tmp.canExecute()) {
            completeCmd.add(tmp);
          }
        } else {
          Activator.log.debug(
              "Impossible to find an edit part for the given representation: " + current);
        }
      }

      //			if(current instanceof View) {
      //				EditPart ep = DiagramEditPartsUtil.getEditPartFromView((View)current,
      // selectedElements.get(0)).getParent();
      //				req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.HIDE,
      // ((View)current).getType());
      //				req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
      //				Command tmp = ep.getCommand(req);
      //				if(tmp != null && tmp.canExecute()) {
      //					completeCmd.add(tmp);
      //				}
      //			} else if(current instanceof CompartmentTitleRepresentation) {
      //				ShowHideTitleOfCompartmentCommand tmp = new
      // ShowHideTitleOfCompartmentCommand(this.domain,
      // (View)((CompartmentTitleRepresentation)current).getRealObject(), false);
      //				if(tmp != null && tmp.canExecute()) {
      //					completeCmd.add(new ICommandProxy(tmp));
      //				}
      //			}
    }

    // the command to show compartment
    for (EditPartRepresentation current : this.viewsToCreate) {
      if (current instanceof CompartmentEditPartRepresentation) {
        CompartmentEditPartRepresentation currentRepresentation =
            (CompartmentEditPartRepresentation) current;
        View currentView = currentRepresentation.getCompartmentView();
        EditPartRepresentation parentRepresentation =
            currentRepresentation.getParentRepresentation();
        IGraphicalEditPart parentEditPart = parentRepresentation.getRepresentedEditPart();
        if (currentView != null && parentEditPart != null) {
          req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.SHOW, currentView);
          req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
          Command tmp = parentEditPart.getCommand(req);
          if (tmp != null && tmp.canExecute()) {
            completeCmd.add(tmp);
          }
        }
      }

      //			if(current instanceof View) {
      //				EditPart ep = CompartmentUtils.getCompartmentTitleRepresentation(rep,
      // (View)current).getParent();
      //				req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.SHOW,
      // ((View)current).getType());
      //				req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
      //				Command tmp = ep.getCommand(req);
      //				if(tmp != null && tmp.canExecute()) {
      //					completeCmd.add(tmp);
      //				}
      //			} else if(current instanceof CompartmentTitleRepresentation) {
      //				CompartmentTitleRepresentation compartmentTitleRep =
      // (CompartmentTitleRepresentation)current;
      //				final View view = (View)compartmentTitleRep.getRealObject();
      //				Style style = view.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
      //				if(style == null) {
      //					// style is not existing yet (true for models created with Papyrus 0.7.x) => create now
      //					// See bug 351084
      //					completeCmd.add(new ICommandProxy(new AbstractTransactionalCommand(domain, "Create
      // title style", Collections.EMPTY_LIST) { //$NON-NLS-1$
      //
      //						public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) {
      //							TitleStyle style =
      // (TitleStyle)view.createStyle(NotationPackage.eINSTANCE.getTitleStyle());
      //							style.setShowTitle(false);
      //							return CommandResult.newOKCommandResult();
      //						}
      //					}));
      //				}
      //				ShowHideTitleOfCompartmentCommand tmp = new
      // ShowHideTitleOfCompartmentCommand(this.domain, view, true);
      //				if(tmp != null && tmp.canExecute()) {
      //					completeCmd.add(new ICommandProxy(tmp));
      //				}
      //			}
    }

    // now sets the visibility for all shown views

    for (CompartmentEditPartRepresentation currentRepresentation : visibleRepresentations) {
      final View currentView = currentRepresentation.getCompartmentView();
      boolean newVisibility = currentRepresentation.isTitleVisible();
      boolean oldVisibility = CompartmentUtils.isCompartmentTitleVisible(currentView);

      IGraphicalEditPart parentEditPart =
          currentRepresentation.getParentRepresentation().getRepresentedEditPart();
      final TransactionalEditingDomain domain = parentEditPart.getEditingDomain();
      // visibility has changed => change the model
      if (newVisibility != oldVisibility) {
        Style style = currentView.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
        if (style == null) {
          // style is not existing yet (true for models created with Papyrus 0.7.x) => create now
          // See bug 351084
          completeCmd.add(
              new ICommandProxy(
                  new AbstractTransactionalCommand(
                      domain, "Create title style", Collections.EMPTY_LIST) { // $NON-NLS-1$

                    @Override
                    public CommandResult doExecuteWithResult(
                        IProgressMonitor dummy, IAdaptable info) {
                      TitleStyle style =
                          (TitleStyle)
                              currentView.createStyle(NotationPackage.eINSTANCE.getTitleStyle());
                      style.setShowTitle(false);
                      return CommandResult.newOKCommandResult();
                    }
                  }));
        }
        ShowHideTitleOfCompartmentCommand tmp =
            new ShowHideTitleOfCompartmentCommand(domain, currentView, newVisibility);
        if (tmp != null && tmp.canExecute()) {
          completeCmd.add(new ICommandProxy(tmp));
        }
      }
    }

    return completeCmd;
  }