| /** |
| * Copyright (c)2020 CEA LIST, Committer Name, and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation |
| * |
| */ |
| package org.eclipse.papyrus.pdp4eng.req.ui.view; |
| |
| import org.eclipse.jface.viewers.StyledCellLabelProvider; |
| import org.eclipse.jface.viewers.StyledString; |
| import org.eclipse.jface.viewers.StyledString.Styler; |
| import org.eclipse.jface.viewers.ViewerCell; |
| import org.eclipse.papyrus.pdp4eng.req.profile.constraints.GDPRRequiementHelper; |
| import org.eclipse.papyrus.sysml14.requirements.Requirement; |
| import org.eclipse.swt.graphics.Color; |
| import org.eclipse.swt.graphics.Font; |
| import org.eclipse.swt.graphics.TextStyle; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.uml2.uml.NamedElement; |
| import org.eclipse.uml2.uml.util.UMLUtil; |
| |
| /** |
| * |
| * This is the label provider to display requirements in the view |
| */ |
| public class ReviewsTreeLabelProvider extends StyledCellLabelProvider { |
| protected Font italicFont; |
| protected Font boldFont; |
| private Styler fBoldStyler; |
| private Styler fItalicStyler; |
| |
| /** |
| * constructor |
| * |
| * @param boldFont |
| * @param italicFont |
| */ |
| public ReviewsTreeLabelProvider(final Font boldFont, final Font italicFont) { |
| this.boldFont = boldFont; |
| this.italicFont = italicFont; |
| // Multi-font support only works in JFace 3.5 and above (specifically, 3.5 M4 and above). |
| // With JFace 3.4, the font information (bold in this example) will be ignored. |
| |
| fBoldStyler = new Styler() { |
| |
| @Override |
| public void applyStyles(TextStyle textStyle) { |
| textStyle.font = boldFont; |
| |
| } |
| }; |
| fItalicStyler = new Styler() { |
| |
| @Override |
| public void applyStyles(TextStyle textStyle) { |
| textStyle.font = italicFont; |
| |
| } |
| }; |
| } |
| |
| |
| /** |
| * update visual appearance of a cell |
| */ |
| @Override |
| public void update(ViewerCell cell) { |
| Object obj = cell.getElement(); |
| |
| if (obj instanceof org.eclipse.uml2.uml.NamedElement) { |
| NamedElement namedElement = (NamedElement) obj; |
| StyledString styledString = new StyledString(""); //$NON-NLS-1$ |
| // if no name |
| if (((org.eclipse.uml2.uml.NamedElement) obj).getName() == null) { |
| styledString.append("###"); //$NON-NLS-1$ |
| |
| } else { |
| // it has a name |
| styledString.append(((org.eclipse.uml2.uml.NamedElement) obj).getName() + ": ", fBoldStyler); //$NON-NLS-1$ |
| Requirement reqStereotypeAppli = UMLUtil.getStereotypeApplication(namedElement, Requirement.class); |
| // this is a stereotype |
| if (reqStereotypeAppli != null) { |
| styledString.append(reqStereotypeAppli.getText(), fItalicStyler); |
| } |
| } |
| |
| cell.setBackground(new Color(Display.getCurrent(), 255, 255, 200)); |
| cell.setText(styledString.toString()); |
| cell.setStyleRanges(styledString.getStyleRanges()); |
| // this is a GDPR requirement |
| if (GDPRRequiementHelper.isGDPR_Requirement(namedElement)) { |
| cell.setBackground(new Color(Display.getCurrent(), 51, 204, 255)); |
| } |
| } |
| super.update(cell); |
| } |
| |
| } |