Search in sources :

Example 36 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project InformationSystem by ObeoNetwork.

the class TransitionPropertiesEditionPartImpl method createKeywordsMultiValuedEditor.

protected Composite createKeywordsMultiValuedEditor(Composite parent) {
    keywords = SWTUtils.createScrollableText(parent, SWT.BORDER | SWT.READ_ONLY);
    GridData keywordsData = new GridData(GridData.FILL_HORIZONTAL);
    keywordsData.horizontalSpan = 2;
    keywords.setLayoutData(keywordsData);
    EditingUtils.setID(keywords, StatemachineViewsRepository.Transition.Properties.keywords);
    // $NON-NLS-1$
    EditingUtils.setEEFtype(keywords, "eef::MultiValuedEditor::field");
    editKeywords = new Button(parent, SWT.NONE);
    editKeywords.setText(getDescription(StatemachineViewsRepository.Transition.Properties.keywords, StatemachineMessages.TransitionPropertiesEditionPart_KeywordsLabel));
    GridData editKeywordsData = new GridData();
    editKeywords.setLayoutData(editKeywordsData);
    editKeywords.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(// $NON-NLS-1$
            keywords.getShell(), // $NON-NLS-1$
            "Transition", // $NON-NLS-1$
            new AdapterFactoryLabelProvider(adapterFactory), keywordsList, EnvironmentPackage.eINSTANCE.getObeoDSMObject_Keywords().getEType(), null, false, true, null, null);
            if (dialog.open() == Window.OK) {
                keywordsList = dialog.getResult();
                if (keywordsList == null) {
                    keywordsList = new BasicEList();
                }
                keywords.setText(keywordsList.toString());
                propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(TransitionPropertiesEditionPartImpl.this, StatemachineViewsRepository.Transition.Properties.keywords, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, new BasicEList(keywordsList)));
                setHasChanged(true);
            }
        }
    });
    EditingUtils.setID(editKeywords, StatemachineViewsRepository.Transition.Properties.keywords);
    // $NON-NLS-1$
    EditingUtils.setEEFtype(editKeywords, "eef::MultiValuedEditor::browsebutton");
    // End of user code
    return parent;
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) BasicEList(org.eclipse.emf.common.util.BasicEList) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) IPropertiesEditionEvent(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent) PropertiesEditionEvent(org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent) EEFFeatureEditorDialog(org.eclipse.emf.eef.runtime.ui.widgets.EEFFeatureEditorDialog)

Example 37 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project InformationSystem by ObeoNetwork.

the class TypeInstancePropertiesEditionPartImpl method createLiteralsMultiValuedEditor.

protected Composite createLiteralsMultiValuedEditor(Composite parent) {
    literals = SWTUtils.createScrollableText(parent, SWT.BORDER | SWT.READ_ONLY);
    GridData literalsData = new GridData(GridData.FILL_HORIZONTAL);
    literalsData.horizontalSpan = 2;
    literals.setLayoutData(literalsData);
    EditingUtils.setID(literals, TypeslibraryViewsRepository.TypeInstance.Properties.literals);
    // $NON-NLS-1$
    EditingUtils.setEEFtype(literals, "eef::MultiValuedEditor::field");
    editLiterals = new Button(parent, SWT.NONE);
    editLiterals.setText(getDescription(TypeslibraryViewsRepository.TypeInstance.Properties.literals, TypeslibraryMessages.TypeInstancePropertiesEditionPart_LiteralsLabel));
    GridData editLiteralsData = new GridData();
    editLiterals.setLayoutData(editLiteralsData);
    editLiterals.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(// $NON-NLS-1$
            literals.getShell(), // $NON-NLS-1$
            "TypeInstance", // $NON-NLS-1$
            new AdapterFactoryLabelProvider(adapterFactory), literalsList, TypesLibraryPackage.eINSTANCE.getTypeInstance_Literals().getEType(), null, false, true, null, null);
            if (dialog.open() == Window.OK) {
                literalsList = dialog.getResult();
                if (literalsList == null) {
                    literalsList = new BasicEList();
                }
                literals.setText(literalsList.toString());
                propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(TypeInstancePropertiesEditionPartImpl.this, TypeslibraryViewsRepository.TypeInstance.Properties.literals, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, new BasicEList(literalsList)));
                setHasChanged(true);
            }
        }
    });
    EditingUtils.setID(editLiterals, TypeslibraryViewsRepository.TypeInstance.Properties.literals);
    // $NON-NLS-1$
    EditingUtils.setEEFtype(editLiterals, "eef::MultiValuedEditor::browsebutton");
    // End of user code
    return parent;
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) BasicEList(org.eclipse.emf.common.util.BasicEList) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) IPropertiesEditionEvent(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent) PropertiesEditionEvent(org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent) EEFFeatureEditorDialog(org.eclipse.emf.eef.runtime.ui.widgets.EEFFeatureEditorDialog)

Example 38 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project dsl-devkit by dsldevkit.

the class AbstractLabelingTest method buildLabelMap.

/**
 * Build a directory of node labels indexed by the {@link ENamedElement}.
 *
 * @param model
 *          the model for which to build the label map
 */
@SuppressWarnings("unchecked")
private void buildLabelMap(final EObject model) {
    // Allow testing root container level
    String rootLabel = getLabelProvider().getText(model);
    addToLabelMap(model.eClass().getInstanceClass(), rootLabel);
    // All contained features
    List<EStructuralFeature> features = model.eClass().getEAllStructuralFeatures();
    for (EStructuralFeature feature : features) {
        if (!model.eIsSet(feature)) {
            continue;
        }
        if (feature instanceof EReference) {
            EList<EObject> children = new BasicEList<EObject>();
            if (feature.isMany()) {
                children.addAll((EList<EObject>) model.eGet(feature));
            } else {
                children.add((EObject) model.eGet(feature, false));
            }
            boolean referenceAdded = false;
            for (EObject childModelElement : children) {
                if (!childModelElement.eIsProxy() && model.equals(childModelElement.eContainer())) {
                    // ignore crossreferenced objects
                    buildLabelMap(childModelElement);
                    // TODO : change to EClass once all tests are refactored
                    Object element = childModelElement.eClass().getInstanceClass();
                    String label = getLabelProvider().getText(childModelElement);
                    addToLabelMap(element, label);
                    // also add the label using the reference feature as key
                    if (!referenceAdded) {
                        addToLabelMap(feature, label);
                        referenceAdded = true;
                    }
                }
            }
        } else {
            // TODO : what to do with unbounded EAttribute? -> decide also in LabelProvider
            String label = getLabelProvider().getText(Tuples.create(model, feature));
            addToLabelMap(feature, label);
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) BasicEList(org.eclipse.emf.common.util.BasicEList) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference)

Example 39 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project dsl-devkit by dsldevkit.

the class AbstractOutlineTreeProvider method internalCreateChildren.

/**
 * Creates children for all {@link EStructuralFeatures} (that are set) of the given {@link EObject} model element. {@inheritDoc}
 *
 * @param parentNode
 *          the parent {@link IOutlineNode}
 * @param modelElement
 *          a valid {@link EObject}
 */
@SuppressWarnings({ "unchecked", "PMD.NPathComplexity" })
@Override
protected void internalCreateChildren(final IOutlineNode parentNode, final EObject modelElement) {
    // from all structural features, select only those which are set and retrieve the text location
    // TODO : sorting for feature lists needs to be based on the objects in the list, not the feature.
    List<Pair<Integer, EStructuralFeature>> pairsLocationFeature = Lists.newArrayList();
    for (EStructuralFeature structuralFeature : modelElement.eClass().getEAllStructuralFeatures()) {
        if (modelElement.eIsSet(structuralFeature)) {
            int offset = 0;
            List<INode> nodes = NodeModelUtils.findNodesForFeature(modelElement, structuralFeature);
            if (!nodes.isEmpty()) {
                offset = nodes.get(0).getTotalOffset();
            }
            pairsLocationFeature.add(Tuples.create(offset, structuralFeature));
        }
    }
    // sort the features according to their appearance in the source text
    Collections.sort(pairsLocationFeature, new Comparator<Pair<Integer, EStructuralFeature>>() {

        @Override
        public int compare(final Pair<Integer, EStructuralFeature> o1, final Pair<Integer, EStructuralFeature> o2) {
            return o1.getFirst() - o2.getFirst();
        }
    });
    // go through the sorted list of children and create nodes
    for (Pair<Integer, EStructuralFeature> pairLocationFeature : pairsLocationFeature) {
        EStructuralFeature feature = pairLocationFeature.getSecond();
        if (feature instanceof EAttribute) {
            if (getRelevantElements().contains(feature)) {
                createNodeDispatcher.invoke(parentNode, modelElement, feature);
            }
        } else if (feature instanceof EReference && ((EReference) feature).isContainment()) {
            // only consider containment references
            IOutlineNode listNode = null;
            EList<EObject> featureElements;
            Object value = modelElement.eGet(feature);
            if (feature.isMany()) {
                featureElements = (EList<EObject>) value;
                if (getRelevantElements().contains(feature)) {
                    listNode = createEStructuralFeatureNode(parentNode, modelElement, feature, getImageDescriptor(feature), feature.getName(), false);
                }
            } else {
                featureElements = new BasicEList<EObject>();
                featureElements.add((EObject) value);
            }
            for (EObject childElement : featureElements) {
                if (childElement == null) {
                    continue;
                }
                if (isRelevantElement(childElement)) {
                    createNodeDispatcher.invoke(listNode != null ? listNode : parentNode, childElement);
                } else {
                    createChildrenDispatcher.invoke(listNode != null ? listNode : parentNode, childElement);
                }
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) BasicEList(org.eclipse.emf.common.util.BasicEList) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EAttribute(org.eclipse.emf.ecore.EAttribute) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode) Pair(org.eclipse.xtext.util.Pair)

Example 40 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project dsl-devkit by dsldevkit.

the class EObjectContentProviderTest method mockSelectedElement.

/**
 * Mocks XtextEditor and XtextElementSelectionListener to return an element selection that has:
 * - given EAttribute with a specific value (AttributeValuePair)
 * - given EStructuralFeature
 * - given EOperation.
 *
 * @param attributeValuePair
 *          EAttribute with a specific value
 * @param feature
 *          the EStructuralFeature
 * @param operation
 *          the EOperation
 * @return the EClass of the "selected" element
 */
@SuppressWarnings("unchecked")
private EClass mockSelectedElement(final AttributeValuePair attributeValuePair, final EStructuralFeature feature, final EOperation operation) {
    EClass mockSelectionEClass = mock(EClass.class);
    when(mockSelectionListener.getSelectedElementType()).thenReturn(mockSelectionEClass);
    // Mockups for returning AttributeValuePair
    URI elementUri = URI.createURI("");
    when(mockSelectionListener.getSelectedElementUri()).thenReturn(elementUri);
    XtextEditor mockEditor = mock(XtextEditor.class);
    when(mockSelectionListener.getEditor()).thenReturn(mockEditor);
    IXtextDocument mockDocument = mock(IXtextDocument.class);
    when(mockEditor.getDocument()).thenReturn(mockDocument);
    when(mockDocument.<ArrayList<AttributeValuePair>>readOnly(any(IUnitOfWork.class))).thenReturn(newArrayList(attributeValuePair));
    // Mockups for returning EOperation
    BasicEList<EOperation> mockEOperationsList = new BasicEList<EOperation>();
    mockEOperationsList.add(operation);
    when(mockSelectionEClass.getEAllOperations()).thenReturn(mockEOperationsList);
    // Mockups for returning EStructuralFeature
    BasicEList<EStructuralFeature> mockEStructuralFeatureList = new BasicEList<EStructuralFeature>();
    mockEStructuralFeatureList.add(feature);
    mockEStructuralFeatureList.add(attributeValuePair.getAttribute());
    when(mockSelectionEClass.getEAllStructuralFeatures()).thenReturn(mockEStructuralFeatureList);
    return mockSelectionEClass;
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) EClass(org.eclipse.emf.ecore.EClass) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EOperation(org.eclipse.emf.ecore.EOperation) URI(org.eclipse.emf.common.util.URI) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Aggregations

BasicEList (org.eclipse.emf.common.util.BasicEList)82 Test (org.junit.Test)25 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)16 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)16 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)16 EEFFeatureEditorDialog (org.eclipse.emf.eef.runtime.ui.widgets.EEFFeatureEditorDialog)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)16 GridData (org.eclipse.swt.layout.GridData)16 EObject (org.eclipse.emf.ecore.EObject)13 TdExpression (org.talend.cwm.relational.TdExpression)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Button (org.eclipse.swt.widgets.Button)8 EList (org.eclipse.emf.common.util.EList)7 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)7 ProductVersion (org.talend.utils.ProductVersion)7 Property (org.eclipse.vorto.core.api.model.datatype.Property)6 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)6