@SuppressWarnings("unchecked")
  private Set<EObject> getTargetsFromSelection(IStructuredSelection iStructuredSelection) {
    Set<EObject> targets = new HashSet<EObject>();
    for (Iterator<Object> iterator = iStructuredSelection.iterator(); iterator.hasNext(); /**/ ) {
      Object element = iterator.next();
      DSemanticDecorator decorator = null;
      if (element instanceof DSemanticDecorator) {
        decorator = (DSemanticDecorator) element;
      } else if (element instanceof IAdaptable) {
        decorator = ((IAdaptable) element).getAdapter(DSemanticDecorator.class);
      }

      if (decorator != null) {
        // If the selection is the representation, we want to select the
        // representation descriptor node and not its semantic element.
        if (decorator instanceof DRepresentation) {
          targets.add(
              new DRepresentationQuery((DRepresentation) decorator).getRepresentationDescriptor());
        } else {
          targets.add(decorator.getTarget());
        }
      }
    }
    return targets;
  }
コード例 #2
0
 /**
  * Builds the command which will execute the user-specified operations with a selection tool.
  *
  * @param tool the selection tool.
  * @param dContainer the clicked diagram element.
  * @param selectedElement the selected elements
  * @param endBefore the event end graphically preceding the position
  * @param location the clicked location.
  * @return a command to execute the tool.
  */
 public static Command buildSequenceSelectionWizardCommandFromTool(
     SelectionWizardDescription tool,
     DSemanticDecorator dContainer,
     Collection<EObject> selectedElement,
     EventEnd endBefore,
     Point location) {
   CommandBuilder builder =
       new SequenceSelectionWizardCommandBuilder(
           tool, dContainer, selectedElement, endBefore, location);
   Session session = SessionManager.INSTANCE.getSession(dContainer.getTarget());
   return getCommand(builder, session);
 }