/** * @see * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { toSelect = new ArrayList<EObject>(); IEditorPart editor = RequirementUtils.getCurrentEditor(); IEditorServices services = SupportingEditorsManager.getInstance().getServices(editor); CurrentPage page = RequirementHelper.INSTANCE.getCurrentPage(); if (services != null && ((EvaluationContext) event.getApplicationContext()).getDefaultVariable() instanceof List<?>) { EditingDomain editingDomain = services.getEditingDomain(editor); // Get the current selection List<?> elements = ((List<?>) ((EvaluationContext) event.getApplicationContext()).getDefaultVariable()); CompoundCommand compoundCmd = new CompoundCommand(Messages.getString("AddAttributeHandler.1")); // $NON-NLS-1$ for (Object currObject : elements) { EObject parent = null; if (currObject instanceof Attribute) { parent = ((Attribute) currObject).eContainer(); int newIndex = calculateIndex(parent, (EObject) currObject); Attribute toDuplicate = null; if (currObject instanceof AttributeLink) { toDuplicate = RequirementHelper.INSTANCE.duplicateAttributeLink((AttributeLink) currObject); } else if (currObject instanceof ObjectAttribute) { toDuplicate = RequirementHelper.INSTANCE.duplicateObjectAttribute((ObjectAttribute) currObject); } if (parent != null && toDuplicate != null) { toSelect.add(toDuplicate); compoundCmd.appendIfCanExecute( AddCommand.create( editingDomain, parent, RequirementPackage.eINSTANCE.getRequirement_Attribute(), toDuplicate, newIndex)); } } } if (!compoundCmd.isEmpty() && compoundCmd.canExecute()) { editingDomain.getCommandStack().execute(compoundCmd); page.setSelection(new StructuredSelection(toSelect)); } } return null; }
/** Refreshes the current page viewer */ private void refreshViewer() { CurrentPage page = RequirementHelper.INSTANCE.getCurrentPage(); page.setSelection(new StructuredSelection(toCopy)); }