/** * Adds listeners on * * <ul> * <li>Affixed Child Node * <li>graphical parent, when its a {@link Property} (we add the listener on its Type) * </ul> */ public void activate() { IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); assert gep != null; View view = ((View) gep.getModel()); if (view instanceof Node) { // the location of the decorator can change if it's an Affixed Child // Node if (isInherited((Node) view) && Util.isAffixedChildNode(gep)) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener(gep.getNotationView(), notificationListener); } } // if the graphical parent is a Property, we add a listener on the type // of the property, to refresh the decoration EObject parent = view.eContainer(); if (parent instanceof DecorationNode) { parent = parent.eContainer(); } if (parent instanceof View) { EObject el = ((View) parent).getElement(); if (el instanceof Property) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener( el, UMLPackage.eINSTANCE.getTypedElement_Type(), notificationListener); } } /* * We listen the changes on the UML parent, in order to know if the * element is changing of parent Adding a listener using the following * EReference doesn't work UMLPackage.eINSTANCE.getElement_Owner(); * UMLPackage.eINSTANCE.getProperty_Class(); * UMLPackage.eINSTANCE.getNamedElement_Namespace(); that's why we * listen the parent */ if (view.getElement() instanceof Element) { Element semanticElement = (Element) view.getElement(); /* * We need add a listener only if the element is an element which * can be inherited, like Property, Operation, Signal, Classifier... */ if (semanticElement != null && canBeInherited(semanticElement)) { // we listen if the container of the element changes! if (semanticElement.eContainer() != null) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener(semanticElement.eContainer(), notificationListener); } } } }
/** * {@inheritDoc} * * @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator#activate() */ public void activate() { final IGraphicalEditPart gep = getTargetEditPart(); DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener( gep.getNotationView(), NotationPackage.eINSTANCE.getNode_LayoutConstraint(), notificationListener); }
/** Removes the listeners and the decorations */ public void deactivate() { removeDecoration(); IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); assert gep != null; DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener(gep.getNotationView(), notificationListener); View view = ((View) gep.getModel()); if (view instanceof Node) { // the location of the decorator can change if it's an Affixed Child // Node if (isInherited((Node) view) && Util.isAffixedChildNode(gep)) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener(gep.getNotationView(), notificationListener); } } EObject parent = view.eContainer(); if (parent instanceof View) { EObject el = ((View) parent).getElement(); if (el instanceof Property) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener( el, UMLPackage.eINSTANCE.getTypedElement_Type(), notificationListener); } } if (view.getElement() instanceof Element) { Element semanticElement = (Element) view.getElement(); if (semanticElement != null) { if (semanticElement.eContainer() != null) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener(semanticElement.eContainer(), notificationListener); } } } }
/** * Deserialize a sequence * * @param mediatorFlow * @param sequence * @param connector * @param reversed * @throws DeserializerException */ protected void deserializeSequence( IGraphicalEditPart part, SequenceMediator sequenceMediator, EsbConnector connector, boolean reversed) throws DeserializerException { LinkedList<EsbNode> nodeList = new LinkedList<>(); LinkedList<CommentMediator> commentMediatorList = new LinkedList<>(); SequenceMediator sequence = EditorUtils.stripUnsupportedMediators(sequenceMediator); TransactionalEditingDomain domain = part.getEditingDomain(); if (connector instanceof OutputConnector) { int mediatorsCount = sequence.getList().size(); boolean lastMediator = false; for (int i = 0; i < mediatorsCount; ++i) { AbstractMediator mediator = (AbstractMediator) sequence.getList().get(i); if (mediatorsCount == (i + 1)) { lastMediator = true; } if (reversedNodes.contains(connector.eContainer())) { executeMediatorDeserializer( part, nodeList, domain, mediator, true, commentMediatorList, lastMediator); reversedNodes.addAll(nodeList); } else { executeMediatorDeserializer( part, nodeList, domain, mediator, reversed, commentMediatorList, lastMediator); if (reversed) { reversedNodes.addAll(nodeList); } } } connectionFlowMap.put(connector, nodeList); } else if (connector instanceof InputConnector) { int mediatorsCount = sequence.getList().size(); boolean lastMediator = false; for (int i = mediatorsCount - 1; i >= 0; --i) { if (i == 0) { lastMediator = true; } AbstractMediator mediator = (AbstractMediator) sequence.getList().get(i); executeMediatorDeserializer( part, nodeList, domain, mediator, true, commentMediatorList, lastMediator); } connectionFlowMap.put(connector, nodeList); reversedNodes.addAll(nodeList); } }
/** * @see * org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener#notifyChanged(org.eclipse.emf.common.notify.Notification) * @param notification */ public void notifyChanged(Notification notification) { if (notification.getEventType() == Notification.REMOVE) { if (notification.getNotifier() instanceof Classifier) { IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); assert gep != null; // we remove the listener on the container (because it's // changing DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener( (EObject) notification.getNotifier(), notificationListener); } } // we update the listeners It's useful when an Element with overlay // changes of parent deactivate(); activate(); refresh(); }
/** creates the command to move the shapes left or right. */ protected Command getCommand() { if (_container == null) { return null; } CompoundCommand command = new CompoundCommand("Multiple Shape Move"); TransactionalEditingDomain editingDomain = _container.getEditingDomain(); Point moveDelta = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy(); Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y); ZoomManager zoomManager = ((DiagramRootEditPart) getCurrentViewer().getRootEditPart()).getZoomManager(); spSizeDelta.scale(1 / zoomManager.getZoom()); command.add(_container.getCommand(getSourceRequest())); for (IGraphicalEditPart sp : _subProcesses) { Dimension spDim = sp.getFigure().getBounds().getSize().getCopy(); spDim.expand(spSizeDelta); SetBoundsCommand setBounds = new SetBoundsCommand(editingDomain, "MultipleShape Move", sp, spDim); command.add(new ICommandProxy(setBounds)); } return command; }
@Override protected void executeCurrentCommand() { FiguresHelper.AVOID_OVERLAP_ENABLE = false; super.executeCurrentCommand(); FiguresHelper.AVOID_OVERLAP_ENABLE = true; CompoundCommand cc = new CompoundCommand("Check Overlap"); for (IGraphicalEditPart ep : _movingShapes) { Location loc = (Location) ((Node) ep.getNotationView()).getLayoutConstraint(); Point oldLoc = new Point(loc.getX(), loc.getY()); Point newLoc = FiguresHelper.handleCompartmentMargin( ep, loc.getX(), loc.getY(), (ep.resolveSemanticElement() instanceof SubProcessEvent)); if ((newLoc.x != 0 && newLoc.y != 0) && !newLoc.equals(oldLoc)) { cc.add( new ICommandProxy( new SetBoundsCommand( _container.getEditingDomain(), "Check Overlap", new EObjectAdapter(ep.getNotationView()), newLoc))); } } executeCommand(cc); }
/** {@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; }