Esempio n. 1
0
    @Override
    protected EObject doRun(CDOTransaction transaction, CDOObject parent, ISelection selection) {
      ComposedAdapterFactory adapterFactory = CDOEditor.createAdapterFactory(true);

      try {
        BasicCommandStack commandStack = new BasicCommandStack();
        ResourceSet resourceSet = transaction.getResourceSet();

        EditingDomain editingDomain =
            new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet);

        CreateChildAction delegate =
            new CreateChildAction(editingDomain, selection, childDescriptor);
        delegate.run();

        if (childDescriptor instanceof CommandParameter) {
          CommandParameter parameter = (CommandParameter) childDescriptor;
          Object value = parameter.getValue();
          if (value instanceof EObject) {
            return (EObject) value;
          }
        }

        return null;
      } finally {
        adapterFactory.dispose();
      }
    }
Esempio n. 2
0
  private void fillNewChildActions(IMenuManager menu, CDOCheckout checkout, EObject object) {
    ResourceSet resourceSet = checkout.getView().getResourceSet();

    ComposedAdapterFactory adapterFactory = getAdapterFactory(checkout);

    EditingDomain editingDomain =
        new AdapterFactoryEditingDomain(adapterFactory, new BasicCommandStack(), resourceSet);
    IStructuredSelection selection = new StructuredSelection(object);
    CDOObject cdoObject = CDOUtil.getCDOObject(object);

    Collection<?> childDescriptors = editingDomain.getNewChildDescriptors(object, null);
    for (Object childDescriptor : childDescriptors) {
      CreateChildAction delegate = new CreateChildAction(editingDomain, selection, childDescriptor);
      String text = delegate.getText();
      String toolTipText = delegate.getToolTipText();
      ImageDescriptor imageDescriptor = delegate.getImageDescriptor();

      NewChildAction action =
          new NewChildAction(
              text, toolTipText, imageDescriptor, checkout, cdoObject, childDescriptor);
      menu.add(action);
    }
  }
  @Override
  public void configureAction(ISelection selection) {
    if (!(selection instanceof IStructuredSelection)) {
      disable();
      return;
    } else {
      IStructuredSelection sSelection = (IStructuredSelection) selection;
      if (sSelection.size() > 0) disable();

      EObject eObject =
          (EObject) ((IAdaptable) sSelection.getFirstElement()).getAdapter(EObject.class);
      EProject eModelerProject = null;

      if (eObject instanceof ESQLObject)
        eModelerProject = (EProject) ((ESQLObject) eObject).getRootContainer();

      // Comprobamos que el elemento no sea externo
      if (eObject instanceof ESchema) {
        ESchema schema = (ESchema) eObject;
        if (eModelerProject != null
            && !(eModelerProject.getCapability().equals(schema.getCapability()))) {
          disable();
          return;
        }
      } else if (eObject instanceof ETable) {
        ETable table = (ETable) eObject;
        if (eModelerProject != null
            && !(eModelerProject.getCapability().equals(table.getSchema().getCapability()))) {
          disable();
          return;
        }
      }

      super.configureAction(new StructuredSelection(eObject));
    }
  }
 @Override
 public void run() {
   super.run();
 }