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);
}
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());
}
}
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;
}
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();
}
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());
}
Aggregations