Search in sources :

Example 66 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class DiagramModelConnectionSection method createRouterTypeControl.

private void createRouterTypeControl(Composite parent) {
    // Label
    createLabel(parent, Messages.DiagramModelConnectionSection_0, ITabbedLayoutConstants.BIG_LABEL_WIDTH, SWT.CENTER);
    // Combo
    fComboRouterType = new Combo(parent, SWT.READ_ONLY);
    getWidgetFactory().adapt(fComboRouterType, true, true);
    fComboRouterType.setItems(comboItems);
    fComboRouterType.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CompoundCommand result = new CompoundCommand();
            for (EObject dm : getEObjects()) {
                if (isAlive(dm)) {
                    Command cmd = new ConnectionRouterTypeCommand((IDiagramModel) dm, ConnectionRouterAction.CONNECTION_ROUTER_TYPES.get(fComboRouterType.getSelectionIndex()));
                    if (cmd.canExecute()) {
                        result.add(cmd);
                    }
                }
            }
            executeCommand(result.unwrap());
        }
    });
    GridData gd = new GridData(SWT.NONE, SWT.NONE, true, false);
    gd.minimumWidth = ITabbedLayoutConstants.COMBO_WIDTH;
    fComboRouterType.setLayoutData(gd);
}
Also used : ConnectionRouterTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionRouterTypeCommand) ConnectionRouterTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionRouterTypeCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IDiagramModel(com.archimatetool.model.IDiagramModel) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EObject(org.eclipse.emf.ecore.EObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) Combo(org.eclipse.swt.widgets.Combo) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 67 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class RenameCommandHandler method doRenameCommands.

/**
 * Rename elements to matching newNames by issuing a CompundCommand(s) on the CommandStack(s)
 * @param elements
 * @param newNames
 */
public static void doRenameCommands(List<INameable> elements, List<String> newNames) {
    // Must match sizes
    if (elements.size() != newNames.size() || elements.isEmpty()) {
        return;
    }
    /*
         * If renaming elements from more than one model in the tree we need to use the
         * Command Stack allocated to each model. And then allocate one CompoundCommand per Command Stack.
         */
    Hashtable<CommandStack, CompoundCommand> commandMap = new Hashtable<CommandStack, CompoundCommand>();
    for (int i = 0; i < elements.size(); i++) {
        INameable element = elements.get(i);
        String newName = newNames.get(i);
        CompoundCommand compoundCommand = getCompoundCommand((IAdapter) element, commandMap);
        if (compoundCommand != null) {
            Command cmd = new // $NON-NLS-1$
            EObjectFeatureCommand(// $NON-NLS-1$
            Messages.RenameCommandHandler_0 + " " + element.getName(), // $NON-NLS-1$
            element, IArchimatePackage.Literals.NAMEABLE__NAME, newName);
            compoundCommand.add(cmd);
        } else {
            // $NON-NLS-1$
            System.err.println("Could not get CompoundCommand in doRenameCommands");
        }
    }
    // Execute the Commands on the CommandStack(s) - there could be more than one if more than one model open in the Tree
    for (Entry<CommandStack, CompoundCommand> entry : commandMap.entrySet()) {
        entry.getKey().execute(entry.getValue().unwrap());
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Hashtable(java.util.Hashtable) INameable(com.archimatetool.model.INameable) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)

Example 68 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class AlignmentAction method createAlignmentCommand.

private Command createAlignmentCommand() {
    AlignmentRequest request = new AlignmentRequest(RequestConstants.REQ_ALIGN);
    request.setAlignmentRectangle(calculateAlignmentRectangle(request));
    request.setAlignment(alignment);
    List editparts = getOperationSet(request);
    if (editparts.size() < 2)
        return null;
    CompoundCommand command = new CompoundCommand();
    command.setDebugLabel(getText());
    for (int i = 0; i < editparts.size(); i++) {
        EditPart editpart = (EditPart) editparts.get(i);
        command.add(editpart.getCommand(request));
    }
    return command;
}
Also used : AlignmentRequest(org.eclipse.gef.requests.AlignmentRequest) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) ArrayList(java.util.ArrayList) List(java.util.List) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 69 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class CommandsTests method testEObjectNonNotifyingCompoundCommand.

@Test
public void testEObjectNonNotifyingCompoundCommand() {
    final boolean[] execute = new boolean[1];
    model.eAdapters().add(new EContentAdapter() {

        @Override
        public void notifyChanged(Notification msg) {
            super.notifyChanged(msg);
            if (msg.getEventType() == EObjectNonNotifyingCompoundCommand.START) {
                assertEquals(model, msg.getNewValue());
                assertEquals(execute[0] ? "Archisurance" : "Hello3", model.getName());
            } else if (msg.getEventType() == EObjectNonNotifyingCompoundCommand.END) {
                assertEquals(model, msg.getNewValue());
                assertEquals(execute[0] ? "Hello3" : "Archisurance", model.getName());
            }
        }
    });
    CompoundCommand compoundCmd = new EObjectNonNotifyingCompoundCommand(model);
    compoundCmd.add(new EObjectFeatureCommand("Rename", model, IArchimatePackage.Literals.NAMEABLE__NAME, "Hello1"));
    compoundCmd.add(new EObjectFeatureCommand("Rename", model, IArchimatePackage.Literals.NAMEABLE__NAME, "Hello2"));
    compoundCmd.add(new EObjectFeatureCommand("Rename", model, IArchimatePackage.Literals.NAMEABLE__NAME, "Hello3"));
    execute[0] = true;
    compoundCmd.execute();
    execute[0] = false;
    compoundCmd.undo();
    execute[0] = true;
    compoundCmd.redo();
}
Also used : Notification(org.eclipse.emf.common.notify.Notification) EContentAdapter(org.eclipse.emf.ecore.util.EContentAdapter) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Test(org.junit.Test)

Example 70 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class FormatPainterToolTests method testCreateCommandForDiagramModelArchimateObject.

// ---------------------------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------------------------
@Test
public void testCreateCommandForDiagramModelArchimateObject() throws Exception {
    // Source component
    IDiagramModelArchimateObject sourceComponent = ArchimateTestModel.createDiagramModelArchimateObject(IArchimateFactory.eINSTANCE.createBusinessActor());
    // Target component
    IDiagramModelArchimateObject targetComponent = ArchimateTestModel.createDiagramModelArchimateObject(IArchimateFactory.eINSTANCE.createBusinessActor());
    // Set FormatPainterInfo to Source component
    FormatPainterInfo.INSTANCE.updatePaintFormat(sourceComponent);
    PaintFormat pf = FormatPainterInfo.INSTANCE.getPaintFormat();
    // Execute command
    FormatPainterTool tool = new FormatPainterTool();
    CompoundCommand compoundCmd = tool.createCommand(pf, targetComponent);
    // Source and Target have same properties except for fill color so only one command
    assertEquals(1, compoundCmd.getCommands().size());
    // Fill Color should be set even if fill colour source is null (default)
    Command cmd = (Command) compoundCmd.getCommands().get(0);
    assertTrue(cmd instanceof FillColorCommand);
    Object newValue = TestUtils.getPrivateField(cmd, "fNewValue");
    assertEquals("#ffffb5", newValue);
    // Now change some properties on the source component
    sourceComponent.setFont("Consolas");
    sourceComponent.setFontColor("#eeeeee");
    sourceComponent.setLineColor("#eeeeee");
    sourceComponent.setLineWidth(3);
    sourceComponent.setTextAlignment(1);
    sourceComponent.setAlpha(100);
    sourceComponent.setLineAlpha(100);
    sourceComponent.setGradient(IDiagramModelObject.GRADIENT_NONE + 1);
    compoundCmd = tool.createCommand(pf, targetComponent);
    assertEquals(9, compoundCmd.getCommands().size());
}
Also used : PaintFormat(com.archimatetool.editor.diagram.tools.FormatPainterInfo.PaintFormat) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) Command(org.eclipse.gef.commands.Command) FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Test(org.junit.Test)

Aggregations

CompoundCommand (org.eclipse.gef.commands.CompoundCommand)193 Command (org.eclipse.gef.commands.Command)86 EObject (org.eclipse.emf.ecore.EObject)40 ArrayList (java.util.ArrayList)28 EditPart (org.eclipse.gef.EditPart)28 List (java.util.List)24 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)23 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)18 Point (org.eclipse.draw2d.geometry.Point)16 IElementParameter (org.talend.core.model.process.IElementParameter)16 Combo (org.eclipse.swt.widgets.Combo)15 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)14 Rectangle (org.eclipse.draw2d.geometry.Rectangle)14 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)14 INode (org.talend.core.model.process.INode)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14