/** @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; }
/** * Sets the selection to the given selection and fires selection changed. The ISelection should be * an {@link IStructuredSelection}or it will be ignored. * * @see ISelectionProvider#setSelection(ISelection) */ public void setSelection(ISelection newSelection, boolean dispatch) { if (!(newSelection instanceof IStructuredSelection)) return; List editparts = ((IStructuredSelection) newSelection).toList(); List selection = primGetSelectedEditParts(); setFocus(null); for (int i = 0; i < selection.size(); i++) ((EditPart) selection.get(i)).setSelected(EditPart.SELECTED_NONE); selection.clear(); editparts = flitterEditpart(editparts); // for create handle selection.addAll(editparts); for (int i = 0; i < editparts.size(); i++) { EditPart part = (EditPart) editparts.get(i); if (i == editparts.size() - 1) part.setSelected(EditPart.SELECTED_PRIMARY); else part.setSelected(EditPart.SELECTED); } if (dispatch) { fireSelectionChanged(); } }
/** * Returns a composite command with the given initial command and the RegionContainer specific * auto-size commands to propagate the auto-size to the regions. * * @param request the initial request * @param autoSizeCommand the initial command * @return a composite command with the initial command and the region container specific * additional commands. */ protected Command getRegionContainerAutoSizeCommand(Request request, Command autoSizeCommand) { IDiagramElementEditPart host = (IDiagramElementEditPart) getHost(); TransactionalEditingDomain domain = host.getEditingDomain(); CompositeTransactionalCommand ctc = new CompositeTransactionalCommand( domain, Messages.RegionContainerResizableEditPolicy_regionContainerAutoSizeCommandLabel); ctc.add(new CommandProxy(autoSizeCommand)); Command regionContainerAutoSizeCommand = new ICommandProxy(ctc); // Propagate the auto-size request to the regions. Request req = new Request(); req.setType(request.getType()); req.getExtendedData().put(REGION_AUTO_SIZE_PROPAGATOR, host); Object object = request.getExtendedData().get(REGION_AUTO_SIZE_PROPAGATOR); for (EditPart regionPart : getRegionParts()) { if (object != regionPart) { ctc.add(new CommandProxy(regionPart.getCommand(req))); } } ctc.add( CommandFactory.createICommand( domain, new RegionContainerUpdateLayoutOperation((Node) host.getModel()))); return regionContainerAutoSizeCommand; }
boolean navigateNextAnchor(int direction) { EditPart focus = getCurrentViewer().getFocusEditPart(); AccessibleAnchorProvider provider; provider = (AccessibleAnchorProvider) focus.getAdapter(AccessibleAnchorProvider.class); if (provider == null) return false; List list; if (isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) list = provider.getTargetAnchorLocations(); else list = provider.getSourceAnchorLocations(); Point start = getLocation(); int distance = Integer.MAX_VALUE; Point next = null; for (int i = 0; i < list.size(); i++) { Point p = (Point) list.get(i); if (p.equals(start) || (direction != 0 && (start.getPosition(p) != direction))) continue; int d = p.getDistanceOrthogonal(start); if (d < distance) { distance = d; next = p; } } if (next != null) { ourPlaceMouseInViewer(next); return true; } return false; }
/** Handle resize InteractionOperand {@inheritDoc} */ @Override protected Command getResizeCommand(ChangeBoundsRequest request) { if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) { EditPart parent = getHost().getParent().getParent(); return parent.getCommand(request); } else { if (this.getHost() instanceof InteractionOperandEditPart && this.getHost().getParent() instanceof CombinedFragmentCombinedFragmentCompartmentEditPart) { InteractionOperandEditPart currentIOEP = (InteractionOperandEditPart) this.getHost(); CombinedFragmentCombinedFragmentCompartmentEditPart compartEP = (CombinedFragmentCombinedFragmentCompartmentEditPart) this.getHost().getParent(); // if first interaction operand and resize direction is NORTH if (this.getHost() == OperandBoundsComputeHelper.findFirstIOEP(compartEP) && (request.getResizeDirection() & PositionConstants.NORTH) != 0) { return getHost().getParent().getParent().getCommand(request); } else { int heightDelta = request.getSizeDelta().height(); if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) { return OperandBoundsComputeHelper.createIOEPResizeCommand( currentIOEP, heightDelta, compartEP, PositionConstants.NORTH); } else if ((request.getResizeDirection() & PositionConstants.SOUTH) != 0) { return OperandBoundsComputeHelper.createIOEPResizeCommand( currentIOEP, heightDelta, compartEP, PositionConstants.SOUTH); } } } return null; } }
/* * (non-Javadoc) * * @see org.eclipse.birt.report.designer.core.util.mediator.request.IRequestConvert#convertSelectionToModelLisr(java.util.List) */ public List convertSelectionToModelLisr(List list) { List retValue = new ArrayList(); int size = list.size(); boolean isDummy = false; for (int i = 0; i < size; i++) { Object object = list.get(i); if (!(object instanceof EditPart)) { continue; } EditPart part = (EditPart) object; if (part instanceof DummyEditpart) { retValue.add(part.getModel()); isDummy = true; } else if (isDummy) { break; } else if (part.getModel() instanceof ListBandProxy) { retValue.add(((ListBandProxy) part.getModel()).getSlotHandle()); } else { Object model = part.getModel(); if (model instanceof IAdaptable) { Object temp = ((IAdaptable) model).getAdapter(DesignElementHandle.class); model = temp == null ? model : temp; } if (model instanceof ReportItemHandle) { ReportItemHandle handle = (ReportItemHandle) model; if (handle.getCurrentView() != null) { model = handle.getCurrentView(); } } retValue.add(model); } } return retValue; }
private GraphElement getTargetElement() { if (selectedPart instanceof EventTreeEditPart) { return (GraphElement) selectedPart.getParent().getModel(); } else { return (GraphElement) selectedPart.getModel(); } }
/** * This is to avoid RJS0007E Semantic refresh failed issue appears in compartments, which has only * one node. This should be replaced with the better approach */ public static void relocateStartNodes() { for (Iterator<EditPart> it = startNodes.iterator(); it.hasNext(); ) { try { EditPart next = it.next(); GraphicalEditPart gEditpart = (GraphicalEditPart) next; Rectangle rect = gEditpart.getFigure().getBounds().getCopy(); rect.x++; SetBoundsCommand sbc = new SetBoundsCommand( gEditpart.getEditingDomain(), "change location", new EObjectAdapter((View) next.getModel()), rect); gEditpart.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(sbc)); Thread.sleep(50); } catch (Exception e) { break; } } startNodes = new ArrayList<EditPart>(); }
/** * Create a decoration based on a figure * * @param decoratorTarget the decorator target * @param figure the figure * @param position the position * @param percentageFromSource the percentage from source * @param margin the margin * @param isVolatile the is volatile * @return the decoration */ public final IDecoration createDecorationFigure( IDecoratorTarget decoratorTarget, IFigure figure, int percentageFromSource, int margin, boolean isVolatile) { final View view = (View) decoratorTarget.getAdapter(View.class); org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration decoration = null; if (view == null || view.eResource() == null || figure == null) { return decoration; } EditPart editPart = (EditPart) decoratorTarget.getAdapter(EditPart.class); if (editPart == null || editPart.getViewer() == null) { return decoration; } if (editPart instanceof GraphicalEditPart) { if (view instanceof Edge) { decoration = decoratorTarget.addConnectionDecoration(figure, percentageFromSource, isVolatile); } else { IFigure parentFig = ((GraphicalEditPart) editPart).getFigure(); margin = MapModeUtil.getMapMode(parentFig).DPtoLP(margin); // Locator locator = new MultiIconTopRightLocator(parentFig, margin); // decoration = decoratorTarget.addDecoration(figure, locator, isVolatile); decoration = decoratorTarget.addShapeDecoration( figure, IDecoratorTarget.Direction.NORTH_EAST, margin, isVolatile); } } return decoration; }
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; }
/* * (non-Javadoc) * * @see * org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, * java.lang.Object) */ public EditPart createEditPart(EditPart context, Object model) { EditPart ret = null; if (model instanceof Diagram) { ret = new DiagramTreeEditPart(id, (Diagram) model); } else if (context instanceof AbstractGraphicsTreeEditPart) { EditPart root = context; while (root.getParent() != null) root = root.getParent(); DiagramTreeEditPart dep = (DiagramTreeEditPart) root.getChildren().get(0); if (model instanceof RootElement) { ret = new RootElementTreeEditPart(dep, (RootElement) model); } else if (model instanceof FlowElement) { ret = new FlowElementTreeEditPart(dep, (FlowElement) model); } else if (model instanceof BaseElement) { ret = new BaseElementTreeEditPart(dep, (BaseElement) model); } else if (model instanceof BPMNDiagram) { ret = new Bpmn2DiagramTreeEditPart(dep, (BPMNDiagram) model); } else if (model instanceof BPMNShape) { ret = new Bpmn2ShapeTreeEditPart(dep, (BPMNShape) model); } else if (model instanceof BPMNEdge) { ret = new Bpmn2EdgeTreeEditPart(dep, (BPMNEdge) model); } } return ret; }
@Override protected Command getCommand() { final EditPart targetEditPart = getTargetEditPart(); final CompositeCommand compositeCommand = new CompositeCommand( Messages.OccurrenceSpecificationCreationTool_CreateOccurrenceSpecification); EditPart timeline; if (targetEditPart instanceof FullStateInvariantEditPartCN) { final FullStateInvariantEditPartCN fullStateInvariantEditPartCN = (FullStateInvariantEditPartCN) targetEditPart; timeline = EditPartUtils.findParentEditPartWithId( targetEditPart, FullLifelineTimelineCompartmentEditPartCN.VISUAL_ID); compositeCommand.add( new CutAndInsertOccurrenceSpecificationCommand( fullStateInvariantEditPartCN, getLocation(), false)); } else if (targetEditPart instanceof CompactStateInvariantEditPartCN) { final CompactStateInvariantEditPartCN compactStateInvariantEditPartCN = (CompactStateInvariantEditPartCN) targetEditPart; timeline = EditPartUtils.findParentEditPartWithId( targetEditPart, CompactLifelineCompartmentEditPartCN.VISUAL_ID); compositeCommand.add( new AddOccurrenceSpecificationInCompactLifelineCommand( compactStateInvariantEditPartCN, getLocation())); } else { return UnexecutableCommand.INSTANCE; } final Command updateLayoutCommand = timeline.getCommand(AbstractTimelineLayoutPolicy.UPDATE_LAYOUT_REQUEST); compositeCommand.add(new CommandProxy(updateLayoutCommand)); return new ICommandProxy(compositeCommand); }
@Override public EditPart createEditPart(EditPart context, Object model) { EditPart part = null; if (model instanceof PigMapData) { part = new PigMapDataEditPart(); } else if (model instanceof InputTable) { part = new PigMapInputTablePart(); } else if (model instanceof OutputTable) { part = new PigMapOutputTablePart(); } else if (model instanceof VarTable) { part = new PigMapVarTablePart(); } else if (model instanceof TableNode) { part = new PigMapTableNodePart(); } else if (model instanceof VarNode) { part = new PigMapVarNodeEditPart(); } else if (model instanceof Connection) { part = new ConnectionEditPart(); } else if (model instanceof LookupConnection) { part = new PigMapLookupConnectionPart(); } else if (model instanceof FilterConnection) { part = new PigMapFilterConnectionPart(); } if (part != null) { part.setModel(model); } return part; }
/** * Test if the selected item is a node. * * @return true / false */ private boolean canPerformAction() { if (getSelectedObjects().isEmpty()) { return false; } List parts = getSelectedObjects(); if (parts.size() == 1) { Object o = parts.get(0); if (!(o instanceof NodePart)) { return false; } NodePart part = (NodePart) o; if (!(part.getModel() instanceof INode)) { return false; } node = (Node) part.getModel(); EditPart parentPart = part.getParent(); while (!(parentPart instanceof ProcessPart)) { parentPart = parentPart.getParent(); } if (!(parentPart instanceof ProcessPart)) { return false; } process = (IProcess) ((ProcessPart) parentPart).getModel(); setText(Messages.getString("PropertiesContextAction.Properties")); // $NON-NLS-1$ } return true; }
/** * This method is invoked when the user presses the space bar. It toggles the selection of the * EditPart that currently has focus. */ protected void processSelect(KeyEvent event) { EditPart part = getViewer().getFocusEditPart(); if ((event.stateMask & SWT.CONTROL) != 0 && part.getSelected() != EditPart.SELECTED_NONE) getViewer().deselect(part); else getViewer().appendSelection(part); getViewer().setFocus(part); }
/** * Method showSourceFeedback. Show the source drag feedback for the drag occurring within the * viewer. */ private void showSourceFeedback() { List editParts = getOperationSet(); for (int i = 0; i < editParts.size(); i++) { EditPart editPart = (EditPart) editParts.get(i); editPart.showSourceFeedback(getSourceRequest()); } setShowingFeedback(true); }
/** * Compares semantically the two given edit parts * * @param one The first edit part to be compared * @param other The second edit part to be compared * @return True if the two edit parts refer to the same model element, false otherwise */ private boolean semanticCompareEditParts(EditPart one, EditPart other) { if (one.getModel() instanceof View && other.getModel() instanceof View) { View view1 = (View) one.getModel(); View view2 = (View) other.getModel(); return view1 != null && view2 != null && view1.getElement() == view2.getElement(); } return false; }
private void checkStyleBeforeCustom(SWTBotGefEditPart botGefEditPart) { EditPart editPart = botGefEditPart.part(); Node model = (Node) editPart.getModel(); ShapeStyle shapeStyle = (ShapeStyle) model.getStyles().get(0); assertEquals("Wrong expected fill color.", EXPECTED_FILL_COLOR, shapeStyle.getFillColor()); assertEquals("Wrong expected font height", EXPECTED_FONT_HEIGHT, shapeStyle.getFontHeight()); assertEquals("Wrong expected font color", EXPECTED_FONT_COLOR, shapeStyle.getFontColor()); assertEquals("Wrong expected line color", EXPECTED_LINE_COLOR, shapeStyle.getLineColor()); }
public Command createOpacityCommand(final String opacity) { final Request opacityReq = new Request("opacity"); // $NON-NLS-1$ final HashMap<String, String> reqData = new HashMap<String, String>(); reqData.put("newOpacity", opacity); // $NON-NLS-1$ opacityReq.setExtendedData(reqData); final EditPart object = (EditPart) getSelectedObjects().get(0); final Command cmd = object.getCommand(opacityReq); return cmd; }
/** * Steps up the parent EditPart hierarchy until the parent is type of an {@link IPrimaryEditPart}. * If the given EditPart is already a {@link IPrimaryEditPart} it is directly returned. * * @param editPart - EditPart to start from * @return The EditPart directly or one of the parent EditParts or {@code NULL} if none of the * parents match IPrimaryEditPart */ protected IPrimaryEditPart getPrimaryEditPart(EditPart editPart) { IPrimaryEditPart ret = null; if (editPart instanceof IPrimaryEditPart) { return (IPrimaryEditPart) editPart; } else if (editPart.getParent() != null) { ret = getPrimaryEditPart(editPart.getParent()); } return ret; }
/** {@inheritDoc} */ @Override protected void refreshChildren() { super.refreshChildren(); for (Object child : this.getChildren()) { EditPart part = (EditPart) child; part.refresh(); } }
public EditPart getMyRoot() { EditPart root = getRoot(); Iterator iter = root.getChildren().iterator(); EditPart part = null; while (iter.hasNext() && !(part instanceof SQLRootEditPart)) { part = (EditPart) iter.next(); } // end of while () return part; }
/** * Gets a command from each child in the group. * * @param request * @return the compound command */ private Command getCommandFromChildren(Request request) { CompoundCommand cc = new CompoundCommand(); for (Iterator iter = getHost().getChildren().iterator(); iter.hasNext(); ) { EditPart childEP = (EditPart) iter.next(); cc.add(childEP.getCommand(request)); } cc.unwrap(); return cc; }
/** * This method returns the target RegionEditPart if any, or returns null. * * @return the target RegionEditPart */ public RegionEditPart getTargetRegionEditPart() { EditPart ep = getTargetEditPart(); if ((ep != null) && (ep instanceof RegionCompartmentEditPart) && ep.getParent().getParent().equals(regionEP.getParent())) { return (RegionEditPart) ep.getParent(); } return null; }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.layout.LayouttoolInterface#getSource(org.eclipse.gef.EditPart) */ public EditPart getSource(EditPart element) { if (element.getModel() instanceof Edge) { Edge edge = (Edge) element.getModel(); removeBendPoints(edge); AbstractConnectionEditPart acep = (AbstractConnectionEditPart) element; return acep.getSource(); } return null; }
public void setEnabled(boolean enabled) { EditPart root = getContents(); List v = root.getChildren(); if (v != null) { int max = v.size(); for (int i = 0; i < max; i++) { setCategoryEnabled((EditPart) v.get(i), enabled); } } }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.layout.LayouttoolInterface#isNode(org.eclipse.gef.EditPart) */ public boolean isNode(EditPart element) { if (element.getModel() instanceof Node) { if (GMFLayoutAreaCreator.getArea() != null && element.equals(GMFLayoutAreaCreator.getArea())) { return false; } return true; } return false; }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.layout.LayouttoolInterface#getBounds(org.eclipse.gef.EditPart) */ public Rectangle getBounds(EditPart element) { if (element.getModel() instanceof Node) { Node node = (Node) element.getModel(); if (node.getLayoutConstraint() instanceof Bounds) { Bounds bounds = (Bounds) node.getLayoutConstraint(); return new Rectangle(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); } } return null; }
/** * Method eraseSourceFeedback. Show the source drag feedback for the drag occurring within the * viewer. */ private void eraseSourceFeedback() { if (!isShowingFeedback()) return; setShowingFeedback(false); List editParts = getOperationSet(); for (int i = 0; i < editParts.size(); i++) { EditPart editPart = (EditPart) editParts.get(i); editPart.eraseSourceFeedback(getSourceRequest()); } }
void retrieveParameters(Request request) { EditPart editPart = getTargetEditPart(request); contract = (Contract) ((View) editPart.getModel()).getElement(); mEditingDomain = ((IGraphicalEditPart) editPart).getEditingDomain(); IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); diagramFile = ((IFileEditorInput) activeEditor.getEditorInput()).getFile(); project = ((IResource) diagramFile).getProject(); }