/** {@inheritedDoc}. */ @Override public Command getDropObjectsCommand(DropObjectsRequest dropRequest) { TypeDropHelper helper = new TypeDropHelper(getEditingDomain()); // Single drop management possible drop action list can be proposed if (dropRequest.getObjects().size() == 1) { // List of available drop commands final List<Command> commandChoice = new ArrayList<Command>(); // 1. Try to set the target element type with dropped object Command dropAsSetType = helper.getDropAsTypedElementType(dropRequest, (GraphicalEditPart) getHost()); if ((dropAsSetType != null) && (dropAsSetType.canExecute())) { commandChoice.add(dropAsSetType); } // 3. Build default drop command (show view of the dropped object) Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { commandChoice.add(defaultDropCommand); } // Prepare the selection command (if several command are available) or return the drop command if (commandChoice.size() > 1) { RunnableWithResult<ICommand> runnable; Display.getDefault() .syncExec( runnable = new RunnableWithResult.Impl<ICommand>() { public void run() { setResult( new SelectAndExecuteCommand( "Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice)); } }); ICommand selectCommand = runnable.getResult(); return new ICommandProxy(selectCommand); } else if (commandChoice.size() == 1) { return commandChoice.get(0); } // else (command choice is empty) return UnexecutableCommand.INSTANCE; } return super.getDropObjectsCommand(dropRequest); }
@Override protected CommandResult doExecuteWithResult( IProgressMonitor progressMonitor, org.eclipse.core.runtime.IAdaptable info) throws ExecutionException { CommandResult cmdResult = super.doExecuteWithResult(progressMonitor, info); if (!cmdResult.getStatus().isOK()) { if (cmdResult.getStatus().getSeverity() != IStatus.CANCEL) { Activator.log.error(cmdResult.getStatus().getException()); } return cmdResult; } Object returnValue = cmdResult.getReturnValue(); if (returnValue instanceof List<?>) { _selectedCmd = (Command) ((List<?>) returnValue) .get(((List<?>) returnValue).size() - 1); // Returns the last command } else { _selectedCmd = (Command) cmdResult.getReturnValue(); } Assert.isTrue(_selectedCmd != null && _selectedCmd.canExecute()); _selectedCmd.execute(); return CommandResult.newOKCommandResult(); }
@Override public void run() { Command cmd = createCommand(getSelectedObjects()); if (cmd != null && cmd.canExecute()) { execute(cmd); } }
public static void createMessageFlow( TransactionalEditingDomain editingDomain, Message event, ThrowMessageEvent source, AbstractCatchMessageEvent target, DiagramEditPart dep) { EditPart targetEP = findEditPart(dep, target); EditPart sourceEP = findEditPart(dep, source); CreateConnectionViewAndElementRequest request = new CreateConnectionViewAndElementRequest( ProcessElementTypes.MessageFlow_4002, ((IHintedType) ProcessElementTypes.MessageFlow_4002).getSemanticHint(), dep.getDiagramPreferencesHint()); Command createMessageFlowCommand = CreateConnectionViewAndElementRequest.getCreateCommand(request, sourceEP, targetEP); if (createMessageFlowCommand.canExecute()) { dep.getDiagramEditDomain().getDiagramCommandStack().execute(createMessageFlowCommand); dep.getDiagramEditDomain().getDiagramCommandStack().flush(); dep.refresh(); ConnectionViewAndElementDescriptor desc = (ConnectionViewAndElementDescriptor) request.getNewObject(); MessageFlow message = (MessageFlow) desc.getElementAdapter().getAdapter(MessageFlow.class); SetCommand setCommand = new SetCommand( editingDomain, message, ProcessPackage.Literals.ELEMENT__NAME, event.getName()); editingDomain.getCommandStack().execute(setCommand); } }
public Command getCreateLinkCommand(View source, View target, GenCommonBase linkType) { IElementType metamodelType = getElementType(linkType); CreateRelationshipRequest relationShipReq = new CreateRelationshipRequest(metamodelType); ConnectionViewAndElementDescriptor desc = new ConnectionViewAndElementDescriptor( new CreateElementRequestAdapter(relationShipReq), metamodelType instanceof IHintedType ? ((IHintedType) metamodelType).getSemanticHint() : "", getDefaultPreferencesHint()); CreateConnectionViewAndElementRequest req = new CreateConnectionViewAndElementRequest(desc); req.setType(RequestConstants.REQ_CONNECTION_START); EditPart sourceEditPart = findEditPart(source); req.setSourceEditPart(sourceEditPart); // Note: initializes the sourceCommand in the request Command sourceCmd = sourceEditPart.getCommand(req); if (sourceCmd == null || !sourceCmd.canExecute()) { return null; } EditPart targetEditPart = target != null ? findEditPart(target) : null; if (targetEditPart != null) { req.setType(RequestConstants.REQ_CONNECTION_END); req.setTargetEditPart(targetEditPart); req.setLocation(new Point(0, 0)); sourceEditPart.getCommand(req); Command targetCmd = targetEditPart.getCommand(req); return targetCmd; } return null; }
@SuppressWarnings("unchecked") @Override protected boolean calculateEnabled() { Command cmd = createCopyCommand(getSelectedObjects()); if (cmd == null) return false; return cmd.canExecute(); }
/** @generated */ private Collection<IAdaptable> createConnections( Collection<TaiPanLinkDescriptor> linkDescriptors, Domain2Notation domain2NotationMap) { LinkedList<IAdaptable> adapters = new LinkedList<IAdaptable>(); for (TaiPanLinkDescriptor nextLinkDescriptor : linkDescriptors) { EditPart sourceEditPart = getSourceEditPart(nextLinkDescriptor, domain2NotationMap); EditPart targetEditPart = getTargetEditPart(nextLinkDescriptor, domain2NotationMap); if (sourceEditPart == null || targetEditPart == null) { continue; } CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor( nextLinkDescriptor.getSemanticAdapter(), TaiPanVisualIDRegistry.getType(nextLinkDescriptor.getVisualID()), ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint()); CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor); ccr.setType(RequestConstants.REQ_CONNECTION_START); ccr.setSourceEditPart(sourceEditPart); sourceEditPart.getCommand(ccr); ccr.setTargetEditPart(targetEditPart); ccr.setType(RequestConstants.REQ_CONNECTION_END); Command cmd = targetEditPart.getCommand(ccr); if (cmd != null && cmd.canExecute()) { executeCommand(cmd); IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject(); if (viewAdapter != null) { adapters.add(viewAdapter); } } } return adapters; }
/** Test that GMF Text drop is not possible in a lifeline. */ public void testGMFTextDropInALifelineNotPossible() { ChangeBoundsRequest changeBoundsRequest = new ChangeBoundsRequest(RequestConstants.REQ_ADD); changeBoundsRequest.setEditParts(textEditPart); Command dropGMFNoteInLifelineCmd = lifelineEditPart.getCommand(changeBoundsRequest); assertFalse( "The GMF Text should not be droppable in lifeline", dropGMFNoteInLifelineCmd.canExecute()); }
private boolean ourHandleKeyDown(KeyEvent event) { if (ourAcceptArrowKey(event)) { int direction = 0; switch (event.keyCode) { case SWT.ARROW_DOWN: direction = PositionConstants.SOUTH; break; case SWT.ARROW_UP: direction = PositionConstants.NORTH; break; case SWT.ARROW_RIGHT: direction = PositionConstants.EAST; break; case SWT.ARROW_LEFT: direction = PositionConstants.WEST; break; } boolean consumed = false; if (direction != 0 && event.stateMask == 0) consumed = navigateNextAnchor(direction); if (!consumed) { event.stateMask |= SWT.CONTROL; event.stateMask &= ~SWT.SHIFT; if (getCurrentViewer().getKeyHandler().keyPressed(event)) { navigateNextAnchor(0); updateTargetRequest(); updateTargetUnderMouse(); Command command = getCommand(); if (command != null) setCurrentCommand(command); return true; } } } if (acceptConnectionStart(event)) { updateTargetUnderMouse(); setConnectionSource(getTargetEditPart()); ((CreateConnectionRequest) getTargetRequest()).setSourceEditPart(getTargetEditPart()); setState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS); ourPlaceMouseInViewer(getLocation().getTranslated(6, 6)); return true; } if (acceptConnectionFinish(event)) { Command command = getCommand(); if (command != null && command.canExecute()) { setState(STATE_INITIAL); ourPlaceMouseInViewer(getLocation().getTranslated(6, 6)); eraseSourceFeedback(); eraseTargetFeedback(); setCurrentCommand(command); executeCurrentCommand(); handleFinished(); } return true; } return super.handleKeyDown(event); }
@SuppressWarnings("unchecked") @Override public void run() { Command cmd = createCopyCommand(getSelectedObjects()); if (cmd != null && cmd.canExecute()) { cmd.execute(); } }
/** Writes the sorting/filtering specified by the dialog */ protected void performApply() { Command sortAndFilteringCommand = getApplyCommand(); if (sortAndFilteringCommand != null && sortAndFilteringCommand.canExecute()) { editPart .getRoot() .getViewer() .getEditDomain() .getCommandStack() .execute(sortAndFilteringCommand); createBackUp(); } updateApplyButton(); }
/** Test that GMF Text creation is not possible in a lifeline. */ public void testGMFTextCreationInALifelineNotPossible() { CreateViewRequest createViewRequest = new CreateViewRequest( Collections.singletonList( new CreateViewRequest.ViewDescriptor( null, Node.class, "Text", ((IDiagramPreferenceSupport) lifelineEditPart.getRoot()) .getPreferencesHint()))); Command createGMFTextInLifelineCmd = lifelineEditPart.getCommand(createViewRequest); assertFalse( "The GMF Text creation should not be allowed in lifeline", createGMFTextInLifelineCmd.canExecute()); }
@Override protected Cursor calculateCursor() { Cursor cursorToReturn; if (moveGroupActivated) { Command command = getCurrentCommand(); if (command == null || !command.canExecute()) { cursorToReturn = getDisabledCursor(); } else { cursorToReturn = SharedCursors.ARROW; } } else { cursorToReturn = super.calculateCursor(); } return cursorToReturn; }
private Command createCommand(List<?> selection, RGB newColor) { CompoundCommand result = new CompoundCommand(Messages.FillColorAction_1); for (Object object : selection) { if (object instanceof EditPart) { Object model = ((EditPart) object).getModel(); if (shouldEnable(model)) { Command cmd = new FillColorCommand( (IDiagramModelObject) model, ColorFactory.convertRGBToString(newColor)); if (cmd.canExecute()) { result.add(cmd); } } } } return result.unwrap(); }
/* * (non-Javadoc) * * @see org.eclipse.gef.commands.Command#execute() */ public void execute() { System.out.println(formData.toString()); commandList = new CompoundCommand(); XamlNode parentNode = (XamlNode) parent.getModel(); XamlAttribute layoutDataAttr = forCreate.getAttribute("layoutData", IConstants.XWT_NAMESPACE); if (layoutDataAttr == null) { layoutDataAttr = XamlFactory.eINSTANCE.createAttribute("layoutData", IConstants.XWT_NAMESPACE); } XamlElement formDataChild = layoutDataAttr.getChild("FormData", IConstants.XWT_NAMESPACE); if (formDataChild == null) { formDataChild = XamlFactory.eINSTANCE.createElement("FormData", IConstants.XWT_NAMESPACE); } // 1. width and height if (formData.width != SWT.DEFAULT) { ApplyAttributeSettingCommand command = new ApplyAttributeSettingCommand( formDataChild, "width", IConstants.XWT_NAMESPACE, Integer.toString(formData.width)); addCommand(command); } if (formData.height != SWT.DEFAULT) { ApplyAttributeSettingCommand command = new ApplyAttributeSettingCommand( formDataChild, "height", IConstants.XWT_NAMESPACE, Integer.toString(formData.height)); addCommand(command); } // 2. left, top, right and bottom. computeFormDataCommand(formDataChild, formData.left, "left"); computeFormDataCommand(formDataChild, formData.top, "top"); computeFormDataCommand(formDataChild, formData.right, "right"); computeFormDataCommand(formDataChild, formData.bottom, "bottom"); // compute commands. addNewChild(layoutDataAttr, formDataChild); addNewChild(forCreate, layoutDataAttr); addNewChild(parentNode, forCreate); command = commandList.unwrap(); if (command.canExecute()) { command.execute(); } }
@Test public void testToManageDurationConstraint() { createChildNode(UMLElementTypes.ActionExecutionSpecification_3006, lifelineProvider); semanticChild = false; testToCreateChildNode(UMLElementTypes.ActionExecutionSpecification_3006, executionProvider); { // DESTROY SEMANTIC+ VIEW IChildTestProvider provider = executionProvider; assertTrue(DESTROY_DELETION + INITIALIZATION_TEST, provider.getEditPartChildrenSize() == 1); assertTrue(DESTROY_DELETION + INITIALIZATION_TEST, provider.getViewChildrenSize() == 1); assertTrue( DESTROY_DELETION + INITIALIZATION_TEST, !provider.hasSemanticChild() || provider.getSemanticChildrenSize() == 1); Request deleteViewRequest = new EditCommandRequestWrapper(new DestroyElementRequest(false)); Command command = provider.getDestroyEditPart().getCommand(deleteViewRequest); assertNotNull(DESTROY_DELETION + COMMAND_NULL, command); assertTrue( DESTROY_DELETION + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE); assertTrue( DESTROY_DELETION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true); getEMFCommandStack().execute(new GEFtoEMFCommandWrapper(command)); assertTrue(DESTROY_DELETION + TEST_THE_EXECUTION, provider.getEditPartChildrenSize() == 0); assertTrue(DESTROY_DELETION + TEST_THE_EXECUTION, provider.getViewChildrenSize() == 0); assertTrue(DESTROY_DELETION + TEST_THE_EXECUTION, provider.getSemanticChildrenSize() == 0); } // the node has been destroyed, the UML element also getEMFCommandStack().undo(); // the node and the UML element are present testViewDeletion(UMLElementTypes.ActionExecutionSpecification_3006, executionProvider); semanticChild = true; }
public void doExecute() { if (setNameCmd != null) { // This is a hack. // TODO: Fix this when we stop using canExecute()==false for no-op commands. if (!setNameCmd.canExecute()) setNameCmd = null; } flow = FlowLinkUtil.getCommonFlow(source, target); if (flow == null) { if (Policy.DEBUG) System.out.println("No common flow found!!"); // $NON-NLS-1$ return; } if (setNameCmd != null) setNameCmd.execute(); FlowLinkUtil.setLinkSource(link, source); FlowLinkUtil.setLinkTarget(link, target); if (link.eContainer() != null) { Flow oldParent = (Flow) link.eContainer().eContainer(); if (oldParent != null) { FlowLinkUtil.removeFlowLink(oldParent, link); } } FlowLinkUtil.addFlowLink(flow, link); }
/** @generated */ private Collection createConnections(Collection linkDescriptors, Map domain2NotationMap) { List adapters = new LinkedList(); for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator.hasNext(); ) { final AutomataLinkDescriptor nextLinkDescriptor = (AutomataLinkDescriptor) linkDescriptorsIterator.next(); EditPart sourceEditPart = getEditPart(nextLinkDescriptor.getSource(), domain2NotationMap); EditPart targetEditPart = getEditPart(nextLinkDescriptor.getDestination(), domain2NotationMap); if (sourceEditPart == null || targetEditPart == null) { continue; } CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor( nextLinkDescriptor.getSemanticAdapter(), null, ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint()); CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor); ccr.setType(RequestConstants.REQ_CONNECTION_START); ccr.setSourceEditPart(sourceEditPart); sourceEditPart.getCommand(ccr); ccr.setTargetEditPart(targetEditPart); ccr.setType(RequestConstants.REQ_CONNECTION_END); Command cmd = targetEditPart.getCommand(ccr); if (cmd != null && cmd.canExecute()) { executeCommand(cmd); IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject(); if (viewAdapter != null) { adapters.add(viewAdapter); } } } return adapters; }
private void addCommand(Command command) { if (command == null || !command.canExecute()) { return; } commandList.add(command); }
@Override protected boolean calculateEnabled() { Command cmd = createCommand(getSelectedObjects()); if (cmd == null) return false; return cmd.canExecute(); }
/** {@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; }
/** @generated */ protected void refreshSemantic() { if (resolveSemanticElement() == null) { return; } LinkedList<IAdaptable> createdViews = new LinkedList<IAdaptable>(); List<UMLNodeDescriptor> childDescriptors = UMLDiagramUpdater.getStateMachine_2000SemanticChildren((View) getHost().getModel()); LinkedList<View> orphaned = new LinkedList<View>(); // we care to check only views we recognize as ours LinkedList<View> knownViewChildren = new LinkedList<View>(); for (View v : getViewChildren()) { if (isMyDiagramElement(v)) { knownViewChildren.add(v); } } // alternative to #cleanCanonicalSemanticChildren(getViewChildren(), semanticChildren) HashMap<UMLNodeDescriptor, LinkedList<View>> potentialViews = new HashMap<UMLNodeDescriptor, LinkedList<View>>(); // // iteration happens over list of desired semantic elements, trying to find best matching View, // while original CEP // iterates views, potentially losing view (size/bounds) information - i.e. if there are few // views to reference same EObject, only last one // to answer isOrphaned == true will be used for the domain element representation, see // #cleanCanonicalSemanticChildren() for (Iterator<UMLNodeDescriptor> descriptorsIterator = childDescriptors.iterator(); descriptorsIterator.hasNext(); ) { UMLNodeDescriptor next = descriptorsIterator.next(); String hint = UMLVisualIDRegistry.getType(next.getVisualID()); LinkedList<View> perfectMatch = new LinkedList<View>(); // both semanticElement and hint match that of NodeDescriptor LinkedList<View> potentialMatch = new LinkedList<View>(); // semanticElement matches, hint does not for (View childView : getViewChildren()) { EObject semanticElement = childView.getElement(); if (next.getModelElement().equals(semanticElement)) { if (hint.equals(childView.getType())) { perfectMatch.add(childView); // actually, can stop iteration over view children here, but // may want to use not the first view but last one as a 'real' match (the way original // CEP does // with its trick with viewToSemanticMap inside #cleanCanonicalSemanticChildren } else { potentialMatch.add(childView); } } } if (perfectMatch.size() > 0) { descriptorsIterator .remove(); // precise match found no need to create anything for the NodeDescriptor // use only one view (first or last?), keep rest as orphaned for further consideration knownViewChildren.remove(perfectMatch.getFirst()); } else if (potentialMatch.size() > 0) { potentialViews.put(next, potentialMatch); } } // those left in knownViewChildren are subject to removal - they are our diagram elements we // didn't find match to, // or those we have potential matches to, and thus need to be recreated, preserving // size/location information. orphaned.addAll(knownViewChildren); // CompositeTransactionalCommand boundsCommand = new CompositeTransactionalCommand( host().getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize); ArrayList<CreateViewRequest.ViewDescriptor> viewDescriptors = new ArrayList<CreateViewRequest.ViewDescriptor>(childDescriptors.size()); for (UMLNodeDescriptor next : childDescriptors) { String hint = UMLVisualIDRegistry.getType(next.getVisualID()); IAdaptable elementAdapter = new CanonicalElementAdapter(next.getModelElement(), hint); CreateViewRequest.ViewDescriptor descriptor = new CreateViewRequest.ViewDescriptor( elementAdapter, Node.class, hint, ViewUtil.APPEND, false, host().getDiagramPreferencesHint()); viewDescriptors.add(descriptor); LinkedList<View> possibleMatches = potentialViews.get(next); if (possibleMatches != null) { // from potential matches, leave those that were not eventually used for some other // NodeDescriptor (i.e. those left as orphaned) possibleMatches.retainAll(knownViewChildren); } if (possibleMatches != null && !possibleMatches.isEmpty()) { View originalView = possibleMatches.getFirst(); knownViewChildren.remove( originalView); // remove not to copy properties of the same view again and again // add command to copy properties if (originalView instanceof Node) { if (((Node) originalView).getLayoutConstraint() instanceof Bounds) { Bounds b = (Bounds) ((Node) originalView).getLayoutConstraint(); boundsCommand.add( new SetBoundsCommand( boundsCommand.getEditingDomain(), boundsCommand.getLabel(), descriptor, new Rectangle(b.getX(), b.getY(), b.getWidth(), b.getHeight()))); } else if (((Node) originalView).getLayoutConstraint() instanceof Location) { Location l = (Location) ((Node) originalView).getLayoutConstraint(); boundsCommand.add( new SetBoundsCommand( boundsCommand.getEditingDomain(), boundsCommand.getLabel(), descriptor, new Point(l.getX(), l.getY()))); } else if (((Node) originalView).getLayoutConstraint() instanceof Size) { Size s = (Size) ((Node) originalView).getLayoutConstraint(); boundsCommand.add( new SetBoundsCommand( boundsCommand.getEditingDomain(), boundsCommand.getLabel(), descriptor, new Dimension(s.getWidth(), s.getHeight()))); } } } } boolean changed = deleteViews(orphaned.iterator()); // CreateViewRequest request = getCreateViewRequest(viewDescriptors); Command cmd = getCreateViewCommand(request); if (cmd != null && cmd.canExecute()) { SetViewMutabilityCommand.makeMutable(new EObjectAdapter(host().getNotationView())).execute(); executeCommand(cmd); if (boundsCommand.canExecute()) { executeCommand(new ICommandProxy(boundsCommand.reduce())); } @SuppressWarnings("unchecked") List<IAdaptable> nl = (List<IAdaptable>) request.getNewObject(); createdViews.addAll(nl); } if (changed || createdViews.size() > 0) { postProcessRefreshSemantic(createdViews); } if (createdViews.size() > 1) { // perform a layout of the container DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host().getEditingDomain(), createdViews, host()); executeCommand(new ICommandProxy(layoutCmd)); } makeViewsImmutable(createdViews); }
/** {@inheritedDoc}. */ @Override public Command getDropObjectsCommand(DropObjectsRequest dropRequest) { BlockDropHelper helper = new BlockDropHelper(getEditingDomain()); // Single drop management possible drop action list can be proposed if (dropRequest.getObjects().size() == 1) { // List of available drop commands List<Command> commandChoice = new ArrayList<Command>(); // 1. Build command to drop BlockProperty PartDropHelper partDropHelper = new PartDropHelper(getEditingDomain()); Command dropPartOnPart = partDropHelper.getDropPartOnPart(dropRequest, (GraphicalEditPart) getHost()); if ((dropPartOnPart != null) && (dropPartOnPart.canExecute())) { commandChoice.add(dropPartOnPart); } // 2. Try to create a Part typed by the dropped object Command dropAsTypedPart = helper.getDropAsStructureItemOnPart( dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.PART_PROPERTY); if ((dropAsTypedPart != null) && (dropAsTypedPart.canExecute())) { commandChoice.add(dropAsTypedPart); } // 3. Try to create a Reference typed by the dropped object Command dropAsTypedReference = helper.getDropAsStructureItemOnPart( dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.REFERENCE_PROPERTY); if ((dropAsTypedReference != null) && (dropAsTypedReference.canExecute())) { commandChoice.add(dropAsTypedReference); } // 4. Try to create an ActorPart typed by the dropped object Command dropAsTypedActorPart = helper.getDropAsStructureItemOnPart( dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.ACTOR_PART_PROPERTY); if ((dropAsTypedActorPart != null) && (dropAsTypedActorPart.canExecute())) { commandChoice.add(dropAsTypedActorPart); } // 5. Try to create a Value typed by the dropped object Command dropAsTypedValue = helper.getDropAsStructureItemOnPart( dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.VALUE_PROPERTY); if ((dropAsTypedValue != null) && (dropAsTypedValue.canExecute())) { commandChoice.add(dropAsTypedValue); } // 6. Try to create a Property typed by the dropped object Command dropAsTypedProperty = helper.getDropAsStructureItemOnPart( dropRequest, (GraphicalEditPart) getHost(), UMLElementTypes.PROPERTY); if ((dropAsTypedProperty != null) && (dropAsTypedProperty.canExecute())) { commandChoice.add(dropAsTypedProperty); } // 7. Build default drop command (show view of the dropped object) Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { commandChoice.add(defaultDropCommand); } // Prepare the selection command (if several command are available) or return the drop command if (commandChoice.size() > 1) { SelectAndExecuteCommand selectCommand = new SelectAndExecuteCommand( "Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice); return new ICommandProxy(selectCommand); } else if (commandChoice.size() == 1) { return commandChoice.get(0); } // else (command choice is empty) return UnexecutableCommand.INSTANCE; } return super.getDropObjectsCommand(dropRequest); }
/** @generated */ protected void refreshSemantic() { if (resolveSemanticElement() == null) { return; } LinkedList<IAdaptable> createdViews = new LinkedList<IAdaptable>(); List<UMLNodeDescriptor> childDescriptors = UMLDiagramUpdater.getInterfaceNestedClassifierCompartment_7029SemanticChildren( (View) getHost().getModel()); LinkedList<View> orphaned = new LinkedList<View>(); // we care to check only views we recognize as ours LinkedList<View> knownViewChildren = new LinkedList<View>(); for (View v : getViewChildren()) { if (isMyDiagramElement(v)) { knownViewChildren.add(v); } } // alternative to #cleanCanonicalSemanticChildren(getViewChildren(), semanticChildren) // // iteration happens over list of desired semantic elements, trying to find best matching View, // while original CEP // iterates views, potentially losing view (size/bounds) information - i.e. if there are few // views to reference same EObject, only last one // to answer isOrphaned == true will be used for the domain element representation, see // #cleanCanonicalSemanticChildren() for (Iterator<UMLNodeDescriptor> descriptorsIterator = childDescriptors.iterator(); descriptorsIterator.hasNext(); ) { UMLNodeDescriptor next = descriptorsIterator.next(); String hint = UMLVisualIDRegistry.getType(next.getVisualID()); LinkedList<View> perfectMatch = new LinkedList<View>(); // both semanticElement and hint match that of NodeDescriptor for (View childView : getViewChildren()) { EObject semanticElement = childView.getElement(); if (next.getModelElement().equals(semanticElement)) { if (hint.equals(childView.getType())) { perfectMatch.add(childView); // actually, can stop iteration over view children here, but // may want to use not the first view but last one as a 'real' match (the way original // CEP does // with its trick with viewToSemanticMap inside #cleanCanonicalSemanticChildren } } } if (perfectMatch.size() > 0) { descriptorsIterator .remove(); // precise match found no need to create anything for the NodeDescriptor // use only one view (first or last?), keep rest as orphaned for further consideration knownViewChildren.remove(perfectMatch.getFirst()); } } // those left in knownViewChildren are subject to removal - they are our diagram elements we // didn't find match to, // or those we have potential matches to, and thus need to be recreated, preserving // size/location information. orphaned.addAll(knownViewChildren); // ArrayList<CreateViewRequest.ViewDescriptor> viewDescriptors = new ArrayList<CreateViewRequest.ViewDescriptor>(childDescriptors.size()); for (UMLNodeDescriptor next : childDescriptors) { String hint = UMLVisualIDRegistry.getType(next.getVisualID()); IAdaptable elementAdapter = new CanonicalElementAdapter(next.getModelElement(), hint); CreateViewRequest.ViewDescriptor descriptor = new CreateViewRequest.ViewDescriptor( elementAdapter, Node.class, hint, ViewUtil.APPEND, false, host().getDiagramPreferencesHint()); viewDescriptors.add(descriptor); } boolean changed = deleteViews(orphaned.iterator()); // CreateViewRequest request = getCreateViewRequest(viewDescriptors); Command cmd = getCreateViewCommand(request); if (cmd != null && cmd.canExecute()) { SetViewMutabilityCommand.makeMutable(new EObjectAdapter(host().getNotationView())).execute(); executeCommand(cmd); @SuppressWarnings("unchecked") List<IAdaptable> nl = (List<IAdaptable>) request.getNewObject(); createdViews.addAll(nl); } if (changed || createdViews.size() > 0) { postProcessRefreshSemantic(createdViews); } if (createdViews.size() > 1) { // perform a layout of the container DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host().getEditingDomain(), createdViews, host()); executeCommand(new ICommandProxy(layoutCmd)); } makeViewsImmutable(createdViews); }
/** @see org.eclipse.emf.common.command.Command#canExecute() */ public boolean canExecute() { return gefCommand.canExecute(); }