/** @generated */ @Override protected void handleNotificationEvent(Notification notification) { super.handleNotificationEvent(notification); if (notification.getNotifier() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Feature && ((EStructuralFeature) notification.getFeature()).getName().equals("expressed")) { IGraphicalEditPart parent = (IGraphicalEditPart) getParent(); de.uni_mannheim.informatik.swt.models.plm.PLM.Element self = (de.uni_mannheim.informatik.swt.models.plm.PLM.Element) resolveSemanticElement(); // Check is visible if (parent.resolveSemanticElement() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Context) { de.uni_mannheim.informatik.swt.models.plm.PLM.Context container = (de.uni_mannheim.informatik.swt.models.plm.PLM.Context) parent.resolveSemanticElement(); if ((container.getOrigin().equalsIgnoreCase("computed") && self.isExpressed()) || (container.getOrigin().equalsIgnoreCase("expressed") && !self.isExpressed())) { getNotationView().setVisible(false); } } else { getNotationView().setVisible(true); } de.uni_mannheim.informatik.swt.models.plm.PLM.Feature f = (de.uni_mannheim.informatik.swt.models.plm.PLM.Feature) resolveSemanticElement(); if (f.isExpressed()) { ((org.eclipse.gmf.runtime.notation.Shape) this.getNotationView()).setItalic(false); ((org.eclipse.gmf.runtime.notation.Shape) this.getNotationView()).setFontColor(0); } else { ((org.eclipse.gmf.runtime.notation.Shape) this.getNotationView()).setItalic(true); ((org.eclipse.gmf.runtime.notation.Shape) this.getNotationView()) .setFontColor(FigureUtilities.colorToInteger(DiagramColorConstants.diagramGray)); } } }
/** Moved to public so that it may be called programmatically by an other tool. */ public boolean handleButtonDown(int button) { Object underMouse = getCurrentViewer().findObjectAt(getCurrentInput().getMouseLocation()); if (!(underMouse instanceof IGraphicalEditPart)) { return true; } stateTransition(STATE_INITIAL, STATE_DRAG_IN_PROGRESS); _initialPosition = getCurrentPosition(); _initPosNoZoom = getCurrentPositionZoomed(); // calculate the initial selection // of shapes that should move _container = (IGraphicalEditPart) findPool(underMouse); // the children that will be moved around List<IGraphicalEditPart> bottomChildren = new ArrayList<IGraphicalEditPart>(); List<IGraphicalEditPart> subProcesses = new ArrayList<IGraphicalEditPart>(); if (_container != null && _container.resolveSemanticElement() instanceof Container) { List children = null; if (_container.resolveSemanticElement() instanceof Container) { children = _container.getChildren(); } else if (_container instanceof ShapeCompartmentEditPart) { children = ((ShapeCompartmentEditPart) _container).getChildren(); } if (children == null) { throw new IllegalArgumentException( "The part " + _container + " did not contain elements"); // $NON-NLS-1$ //$NON-NLS-2$ } // now iterate over the compartment children // and take those that are on the right. for (Object child : children) { if (child instanceof ShapeNodeEditPart) { setBoundsForOverlapComputation((IGraphicalEditPart) child, SINGLETON); ((DiagramEditPart) getCurrentViewer().getContents()) .getFigure() .translateToRelative(SINGLETON); if (SINGLETON.y > _initPosNoZoom) { bottomChildren.add((IGraphicalEditPart) child); } } } } _movingShapes = bottomChildren; _subProcesses = subProcesses; updateSourceRequest(); showSourceFeedback(); return true; }
/** * @see * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, * org.eclipse.core.runtime.IAdaptable) * @param arg0 * @param arg1 * @return * @throws ExecutionException */ @SuppressWarnings("unchecked") @Override protected CommandResult doExecuteWithResult(IProgressMonitor arg0, IAdaptable arg1) throws ExecutionException { Object createdElement = elementAdapter.getAdapter(EObject.class); if (createdElement instanceof EObject) { EObject eObjectCreatedElement = (EObject) createdElement; for (IGraphicalEditPart parent : graphicalParent) { EObject eObjectSourceReference = parent.resolveSemanticElement(); AbstractContainerNodeDescriptor desc = GroupContainmentRegistry.getContainerDescriptor(parent); List<EReference> refs = desc.getReferenceFor(eObjectCreatedElement.eClass()); for (EReference ref : refs) { if (ref != null && ref.isMany()) { Collection<EObject> collection = (Collection<EObject>) eObjectSourceReference.eGet(ref); if (!collection.contains(eObjectCreatedElement)) { collection.add(eObjectCreatedElement); } } else if (ref != null && !ref.isMany()) { eObjectSourceReference.eSet(ref, eObjectCreatedElement); } } } } return CommandResult.newOKCommandResult(); }
public boolean select(Object object) { if (object instanceof IGraphicalEditPart) { IGraphicalEditPart editPart = (IGraphicalEditPart) object; Object model = editPart.resolveSemanticElement(); return model instanceof Widget; } return false; }
public boolean select(Object object) { if (object instanceof IGraphicalEditPart) { IGraphicalEditPart editPart = (IGraphicalEditPart) object; Object model = editPart.resolveSemanticElement(); if (model instanceof MainProcess) return false; return model instanceof ConnectableElement; } return false; }
public void setBoundsForOverlapComputation(IGraphicalEditPart ep, Rectangle result) { if (ep.resolveSemanticElement() instanceof FlowElement) { IFigure fig = ((IGraphicalEditPart) ep).getContentPane(); result.setBounds(fig.getBounds()); fig.translateToAbsolute(result); return; } else { result.setBounds(ep.getFigure().getBounds()); ep.getFigure().translateToAbsolute(result); } }
public List getRelTypesOnSource(IAdaptable source) { IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source.getAdapter(IGraphicalEditPart.class); if (sourceEditPart != null) { EObject element = sourceEditPart.resolveSemanticElement(); if (element instanceof Constraint || element instanceof Observation || element instanceof Comment) { ArrayList<IElementType> types = new ArrayList<IElementType>(1); types.add(UMLElementTypes.CommentAnnotatedElement_4010); return types; } } return super.getRelTypesOnSource(source); }
private boolean prepared() { if (fragmentRootEditPart == null) { return false; } EObject element = fragmentRootEditPart.resolveSemanticElement(); if (element instanceof Interaction || element instanceof InteractionOperand) { fragmentRoot = (InteractionFragment) element; } else { return false; } // compute fragment position; fragmentPositions = new HashMap<InteractionFragment, Float>(); // compute new indexes. fragmentIndexes = new HashMap<InteractionFragment, Integer>(); EList<InteractionFragment> orderingFragments = getOrderingFragments(); return orderingFragments != null && !orderingFragments.isEmpty(); }
@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); }
/** * Performs a <code>DropObjectsRequest</code> in a modal context thread. Verifies that the diagram * refreshes on the UI thread. * * @throws Exception if an unexpected exception occurs */ public void test_drop_modalContextThread() throws Exception { // Open the test fixture diagram getTestFixture().openDiagram(); final DiagramEditPart diagramEditPart = getDiagramEditPart(); // Create an AND gate in the semantic model ICommand andCommand = new AbstractTransactionalCommand( getTestFixture().getEditingDomain(), "Create AND Gate", null) { // $NON-NLS-1$ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { AndGate newElement = (AndGate) SemanticPackage.eINSTANCE .getEFactoryInstance() .create(SemanticPackage.eINSTANCE.getAndGate()); ContainerElement semanticElement = (ContainerElement) diagramEditPart.resolveSemanticElement(); semanticElement.getChildren().add(newElement); return CommandResult.newOKCommandResult(newElement); } }; andCommand.execute(new NullProgressMonitor(), null); AndGate andGate = (AndGate) andCommand.getCommandResult().getReturnValue(); // Get the initial number of edit parts on the diagram List primaryEditParts = diagramEditPart.getPrimaryEditParts(); int initialEditPartCount = primaryEditParts.size(); // Get the command to drop the AND gate onto the diagram Point dropLocation = ICanonicalShapeCompartmentLayout.UNDEFINED.getLocation(); DropObjectsRequest request = new DropObjectsRequest(); request.setObjects(Collections.singletonList(andGate)); request.setAllowedDetail(DND.DROP_COPY); request.setLocation(dropLocation); Command command = diagramEditPart.getCommand(request); final CommandProxy proxy = new CommandProxy(command); // Execute the command in a forking progress monitor dialog IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { OperationHistoryFactory.getOperationHistory().execute(proxy, monitor, null); } catch (ExecutionException e) { throw new InvocationTargetException(e); } } }; new ProgressMonitorDialog(null).run(true, true, runnable); // Verify that a new edit part has been added to the diagram for the AND gate primaryEditParts = getDiagramEditPart().getPrimaryEditParts(); assertTrue( "Size of primary edit parts should have increased.", primaryEditParts.size() > initialEditPartCount); // $NON-NLS-1$ IGraphicalEditPart andGateEditPart = null; for (Iterator i = primaryEditParts.iterator(); i.hasNext(); ) { IGraphicalEditPart nextEditPart = (IGraphicalEditPart) i.next(); if (andGate.equals(nextEditPart.resolveSemanticElement())) { andGateEditPart = nextEditPart; break; } } assertNotNull("Expected a new edit part for the AND gate", andGateEditPart); // $NON-NLS-1$ }