/******************************************************************************* * Copyright (c) 2008, 2012 Obeo. * 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: * Obeo - initial API and implementation *******************************************************************************/ package org.eclipse.emf.samples.conference.parts.forms; // Start of user code for imports import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; import org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent; import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent; import org.eclipse.emf.eef.runtime.api.parts.IFormPropertiesEditionPart; import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent; import org.eclipse.emf.eef.runtime.part.impl.SectionPropertiesEditingPart; import org.eclipse.emf.eef.runtime.ui.parts.PartComposer; import org.eclipse.emf.eef.runtime.ui.parts.sequence.BindingCompositionSequence; import org.eclipse.emf.eef.runtime.ui.parts.sequence.CompositionSequence; import org.eclipse.emf.eef.runtime.ui.parts.sequence.CompositionStep; import org.eclipse.emf.eef.runtime.ui.utils.EditingUtils; import org.eclipse.emf.eef.runtime.ui.widgets.EEFFeatureEditorDialog; import org.eclipse.emf.eef.runtime.ui.widgets.FormUtils; import org.eclipse.emf.samples.conference.ConferencePackage; import org.eclipse.emf.samples.conference.parts.ConferenceViewsRepository; import org.eclipse.emf.samples.conference.parts.TopicPropertiesEditionPart; import org.eclipse.emf.samples.conference.providers.ConferenceMessages; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusAdapter; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.widgets.Form; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.forms.widgets.Section; // End of user code /** * @author <a href="mailto:stephane.bouchet@obeo.fr">Stephane Bouchet</a> * */ public class TopicPropertiesEditionPartForm extends SectionPropertiesEditingPart implements IFormPropertiesEditionPart, TopicPropertiesEditionPart { protected Text description; protected Text references; protected Button editReferences; private EList referencesList; protected Text documentation; /** * For {@link ISection} use only. */ public TopicPropertiesEditionPartForm() { super(); } /** * Default constructor * @param editionComponent the {@link IPropertiesEditionComponent} that manage this part * */ public TopicPropertiesEditionPartForm(IPropertiesEditionComponent editionComponent) { super(editionComponent); } /** * {@inheritDoc} * * @see org.eclipse.emf.eef.runtime.api.parts.IFormPropertiesEditionPart# * createFigure(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit) * */ public Composite createFigure(final Composite parent, final FormToolkit widgetFactory) { ScrolledForm scrolledForm = widgetFactory.createScrolledForm(parent); Form form = scrolledForm.getForm(); view = form.getBody(); GridLayout layout = new GridLayout(); layout.numColumns = 3; view.setLayout(layout); createControls(widgetFactory, view); return scrolledForm; } /** * {@inheritDoc} * * @see org.eclipse.emf.eef.runtime.api.parts.IFormPropertiesEditionPart# * createControls(org.eclipse.ui.forms.widgets.FormToolkit, org.eclipse.swt.widgets.Composite) * */ public void createControls(final FormToolkit widgetFactory, Composite view) { CompositionSequence topicStep = new BindingCompositionSequence(propertiesEditionComponent); CompositionStep propertiesStep = topicStep.addStep(ConferenceViewsRepository.Topic.Properties.class); propertiesStep.addStep(ConferenceViewsRepository.Topic.Properties.description); propertiesStep.addStep(ConferenceViewsRepository.Topic.Properties.references); propertiesStep.addStep(ConferenceViewsRepository.Topic.Properties.documentation); composer = new PartComposer(topicStep) { @Override public Composite addToPart(Composite parent, Object key) { if (key == ConferenceViewsRepository.Topic.Properties.class) { return createPropertiesGroup(widgetFactory, parent); } if (key == ConferenceViewsRepository.Topic.Properties.description) { return createDescriptionText(widgetFactory, parent); } if (key == ConferenceViewsRepository.Topic.Properties.references) { return createReferencesMultiValuedEditor(widgetFactory, parent); } if (key == ConferenceViewsRepository.Topic.Properties.documentation) { return createDocumentationTextarea(widgetFactory, parent); } return parent; } }; composer.compose(view); } /** * */ protected Composite createPropertiesGroup(FormToolkit widgetFactory, final Composite parent) { Section propertiesSection = widgetFactory.createSection(parent, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED); propertiesSection.setText(ConferenceMessages.TopicPropertiesEditionPart_PropertiesGroupLabel); GridData propertiesSectionData = new GridData(GridData.FILL_HORIZONTAL); propertiesSectionData.horizontalSpan = 3; propertiesSection.setLayoutData(propertiesSectionData); Composite propertiesGroup = widgetFactory.createComposite(propertiesSection); GridLayout propertiesGroupLayout = new GridLayout(); propertiesGroupLayout.numColumns = 3; propertiesGroup.setLayout(propertiesGroupLayout); propertiesSection.setClient(propertiesGroup); return propertiesGroup; } protected Composite createDescriptionText(FormToolkit widgetFactory, Composite parent) { createDescription(parent, ConferenceViewsRepository.Topic.Properties.description, ConferenceMessages.TopicPropertiesEditionPart_DescriptionLabel); description = widgetFactory.createText(parent, ""); //$NON-NLS-1$ description.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); widgetFactory.paintBordersFor(parent); GridData descriptionData = new GridData(GridData.FILL_HORIZONTAL); description.setLayoutData(descriptionData); description.addFocusListener(new FocusAdapter() { /** * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent) * */ @Override @SuppressWarnings("synthetic-access") public void focusLost(FocusEvent e) { if (propertiesEditionComponent != null) { propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent( TopicPropertiesEditionPartForm.this, ConferenceViewsRepository.Topic.Properties.description, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, description.getText())); propertiesEditionComponent .firePropertiesChanged(new PropertiesEditionEvent( TopicPropertiesEditionPartForm.this, ConferenceViewsRepository.Topic.Properties.description, PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_LOST, null, description.getText())); } } /** * @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent) */ @Override public void focusGained(FocusEvent e) { if (propertiesEditionComponent != null) { propertiesEditionComponent .firePropertiesChanged(new PropertiesEditionEvent( TopicPropertiesEditionPartForm.this, null, PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_GAINED, null, null)); } } }); description.addKeyListener(new KeyAdapter() { /** * @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent) * */ @Override @SuppressWarnings("synthetic-access") public void keyPressed(KeyEvent e) { if (e.character == SWT.CR) { if (propertiesEditionComponent != null) propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(TopicPropertiesEditionPartForm.this, ConferenceViewsRepository.Topic.Properties.description, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, description.getText())); } } }); EditingUtils.setID(description, ConferenceViewsRepository.Topic.Properties.description); EditingUtils.setEEFtype(description, "eef::Text"); //$NON-NLS-1$ FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(ConferenceViewsRepository.Topic.Properties.description, ConferenceViewsRepository.FORM_KIND), null); //$NON-NLS-1$ // Start of user code for createDescriptionText // End of user code return parent; } /** * */ protected Composite createReferencesMultiValuedEditor(FormToolkit widgetFactory, Composite parent) { references = widgetFactory.createText(parent, "", SWT.READ_ONLY); //$NON-NLS-1$ GridData referencesData = new GridData(GridData.FILL_HORIZONTAL); referencesData.horizontalSpan = 2; references.setLayoutData(referencesData); EditingUtils.setID(references, ConferenceViewsRepository.Topic.Properties.references); EditingUtils.setEEFtype(references, "eef::MultiValuedEditor::field"); //$NON-NLS-1$ editReferences = widgetFactory.createButton(parent, getDescription(ConferenceViewsRepository.Topic.Properties.references, ConferenceMessages.TopicPropertiesEditionPart_ReferencesLabel), SWT.NONE); GridData editReferencesData = new GridData(); editReferences.setLayoutData(editReferencesData); editReferences.addSelectionListener(new SelectionAdapter() { /** * {@inheritDoc} * * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) * */ public void widgetSelected(SelectionEvent e) { EEFFeatureEditorDialog dialog = new EEFFeatureEditorDialog( references.getShell(), "Topic", new AdapterFactoryLabelProvider(adapterFactory), //$NON-NLS-1$ referencesList, ConferencePackage.eINSTANCE.getTopic_References().getEType(), null, false, true, null, null); if (dialog.open() == Window.OK) { referencesList = dialog.getResult(); if (referencesList == null) { referencesList = new BasicEList(); } references.setText(referencesList.toString()); propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(TopicPropertiesEditionPartForm.this, ConferenceViewsRepository.Topic.Properties.references, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, new BasicEList(referencesList))); setHasChanged(true); } } }); EditingUtils.setID(editReferences, ConferenceViewsRepository.Topic.Properties.references); EditingUtils.setEEFtype(editReferences, "eef::MultiValuedEditor::browsebutton"); //$NON-NLS-1$ // Start of user code for createReferencesMultiValuedEditor // End of user code return parent; } protected Composite createDocumentationTextarea(FormToolkit widgetFactory, Composite parent) { Label documentationLabel = createDescription(parent, ConferenceViewsRepository.Topic.Properties.documentation, ConferenceMessages.TopicPropertiesEditionPart_DocumentationLabel); GridData documentationLabelData = new GridData(GridData.FILL_HORIZONTAL); documentationLabelData.horizontalSpan = 3; documentationLabel.setLayoutData(documentationLabelData); documentation = widgetFactory.createText(parent, "", SWT.BORDER | SWT.WRAP | SWT.MULTI | SWT.V_SCROLL); //$NON-NLS-1$ GridData documentationData = new GridData(GridData.FILL_HORIZONTAL); documentationData.horizontalSpan = 2; documentationData.heightHint = 80; documentationData.widthHint = 200; documentation.setLayoutData(documentationData); documentation.addFocusListener(new FocusAdapter() { /** * {@inheritDoc} * * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent) * */ public void focusLost(FocusEvent e) { if (propertiesEditionComponent != null) { propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent( TopicPropertiesEditionPartForm.this, ConferenceViewsRepository.Topic.Properties.documentation, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, documentation.getText())); propertiesEditionComponent .firePropertiesChanged(new PropertiesEditionEvent( TopicPropertiesEditionPartForm.this, ConferenceViewsRepository.Topic.Properties.documentation, PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_LOST, null, documentation.getText())); } } /** * @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent) */ @Override public void focusGained(FocusEvent e) { if (propertiesEditionComponent != null) { propertiesEditionComponent .firePropertiesChanged(new PropertiesEditionEvent( TopicPropertiesEditionPartForm.this, null, PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_GAINED, null, null)); } } }); EditingUtils.setID(documentation, ConferenceViewsRepository.Topic.Properties.documentation); EditingUtils.setEEFtype(documentation, "eef::Textarea"); //$NON-NLS-1$ FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(ConferenceViewsRepository.Topic.Properties.documentation, ConferenceViewsRepository.FORM_KIND), null); //$NON-NLS-1$ // Start of user code for createDocumentationTextArea // End of user code return parent; } /** * {@inheritDoc} * * @see org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionListener#firePropertiesChanged(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent) * */ public void firePropertiesChanged(IPropertiesEditionEvent event) { // Start of user code for tab synchronization // End of user code } /** * {@inheritDoc} * * @see org.eclipse.emf.samples.conference.parts.TopicPropertiesEditionPart#getDescription() * */ public String getDescription() { return description.getText(); } /** * {@inheritDoc} * * @see org.eclipse.emf.samples.conference.parts.TopicPropertiesEditionPart#setDescription(String newValue) * */ public void setDescription(String newValue) { if (newValue != null) { description.setText(newValue); } else { description.setText(""); //$NON-NLS-1$ } boolean eefElementEditorReadOnlyState = isReadOnly(ConferenceViewsRepository.Topic.Properties.description); if (eefElementEditorReadOnlyState && description.isEnabled()) { description.setEnabled(false); description.setToolTipText(ConferenceMessages.Topic_ReadOnly); } else if (!eefElementEditorReadOnlyState && !description.isEnabled()) { description.setEnabled(true); } } /** * {@inheritDoc} * * @see org.eclipse.emf.samples.conference.parts.TopicPropertiesEditionPart#getReferences() * */ public EList getReferences() { return referencesList; } /** * {@inheritDoc} * * @see org.eclipse.emf.samples.conference.parts.TopicPropertiesEditionPart#setReferences(EList newValue) * */ public void setReferences(EList newValue) { referencesList = newValue; if (newValue != null) { references.setText(referencesList.toString()); } else { references.setText(""); //$NON-NLS-1$ } boolean eefElementEditorReadOnlyState = isReadOnly(ConferenceViewsRepository.Topic.Properties.references); if (eefElementEditorReadOnlyState && references.isEnabled()) { references.setEnabled(false); references.setToolTipText(ConferenceMessages.Topic_ReadOnly); } else if (!eefElementEditorReadOnlyState && !references.isEnabled()) { references.setEnabled(true); } } public void addToReferences(Object newValue) { referencesList.add(newValue); if (newValue != null) { references.setText(referencesList.toString()); } else { references.setText(""); //$NON-NLS-1$ } } public void removeToReferences(Object newValue) { referencesList.remove(newValue); if (newValue != null) { references.setText(referencesList.toString()); } else { references.setText(""); //$NON-NLS-1$ } } /** * {@inheritDoc} * * @see org.eclipse.emf.samples.conference.parts.TopicPropertiesEditionPart#getDocumentation() * */ public String getDocumentation() { return documentation.getText(); } /** * {@inheritDoc} * * @see org.eclipse.emf.samples.conference.parts.TopicPropertiesEditionPart#setDocumentation(String newValue) * */ public void setDocumentation(String newValue) { if (newValue != null) { documentation.setText(newValue); } else { documentation.setText(""); //$NON-NLS-1$ } boolean eefElementEditorReadOnlyState = isReadOnly(ConferenceViewsRepository.Topic.Properties.documentation); if (eefElementEditorReadOnlyState && documentation.isEnabled()) { documentation.setEnabled(false); documentation.setBackground(documentation.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); documentation.setToolTipText(ConferenceMessages.Topic_ReadOnly); } else if (!eefElementEditorReadOnlyState && !documentation.isEnabled()) { documentation.setEnabled(true); } } /** * {@inheritDoc} * * @see org.eclipse.emf.eef.runtime.api.parts.IPropertiesEditionPart#getTitle() * */ public String getTitle() { return ConferenceMessages.Topic_Part_Title; } // Start of user code additional methods // End of user code }