@Override public void setSelected(int value) { final EditPart parent = this.getParent(); final NormalColumnFigure figure = (NormalColumnFigure) this.getFigure(); Color backgroundColor = null; Color foregroundColor = null; boolean isSelected = false; if (value != 0 && parent != null && parent.getParent() != null) { List selectedEditParts = this.getViewer().getSelectedEditParts(); if (selectedEditParts == null || selectedEditParts.size() != 1) { return; } backgroundColor = ColorConstants.titleBackground; foregroundColor = ColorConstants.titleForeground; isSelected = true; } final NormalColumn normalColumn = (NormalColumn) this.getModel(); final ColumnHolder columnHolder = normalColumn.getColumnHolder(); if (columnHolder instanceof ColumnGroup) { if (parent != null) { for (Object child : parent.getChildren()) { final GraphicalEditPart childEditPart = (GraphicalEditPart) child; if (childEditPart.getModel() instanceof NormalColumn) { final NormalColumn column = (NormalColumn) childEditPart.getModel(); if (column.getColumnHolder() == columnHolder) { setGroupColumnFigureColor( (TableViewEditPart) parent, (ColumnGroup) columnHolder, isSelected); } } } } } else { figure.setBackgroundColor(backgroundColor); figure.setForegroundColor(foregroundColor); selected = isSelected; } super.setSelected(value); }
/** * Override to return the <code>Command</code> to perform an {@link RequestConstants#REQ_CLONE * CLONE}. By default, <code>null</code> is returned. * * @param request the Clone Request * @return A command to perform the Clone. */ protected Command getCloneCommand(ChangeBoundsRequest request) { CloneCommand clone = new CloneCommand(); clone.setParent((LogicDiagram) getHost().getModel()); Iterator i = request.getEditParts().iterator(); GraphicalEditPart currPart = null; while (i.hasNext()) { currPart = (GraphicalEditPart) i.next(); clone.addPart( (LogicSubpart) currPart.getModel(), (Rectangle) getConstraintFor(request, currPart)); } // Attach to horizontal guide, if one is given Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE); if (guidePos != null) { int hAlignment = ((Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_ANCHOR)).intValue(); clone.setGuide(findGuideAt(guidePos.intValue(), true), hAlignment, true); } // Attach to vertical guide, if one is given guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE); if (guidePos != null) { int vAlignment = ((Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_ANCHOR)).intValue(); clone.setGuide(findGuideAt(guidePos.intValue(), false), vAlignment, false); } return clone; }
/** * Refreshes the label of the figure associated to the specified edit part * * @param editPart the edit part managing the refreshed figure */ public void refreshEditPartDisplay(GraphicalEditPart editPart) { IFigure figure = editPart.getFigure(); // computes the icon to be displayed final Collection<Image> imageToDisplay = stereotypeIconsToDisplay(editPart); // should check if edit part has to display the element icon or not if (AppearanceHelper.showElementIcon((View) editPart.getModel())) { imageToDisplay.add(getImage(editPart)); } // for each element in the list of stereotype icon, adds it to the icons // list of the // wrapping label // problem (RS - CEA LIST): more icons were displayed before refresh: // has to clean // problem 2 (RS - CEA LIST): no method to know how many icons were // displayed => should fix // a max number ?! // solution: set all images to null, and then add the correct icons int i = 0; if (figure instanceof WrappingLabel) { while (((WrappingLabel) figure).getIcon(i) != null) { ((WrappingLabel) figure).setIcon(null, i); i++; } i = 0; for (Image image : imageToDisplay) { ((WrappingLabel) figure).setIcon(image, i); i++; } ((WrappingLabel) figure).setText(labelToDisplay(editPart)); } }
/** * get the list of stereotype to display from the eannotation * * @return the list of stereotypes to display */ public String stereotypesToDisplay(GraphicalEditPart editPart) { View view = (View) editPart.getModel(); // retrieve all stereotypes to be displayed // try to display stereotype properties String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay(view); String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay(view); String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view); // now check presentation. // if horizontal => equivalent to the inBrace visualization in nodes // (i.e. only name = // value, separator = comma, delimited with brace // if vertical => equivalent to compartment visualization name of // stereotype, NL, property = // value, NL, etC. // check the presentation kind. if only icon => do not display // stereotype, only values if (UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION.equals( stereotypespresentationKind)) { return StereotypeUtil.getPropertiesValuesInBrace( stereotypesPropertiesToDisplay, getUMLElement(editPart)); } String stereotypesToDisplayWithQN = AppliedStereotypeHelper.getStereotypesQNToDisplay(view); String display = ""; if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals( stereotypespresentationKind)) { display += stereotypesAndPropertiesToDisplay( editPart, "\n", stereotypesToDisplay, stereotypesToDisplayWithQN, stereotypesPropertiesToDisplay); } else { final String st = stereotypesToDisplay(editPart, ", ", stereotypesToDisplay, stereotypesToDisplayWithQN); if (st != null && !st.equals("")) { display += Activator.ST_LEFT + st + Activator.ST_RIGHT + " "; } final String propSt = StereotypeUtil.getPropertiesValuesInBrace( stereotypesPropertiesToDisplay, getUMLElement(editPart)); if (propSt != null && !propSt.equals("")) { if (st != null && !st.equals("")) { // display += "\n"; } display += "{" + propSt + "} "; } } return display; }
/** * Returns the image to be displayed for the applied stereotypes. * * @return the image that represents the first applied stereotype or <code>null</code> if no image * has to be displayed */ public Collection<Image> stereotypeIconsToDisplay(GraphicalEditPart editPart) { String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind((View) editPart.getModel()); if (stereotypespresentationKind == null) { return null; } if (stereotypespresentationKind.equals( UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION) || stereotypespresentationKind.equals( UMLVisualInformationPapyrusConstant.TEXT_ICON_STEREOTYPE_PRESENTATION)) { // retrieve the first stereotype in the list of displayed stereotype String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay((View) editPart.getModel()); Collection<Stereotype> stereotypes = new ArrayList<Stereotype>(); StringTokenizer tokenizer = new StringTokenizer(stereotypesToDisplay, ","); while (tokenizer.hasMoreTokens()) { String firstStereotypeName = tokenizer.nextToken(); stereotypes.add(getUMLElement(editPart).getAppliedStereotype(firstStereotypeName)); } return Activator.getIconElements(getUMLElement(editPart), stereotypes, false); } return new ArrayList<Image>(); }
/** {@inheritDoc} */ @Override public Property getUMLElement(GraphicalEditPart editPart) { if ((View) editPart.getModel() != null && ((View) editPart.getModel()).eContainer() != null) { EObject container = ((View) editPart.getModel()).eContainer(); if (!(container instanceof Edge)) { return null; // Happens e.g. when redoing the suppression of an association's end. The // association is contained in a ChangeDescription } if (((Edge) ((View) editPart.getModel()).eContainer()).getTarget() == null) { return null; } Classifier target = (Classifier) ((Edge) ((View) editPart.getModel()).eContainer()).getTarget().getElement(); Property propertyToDisplay = null; if (((View) editPart.getModel()) != null && (((View) editPart.getModel()).getElement() instanceof Association)) { // look for the property that is typed by the classifier Iterator<Property> propertiesIterator = ((Association) ((View) editPart.getModel()).getElement()).getMemberEnds().iterator(); // find the last while (propertiesIterator.hasNext()) { Property currentProperty = propertiesIterator.next(); if (EcoreUtil.equals(currentProperty.getType(), target)) { propertyToDisplay = currentProperty; } } } if (propertyToDisplay != null) { return propertyToDisplay; } // /in the case of reorient the property must be not found, // so we have to find the property that is different from the source. Classifier source = (Classifier) ((Edge) ((View) editPart.getModel()).eContainer()).getSource().getElement(); if (((View) editPart.getModel()) != null && (((View) editPart.getModel()).getElement() instanceof Association)) { // look for the property that is typed by the classifier Iterator<Property> propertiesIterator = ((Association) ((View) editPart.getModel()).getElement()).getMemberEnds().iterator(); // find the last while (propertiesIterator.hasNext()) { Property currentProperty = propertiesIterator.next(); if (!EcoreUtil.equals(currentProperty.getType(), source)) { propertyToDisplay = currentProperty; } } } return propertyToDisplay; } return null; }
@Override public void fill(Menu menu, int index) { // this is a hack to prevent this menu from being created twice if (menu.getItemCount() > MIDContextMenu.INVALID_MENU_ITEM_LIMIT) { return; } // check selection ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection(); if (selection == null || selection.isEmpty() || !(selection instanceof StructuredSelection)) { return; } Object[] objects = ((StructuredSelection) selection).toArray(); boolean doDerivation = true; if (objects.length > 1) { doDerivation = false; } // get selection ModelElementReference modelElemRef = null; for (Object object : objects) { if (object instanceof ModelElementReferenceEditPart || object instanceof ModelElementReference2EditPart) { GraphicalEditPart editPart = (GraphicalEditPart) object; modelElemRef = (ModelElementReference) ((View) editPart.getModel()).getElement(); // TODO MMINT[KLEISLI] replace with KleisliModelElement EMFInfo eInfo = modelElemRef.getObject().getEInfo(); if (!(((ModelEndpointReference) modelElemRef.eContainer()).getObject() instanceof KleisliModelEndpoint) || MultiModelConstraintChecker.isInstancesLevel(modelElemRef) || ( // only types !eInfo.getClassName().startsWith("_") && ( // only derived classes eInfo.getFeatureName() == null || !eInfo.getFeatureName().startsWith("_"))) || (eInfo.getClassName().startsWith("_") && // only derived features eInfo.getFeatureName() != null && !eInfo.getFeatureName().startsWith("_"))) { doDerivation = false; } } if (!doDerivation) { return; } } if (modelElemRef == null) { // no relevant edit parts selected return; } // create dynamic menus MenuItem mmintItem = new MenuItem(menu, SWT.CASCADE, index); mmintItem.setText(MIDContextMenu.MMINT_MENU_LABEL); Menu mmintMenu = new Menu(menu); mmintItem.setMenu(mmintMenu); // derivation if (doDerivation) { MenuItem derivationItem = new MenuItem(mmintMenu, SWT.NONE); derivationItem.setText(MMINT_MENU_KLEISLI_LABEL); derivationItem.addSelectionListener( new KleisliAddModifyQueryListener(MMINT_MENU_KLEISLI_LABEL, modelElemRef.getObject())); } }