コード例 #1
0
 /**
  * Constructor for use within the package so this handler can be used by other handlers.
  *
  * @param editor
  * @param editingDomain
  * @param resource
  * @param softPkg
  */
 public RemovePortsHandler(
     final EditingDomain editingDomain, final Resource resource, final SoftPkg softPkg) {
   this.editingDomain = editingDomain;
   this.resource = resource;
   this.softPkg = softPkg;
   this.interfaceMap = PortsHandlerUtil.getInterfaceMap(this.softPkg);
 }
コード例 #2
0
 /**
  * Creates and returns a command to remove the interface and associated inherited interfaces if
  * they are not referenced by other ports.
  *
  * @param i the {@link Interface} to remove
  * @param removePorts the {@link Uses} or {@link Provides} to ignore when considering which
  *     interfaces to remove
  * @param removeInterfaces the {@link Set} of repIds already scheduled for removal
  * @return a {@link Command} to remove the specified {@link Interface} and {@link
  *     InheritsInterface} if they can be removed
  */
 public Command createRemoveInterfaceCommand(
     final Collection<EObject> removePorts,
     final Set<String> removeInterfaces,
     final Interface i) {
   if (!containsRepId(i.getRepid(), removePorts)) {
     final CompoundCommand command = new CompoundCommand("Remove Interfaces");
     for (final InheritsInterface inherited : i.getInheritsInterfaces()) {
       if (!containsRepId(inherited.getRepid(), removePorts)) {
         if (!removeInterfaces.contains(inherited.getRepid())) {
           // If the inherited interface isn't referenced by another port and isn't already
           // scheduled for
           // removal, make a recursive call to remove it
           if (inherited.getInterface() != null) {
             command.append(
                 this.createRemoveInterfaceCommand(
                     removePorts, removeInterfaces, inherited.getInterface()));
           }
         }
       }
     }
     // If the interface isn't already scheduled for removal, create a command to remove it
     if (removeInterfaces.add(i.getRepid())) {
       command.append(
           RemoveCommand.create(
               this.editingDomain,
               PortsHandlerUtil.getInterfaces(this.softPkg),
               ScdPackage.Literals.INTERFACES__INTERFACE,
               i));
     }
     return command;
   }
   return null;
 }
コード例 #3
0
  /** {@inheritDoc} */
  @Override
  public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection =
        HandlerUtil.getActiveWorkbenchWindow(event).getSelectionService().getSelection();
    final ComponentEditor editor = (ComponentEditor) HandlerUtil.getActiveEditor(event);
    this.editingDomain = editor.getEditingDomain();
    this.resource = editor.getMainResource();
    this.softPkg = ModelUtil.getSoftPkg(this.resource);
    this.interfaceMap = PortsHandlerUtil.getInterfaceMap(this.softPkg);
    final List<Object> ports = Arrays.asList(((IStructuredSelection) selection).toArray());

    Command command = this.createRemovePortCommand(ports, new HashSet<String>());
    this.editingDomain.getCommandStack().execute(command);

    return null;
  }