| /********************************************************************* |
| * Copyright (c) 2005, 2019 SAP SE |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * Contributors: |
| * SAP SE - initial API, implementation and documentation |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| **********************************************************************/ |
| package org.eclipse.graphiti.examples.tutorial.property; |
| |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.graphiti.mm.pictograms.PictogramElement; |
| import org.eclipse.graphiti.services.Graphiti; |
| import org.eclipse.graphiti.ui.platform.GFPropertySection; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.custom.CLabel; |
| import org.eclipse.swt.layout.FormAttachment; |
| import org.eclipse.swt.layout.FormData; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Text; |
| import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants; |
| import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; |
| import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; |
| |
| public class TutorialEClassSection extends GFPropertySection implements ITabbedPropertyConstants { |
| |
| private Text nameText; |
| private PictogramElement currentPe; |
| |
| @Override |
| public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) { |
| super.createControls(parent, tabbedPropertySheetPage); |
| |
| TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); |
| Composite composite = factory.createFlatFormComposite(parent); |
| FormData data; |
| |
| nameText = factory.createText(composite, ""); //$NON-NLS-1$ |
| nameText.setEditable(false); |
| data = new FormData(); |
| data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH); |
| data.right = new FormAttachment(100, 0); |
| data.top = new FormAttachment(0, VSPACE); |
| nameText.setLayoutData(data); |
| |
| CLabel valueLabel = factory.createCLabel(composite, "Name:"); //$NON-NLS-1$ |
| data = new FormData(); |
| data.left = new FormAttachment(0, 0); |
| data.right = new FormAttachment(nameText, -HSPACE); |
| data.top = new FormAttachment(nameText, 0, SWT.CENTER); |
| valueLabel.setLayoutData(data); |
| } |
| |
| @Override |
| public void refresh() { |
| PictogramElement pe = getSelectedPictogramElement(); |
| if (pe != null && !pe.equals(currentPe)) { |
| currentPe = pe; |
| Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); |
| // the filter assured, that it is a EClass |
| if (bo == null) |
| return; |
| String name = ((EClass) bo).getName(); |
| nameText.setText(name == null ? "" : name); //$NON-NLS-1$ |
| } |
| } |
| } |