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;
}
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;
}
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);
}
}
}
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);
}
}
}
}
}
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;
}
Aggregations