Ejemplo 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();
      }
    }
 /** Default constructor. */
 public PageflowStructureViewerLabelProvider() {
   adapterProvider = new AdapterFactoryLabelProvider(AdapterUtils.getAdapterFactory());
   if (adapterProvider.getAdapterFactory() instanceof ComposedAdapterFactory) {
     ComposedAdapterFactory cFactory =
         (ComposedAdapterFactory) adapterProvider.getAdapterFactory();
     cFactory.insertAdapterFactory(new PageflowCompareItemProviderAdapterFactory());
   }
 }
  public void unregisterEditingDomain(AdapterFactoryEditingDomain domain) {
    AdapterFactory adapterFactory = domain.getAdapterFactory();
    if (adapterFactory instanceof ComposedAdapterFactory) {
      ComposedAdapterFactory composedAdapterFactory = (ComposedAdapterFactory) adapterFactory;
      composedAdapterFactory.removeListener(notifyChangedListener);
    }

    domain.getCommandStack().removeCommandStackListener(commandStackListener);
  }
Ejemplo n.º 4
0
  /**
   * This sets up the editing domain for the model editor.
   * <!-- begin-user-doc
   * -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  protected void initializeEditingDomain() {
    // Create an adapter factory that yields item providers.
    //
    adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);

    adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new RmapItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new CommonItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

    // Create the command stack that will notify this editor as commands are
    // executed.
    //
    BasicCommandStack commandStack = new BasicCommandStack();

    // Add a listener to set the most recent command's affected objects to
    // be the selection of the viewer with focus.
    //
    commandStack.addCommandStackListener(
        new CommandStackListener() {
          @Override
          public void commandStackChanged(final EventObject event) {
            getContainer()
                .getDisplay()
                .asyncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        firePropertyChange(IEditorPart.PROP_DIRTY);

                        // Try to select the affected objects.
                        //
                        Command mostRecentCommand =
                            ((CommandStack) event.getSource()).getMostRecentCommand();
                        if (mostRecentCommand != null) {
                          setSelectionToViewer(mostRecentCommand.getAffectedObjects());
                        }
                        if (propertySheetPage != null
                            && !propertySheetPage.getControl().isDisposed()) {
                          propertySheetPage.refresh();
                        }
                      }
                    });
          }
        });

    // Create the editing domain with a special command stack.
    //
    editingDomain =
        new AdapterFactoryEditingDomain(
            adapterFactory, commandStack, new HashMap<Resource, Boolean>());
  }
 protected Image getImage(EObject element) {
   if (!Platform.isRunning()) {
     return null;
   }
   ComposedAdapterFactory adapterFactory =
       new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
   adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
   adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
   adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
   AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
   return labelProvider.getImage(element);
 }
  /**
   * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  public void fireNotifyChanged(Notification notification) {
    changeNotifier.fireNotifyChanged(notification);

    if (parentAdapterFactory != null) {
      parentAdapterFactory.fireNotifyChanged(notification);
    }
  }
  /** @generated */
  protected ItemPropertyDescriptor createItemPropertyDescriptor(
      AdapterFactory adapterFactory,
      ResourceLocator resourceLocator,
      String displayName,
      String description,
      EStructuralFeature feature,
      boolean isSettable,
      boolean multiLine,
      boolean sortChoices,
      Object staticImage,
      String category,
      String[] filterFlags) {

    ComposedAdapterFactory composedAdapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);

    IItemPropertyDescriptorProvider descriptorProvider =
        (IItemPropertyDescriptorProvider)
            composedAdapterFactory.adapt(getTarget(), IItemPropertyDescriptorProvider.class);

    if (descriptorProvider != null)
      return descriptorProvider.createItemPropertyDescriptor(
          adapterFactory,
          resourceLocator,
          displayName,
          description,
          feature,
          isSettable,
          multiLine,
          sortChoices,
          staticImage,
          category,
          filterFlags);

    return super.createItemPropertyDescriptor(
        adapterFactory,
        resourceLocator,
        displayName,
        description,
        feature,
        isSettable,
        multiLine,
        sortChoices,
        staticImage,
        category,
        filterFlags);
  }
Ejemplo n.º 8
0
  protected void initializeEditingDomain() {
    adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);

    adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new SemanticmanagerItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

    BasicCommandStack commandStack = new BasicCommandStack();

    // Add a listener to set the most recent command's affected objects to be the selection of the
    // viewer with focus.
    //
    /*commandStack.addCommandStackListener
    (new CommandStackListener() {
    	 public void commandStackChanged(final EventObject event) {
    		 viewer.getDisplay().asyncExec
    			 (new Runnable() {
    				  public void run() {
    					  firePropertyChange(IEditorPart.PROP_DIRTY);

    					  // Try to select the affected objects.
    					  //
    					  Command mostRecentCommand = ((CommandStack)event.getSource()).getMostRecentCommand();
    					  if (mostRecentCommand != null) {
    						  setSelectionToViewer(mostRecentCommand.getAffectedObjects());
    					  }
    					  for (Iterator<PropertySheetPage> i = propertySheetPages.iterator(); i.hasNext(); ) {
    						  PropertySheetPage propertySheetPage = i.next();
    						  if (propertySheetPage.getControl().isDisposed()) {
    							  i.remove();
    						  }
    						  else {
    							  propertySheetPage.refresh();
    						  }
    					  }
    				  }
    			  });
    	 }
     });*/

    editingDomain =
        new AdapterFactoryEditingDomain(
            adapterFactory,
            commandStack,
            new HashMap<org.eclipse.emf.ecore.resource.Resource, Boolean>());
  }
  /**
   * Stops listening to change notifications sent from an adapter factory.
   *
   * @param adapterFactory an adapter factory
   */
  public void stopListeningTo(ComposedAdapterFactory adapterFactory) {
    if (debug) {
      DebugTrace.print(
          this, "stopListeningTo", "adapterFactory=" + adapterFactory); // $NON-NLS-1$ //$NON-NLS-2$
    }

    adapterFactory.removeListener(notifyChangedListener);
  }
 /** @generated */
 public ImageDescriptor getItemImageDescriptor(Object item) {
   IItemLabelProvider labelProvider =
       (IItemLabelProvider) adapterFactory.adapt(item, IItemLabelProvider.class);
   if (labelProvider != null) {
     return ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(item));
   }
   return null;
 }
 /** @generated */
 public void stop(BundleContext context) throws Exception {
   adapterFactory.dispose();
   adapterFactory = null;
   linkConstraints = null;
   initializers = null;
   instance = null;
   super.stop(context);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritDoc}
  *
  * @see org.eclipse.jface.dialogs.Dialog#close()
  */
 @Override
 public boolean close() {
   if (objectChangeAdapter != null) {
     selection.eAdapters().remove(objectChangeAdapter);
   }
   if (composedAdapterFactory != null) {
     composedAdapterFactory.dispose();
   }
   return super.close();
 }
 static {
   ComposedAdapterFactory caf = new ComposedAdapterFactory();
   caf.addAdapterFactory(new SQLSchemaItemProviderAdapterFactory());
   caf.addAdapterFactory(new SQLTablesItemProviderAdapterFactory());
   caf.addAdapterFactory(new SQLRoutinesItemProviderAdapterFactory());
   caf.addAdapterFactory(new SQLDataTypesItemProviderAdapterFactory());
   caf.addAdapterFactory(new SQLConstraintsItemProviderAdapterFactory());
   caf.addAdapterFactory(new SQLAccessControlItemProviderAdapterFactory());
   caf.addAdapterFactory(new SQLExpressionsItemProviderAdapterFactory());
   caf.addAdapterFactory(new SQLStatementsItemProviderAdapterFactory());
   sAdapterFactory = new AdapterFactoryContentProvider(caf);
 }
Ejemplo n.º 14
0
 @Override
 public void dispose() {
   currentViewer.removeSelectionChangedListener(propertiesViewUpdater);
   if (adapterFactory != null) {
     adapterFactory.dispose();
   }
   editingDomain = null;
   propertiesViewUpdater = null;
   selectionViewer = null;
   currentViewer = null;
   super.dispose();
 }
Ejemplo n.º 15
0
 public void createControl(org.eclipse.swt.widgets.Composite parent) {
   treeViewer =
       new west.twouse.language.owl2fs.resource.owl2fs.ui.Owl2fsOutlinePageTreeViewer(
           parent,
           org.eclipse.swt.SWT.MULTI
               | org.eclipse.swt.SWT.H_SCROLL
               | org.eclipse.swt.SWT.V_SCROLL);
   Object[] listeners = selectionChangedListeners.getListeners();
   for (int i = 0; i < listeners.length; ++i) {
     org.eclipse.jface.viewers.ISelectionChangedListener l =
         (org.eclipse.jface.viewers.ISelectionChangedListener) listeners[i];
     treeViewer.addSelectionChangedListener(l);
   }
   selectionChangedListeners.clear();
   org.eclipse.emf.edit.provider.ComposedAdapterFactory adapterFactory =
       new org.eclipse.emf.edit.provider.ComposedAdapterFactory(
           org.eclipse.emf.edit.provider.ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
   adapterFactory.addAdapterFactory(
       new org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory());
   adapterFactory.addAdapterFactory(
       new org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory());
   adapterFactory.addAdapterFactory(
       new org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory());
   org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider contentProvider =
       new org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider(adapterFactory);
   treeViewer.setAutoExpandLevel(3);
   treeViewer.setContentProvider(contentProvider);
   treeViewer.setLabelProvider(
       new org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider(adapterFactory));
   org.eclipse.emf.ecore.resource.ResourceSet resourceSet = editor.getResourceSet();
   org.eclipse.emf.common.util.EList<org.eclipse.emf.ecore.resource.Resource> resources =
       resourceSet.getResources();
   treeViewer.setInput(resources.get(0));
   if (!resources.isEmpty()) {
     // Select the root object in the view.
     treeViewer.setSelection(
         new org.eclipse.jface.viewers.StructuredSelection(resources.get(0)), true);
   }
 }
Ejemplo n.º 16
0
  public void initializeOfferedServicesDomain() {
    // Create an adapter factory that yields item providers.
    adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    AdapterFactory factory = (AdapterFactory) new FederationOfficeItemProviderAdapterFactory();
    adapterFactory.addAdapterFactory(factory);

    OfficeTaxonomiesContentProvider offProvider =
        new OfficeTaxonomiesContentProvider(getViewSite(), true, true, false);
    offProvider.AddOfficesFromManager(Activator.getDefault().getOfficeManager());
    viewer.setContentProvider(offProvider);
    viewer.expandToLevel(2);
  }
  /**
   * Registers an editing domain with the managed method library.
   *
   * @param domain an editing domain
   */
  public void registerEditingDomain(AdapterFactoryEditingDomain domain) {
    if (debug) {
      DebugTrace.print(
          this, "registerEditingDomain", "domain=" + domain); // $NON-NLS-1$ //$NON-NLS-2$
    }

    // Add a listener to monitor library changes made in the given editing
    // domain.
    AdapterFactory adapterFactory = domain.getAdapterFactory();
    if (adapterFactory instanceof ComposedAdapterFactory) {
      ComposedAdapterFactory composedAdapterFactory = (ComposedAdapterFactory) adapterFactory;
      // remove the listener before adding it to make sure that the same listener is not added more
      // than one
      composedAdapterFactory.removeListener(notifyChangedListener);
      composedAdapterFactory.addListener(notifyChangedListener);
    }

    // Add a listener to monitor changes made to the command stack.
    // This is used to select the most recently affected objects in the
    // viewer.
    domain.getCommandStack().removeCommandStackListener(commandStackListener);
    domain.getCommandStack().addCommandStackListener(commandStackListener);
  }
Ejemplo n.º 18
0
  /**
   *
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  public void dispose() {
    ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);

    getSite().getPage().removePartListener(partListener);

    adapterFactory.dispose();

    if (getActionBarContributor().getActiveEditor() == this) {
      getActionBarContributor().setActiveEditor(null);
    }

    if (propertySheetPage != null) {
      propertySheetPage.dispose();
    }

    if (contentOutlinePage != null) {
      contentOutlinePage.dispose();
    }

    super.dispose();
  }
 /**
  * This returns the root adapter factory that contains this factory.
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public ComposeableAdapterFactory getRootAdapterFactory() {
   return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();
 }
Ejemplo n.º 20
0
  @Override
  public void createPartControl(Composite parent) {
    sashForm = new SashForm(parent, SWT.HORIZONTAL);
    // composite to have control on the xtextEditor control created by super class.
    final Composite leftComposite = new Composite(sashForm, SWT.NONE);
    leftComposite.setLayout(new FillLayout());
    super.createPartControl(leftComposite);
    getSourceViewer()
        .getTextWidget()
        .addMouseListener(
            new MouseAdapter() {
              @Override
              public void mouseDoubleClick(MouseEvent e) {
                maximizeControl(leftComposite);
              }
            });
    document = getDocument();
    resourceSet =
        document.readOnly(
            new IUnitOfWork<ResourceSet, XtextResource>() {
              public ResourceSet exec(final XtextResource xtextResource) throws Exception {
                return xtextResource.getResourceSet();
              }
            });
    adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

    initializeEditingDomain();

    propertiesViewUpdater = createPropertiesViewUpdater();
    getSelectionProvider().addSelectionChangedListener(propertiesViewUpdater);
    if (getSelectionProvider() instanceof IPostSelectionProvider) {
      ((IPostSelectionProvider) getSelectionProvider())
          .addPostSelectionChangedListener(propertiesViewUpdater);
    }

    final Tree tree = new Tree(sashForm, SWT.MULTI);
    selectionViewer = new TreeViewer(tree);
    setCurrentViewer(selectionViewer);

    selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
    selectionViewer.setLabelProvider(
        new DecoratingColumLabelProvider(
            new AdapterFactoryLabelProvider(adapterFactory),
            new DiagnosticDecorator(
                editingDomain,
                selectionViewer,
                EcoreEditorPlugin.getPlugin().getDialogSettings())));
    selectionViewer.setInput(getInputForSelectionViewer(editingDomain));
    selectionViewer.setSelection(
        new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
    selectionViewer.addSelectionChangedListener(propertiesViewUpdater);
    selectionViewer.expandAll();
    tree.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDoubleClick(MouseEvent e) {
            maximizeControl(tree);
          }
        });

    new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
    new ColumnViewerInformationControlToolTipSupport(
        selectionViewer,
        new DiagnosticDecorator.EditingDomainLocationListener(editingDomain, selectionViewer));
    getSite().setSelectionProvider(this);
    createContextMenuFor(selectionViewer);

    ViewerFilter filter =
        new ViewerFilter() {
          @Override
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return (!(element instanceof FactoryImpl));
          }
        };
    selectionViewer.addFilter(filter);
  }
Ejemplo n.º 21
0
  public void createControl(Composite parent) {
    treeViewer =
        new org.emftext.language.xpath3.resource.xpath3.ui.Xpath3OutlinePageTreeViewer(
            parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    Object[] listeners = selectionChangedListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
      ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
      treeViewer.addSelectionChangedListener(l);
    }
    selectionChangedListeners.clear();
    ComposedAdapterFactory adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
    AdapterFactoryContentProvider contentProvider =
        new AdapterFactoryContentProvider(adapterFactory) {

          @Override
          public void notifyChanged(Notification notification) {
            if (viewer != null
                && viewer.getControl() != null
                && !viewer.getControl().isDisposed()) {
              viewerRefresh =
                  new ViewerRefresh(viewer) {

                    protected void refresh(IViewerNotification notification) {
                      if (viewer
                          instanceof
                          org.emftext.language.xpath3.resource.xpath3.ui
                              .Xpath3OutlinePageTreeViewer) {
                        org.emftext.language.xpath3.resource.xpath3.ui.Xpath3OutlinePageTreeViewer
                            pageTreeViewer =
                                (org.emftext.language.xpath3.resource.xpath3.ui
                                        .Xpath3OutlinePageTreeViewer)
                                    viewer;
                        pageTreeViewer.setSuppressNotifications(true);
                        super.refresh(notification);
                        pageTreeViewer.setSuppressNotifications(false);
                      } else {
                        super.refresh(notification);
                      }
                    }
                  };
            }
            super.notifyChanged(notification);
          }
        };

    treeViewer.setAutoExpandLevel(AUTO_EXPAND_LEVEL);
    treeViewer.setContentProvider(contentProvider);
    treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
    Resource resource = resourceProvider.getResource();
    treeViewer.setInput(resource);
    if (resource != null) {
      // Select the root object in the view.
      treeViewer.setSelection(new StructuredSelection(resource), true);
    }
    treeViewer.setComparator(
        new org.emftext.language.xpath3.resource.xpath3.ui.Xpath3OutlinePageTreeViewerComparator());
    createContextMenu();
    createActions();
  }
  /**
   *
   *
   * <pre>
   *  The method executes the creation :
   *  - opens a selection dialog to choose a {@link ConnectableElement} reference as a role by the {@link CollaborationUse} type
   *  - created a dependency between the selected role and the {@link ConnectableElement} that will be bind to it
   *
   * {@inheritDoc}
   * </pre>
   */
  @Override
  protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info)
      throws ExecutionException {

    if (!canExecute()) {
      throw new ExecutionException(Messages.RoleBindingCreateCommand_INVALID_ARGS_MSG);
    }

    // Retrieve the graphical source of the binding.
    // This differs from the semantic source of the binding which is a role of the
    // CollaborationUse type.
    CollaborationUse graphicalSource = (CollaborationUse) getSource();

    // Create and open the selection dialog
    ComposedAdapterFactory adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    Shell currentShell = new Shell(Display.getCurrent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    ElementTreeSelectionDialog dialog =
        new ElementTreeSelectionDialog(
            currentShell,
            new AdapterFactoryLabelProvider(adapterFactory),
            new CollaborationRoleTreeContentProvider());

    try {
      // Set dialog parameters
      dialog.setTitle(Messages.RoleBindingRoleSelectionDialog_Title);
      dialog.setMessage(Messages.RoleBindingRoleSelectionDialog_Message);
      dialog.setAllowMultiple(false);
      dialog.setHelpAvailable(false);
      // The source CollaborationUse is set as input for the selection dialog,
      // the CollaborationRoleTreeContentProvider provides the roles that can possibly be
      // selected.
      dialog.setInput(graphicalSource);

      dialog.open();
    } finally {
      adapterFactory.dispose();
    }

    // If a ConnectableElement has been selected, complete command execution
    // using selection as the "newly created" element and make the edited
    // Collaboration reference it in the CollaborationRoles eReference.
    if (dialog.getReturnCode() == ElementTreeSelectionDialog.OK) {

      ConnectableElement roleToBind = (ConnectableElement) dialog.getFirstResult();
      // Create a Dependency (the binding) between selected role and a ConnectableElement
      // (the target)
      Dependency newBinding = UMLFactory.eINSTANCE.createDependency();
      getContainer().getPackagedElements().add(newBinding);
      newBinding.getClients().add(roleToBind);
      newBinding.setName("binding_" + roleToBind.getName() + "_" + getTarget().getName());
      newBinding.getSuppliers().add(getTarget());
      graphicalSource.getRoleBindings().add(newBinding);

      doConfigure(newBinding, monitor, info);

      ((CreateElementRequest) getRequest()).setNewElement(newBinding);

      return CommandResult.newOKCommandResult(newBinding);
    }

    // No role selected: abort element creation
    return CommandResult.newCancelledCommandResult();
  }
  /**
   *
   *
   * <pre>
   *  The method executes the creation :
   *  - opens a selection dialog to choose {@link InformationItem} or {@link Classifier} reference as a convoyed Classifier
   *   by the {@link InformationFlow} type
   *  - create the InformationFlow between the source and the target
   *
   * {@inheritDoc}
   * </pre>
   */
  @Override
  protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info)
      throws ExecutionException {

    // Create and open the selection dialog
    ComposedAdapterFactory adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    Shell currentShell = new Shell(Display.getCurrent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    InformationItemElementTreeSelectionDialog dialog =
        new InformationItemElementTreeSelectionDialog(
            currentShell,
            new AdapterFactoryLabelProvider(adapterFactory),
            new AdapterFactoryContentProvider(adapterFactory));

    try {
      // Set dialog parameters
      dialog.setTitle(Messages.InformationFlowSelectionDialog_Title);
      dialog.setMessage(Messages.InformationFlowSelectionDialog_Message);
      dialog.setAllowMultiple(true);
      dialog.setHelpAvailable(false);
      dialog.setInput(getSource().getModel());
      dialog.setValidator(new InformationItemValidator());

      ArrayList<Classifier> initialSelection = new ArrayList<Classifier>();

      // here the dialog.getReturnCode is IDialogConstants.OK_ID
      while (dialog.open() != IDialogConstants.CANCEL_ID) {

        /*
         * If classifiers have been selected, complete command execution and write the selection
         * in the conveyed:Classifief Association
         */
        if (dialog.getReturnCode() == ElementTreeSelectionDialog.OK) {
          Object[] conveyedClassified = dialog.getResult();

          InformationFlow newInformationFlow = UMLFactory.eINSTANCE.createInformationFlow();
          getContainer().getPackagedElements().add(newInformationFlow);
          newInformationFlow.getInformationSources().add(getSource());
          newInformationFlow.getInformationTargets().add(getTarget());

          // add the classifier in the list of conveyed Classifier
          for (int i = 0; i < conveyedClassified.length; i++) {
            newInformationFlow.getConveyeds().add((Classifier) conveyedClassified[i]);
          }

          ElementInitializers.getInstance().init_InformationFlow_4021(newInformationFlow);

          ((CreateElementRequest) getRequest()).setNewElement(newInformationFlow);
          return CommandResult.newOKCommandResult(newInformationFlow);

        } else if (dialog.getReturnCode()
            == InformationItemElementTreeSelectionDialog.newInformationItemButton_ID) {
          // create a new InformationItem
          initialSelection.add((Classifier) createNewInformationItem());
          dialog.setInitialElementSelections(initialSelection);
        }
      } // end of while()
    } finally {
      adapterFactory.dispose();
    }

    // No Classifier selected: abort element creation
    return CommandResult.newCancelledCommandResult();
  }
Ejemplo n.º 24
0
  private IStructuredSelection buildStructuredSelection(final EObject object) {
    if (object == null) {
      return new StructuredSelection();
    }
    final IItemPropertySource source =
        (IItemPropertySource) adapterFactory.adapt(object, IItemPropertySource.class);
    return new StructuredSelection() {
      public Object[] toArray() {
        return new Object[] {
          new URIBasedPropertySource(object, source, document) {

            protected IPropertyDescriptor createPropertyDescriptor(
                EObject object, IItemPropertyDescriptor itemPropertyDescriptor) {
              return new EFactoryPropertyDescriptor(object, itemPropertyDescriptor) {
                @Override
                protected CellEditor createEDataTypeCellEditor(
                    final EDataType eDataType, Composite composite) {
                  return new EFactoryEDataTypeCellEditor(eDataType, composite);
                }

                @Override
                public CellEditor createPropertyEditor(final Composite composite) {
                  CellEditor editor = null;
                  final Object feature = itemPropertyDescriptor.getFeature(this.object);
                  if (feature instanceof EReference) {
                    final EReference eReference = (EReference) feature;
                    editor =
                        new ExtendedDialogCellEditor(composite, getEditLabelProvider()) {
                          @Override
                          protected Object openDialogBox(Control cellEditorWindow) {
                            EObject result = null;
                            XtextEObjectSearchDialog2 dlg =
                                new XtextEObjectSearchDialog2(
                                    composite.getShell(),
                                    eObjectSearch,
                                    globalDescriptionLabelProvider);
                            eReference.getClass();
                            dlg.setInitialTypePattern(
                                eReference.getEReferenceType().getName(), false);
                            dlg.open();
                            Object[] dlgResult = dlg.getResult();
                            if (dlgResult != null && dlgResult.length == 1) {
                              result = ((IEObjectDescription) dlgResult[0]).getEObjectOrProxy();
                            }
                            // This is probably more of a work-around than a fix of the actual root
                            // cause :( but it works
                            if (result != null && result.eIsProxy())
                              result = EcoreUtil.resolve(result, eReference.eResource());
                            return result;
                          }
                        };
                  } else {
                    // return the default cell editor
                    editor = super.createPropertyEditor(composite);
                  }
                  return editor;
                }
              };
            }
          }
        };
      }
    };
  }