Java Code Examples for org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain#getEditingDomainFor()

The following examples show how to use org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain#getEditingDomainFor() . 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: DeleteHandler.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public void removeMessage(final MessageFlow flow) {
    final MainProcess diagram = ModelHelper.getMainProcess(flow);
    Assert.isNotNull(diagram);
    final AbstractCatchMessageEvent catchEvent = flow.getTarget();
    final ThrowMessageEvent thowEvent = flow.getSource();
    final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(diagram);
    Assert.isNotNull(domain);
    final CompoundCommand cc = new CompoundCommand();
    if (flow.getSource() != null) {
        final List<Message> messages = flow.getSource().getEvents();
        for (final Message message : messages) {
            if (flow.getName().equals(message.getName())) {
                cc.append(DeleteCommand.create(domain, message));
                break;
            }
        }
    }
    cc.append(SetCommand.create(domain, catchEvent, ProcessPackage.Literals.ABSTRACT_CATCH_MESSAGE_EVENT__EVENT, null));
    domain.getCommandStack().execute(cc);
}
 
Example 2
Source File: CustomCutCommand.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected CommandResult doExecuteWithResult(
		IProgressMonitor progressMonitor, IAdaptable info)
		throws ExecutionException {
	
	Clipboard.setToCopyEditParts(toCopyElement);
	TransactionalEditingDomain domain = (TransactionalEditingDomain) AdapterFactoryEditingDomain.getEditingDomainFor(toCopyElement);
	domain.getCommandStack().execute(new RecordingCommand(domain) {
		protected void doExecute() {
			for (IGraphicalEditPart part : toCopyElement) {
				EcoreUtil.delete(part.resolveSemanticElement());
			}
		}
	});		
	
	return CommandResult.newOKCommandResult();
}
 
Example 3
Source File: SetConnectionHandler.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public void setConnection ( final Driver driver )
{
    final CompoundManager manager = new CompoundManager ();

    for ( final ExternalValue v : SelectionHelper.iterable ( getSelection (), ExternalValue.class ) )
    {
        final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor ( v );
        if ( domain == null )
        {
            continue;
        }
        manager.append ( domain, SetCommand.create ( domain, v, ComponentPackage.Literals.EXTERNAL_VALUE__CONNECTION, driver ) );
    }

    manager.executeAll ();
}
 
Example 4
Source File: SetExternalNameWizard.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public void setExternalName ( final CompiledScript script ) throws Exception
{
    final CompoundManager manager = new CompoundManager ();

    for ( final ExternalValue v : SelectionHelper.iterable ( this.selection, ExternalValue.class ) )
    {
        final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor ( v );
        if ( domain == null )
        {
            continue;
        }
        final String name = evalName ( script, v );
        manager.append ( domain, SetCommand.create ( domain, v, ComponentPackage.Literals.EXTERNAL_VALUE__SOURCE_NAME, name ) );
    }

    manager.executeAll ();
}
 
Example 5
Source File: GraphEditorPersistence.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Saves the graph editor's model state in the given file.
 *
 * @param file the {@link File} the model state will be saved in
 * @param model the {@link GModel} to be saved
 */
private void saveModel(final File file, final GModel model) {

    String absolutePath = file.getAbsolutePath();
    if (!absolutePath.endsWith(FILE_EXTENSION)) {
        absolutePath += FILE_EXTENSION;
    }

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);

    final URI fileUri = URI.createFileURI(absolutePath);
    final XMIResourceFactoryImpl resourceFactory = new XMIResourceFactoryImpl();
    final Resource resource = resourceFactory.createResource(fileUri);
    resource.getContents().add(model);

    try {
        resource.save(Collections.EMPTY_MAP);
    } catch (final IOException e) {
        e.printStackTrace();
    }

    editingDomain.getResourceSet().getResources().clear();
    editingDomain.getResourceSet().getResources().add(resource);

    initialDirectory = file.getParentFile();
}
 
Example 6
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 7
Source File: SelectionCopier.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds the pasted elements to the graph editor via a single EMF command.
 *
 * @param pastedNodes the pasted nodes to be added
 * @param pastedConnections the pasted connections to be added
 * @param consumer a consumer to allow custom commands to be appended to the paste command
 */
private void addPastedElements(final List<GNode> pastedNodes, final List<GConnection> pastedConnections,
        final BiConsumer<List<GNode>, CompoundCommand> consumer) {

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);
    final CompoundCommand command = new CompoundCommand();

    for (final GNode pastedNode : pastedNodes) {
        command.append(AddCommand.create(editingDomain, model, NODES, pastedNode));
    }

    for (final GConnection pastedConnection : pastedConnections) {
        command.append(AddCommand.create(editingDomain, model, CONNECTIONS, pastedConnection));
    }

    if (command.canExecute()) {
        editingDomain.getCommandStack().execute(command);
    }

    if (consumer != null) {
        consumer.accept(pastedNodes, command);
    }

}
 
Example 8
Source File: FillFieldNumbersHandler.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute ( final ExecutionEvent event ) throws ExecutionException
{

    final IEditorPart editor = getActivePage ().getActiveEditor ();

    byte b = (byte)1;
    for ( final Attribute attribute : SelectionHelper.iterable ( getSelection (), Attribute.class ) )
    {
        EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor ( attribute );

        if ( domain == null && editor instanceof IEditingDomainProvider )
        {
            domain = ( (IEditingDomainProvider)editor ).getEditingDomain ();
        }

        SetCommand.create ( domain, attribute, ProtocolPackage.Literals.ATTRIBUTE__FIELD_NUMBER, b ).execute ();

        b++;
    }

    return null;
}
 
Example 9
Source File: ConnectionCommands.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes a connection from the model.
 *
 * @param model the {@link GModel} from which the connection should be removed
 * @param connection the {@link GConnection} to be removed
 * @return the newly-executed {@link CompoundCommand} that removed the connection
 */
public static CompoundCommand removeConnection(final GModel model, final GConnection connection) {

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);

    if (editingDomain != null) {
        final CompoundCommand command = new CompoundCommand();

        final GConnector source = connection.getSource();
        final GConnector target = connection.getTarget();

        command.append(RemoveCommand.create(editingDomain, model, CONNECTIONS, connection));
        command.append(RemoveCommand.create(editingDomain, source, CONNECTOR_CONNECTIONS, connection));
        command.append(RemoveCommand.create(editingDomain, target, CONNECTOR_CONNECTIONS, connection));

        if (command.canExecute()) {
            editingDomain.getCommandStack().execute(command);
        }
        return command;

    } else {
        return null;
    }
}
 
Example 10
Source File: JointCommands.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes any existing joints from the connection and creates a new set of joints at the given positions.
 *
 * <p>
 * This is executed as a single compound command and is therefore a single element in the undo-redo stack.
 * </p>
 *
 * @param positions a list of {@link Point2D} instances speciying the x and y positions of the new joints
 * @param connection the connection in which the joints will be set
 */
public static void setNewJoints(final List<Point2D> positions, final GConnection connection) {

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(connection);
    final CompoundCommand command = new CompoundCommand();

    command.append(RemoveCommand.create(editingDomain, connection, JOINTS, connection.getJoints()));

    for (final Point2D position : positions) {

        final GJoint newJoint = GraphFactory.eINSTANCE.createGJoint();
        newJoint.setX(position.getX());
        newJoint.setY(position.getY());

        command.append(AddCommand.create(editingDomain, connection, JOINTS, newJoint));
    }

    if (command.canExecute()) {
        editingDomain.getCommandStack().execute(command);
    }
}
 
Example 11
Source File: Commands.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the editing domain associated to the model.
 * 
 * <p>
 * Logs an error if none is found.
 * </p>
 * 
 * @param model a {@link GModel} instance
 * @return the {@link EditingDomain} associated to this model instance
 */
private static EditingDomain getEditingDomain(final GModel model) {

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);

    if (editingDomain == null) {
        LOGGER.error(LogMessages.NO_EDITING_DOMAIN);
    }

    return editingDomain;
}
 
Example 12
Source File: ConnectorWizard.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean performFinish() {
    final EditingDomain editingDomain = AdapterFactoryEditingDomain
            .getEditingDomainFor(container);
    if (editMode) {
        modelUpdater.update();
    } else {
        editingDomain.getCommandStack().execute(
                createPerformFinishCommandOnCreation(editingDomain));
    }
    return true;
}
 
Example 13
Source File: GraphEditorTest.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() {

    graphEditor = new DefaultGraphEditor();
    model = DummyDataFactory.createModel();
    skinLookup = graphEditor.getSkinLookup();

    graphEditor.setModel(model);

    editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);
    if (editingDomain != null) {
        commandStack = editingDomain.getCommandStack();
    }
}
 
Example 14
Source File: ConnectionCommands.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds a connection to the model.
 *
 * @param model the {@link GModel} to which the connection should be added
 * @param source the source {@link GConnector} of the new connection
 * @param target the target {@link GConnector} of the new connection
 * @param type the type attribute for the new connection
 * @param joints the list of {@link GJoint} instances to be added inside the new connection
 * @return the newly-executed {@link CompoundCommand} that added the connection
 */
public static CompoundCommand addConnection(final GModel model, final GConnector source, final GConnector target,
        final String type, final List<GJoint> joints) {

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);

    if (editingDomain != null) {
        final CompoundCommand command = new CompoundCommand();

        final GConnection connection = GraphFactory.eINSTANCE.createGConnection();

        command.append(AddCommand.create(editingDomain, model, CONNECTIONS, connection));

        if (type != null) {
            command.append(SetCommand.create(editingDomain, connection, CONNECTION_TYPE, type));
        }

        command.append(SetCommand.create(editingDomain, connection, SOURCE, source));
        command.append(SetCommand.create(editingDomain, connection, TARGET, target));
        command.append(AddCommand.create(editingDomain, source, CONNECTOR_CONNECTIONS, connection));
        command.append(AddCommand.create(editingDomain, target, CONNECTOR_CONNECTIONS, connection));

        for (final GJoint joint : joints) {
            command.append(AddCommand.create(editingDomain, connection, JOINTS, joint));
        }

        if (command.canExecute()) {
            editingDomain.getCommandStack().execute(command);
        }
        return command;

    } else {
        return null;
    }
}
 
Example 15
Source File: JointCommands.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes joints from a connection.
 *
 * <p>
 * This method adds the remove operations to the given compound command and does not execute it.
 * </p>
 *
 * @param command a {@link CompoundCommand} to which the remove commands will be added
 * @param indices the indices within the connection's list of joints specifying the joints to be removed
 * @param connection the connection whose joints are to be removed
 */
public static void removeJoints(final CompoundCommand command, final Set<Integer> indices,
        final GConnection connection) {

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(connection);

    for (int i = 0; i < connection.getJoints().size(); i++) {
        if (indices.contains(i)) {
            final GJoint joint = connection.getJoints().get(i);
            command.append(RemoveCommand.create(editingDomain, connection, JOINTS, joint));
        }
    }
}
 
Example 16
Source File: DefaultSkinController.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds a connector of the given type to all nodes that are currently selected.
 *
 * @param position the position of the new connector
 * @param input {@code true} for input, {@code false} for output
 */
@Override
public void addConnector(final Side position, final boolean input) {

    final String type = getType(position, input);

    final GModel model = graphEditor.getModel();
    final SkinLookup skinLookup = graphEditor.getSkinLookup();
    final CompoundCommand command = new CompoundCommand();
    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);

    for (final GNode node : model.getNodes()) {

        if (skinLookup.lookupNode(node).isSelected()) {
            if (countConnectors(node, position) < MAX_CONNECTOR_COUNT) {

                final GConnector connector = GraphFactory.eINSTANCE.createGConnector();
                connector.setType(type);

                final EReference connectors = GraphPackage.Literals.GCONNECTABLE__CONNECTORS;
                command.append(AddCommand.create(editingDomain, node, connectors, connector));
            }
        }
    }

    if (command.canExecute()) {
        editingDomain.getCommandStack().execute(command);
    }
}
 
Example 17
Source File: GraphEditorDemoController.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Flushes the command stack, so that the undo/redo history is cleared.
 */
private void flushCommandStack() {

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(graphEditor.getModel());
    if (editingDomain != null) {
        editingDomain.getCommandStack().flush();
    }
}
 
Example 18
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 19
Source File: JointCleaner.java    From graph-editor with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Adds handlers to remove all joints that are on top of each other after a mouse-released gesture.
 *
 * @param jointSkins the connection's joint skins
 */
public void addCleaningHandlers(final List<GJointSkin> jointSkins) {

    final Map<GJoint, EventHandler<MouseEvent>> oldCleaningHandlers = new HashMap<>(cleaningHandlers);

    cleaningHandlers.clear();

    for (final GJointSkin jointSkin : jointSkins) {

        final GJoint joint = jointSkin.getJoint();
        final Region jointRegion = jointSkin.getRoot();
        final EventHandler<MouseEvent> oldHandler = oldCleaningHandlers.get(joint);

        if (oldHandler != null) {
            jointRegion.removeEventHandler(MouseEvent.MOUSE_RELEASED, oldHandler);
        }

        final EventHandler<MouseEvent> newHandler = event -> {

            final Parent parent = jointRegion.getParent();

            if (jointSkins.size() == 2 || !event.getButton().equals(MouseButton.PRIMARY)) {
                return;
            }

            final List<Point2D> jointPositions = GeometryUtils.getJointPositions(jointSkins);
            final Set<Integer> jointsToCleanUp = findJointsToCleanUp(jointPositions);

            if (!jointsToCleanUp.isEmpty()) {

                final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(connection);
                final CompoundCommand command = new CompoundCommand();

                final GModel model = graphEditor.getModel();
                final SkinLookup skinLookup = graphEditor.getSkinLookup();

                JointCommands.removeJoints(command, jointsToCleanUp, connection);
                Commands.updateLayoutValues(command, model, skinLookup);

                if (command.canExecute()) {
                    editingDomain.getCommandStack().execute(command);
                }
            }

            parent.layout();
        };

        jointRegion.addEventHandler(MouseEvent.MOUSE_RELEASED, newHandler);
        cleaningHandlers.put(joint, newHandler);
    }
}
 
Example 20
Source File: TreeNodeSkin.java    From graph-editor with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Adds a child node with one input and one output connector, placed directly underneath its parent.
 */
private void addChildNode() {

    final GNode childNode = GraphFactory.eINSTANCE.createGNode();

    childNode.setType(TreeSkinConstants.TREE_NODE);
    childNode.setX(getNode().getX() + (getNode().getWidth() - childNode.getWidth()) / 2);
    childNode.setY(getNode().getY() + getNode().getHeight() + CHILD_Y_OFFSET);

    final GModel model = getGraphEditor().getModel();
    final double maxAllowedY = model.getContentHeight() - VIEW_PADDING;

    if (childNode.getY() + childNode.getHeight() > maxAllowedY) {
        childNode.setY(maxAllowedY - childNode.getHeight());
    }

    final GConnector input = GraphFactory.eINSTANCE.createGConnector();
    final GConnector output = GraphFactory.eINSTANCE.createGConnector();

    input.setType(TreeSkinConstants.TREE_INPUT_CONNECTOR);
    output.setType(TreeSkinConstants.TREE_OUTPUT_CONNECTOR);

    childNode.getConnectors().add(input);
    childNode.getConnectors().add(output);

    // This allows multiple connections to be created from the output.
    output.setConnectionDetachedOnDrag(false);

    final GConnector parentOutput = findOutput();
    final GConnection connection = GraphFactory.eINSTANCE.createGConnection();

    connection.setType(TreeSkinConstants.TREE_CONNECTION);
    connection.setSource(parentOutput);
    connection.setTarget(input);

    input.getConnections().add(connection);

    // Set the rest of the values via EMF commands because they touch the currently-edited model.
    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);
    final CompoundCommand command = new CompoundCommand();

    command.append(AddCommand.create(editingDomain, model, NODES, childNode));
    command.append(AddCommand.create(editingDomain, model, CONNECTIONS, connection));
    command.append(AddCommand.create(editingDomain, parentOutput, CONNECTOR_CONNECTIONS, connection));

    if (command.canExecute()) {
        editingDomain.getCommandStack().execute(command);
    }
}