| /** |
| * <copyright> |
| * |
| * Copyright (c) 2009-2010 Thales Corporate Services S.A.S. |
| * This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-v2.0.
|
| *
|
| * SPDX-License-Identifier: EPL-2.0
|
| * |
| * Contributors: |
| * Thales Corporate Services S.A.S - initial API and implementation |
| * |
| * </copyright> |
| */ |
| |
| package org.eclipse.egf.pattern.ui.contributions; |
| |
| import org.eclipse.egf.core.ui.contributor.DefaultPropertyEditorContributor; |
| import org.eclipse.egf.model.pattern.Pattern; |
| import org.eclipse.egf.model.pattern.PatternPackage; |
| import org.eclipse.egf.model.pattern.Substitution; |
| import org.eclipse.egf.pattern.ui.Messages; |
| import org.eclipse.egf.pattern.ui.editors.dialogs.PatternSelectionDialog; |
| import org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEditor; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
| import org.eclipse.jface.viewers.CellEditor; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Control; |
| |
| /** |
| * @author Thomas Guiu |
| * |
| */ |
| public class PatternSubstitutionOutgoingPropertyEditorContributor extends DefaultPropertyEditorContributor { |
| |
| public boolean canApply(Object object, IItemPropertyDescriptor descriptor) { |
| return checkFeature(object, descriptor, PatternPackage.Literals.SUBSTITUTION__REPLACED_ELEMENT) && object instanceof Substitution; |
| } |
| |
| public CellEditor createPropertyEditor(final Composite composite, final Object object, IItemPropertyDescriptor descriptor) { |
| return new ExtendedDialogCellEditor(composite, getLabelProvider(object, descriptor)) { |
| |
| @Override |
| protected Object openDialogBox(Control cellEditorWindow) { |
| PatternSelectionDialog dialog = new PatternSelectionDialog(cellEditorWindow.getShell(), false); |
| dialog.setTitle(Messages.SpecificationPage_browse_dialog_title); |
| dialog.open(); |
| Object[] result = dialog.getResult(); |
| // Solve the result against our current resourceSet |
| if (result != null && result.length > 0 && result[0] instanceof Pattern) { |
| return ((EObject) object).eResource().getResourceSet().getEObject(EcoreUtil.getURI((EObject) result[0]), true); |
| } |
| return null; |
| } |
| }; |
| } |
| |
| } |