| /******************************************************************************* |
| * Copyright (c) 2009 Zoltan Ujhelyi and Daniel Varro. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Zoltan Ujhelyi - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.viatra2.visualisation.patterns.properties; |
| |
| import org.eclipse.core.runtime.Assert; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| 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.IWorkbenchPart; |
| import org.eclipse.ui.forms.widgets.ColumnLayout; |
| import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; |
| import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants; |
| import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; |
| import org.eclipse.viatra2.visualisation.patterns.viewmodel.AbstractViewModelElement; |
| |
| /** |
| * A Property Page Section capable of describing the identification parameters |
| * (most typically name) of the visualised elements. |
| * @author Zoltan Ujhelyi |
| */ |
| public class NamePropertySection extends AbstractPropertySection { |
| private Text name, fqName; |
| |
| // private Label parametersLabel; |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see |
| * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls |
| * (org.eclipse.swt.widgets.Composite, |
| * org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage) |
| */ |
| @Override |
| public void createControls(Composite parent, |
| TabbedPropertySheetPage aTabbedPropertySheetPage) { |
| super.createControls(parent, aTabbedPropertySheetPage); |
| parent.setLayout(new ColumnLayout()); |
| Composite nameComposite = getWidgetFactory().createFlatFormComposite( |
| parent); |
| FormData data; |
| name = getWidgetFactory().createText(nameComposite, ""); |
| name.setEditable(false); |
| data = new FormData(); |
| data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH); |
| data.right = new FormAttachment(100, 0); |
| data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE); |
| name.setLayoutData(data); |
| CLabel label = getWidgetFactory().createCLabel(nameComposite, |
| "Name:"); |
| data = new FormData(); |
| data.left = new FormAttachment(0, 0); |
| data.right = new FormAttachment(name, -ITabbedPropertyConstants.HSPACE); |
| data.top = new FormAttachment(name, 0, SWT.CENTER); |
| label.setLayoutData(data); |
| |
| fqName = getWidgetFactory().createText(nameComposite, ""); |
| data = new FormData(); |
| data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH); |
| data.right = new FormAttachment(100, 0); |
| data.top = new FormAttachment(name, ITabbedPropertyConstants.VMARGIN, ITabbedPropertyConstants.VSPACE); |
| fqName.setLayoutData(data); |
| label = getWidgetFactory().createCLabel(nameComposite, |
| "FQ Name:"); |
| data = new FormData(); |
| data.left = new FormAttachment(0, 0); |
| data.right = new FormAttachment(fqName, -ITabbedPropertyConstants.HSPACE); |
| data.top = new FormAttachment(fqName, 0, SWT.CENTER); |
| label.setLayoutData(data); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see |
| * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#setInput |
| * (org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) |
| */ |
| @Override |
| public void setInput(IWorkbenchPart part, ISelection selection) { |
| super.setInput(part, selection); |
| Assert.isTrue(selection instanceof IStructuredSelection); |
| Object input = ((IStructuredSelection) selection).getFirstElement(); |
| Assert.isTrue(input instanceof AbstractViewModelElement); |
| AbstractViewModelElement element = (AbstractViewModelElement) input; |
| name.setText(element.getName()); |
| fqName.setText(element.getFQName()); |
| |
| } |
| |
| } |