| /******************************************************************************* |
| * 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.eef.extended.editor.parts.forms; |
| |
| // Start of user code for imports |
| import java.util.ArrayList; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.eef.extended.editor.parts.EditorViewsRepository; |
| import org.eclipse.emf.eef.extended.editor.parts.StaticEEFEditorContributionPropertiesEditionPart; |
| import org.eclipse.emf.eef.extended.editor.providers.EditorMessages; |
| 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.context.impl.EObjectPropertiesEditionContext; |
| import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent; |
| import org.eclipse.emf.eef.runtime.part.impl.SectionPropertiesEditingPart; |
| import org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy; |
| import org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider; |
| 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.utils.EditingUtils; |
| import org.eclipse.emf.eef.runtime.ui.widgets.FormUtils; |
| import org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable; |
| import org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable.ReferencesTableListener; |
| import org.eclipse.emf.eef.runtime.ui.widgets.TabElementTreeSelectionDialog; |
| import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableContentProvider; |
| import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.jface.viewers.ViewerFilter; |
| 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.Composite; |
| 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; |
| import org.eclipse.ui.views.properties.tabbed.ISection; |
| |
| |
| // End of user code |
| |
| /** |
| * @author <a href="mailto:goulwen.lefur@obeo.fr">Goulwen LeFur</a> |
| * |
| */ |
| public class StaticEEFEditorContributionPropertiesEditionPartForm extends SectionPropertiesEditingPart implements IFormPropertiesEditionPart, StaticEEFEditorContributionPropertiesEditionPart { |
| |
| protected Text name; |
| protected ReferencesTable views; |
| protected List<ViewerFilter> viewsBusinessFilters = new ArrayList<ViewerFilter>(); |
| protected List<ViewerFilter> viewsFilters = new ArrayList<ViewerFilter>(); |
| |
| |
| |
| /** |
| * For {@link ISection} use only. |
| */ |
| public StaticEEFEditorContributionPropertiesEditionPartForm() { super(); } |
| |
| /** |
| * Default constructor |
| * @param editionComponent the {@link IPropertiesEditionComponent} that manage this part |
| * |
| */ |
| public StaticEEFEditorContributionPropertiesEditionPartForm(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 staticEEFEditorContributionStep = new BindingCompositionSequence(propertiesEditionComponent); |
| staticEEFEditorContributionStep |
| .addStep(EditorViewsRepository.StaticEEFEditorContribution.Naming.class) |
| .addStep(EditorViewsRepository.StaticEEFEditorContribution.Naming.name); |
| |
| staticEEFEditorContributionStep |
| .addStep(EditorViewsRepository.StaticEEFEditorContribution.Binding.class) |
| .addStep(EditorViewsRepository.StaticEEFEditorContribution.Binding.views); |
| |
| |
| composer = new PartComposer(staticEEFEditorContributionStep) { |
| |
| @Override |
| public Composite addToPart(Composite parent, Object key) { |
| if (key == EditorViewsRepository.StaticEEFEditorContribution.Naming.class) { |
| return createNamingGroup(widgetFactory, parent); |
| } |
| if (key == EditorViewsRepository.StaticEEFEditorContribution.Naming.name) { |
| return createNameText(widgetFactory, parent); |
| } |
| if (key == EditorViewsRepository.StaticEEFEditorContribution.Binding.class) { |
| return createBindingGroup(widgetFactory, parent); |
| } |
| if (key == EditorViewsRepository.StaticEEFEditorContribution.Binding.views) { |
| return createViewsReferencesTable(widgetFactory, parent); |
| } |
| return parent; |
| } |
| }; |
| composer.compose(view); |
| } |
| /** |
| * |
| */ |
| protected Composite createNamingGroup(FormToolkit widgetFactory, final Composite parent) { |
| Section namingSection = widgetFactory.createSection(parent, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED); |
| namingSection.setText(EditorMessages.StaticEEFEditorContributionPropertiesEditionPart_NamingGroupLabel); |
| GridData namingSectionData = new GridData(GridData.FILL_HORIZONTAL); |
| namingSectionData.horizontalSpan = 3; |
| namingSection.setLayoutData(namingSectionData); |
| Composite namingGroup = widgetFactory.createComposite(namingSection); |
| GridLayout namingGroupLayout = new GridLayout(); |
| namingGroupLayout.numColumns = 3; |
| namingGroup.setLayout(namingGroupLayout); |
| namingSection.setClient(namingGroup); |
| return namingGroup; |
| } |
| |
| |
| protected Composite createNameText(FormToolkit widgetFactory, Composite parent) { |
| createDescription(parent, EditorViewsRepository.StaticEEFEditorContribution.Naming.name, EditorMessages.StaticEEFEditorContributionPropertiesEditionPart_NameLabel); |
| name = widgetFactory.createText(parent, ""); //$NON-NLS-1$ |
| name.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); |
| widgetFactory.paintBordersFor(parent); |
| GridData nameData = new GridData(GridData.FILL_HORIZONTAL); |
| name.setLayoutData(nameData); |
| name.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( |
| StaticEEFEditorContributionPropertiesEditionPartForm.this, |
| EditorViewsRepository.StaticEEFEditorContribution.Naming.name, |
| PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText())); |
| propertiesEditionComponent |
| .firePropertiesChanged(new PropertiesEditionEvent( |
| StaticEEFEditorContributionPropertiesEditionPartForm.this, |
| EditorViewsRepository.StaticEEFEditorContribution.Naming.name, |
| PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_LOST, |
| null, name.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( |
| StaticEEFEditorContributionPropertiesEditionPartForm.this, |
| null, |
| PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_GAINED, |
| null, null)); |
| } |
| } |
| }); |
| name.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(StaticEEFEditorContributionPropertiesEditionPartForm.this, EditorViewsRepository.StaticEEFEditorContribution.Naming.name, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText())); |
| } |
| } |
| }); |
| EditingUtils.setID(name, EditorViewsRepository.StaticEEFEditorContribution.Naming.name); |
| EditingUtils.setEEFtype(name, "eef::Text"); //$NON-NLS-1$ |
| FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(EditorViewsRepository.StaticEEFEditorContribution.Naming.name, EditorViewsRepository.FORM_KIND), null); //$NON-NLS-1$ |
| return parent; |
| } |
| |
| /** |
| * |
| */ |
| protected Composite createBindingGroup(FormToolkit widgetFactory, final Composite parent) { |
| Section bindingSection = widgetFactory.createSection(parent, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED); |
| bindingSection.setText(EditorMessages.StaticEEFEditorContributionPropertiesEditionPart_BindingGroupLabel); |
| GridData bindingSectionData = new GridData(GridData.FILL_HORIZONTAL); |
| bindingSectionData.horizontalSpan = 3; |
| bindingSection.setLayoutData(bindingSectionData); |
| Composite bindingGroup = widgetFactory.createComposite(bindingSection); |
| GridLayout bindingGroupLayout = new GridLayout(); |
| bindingGroupLayout.numColumns = 3; |
| bindingGroup.setLayout(bindingGroupLayout); |
| bindingSection.setClient(bindingGroup); |
| return bindingGroup; |
| } |
| |
| /** |
| * |
| */ |
| protected Composite createViewsReferencesTable(FormToolkit widgetFactory, Composite parent) { |
| this.views = new ReferencesTable(getDescription(EditorViewsRepository.StaticEEFEditorContribution.Binding.views, EditorMessages.StaticEEFEditorContributionPropertiesEditionPart_ViewsLabel), new ReferencesTableListener () { |
| public void handleAdd() { addViews(); } |
| public void handleEdit(EObject element) { editViews(element); } |
| public void handleMove(EObject element, int oldIndex, int newIndex) { moveViews(element, oldIndex, newIndex); } |
| public void handleRemove(EObject element) { removeFromViews(element); } |
| public void navigateTo(EObject element) { } |
| }); |
| this.views.setHelpText(propertiesEditionComponent.getHelpContent(EditorViewsRepository.StaticEEFEditorContribution.Binding.views, EditorViewsRepository.FORM_KIND)); |
| this.views.createControls(parent, widgetFactory); |
| this.views.addSelectionListener(new SelectionAdapter() { |
| |
| public void widgetSelected(SelectionEvent e) { |
| if (e.item != null && e.item.getData() instanceof EObject) { |
| propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(StaticEEFEditorContributionPropertiesEditionPartForm.this, EditorViewsRepository.StaticEEFEditorContribution.Binding.views, PropertiesEditionEvent.CHANGE, PropertiesEditionEvent.SELECTION_CHANGED, null, e.item.getData())); |
| } |
| } |
| |
| }); |
| GridData viewsData = new GridData(GridData.FILL_HORIZONTAL); |
| viewsData.horizontalSpan = 3; |
| this.views.setLayoutData(viewsData); |
| this.views.disableMove(); |
| views.setID(EditorViewsRepository.StaticEEFEditorContribution.Binding.views); |
| views.setEEFType("eef::AdvancedReferencesTable"); //$NON-NLS-1$ |
| return parent; |
| } |
| |
| /** |
| * |
| */ |
| protected void addViews() { |
| TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(views.getInput(), viewsFilters, viewsBusinessFilters, |
| "views", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) { |
| @Override |
| public void process(IStructuredSelection selection) { |
| for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { |
| EObject elem = (EObject) iter.next(); |
| propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(StaticEEFEditorContributionPropertiesEditionPartForm.this, EditorViewsRepository.StaticEEFEditorContribution.Binding.views, |
| PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem)); |
| } |
| views.refresh(); |
| } |
| }; |
| dialog.open(); |
| } |
| |
| /** |
| * |
| */ |
| protected void moveViews(EObject element, int oldIndex, int newIndex) { |
| propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(StaticEEFEditorContributionPropertiesEditionPartForm.this, EditorViewsRepository.StaticEEFEditorContribution.Binding.views, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.MOVE, element, newIndex)); |
| views.refresh(); |
| } |
| |
| /** |
| * |
| */ |
| protected void removeFromViews(EObject element) { |
| propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(StaticEEFEditorContributionPropertiesEditionPartForm.this, EditorViewsRepository.StaticEEFEditorContribution.Binding.views, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.REMOVE, null, element)); |
| views.refresh(); |
| } |
| |
| /** |
| * |
| */ |
| protected void editViews(EObject element) { |
| EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(propertiesEditionComponent.getEditingContext(), propertiesEditionComponent, element, adapterFactory); |
| PropertiesEditingProvider provider = (PropertiesEditingProvider)adapterFactory.adapt(element, PropertiesEditingProvider.class); |
| if (provider != null) { |
| PropertiesEditingPolicy policy = provider.getPolicy(context); |
| if (policy != null) { |
| policy.execute(); |
| views.refresh(); |
| } |
| } |
| } |
| |
| |
| /** |
| * {@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.eef.extended.editor.parts.StaticEEFEditorContributionPropertiesEditionPart#getName() |
| * |
| */ |
| public String getName() { |
| return name.getText(); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.eef.extended.editor.parts.StaticEEFEditorContributionPropertiesEditionPart#setName(String newValue) |
| * |
| */ |
| public void setName(String newValue) { |
| if (newValue != null) { |
| name.setText(newValue); |
| } else { |
| name.setText(""); //$NON-NLS-1$ |
| } |
| } |
| |
| |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.eef.extended.editor.parts.StaticEEFEditorContributionPropertiesEditionPart#initViews(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) |
| */ |
| public void initViews(ReferencesTableSettings settings) { |
| if (current.eResource() != null && current.eResource().getResourceSet() != null) |
| this.resourceSet = current.eResource().getResourceSet(); |
| ReferencesTableContentProvider contentProvider = new ReferencesTableContentProvider(); |
| views.setContentProvider(contentProvider); |
| views.setInput(settings); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.eef.extended.editor.parts.StaticEEFEditorContributionPropertiesEditionPart#updateViews() |
| * |
| */ |
| public void updateViews() { |
| views.refresh(); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.eef.extended.editor.parts.StaticEEFEditorContributionPropertiesEditionPart#addFilterViews(ViewerFilter filter) |
| * |
| */ |
| public void addFilterToViews(ViewerFilter filter) { |
| viewsFilters.add(filter); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.eef.extended.editor.parts.StaticEEFEditorContributionPropertiesEditionPart#addBusinessFilterViews(ViewerFilter filter) |
| * |
| */ |
| public void addBusinessFilterToViews(ViewerFilter filter) { |
| viewsBusinessFilters.add(filter); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.eef.extended.editor.parts.StaticEEFEditorContributionPropertiesEditionPart#isContainedInViewsTable(EObject element) |
| * |
| */ |
| public boolean isContainedInViewsTable(EObject element) { |
| return ((ReferencesTableSettings)views.getInput()).contains(element); |
| } |
| |
| |
| |
| |
| |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.eef.runtime.api.parts.IPropertiesEditionPart#getTitle() |
| * |
| */ |
| public String getTitle() { |
| return EditorMessages.StaticEEFEditorContribution_Part_Title; |
| } |
| |
| // Start of user code additional methods |
| |
| // End of user code |
| |
| |
| } |