Java Code Examples for org.eclipse.emf.common.util.EList#indexOf()
The following examples show how to use
org.eclipse.emf.common.util.EList#indexOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeadCodeAnalyser.java From n4js with Eclipse Public License 1.0 | 6 votes |
private ControlFlowElement findPrecedingStatement(ControlFlowElement cfe) { ControlFlowElement precedingStatement = null; Statement stmt = EcoreUtil2.getContainerOfType(cfe, Statement.class); if (stmt != null) { EObject stmtContainer = stmt.eContainer(); if (stmtContainer != null && stmtContainer instanceof Block) { Block block = (Block) stmtContainer; EList<Statement> stmts = block.getStatements(); int index = stmts.indexOf(stmt); if (index > 0) { precedingStatement = stmts.get(index - 1); } } } return precedingStatement; }
Example 2
Source File: OrderElementControl.java From statecharts with Eclipse Public License 1.0 | 6 votes |
public void selectionChanged(SelectionChangedEvent event) { EList<EObject> listInput = getListInput(); int indexOf = listInput.indexOf(getSelectedObject()); if (indexOf == -1 || listInput.size() <= 1) { btnUp.setEnabled(false); btnDown.setEnabled(false); } else if (indexOf == 0) { btnUp.setEnabled(false); btnDown.setEnabled(true); } else if (indexOf == listInput.size() - 1) { btnUp.setEnabled(true); btnDown.setEnabled(false); } else { btnUp.setEnabled(true); btnDown.setEnabled(true); } }
Example 3
Source File: AxesRenderer.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Gets current internal primary orthogonal OneAxis * * @return internal OneAxis */ protected final OneAxis getInternalOrthogonalAxis( ) { final AllAxes allAxes = ( (PlotWithAxes) getComputations( ) ).getAxes( ); if ( allAxes.getOverlayCount( ) == 0 ) { return allAxes.getPrimaryOrthogonal( ); } EList<Axis> axesList = ( (Axis) getAxis( ).eContainer( ) ).getAssociatedAxes( ); int index = axesList.indexOf( getAxis( ) ); if ( index == 0 ) { return allAxes.getPrimaryOrthogonal( ); } return allAxes.getOverlay( index - 1 ); }
Example 4
Source File: LegendImpl.java From birt with Eclipse Public License 1.0 | 6 votes |
public final void updateLayout( Chart cm ) { final Legend lg = this; final Plot pl = cm.getPlot( ); final EList<Block> el = pl.getChildren( ); final Position p = lg.getPosition( ); final boolean bLegendInsidePlot = p.getValue( ) == Position.INSIDE; final boolean bPlotContainsLegend = el.indexOf( lg ) >= 0; // IF PLOT DOESNT CONTAIN LEGEND AND LEGEND IS SUPPOSED TO BE INSIDE if ( !bPlotContainsLegend && bLegendInsidePlot ) { el.add( lg ); // ADD LEGEND TO PLOT } else if ( bPlotContainsLegend && !bLegendInsidePlot ) { cm.getBlock( ).getChildren( ).add( lg ); // ADD LEGEND TO BLOCK } else { // PLOT/LEGEND RELATIONSHIP IS FINE; DON'T DO ANYTHING } }
Example 5
Source File: ExtractMethodRefactoring.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected boolean isEndOfOriginalMethod() { EObject eContainer = lastExpression.eContainer(); if(eContainer instanceof XBlockExpression) { if(eContainer.eContainer() == originalMethod) { EList<XExpression> siblings = ((XBlockExpression)eContainer).getExpressions(); return siblings.indexOf(lastExpression) == siblings.size()-1; } } return false; }
Example 6
Source File: CrossReferenceSerializer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.11 */ protected EObject handleProxy(EObject proxy, EObject semanticObject, EReference reference) { if (reference != null && reference.isResolveProxies()) { if (reference.isMany()) { @SuppressWarnings("unchecked") EList<? extends EObject> list = (EList<? extends EObject>) semanticObject.eGet(reference); int index = list.indexOf(proxy); if (index >= 0) return list.get(index); } else { return (EObject) semanticObject.eGet(reference, true); } } return EcoreUtil.resolve(proxy, semanticObject); }
Example 7
Source File: CheckJavaValidator.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Checks that if guards have been provided as part of a context's constraint, they appear in the * beginning of a block expression. * * @param context * the context for which the constraint is checked */ @SuppressWarnings("unchecked") @Check public void checkGuardsFirst(final Context context) { if (context.getContextVariable() == null || context.getConstraint() == null) { return; } List<XGuardExpression> guards = EcoreUtil2.eAllOfType(context.getConstraint(), XGuardExpression.class); if (Iterables.isEmpty(guards)) { return; // no guards makes check irrelevant } EList<XExpression> topLevelExpressions = (EList<XExpression>) ((XBlockExpression) context.getConstraint()).eGet(XbasePackage.Literals.XBLOCK_EXPRESSION__EXPRESSIONS); for (final XGuardExpression guard : guards) { final EStructuralFeature eContainingFeature = guard.eContainingFeature(); if (guard.eContainer() != null && eContainingFeature != null) { if (guard.eContainer().eGet(eContainingFeature) != topLevelExpressions) { // guards not allowed in nested expressions, must be on root level error(Messages.CheckJavaValidator_GUARDS_COME_FIRST, guard, null, IssueCodes.GUARDS_COME_FIRST); } else { // check that guards precede other expressions int pos = topLevelExpressions.indexOf(guard); if (pos > 0) { for (int i = 0; i < pos; i++) { if (!(topLevelExpressions.get(i) instanceof XGuardExpression)) { error(Messages.CheckJavaValidator_GUARDS_COME_FIRST, guard, null, IssueCodes.GUARDS_COME_FIRST); break; } } } } } } }
Example 8
Source File: ConnectorSection.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private void moveSelectedConnector(final int diff) { final EObject selectConnector = (EObject) ((IStructuredSelection) tableViewer .getSelection()).getFirstElement(); @SuppressWarnings("unchecked") final EList<Connector> connectors = (EList<Connector>) getEObject() .eGet(getConnectorFeature()); final int destIndex = connectors.indexOf(selectConnector) + diff; final Command c = new MoveCommand(getEditingDomain(), connectors, selectConnector, destIndex); getEditingDomain().getCommandStack().execute(c); refresh(); }
Example 9
Source File: TransitionOrderingPropertySection.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected void updateButtonsEnablement() { if(listViewer.getSelection().isEmpty()){ upButton.setEnabled(false); downButton.setEnabled(false); } else { final Object selectedConnection = ((IStructuredSelection) listViewer.getSelection()).getFirstElement(); final EList<Connection> outgoingConnections = getSourceElement().getOutgoing(); final int indexSelected = outgoingConnections.indexOf(selectedConnection); upButton.setEnabled(indexSelected != 0); downButton.setEnabled(indexSelected < outgoingConnections.size() -1); } }
Example 10
Source File: AbstractSelectorFragmentProvider.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
/** * Computes a segment of the fragment with a selector for the given object and appends it to the given {@link StringBuilder}. * * @param obj * object to compute fragment for * @param selectorFeature * selector feature * @param unique * {@code true} the values for selectorFeature are unique within the object's containment feature setting * @param builder * builder to append fragment segment to, must not be {@code null} * @return {@code true} if a fragment segment was appended to {@code builder} */ @SuppressWarnings("unchecked") protected boolean computeSelectorFragmentSegment(final EObject obj, final EStructuralFeature selectorFeature, final boolean unique, final StringBuilder builder) { final EObject container = obj.eContainer(); if (container == null) { return shortFragmentProvider.appendFragmentSegment(obj, builder); } // containment feature final EStructuralFeature containmentFeature = obj.eContainmentFeature(); builder.append(container.eClass().getFeatureID(containmentFeature)); // selector final Object selectorValue = obj.eGet(selectorFeature); builder.append(SELECTOR_START).append(obj.eClass().getFeatureID(selectorFeature)).append(EQ_OP); if (selectorValue != null) { builder.append(VALUE_SEP); appendEscaped(selectorValue.toString(), builder); builder.append(VALUE_SEP); } else { builder.append(NULL_VALUE); } if (unique) { builder.append(UNIQUE); } builder.append(SELECTOR_END); // selector index if (!unique && containmentFeature.isMany()) { builder.append(ShortFragmentProvider.LIST_SEPARATOR); final EList<? extends EObject> containmentList = (EList<? extends EObject>) container.eGet(containmentFeature); int selectorIndex = 0; final int objectIndex = containmentList.indexOf(obj); for (int i = 0; i < objectIndex; i++) { final Object value = containmentList.get(i).eGet(selectorFeature); if ((selectorValue == null && value == null) || (selectorValue != null && selectorValue.equals(value))) { selectorIndex++; } } builder.append(selectorIndex); } return true; }