Java 类org.eclipse.xtext.ui.editor.outline.impl.EObjectNode 实例源码

项目:n4js    文件:MetaTypeAwareComparator.java   
private int getCategory(IOutlineNode node) {
    if (node instanceof EObjectNode) {
        EClass eclass = ((EObjectNode) node).getEClass();
        int id = eclass.getClassifierID();
        int key = 10000 + id;
        Integer sortKey = METATYPESORTORDER.get(id);
        if (sortKey != null) {
            key = sortKey * 1000;
        }
        if (node instanceof N4JSEObjectNode) {
            N4JSEObjectNode n4node = (N4JSEObjectNode) node;
            if (!n4node.isStatic) {
                key += 100;
            }
            if (n4node.isConstructor) {
                key -= 50;
            }
        }
        return key;
    }
    return -1;
}
项目:dsl-devkit    文件:XtextElementSelectionListener.java   
/**
 * Gets the EClass of the semantic element currently selected.
 *
 * @return EClass or null
 */
public EClass getSelectedElementType() {
  if (selection instanceof IStructuredSelection) {
    if (((IStructuredSelection) selection).getFirstElement() instanceof EObject) {
      // structured selection, e.g. GMFEditor
      EObject eObject = (EObject) ((IStructuredSelection) selection).getFirstElement();
      if (eObject.eResource() != null) {
        return eObject.eClass();
      }
    } else if (((IStructuredSelection) selection).getFirstElement() instanceof EObjectNode) {
      // selection in outline
      return ((EObjectNode) ((IStructuredSelection) selection).getFirstElement()).getEClass();
    }
  } else {
    ILeafNode node = nodeAtTextSelection();
    EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
    if (semanticObject != null) {
      return semanticObject.eClass();
    }
  }
  return null;
}
项目:dsl-devkit    文件:XtextElementSelectionListener.java   
/**
 * Gets the URI of the semantic element currently selected.
 *
 * @return URI or null
 */
public URI getSelectedElementUri() {
  if (selection instanceof IStructuredSelection) {
    if (((IStructuredSelection) selection).getFirstElement() instanceof InternalEObject) {
      // structured selection, e.g. GMFEditor
      return EcoreUtil.getURI((EObject) ((IStructuredSelection) selection).getFirstElement());
    } else if (((IStructuredSelection) selection).getFirstElement() instanceof EObjectNode) {
      // selection in outline
      return ((EObjectNode) ((IStructuredSelection) selection).getFirstElement()).getEObjectURI();
    }
  } else {
    ILeafNode node = nodeAtTextSelection();
    EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
    if (semanticObject != null) {
      return EcoreUtil.getURI(semanticObject);
    }
  }
  return null;
}
项目:dsl-devkit    文件:AbstractOutlineTest.java   
/**
 * Add the given outline node to the outline map.
 *
 * @param node
 *          IOutlineNode to add.
 */
private void addToOutlineMap(final IOutlineNode node) {
  EStructuralFeature eFeature = null;
  if (node instanceof EObjectNode) {
    eFeature = ((EObjectNode) node).getEObject(getTestSource().getXtextResource()).eContainingFeature();
    // TODO : remove the following part once all tests have been refactored
    Class<?> nodeClazz = ((EObjectNode) node).getEClass().getInstanceClass();
    if (!getOutlineMap().containsKey(nodeClazz)) {
      getOutlineMap().put(nodeClazz, new ArrayList<IOutlineNode>());
    }
    getOutlineMap().get(nodeClazz).add(node);
  } else if (node instanceof EStructuralFeatureNode) {
    eFeature = ((EStructuralFeatureNode) node).getEStructuralFeature();
  }
  if (eFeature == null) {
    return;
  }
  if (!getOutlineMap().containsKey(eFeature)) {
    getOutlineMap().put(eFeature, new ArrayList<IOutlineNode>());
  }
  getOutlineMap().get(eFeature).add(node);
}
项目:dsl-devkit    文件:CheckOutlineTreeProvider.java   
@Override
protected void internalCreateChildren(final DocumentRootNode parentNode, final EObject modelElement) {
  CheckCatalog catalog = (CheckCatalog) modelElement;
  if (catalog.getPackageName() != null) {
    getOutlineNodeFactory().createEStructuralFeatureNode(parentNode, catalog, CheckPackage.Literals.CHECK_CATALOG__PACKAGE_NAME, ImageDescriptor.createFromImage(checkImages.forPackage()), catalog.getPackageName(), true);
  }

  if (catalog.getImports() != null && !catalog.getImports().getImportDeclarations().isEmpty()) {
    EStructuralFeatureNode importNode = getOutlineNodeFactory().createEStructuralFeatureNode(parentNode, catalog, CheckPackage.Literals.CHECK_CATALOG__IMPORTS, ImageDescriptor.createFromImage(checkImages.forImportContainer()), "Import declarations", false);
    for (final org.eclipse.xtext.xtype.XImportDeclaration imported : catalog.getImports().getImportDeclarations()) {
      createNode(importNode, imported);
    }
  }

  EObjectNode catalogNode = createNode(parentNode, catalog);

  for (final Category category : catalog.getCategories()) {
    createNode(catalogNode, category);
  }
  for (final Check check : catalog.getChecks()) {
    createNode(catalogNode, check);
  }

}
项目:smaccm    文件:AadlHandler.java   
@Override
public Object execute(ExecutionEvent event) {
    EObjectNode node = getEObjectNode(HandlerUtil.getCurrentSelection(event));
    this.executionEvent = event;
    if (node == null) {
        return null;
    }
    final URI uri = node.getEObjectURI();

    window = HandlerUtil.getActiveWorkbenchWindow(event);
    if (window == null) {
        return null;
    }

    return executeURI(uri);
}
项目:smaccm    文件:AadlHandler.java   
private URI getSelectionURI(ISelection currentSelection) {
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection iss = (IStructuredSelection) currentSelection;
        if (iss.size() == 1) {
            EObjectNode node = (EObjectNode) iss.getFirstElement();
            return node.getEObjectURI();
        }
    } else if (currentSelection instanceof TextSelection) {
        // Selection may be stale, get latest from editor
        XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor();
        TextSelection ts = (TextSelection) xtextEditor.getSelectionProvider().getSelection();
        return xtextEditor.getDocument().readOnly(resource -> {
            EObject e = new EObjectAtOffsetHelper().resolveContainedElementAt(resource, ts.getOffset());
            return EcoreUtil2.getURI(e);
        });
    }
    return null;
}
项目:smaccm    文件:AadlHandler.java   
@Override
public Object execute(ExecutionEvent event) {
    EObjectNode node = getEObjectNode(HandlerUtil.getCurrentSelection(event));
    if (node == null) {
        return null;
    }
    final URI uri = node.getEObjectURI();

    window = HandlerUtil.getActiveWorkbenchWindow(event);
    if (window == null) {
        return null;
    }

    return executeURI(uri);
}
项目:smaccm    文件:AadlHandler.java   
private EObjectNode getEObjectNode(ISelection currentSelection) {
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection iss = (IStructuredSelection) currentSelection;
        if (iss.size() == 1) {
            return (EObjectNode) iss.getFirstElement();
        }
    }
    return null;
}
项目:smaccm    文件:AadlHandler.java   
@Override
public Object execute(ExecutionEvent event) {
    EObjectNode node = getEObjectNode(HandlerUtil.getCurrentSelection(event));
    if (node == null) {
        return null;
    }
    final URI uri = node.getEObjectURI();

    window = HandlerUtil.getActiveWorkbenchWindow(event);
    if (window == null) {
        return null;
    }

    return executeURI(uri);
}
项目:smaccm    文件:AadlHandler.java   
private EObjectNode getEObjectNode(ISelection currentSelection) {
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection iss = (IStructuredSelection) currentSelection;
        if (iss.size() == 1) {
            return (EObjectNode) iss.getFirstElement();
        }
    }
    return null;
}
项目:smaccm    文件:AadlHandler.java   
private EObjectNode getEObjectNode(ISelection currentSelection) {
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection iss = (IStructuredSelection) currentSelection;
        if (iss.size() == 1) {
            return (EObjectNode) iss.getFirstElement();
        }
    }
    return null;
}
项目:smaccm    文件:AadlHandler.java   
@Override
public Object execute(ExecutionEvent event) {
    EObjectNode node = getEObjectNode(HandlerUtil.getCurrentSelection(event));
    if (node == null) {
        return null;
    }
    final URI uri = node.getEObjectURI();

    window = HandlerUtil.getActiveWorkbenchWindow(event);
    if (window == null) {
        return null;
    }

    return executeURI(uri);
}
项目:smaccm    文件:AadlHandler.java   
private EObjectNode getEObjectNode(ISelection currentSelection) {
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection iss = (IStructuredSelection) currentSelection;
        if (iss.size() == 1) {
            return (EObjectNode) iss.getFirstElement();
        }
    }
    return null;
}
项目:smaccm    文件:SimulationLaunchShortcut.java   
private ComponentImplementation getComponentImplementation(final ISelection selection) {
    ComponentImplementation componentImplementation = null;

    // Determine a component implementation based on the current selection
    if(selection instanceof IStructuredSelection) {
        final Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
        if(selectedObject instanceof IFile) {
            final IFile iFile = (IFile)selectedObject;
            final ResourceSet resourceSet = new ResourceSetImpl();
            final Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(iFile.getFullPath().toString(), true), true);
            if(resource != null) {
                if(resource.getContents().size() > 0) {
                    final SystemInstance systemInstance = (SystemInstance)resource.getContents().get(0);
                    componentImplementation = systemInstance.getComponentImplementation();
                }
            }
        } else if(selectedObject instanceof EObjectNode) {
            final EObject selectedEObject = selectionHelper.getEObject((EObjectNode)selectedObject);
            if(selectedEObject instanceof ComponentImplementation) {
                componentImplementation = (ComponentImplementation)selectedEObject;
            }
        } else if(graphicalEditorSelectionHelper.isApplicable(selectedObject)) {
            componentImplementation = graphicalEditorSelectionHelper.getComponentImplementationByApplicableObject(selectedObject);
        }           
    }

    return componentImplementation;
}
项目:smaccm    文件:XtextSelectionHelper.java   
public EObject getEObject(final EObjectNode node) {
    Objects.requireNonNull(node, "node must not be null");
    return node.getDocument().readOnly(new IUnitOfWork<EObject, XtextResource>() {
        @Override
        public EObject exec(final XtextResource res) throws Exception {
            return res == null ? null : node.getEObject(res);
        }                   
    });
}
项目:smaccm    文件:SimulationPropertyTester.java   
@Override
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
    if(property.equals(canStartProperty)) {
        if(simulationUiService.isUserInterfaceLocked()) {
            return false;
        }

        if(receiver instanceof IFile) {
            final IFile file = (IFile)receiver;
            return file.getName().toLowerCase().endsWith(".aaxl2");
        } else if(receiver instanceof EObjectNode) {
            final Aadl2Package p = Aadl2Factory.eINSTANCE.getAadl2Package();
            final EClass eClass = ((EObjectNode) receiver).getEClass();
            return p.getComponentImplementation().isSuperTypeOf(eClass);       
        } else if(graphicalEditorSelectionHelper.isApplicable(receiver)) {
            return graphicalEditorSelectionHelper.getComponentImplementationByApplicableObject(receiver) != null;
        }           
    }  else if(property.equals(canStepForwardProperty)) {
        return simulationUiService.canStepForward();
    } else if(property.equals(canStepBackwardProperty)) {
        return simulationUiService.canStepBackward();
    } else if(property.equals(isRunning)) {
        return simulationUiService.getCurrentState().getSimulationEngine() != null;
    }

    return false;
}
项目:dsl-devkit    文件:AbstractOutlineTreeProvider.java   
/**
 * {@inheritDoc}
 */
@Override
protected EObjectNode createNode(final IOutlineNode parent, final EObject modelElement) {
  return createNodeDispatcher.invoke(parent, modelElement);
}
项目:smaccm    文件:XtextSelectionHelper.java   
private static EObject getEObjectFromSelection(final XtextEditor editor, final ISelection selection) {
    assert(editor != null);
    assert(selection != null);

    return editor.getDocument().readOnly(
        new IUnitOfWork<EObject, XtextResource>() {
            public EObject exec(XtextResource resource)
                    throws Exception {
                EObject targetElement = null;
                if (selection instanceof IStructuredSelection) {
                    IStructuredSelection ss = (IStructuredSelection) selection;
                    Object eon = ss.getFirstElement();
                    if (eon instanceof EObjectNode) {
                        targetElement = ((EObjectNode) eon)
                                .getEObject(resource);
                    }
                } else {
                    final int offset = ((ITextSelection) selection).getOffset();
                    targetElement = eObjectAtOffsetHelper.resolveContainedElementAt(resource, offset);

                    // Check if the node for the semantic element that was retrieved by the offset helper starts after the line number of the node
                    // retrieved using the offset. If it is, return the container. This prevents returning a classifier when the select is actually in
                    // whitespace before the classifier.
                    final IParseResult parseResult = resource.getParseResult();
                    if(targetElement != null && parseResult != null) {
                        final ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
                        final INode targetElementNode = NodeModelUtils.getNode(targetElement);
                        if(leaf.getStartLine() < targetElementNode.getStartLine()) {
                            targetElement = targetElement.eContainer();
                        }
                    }

                    // If there isn't a selected element, that usually means the selection is outside of the root package. Get the first EObject in the resource
                    if(targetElement == null && resource.getContents().size() > 0) {
                        targetElement = resource.getContents().get(0);  
                    }
                }

                return targetElement;
            }
        });
}