/** * * * <pre> * This method returns the role referenced by the {@link Collaboration} that is * the type of the {@link CollaborationUse}. * * {@inheritDoc} * </pre> */ public Object[] getElements(Object inputElement) { Object[] children = null; if (inputElement instanceof CollaborationUse) { CollaborationUse parentUMLElement = (CollaborationUse) inputElement; if (parentUMLElement.getType() != null) { children = parentUMLElement.getType().getCollaborationRoles().toArray(); } } return children; }
// TODO add types from the loaded resources // traverse deep into the nested packages public IContentAssistProcessor getCompletionProcessor(IAdaptable subject) { CollaborationUse cu = doAdapt(subject); String name = cu.getName() == null ? "" : cu.getName(); // $NON-NLS-1$ List<Type> types = getTypeProposals(cu); LinkedList<String> names = new LinkedList<String>(); for (Type next : types) { names.add(COLLABORATION_USE_FORMAT.format(new Object[] {name, next.getName()})); } FixedSetCompletionProcessor cp = new FixedSetCompletionProcessor(names); cp.setContext(cu); return cp; }
public ICommand getParseCommand(IAdaptable element, String newString, int flags) { CollaborationUse cu = doAdapt(element); if (cu == null) { return UnexecutableCommand.INSTANCE; } if (newString == null) { return UnexecutableCommand.INSTANCE; } Collaboration oldType = cu.getType(); String oldName = cu.getName() == null ? "" : cu.getName(); // $NON-NLS-1$ List<Type> types = getTypeProposals(cu); try { Object[] parsed = COLLABORATION_USE_FORMAT.parse(newString); String newName = (String) parsed[0]; CompositeCommand cc = new CompositeCommand( CustomMessages.CollaborationUseParser_collaboration_use_name_parser_command); if (!oldName.equals(newName)) { cc.add( new SetValueCommand( new SetRequest(cu, UMLPackage.eINSTANCE.getNamedElement_Name(), newName))); } if (parsed.length < 2) { return cc; } String newType = (String) parsed[1]; for (Type next : types) { if (newType.equals(next.getName()) && !newType.equals(oldType)) { cc.add( new SetValueCommand( new SetRequest(cu, UMLPackage.eINSTANCE.getCollaborationUse_Type(), next))); break; } } return cc; } catch (ParseException e) { } return UnexecutableCommand.INSTANCE; }
private List<Type> getTypeProposals(CollaborationUse cu) { EObject root = cu.eContainer(); while (root.eContainer() != null) { root = root.eContainer(); } if (false == root instanceof org.eclipse.uml2.uml.Package) { return Collections.<Type>emptyList(); } List<Type> types = new LinkedList<Type>(); for (Type next : ((org.eclipse.uml2.uml.Package) root).getOwnedTypes()) { types.add(next); } return types; }
/** * * * <pre> * The method executes the creation : * - opens a selection dialog to choose a {@link ConnectableElement} reference as a role by the {@link CollaborationUse} type * - created a dependency between the selected role and the {@link ConnectableElement} that will be bind to it * * {@inheritDoc} * </pre> */ @Override protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { if (!canExecute()) { throw new ExecutionException(Messages.RoleBindingCreateCommand_INVALID_ARGS_MSG); } // Retrieve the graphical source of the binding. // This differs from the semantic source of the binding which is a role of the // CollaborationUse type. CollaborationUse graphicalSource = (CollaborationUse) getSource(); // Create and open the selection dialog ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); Shell currentShell = new Shell(Display.getCurrent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( currentShell, new AdapterFactoryLabelProvider(adapterFactory), new CollaborationRoleTreeContentProvider()); try { // Set dialog parameters dialog.setTitle(Messages.RoleBindingRoleSelectionDialog_Title); dialog.setMessage(Messages.RoleBindingRoleSelectionDialog_Message); dialog.setAllowMultiple(false); dialog.setHelpAvailable(false); // The source CollaborationUse is set as input for the selection dialog, // the CollaborationRoleTreeContentProvider provides the roles that can possibly be // selected. dialog.setInput(graphicalSource); dialog.open(); } finally { adapterFactory.dispose(); } // If a ConnectableElement has been selected, complete command execution // using selection as the "newly created" element and make the edited // Collaboration reference it in the CollaborationRoles eReference. if (dialog.getReturnCode() == ElementTreeSelectionDialog.OK) { ConnectableElement roleToBind = (ConnectableElement) dialog.getFirstResult(); // Create a Dependency (the binding) between selected role and a ConnectableElement // (the target) Dependency newBinding = UMLFactory.eINSTANCE.createDependency(); getContainer().getPackagedElements().add(newBinding); newBinding.getClients().add(roleToBind); newBinding.setName("binding_" + roleToBind.getName() + "_" + getTarget().getName()); newBinding.getSuppliers().add(getTarget()); graphicalSource.getRoleBindings().add(newBinding); doConfigure(newBinding, monitor, info); ((CreateElementRequest) getRequest()).setNewElement(newBinding); return CommandResult.newOKCommandResult(newBinding); } // No role selected: abort element creation return CommandResult.newCancelledCommandResult(); }
public String getEditString(IAdaptable element, int flags) { CollaborationUse cu = doAdapt(element); String name = cu.getName() == null ? "" : cu.getName(); // $NON-NLS-1$ String type = cu.getType() == null ? "" : cu.getType().getName(); // $NON-NLS-1$ return COLLABORATION_USE_FORMAT.format(new Object[] {name, type}); }