org.eclipse.emf.common.command.Command Java Examples

The following examples show how to use org.eclipse.emf.common.command.Command. 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: TaxonomyCheckboxListView.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
	Optional<Document> activeDocument = ModelRegistryPlugin.getModelRegistry().getActiveDocument();
	if (activeDocument.isPresent()) {
		Document document = activeDocument.get();
		Command changeCommand = new ExecuteCommand() {
			@Override
			public void execute() {
				final Term element = (Term) event.getElement();
				setTermChanged(document, element, event.getChecked());
			}
		};
		executeCommand(changeCommand);
	}
	viewer.update(event.getElement(), null);
}
 
Example #2
Source File: ExpressionScriptContrainer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public CompoundCommand removeDependencies(final TransactionalEditingDomain editingDomain,
        final List<? extends RefactorPair<? extends EObject, ? extends EObject>> pairsToRefactor) {
    final CompoundCommand compoundCommand = new CompoundCommand();
    final Expression expression = getModelElement();
    for (final EObject dep : expression.getReferencedElements()) {
        for (final RefactorPair<?, ? extends EObject> pair : pairsToRefactor) {
            final String oldValueName = pair.getOldValueName();
            final EClass eClass = pair.getOldValue().eClass();
            if (eClass.equals(dep.eClass()) && oldValueName.equals(dependencyName(dep))) {
                final Command removeCmd = RemoveCommand.create(editingDomain, expression,
                        ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS,
                        dep);
                if (!compoundCommand.getCommandList().contains(removeCmd)) {
                    compoundCommand.append(removeCmd);
                }
            }
        }
    }
    return compoundCommand;
}
 
Example #3
Source File: AbstractCreateEdgeHandler.java    From graphical-lsp with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doExecute(AbstractOperationAction action, GraphicalModelState modelState,
		WorkflowModelServerAccess modelAccess) throws Exception {
	CreateConnectionOperationAction createConnectionAction = (CreateConnectionOperationAction) action;
	WorkflowFacade workflowFacade = modelAccess.getWorkflowFacade();
	Workflow workflow = workflowFacade.getCurrentWorkflow();

	Flow flow = (Flow) CoffeeFactory.eINSTANCE.create(eClass);
	flow.setSource(modelAccess.getNodeById(createConnectionAction.getSourceElementId()));
	flow.setTarget(modelAccess.getNodeById(createConnectionAction.getTargetElementId()));

	Command addCommand = AddCommand.create(modelAccess.getEditingDomain(), workflow,
			CoffeePackage.Literals.WORKFLOW__FLOWS, flow);

	createDiagramElement(workflowFacade, workflow, flow, createConnectionAction);

	if (!modelAccess.edit(addCommand).thenApply(res -> res.body()).get()) {
		throw new IllegalAccessError("Could not execute command: " + addCommand);
	}
}
 
Example #4
Source File: WorkflowModelServerSubscriptionListener.java    From graphical-lsp with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void onIncrementalUpdate(CCommand command) {
	LOG.debug("Incremental update from model server received: " + command);
	Resource commandResource = null;
	try {
		// execute command on semantic resource
		EditingDomain domain = modelServerAccess.getEditingDomain();
		commandResource = createCommandResource(domain, command);
		command.getObjectsToAdd().forEach(GModelIdAdpater::addGModelIdAdpater);
		Command cmd = modelServerAccess.getCommandCodec().decode(domain, command);
		domain.getCommandStack().execute(cmd);

		// update notation resource
		WorkflowFacade facade = modelServerAccess.getWorkflowFacade();
		Resource notationResource = facade.getNotationResource();
		updateNotationResource(facade, notationResource);
	} catch (DecodingException ex) {
		LOG.error("Could not decode command: " + command, ex);
		throw new RuntimeException(ex);
	} finally {
		if (commandResource != null) {
			commandResource.getResourceSet().getResources().remove(commandResource);
		}
	}
}
 
Example #5
Source File: AbstractCreateNodeHandler.java    From graphical-lsp with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doExecute(AbstractOperationAction action, GraphicalModelState modelState,
		WorkflowModelServerAccess modelAccess) throws Exception {
	CreateNodeOperationAction createNodeOperationAction = (CreateNodeOperationAction) action;
	WorkflowFacade workflowFacade = modelAccess.getWorkflowFacade();
	Workflow workflow = workflowFacade.getCurrentWorkflow();

	Node node = initializeNode((Node) CoffeeFactory.eINSTANCE.create(eClass), modelState);

	Command addCommand = AddCommand.create(modelAccess.getEditingDomain(), workflow,
			CoffeePackage.Literals.WORKFLOW__NODES, node);

	createDiagramElement(workflowFacade, workflow, node, createNodeOperationAction);

	if (!modelAccess.edit(addCommand).thenApply(res -> res.body()).get()) {
		throw new IllegalAccessError("Could not execute command: " + addCommand);
	}

}
 
Example #6
Source File: ApplyLabelEditOperationHandler.java    From graphical-lsp with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doExecute(AbstractOperationAction action, GraphicalModelState modelState,
		WorkflowModelServerAccess modelAccess) throws Exception {
	ApplyLabelEditOperationAction editLabelAction = (ApplyLabelEditOperationAction) action;
	Optional<GModelElement> element = modelState.getIndex().get(editLabelAction.getLabelId());
	if (!element.isPresent() && !(element.get() instanceof GLabel)) {
		throw new IllegalArgumentException("Element with provided ID cannot be found or is not a GLabel");
	}

	GNode gNode = getParentGNode((GLabel) element.get());
	Node node = modelAccess.getNodeById(gNode.getId());
	if (!(node instanceof Task)) {
		throw new IllegalAccessError("Edited label isn't label representing a task");
	}
	
	Command setCommand = SetCommand.create(modelAccess.getEditingDomain(), node, CoffeePackage.Literals.TASK__NAME, editLabelAction.getText());
	if(!modelAccess.edit(setCommand).thenApply(res -> res.body()).get()) {
		throw new IllegalAccessError("Could not execute command: " + setCommand);
	}
}
 
Example #7
Source File: TaskPriorityPropertySection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
    ExtensibleGridPropertySection extensibleGridPropertySection) {
combo = new ComboViewer(composite);
combo.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
combo.setContentProvider(new ArrayContentProvider());
combo.setLabelProvider(new PriorityLabelProvider());
Object[] input = new Object[TaskPriority.values().length];
for (int i = 0; i < TaskPriority.values().length; i++) {
    input[i] = i;
}
combo.setInput(input);
combo.setSelection(new StructuredSelection(task.getPriority()));

combo.addPostSelectionChangedListener(new ISelectionChangedListener() {
    public void selectionChanged(SelectionChangedEvent event) {
	IStructuredSelection selection = (IStructuredSelection) event.getSelection();
	if (!selection.isEmpty()) {
	    Command setCommand = new SetCommand(editDomain, task, ProcessPackage.Literals.TASK__PRIORITY,
		    selection.getFirstElement());
	    editDomain.getCommandStack().execute(setCommand);
	}
    }
});
   }
 
Example #8
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorGroup(Group oldGroup, Group newGroup, Configuration configuration,
        EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Groups groups = ac.getGroups();
        if (groups != null) {
            if (groups.getGroup().contains(GroupContentProvider.getGroupPath(oldGroup))) {
                cc.appendIfCanExecute(RemoveCommand.create(editingDomain, groups,
                        ActorMappingPackage.Literals.GROUPS__GROUP, GroupContentProvider.getGroupPath(oldGroup)));
                cc.appendIfCanExecute(AddCommand.create(editingDomain, groups,
                        ActorMappingPackage.Literals.GROUPS__GROUP, GroupContentProvider.getGroupPath(newGroup)));
                //                    cc.append(new ReplaceCommand(editingDomain, groups.getGroup(), GroupContentProvider.getGroupPath(oldGroup),
                //                            GroupContentProvider.getGroupPath(newGroup)));
            }
        }
    }
    return cc;
}
 
Example #9
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorUsername(final User oldUser, final User newUser,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Users users = ac.getUsers();
        if (users != null) {
            if (users.getUser().contains(oldUser.getUserName())) {
                cc.appendIfCanExecute(RemoveCommand.create(editingDomain, users,
                        ActorMappingPackage.Literals.USERS__USER, oldUser.getUserName()));
                cc.appendIfCanExecute(AddCommand.create(editingDomain, users,
                        ActorMappingPackage.Literals.USERS__USER, newUser.getUserName()));
            }
        }
    }
    if (Objects.equals(configuration.getUsername(), oldUser.getUserName())) {
        cc.appendIfCanExecute(SetCommand.create(editingDomain, configuration,
                ConfigurationPackage.Literals.CONFIGURATION__USERNAME, newUser.getUserName()));
    }
    return cc;
}
 
Example #10
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorMembership(final Group oldGroup, final Group newGroup,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Membership memberships = ac.getMemberships();
        if (memberships != null) {
            for (final MembershipType membershipType : memberships.getMembership()) {
                if (membershipType.getGroup().equals(GroupContentProvider.getGroupPath(oldGroup))) {
                    cc.appendIfCanExecute(SetCommand.create(editingDomain, membershipType,
                            ActorMappingPackage.Literals.MEMBERSHIP_TYPE__GROUP,
                            GroupContentProvider.getGroupPath(newGroup)));
                }
            }
        }
    }
    return cc;
}
 
Example #11
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorMembership(final Role oldRole, final Role newRole,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Membership memberships = ac.getMemberships();
        if (memberships != null) {
            for (final MembershipType membershipType : memberships.getMembership()) {
                if (membershipType.getRole().equals(oldRole.getName())) {
                    cc.appendIfCanExecute(SetCommand.create(editingDomain, membershipType,
                            ActorMappingPackage.Literals.MEMBERSHIP_TYPE__ROLE, newRole.getName()));
                }
            }
        }
    }
    return cc;
}
 
Example #12
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorUsername(
        final org.bonitasoft.studio.actors.model.organization.Membership oldMembership,
        final org.bonitasoft.studio.actors.model.organization.Membership newMembership,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Users users = ac.getUsers();
        if (users != null) {
            if (users.getUser().contains(oldMembership.getUserName())) {
                cc.appendIfCanExecute(new ReplaceCommand(editingDomain, users.getUser(),
                        oldMembership.getUserName(), newMembership.getUserName()));
            }
        }
    }
    return cc;
}
 
Example #13
Source File: GenconfEditor.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
public void commandStackChanged(final EventObject event) {
    getContainer().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();
                }
            }
        }
    });
}
 
Example #14
Source File: TitledSkinController.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Allocates ID's to recently pasted nodes.
 * 
 * @param nodes the recently pasted nodes
 * @param command the command responsible for adding the nodes
 */
private void allocateIds(final List<GNode> nodes, final CompoundCommand command) {

    final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(graphEditor.getModel());
    final EAttribute feature = GraphPackage.Literals.GNODE__ID;

    for (final GNode node : nodes) {

        if (checkNeedsNewId(node, nodes)) {

            final String id = allocateNewId();
            final Command setCommand = SetCommand.create(domain, node, feature, id);

            if (setCommand.canExecute()) {
                command.appendAndExecute(setCommand);
            }

            graphEditor.getSkinLookup().lookupNode(node).initialize();
        }
    }
}
 
Example #15
Source File: PrepareDiagramCommand.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
 */
@Override
protected void doExecute() {
    if (this.layers.isEmpty() && this.representation instanceof DDiagram) {
        this.exportedDiagram = (DDiagram) this.representation;
        if (!isRepresentationOpened && refreshRepresentations) {
            // Force a refresh of the representation
            DialectManager.INSTANCE.refresh(exportedDiagram, new NullProgressMonitor());
        }
    } else {
        // copy representation
        this.exportedDiagram = (DDiagram) DialectManager.INSTANCE.copyRepresentation(this.representation,
                this.representation.getName() + SUFFIXE_COPY, session, MONITOR);
        // activate layers list.
        Command compoundCmd = activateLayers(this.exportedDiagram);
        if (!isRepresentationOpened) {
            new GMFDiagramUpdater(session, (DDiagram) representation);
        }
        session.getTransactionalEditingDomain().getCommandStack().execute(compoundCmd);
    }
}
 
Example #16
Source File: AdditionalResourcesConfigurationSyncronizer.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void addNewAdditionalResources(Configuration configuration, Pool pool, EditingDomain editingDomain,
        CompoundCommand cc) {
    pool.getAdditionalResources().stream()
            .filter(additionalResource -> configuration.getAdditionalResources().stream()
                    .noneMatch(anAdditionalResource -> Objects.equals(additionalResource.getName(),
                            anAdditionalResource.getBarPath())))
            .forEach(additionalResource -> {
                Resource newAdditionalResource = ConfigurationFactory.eINSTANCE.createResource();
                newAdditionalResource.setBarPath(additionalResource.getName());
                Command command = createAddCommand(editingDomain, configuration, newAdditionalResource);
                cc.append(command);
            });
}
 
Example #17
Source File: AdditionalResourcesConfigurationSyncronizer.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void removeDeletedAdditionalResources(Configuration configuration, Pool pool,
        EditingDomain editingDomain, CompoundCommand cc) {
    configuration.getAdditionalResources().stream()
            .filter(additionalResource -> pool.getAdditionalResources().stream()
                    .noneMatch(anAdditionalResource -> Objects.equals(additionalResource.getBarPath(),
                            anAdditionalResource.getName())))
            .forEach(additionalResource -> {
                Command command = createRemoveCommand(editingDomain, configuration, additionalResource);
                cc.append(command);
            });
}
 
Example #18
Source File: AddBusinessObjectDataWizard.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean performFinish() {
    final Command addCommand = AddCommand.create(editingDomain, container, ProcessPackage.Literals.DATA_AWARE__DATA,
            businessObjectData);
    editingDomain.getCommandStack().execute(addCommand);
    return !addCommand.getResult().isEmpty();
}
 
Example #19
Source File: CustomWorkspaceCommandStackTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_create_always_valid_trigger_command_transaction_if_command_a_command_trigger() throws Exception {
    final CustomWorkspaceCommandStack commandStack = new CustomWorkspaceCommandStack(new DefaultOperationHistory());
    commandStack.setEditingDomain(new TransactionalEditingDomainImpl(new ProcessAdapterFactory()));

    final EMFCommandTransaction transaction = commandStack.createTransaction(new TriggerCommand(Collections.<Command> emptyList()), Collections.emptyMap());

    assertThat(transaction).isInstanceOf(AlwaysValidTriggerCommandTransaction.class);
}
 
Example #20
Source File: CustomWorkspaceCommandStack.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public EMFCommandTransaction createTransaction(final Command command, final Map<?, ?> options) throws InterruptedException {
    EMFCommandTransaction result;
    if (command instanceof TriggerCommand) {
        result = new AlwaysValidTriggerCommandTransaction((TriggerCommand) command,
                getDomain(), options);
    } else {
        result = new AlwaysValidEMFOperationTransaction(command, getDomain(), options);
    }

    result.start();

    return result;
}
 
Example #21
Source File: ConnectorSection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
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 #22
Source File: ModelStateImpl.java    From graphical-lsp with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void execute(Command command) {
	if (commandStack == null) {
		return;
	}
	commandStack.execute(command);
}
 
Example #23
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Command refactorRole(final Role oldRole, final Role newRole,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Roles roles = ac.getRoles();
        if (roles != null) {
            if (roles.getRole().contains(oldRole.getName())) {
                cc.appendIfCanExecute(
                        new ReplaceCommand(editingDomain, roles.getRole(), oldRole.getName(), newRole.getName()));
            }
        }
    }
    return cc;
}
 
Example #24
Source File: EditingDomainEObjectObservableValueWithRefactoring.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void doSetValue(final Object value) {
    final CompoundCommand cc = new CompoundCommand();
    cc.append(SetCommand.create(domain, eObject, eStructuralFeature, value));
    final Command refactoringCommand = getRefactoringCommand();
    if (refactoringCommand != null && refactoringCommand.canExecute()) {
        cc.append(refactoringCommand);
    }
    domain.getCommandStack().execute(cc);
}
 
Example #25
Source File: CompoundManager.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void append ( final EditingDomain domain, final Command command )
{
    CompoundHandler handler = this.handlers.get ( domain );
    if ( handler == null )
    {
        handler = new CompoundHandler ( domain );
        this.handlers.put ( domain, handler );
    }
    handler.addCommand ( command );
}
 
Example #26
Source File: ConvertToExternalHandler.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void replace ( final CompoundManager manager, final SingleValue v )
{
    if ( v instanceof ExternalValue )
    {
        return;
    }

    final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor ( v );

    final Command command = ReplaceCommand.create ( domain, v.eContainer (), v.eContainmentFeature (), v, Collections.singletonList ( convert ( v ) ) );
    manager.append ( domain, command );
}
 
Example #27
Source File: Commands.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds a node to the model.
 *
 * <p>
 * The node's x, y, width, and height values should be set before calling this method.
 * </p>
 *
 * @param model the {@link GModel} to which the node should be added
 * @param node the {@link GNode} to add to the model
 */
public static void addNode(final GModel model, final GNode node) {

    final EditingDomain editingDomain = getEditingDomain(model);

    if (editingDomain != null) {
        final Command command = AddCommand.create(editingDomain, model, NODES, node);

        if (command.canExecute()) {
            editingDomain.getCommandStack().execute(command);
        }
    }
}
 
Example #28
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Command refactorGroup(final org.bonitasoft.studio.actors.model.organization.Membership oldMembership,
        final org.bonitasoft.studio.actors.model.organization.Membership newMembership,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Groups groups = ac.getGroups();
        if (groups != null) {
            if (groups.getGroup().contains(GroupContentProvider.getGroupPath(oldMembership.getGroupName(),
                    oldMembership.getGroupParentPath()))) {
                cc.appendIfCanExecute(
                        RemoveCommand.create(editingDomain, groups, ActorMappingPackage.Literals.GROUPS__GROUP,
                                GroupContentProvider.getGroupPath(oldMembership.getGroupName(),
                                        oldMembership.getGroupParentPath())));
                cc.appendIfCanExecute(
                        AddCommand.create(editingDomain, groups, ActorMappingPackage.Literals.GROUPS__GROUP,
                                GroupContentProvider.getGroupPath(newMembership.getGroupName(),
                                        newMembership.getGroupParentPath())));

                //                    cc.appendIfCanExecute(new ReplaceCommand(editingDomain, groups.getGroup(),
                //                            GroupContentProvider.getGroupPath(oldMembership.getGroupName(),
                //                                    oldMembership.getGroupParentPath()),
                //                            GroupContentProvider.getGroupPath(newMembership.getGroupName(),
                //                                    newMembership.getGroupParentPath())));
            }
        }
    }
    return cc;
}
 
Example #29
Source File: TaxonomyCheckboxListView.java    From slr-toolkit with Eclipse Public License 1.0 4 votes vote down vote up
private void executeCommand(Command command) {
	Optional<AdapterFactoryEditingDomain> editingDomain = ModelRegistryPlugin.getModelRegistry().getEditingDomain();
	editingDomain.ifPresent((domain) -> domain.getCommandStack().execute(command));
}
 
Example #30
Source File: CoreEditor.java    From ifml-editor with MIT License 4 votes vote down vote up
/**
 * 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 CoreItemProviderAdapterFactory());
	adapterFactory.addAdapterFactory(new ExtensionsItemProviderAdapterFactory());
	adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
	adapterFactory.addAdapterFactory(new UMLItemProviderAdapterFactory());
	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() {
			 public void commandStackChanged(final EventObject event) {
				 getContainer().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();
								  }
							  }
						  }
					  });
			 }
		 });

	// Create the editing domain with a special command stack.
	//
	editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap<Resource, Boolean>());
}