use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class DuplicateCommandHandler method createCommands.
private void createCommands() {
for (Object object : fElementsToDuplicate) {
CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
if (compoundCommand == null) {
// sanity check
// $NON-NLS-1$
System.err.println("Could not get CompoundCommand in " + getClass());
continue;
}
if (object instanceof IDiagramModel) {
Command cmd = new DuplicateDiagramModelCommand((IDiagramModel) object);
compoundCommand.add(cmd);
} else if (object instanceof IArchimateElement) {
Command cmd = new DuplicateElementCommand((IArchimateElement) object);
compoundCommand.add(cmd);
}
}
}
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 HintContentSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.HintContentSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
Text text = createSingleTextControl(parent, SWT.NONE);
fTextTitleControl = new PropertySectionTextControl(text, ICanvasPackage.Literals.HINT_PROVIDER__HINT_TITLE) {
@Override
protected void textChanged(String oldText, String newText) {
CompoundCommand result = new CompoundCommand();
for (EObject provider : getEObjects()) {
if (isAlive(provider)) {
Command cmd = new EObjectFeatureCommand(Messages.HintContentSection_1, provider, ICanvasPackage.Literals.HINT_PROVIDER__HINT_TITLE, newText);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
};
fTextTitleControl.setHint(Messages.HintContentSection_2);
createLabel(parent, Messages.HintContentSection_3, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
StyledTextControl styledTextControl = createStyledTextControl(parent, SWT.NONE);
fTextContentControl = new PropertySectionTextControl(styledTextControl.getControl(), ICanvasPackage.Literals.HINT_PROVIDER__HINT_CONTENT) {
@Override
protected void textChanged(String oldText, String newText) {
CompoundCommand result = new CompoundCommand();
for (EObject provider : getEObjects()) {
if (isAlive(provider)) {
Command cmd = new EObjectFeatureCommand(Messages.HintContentSection_4, provider, ICanvasPackage.Literals.HINT_PROVIDER__HINT_CONTENT, newText);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
};
fTextContentControl.setHint(Messages.HintContentSection_5);
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTextContentControl.getTextControl(), HELP_ID);
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class NotesSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.NotesSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
StyledTextControl styledTextControl = createStyledTextControl(parent, SWT.NONE);
fTextNotesControl = new PropertySectionTextControl(styledTextControl.getControl(), ICanvasPackage.Literals.NOTES_CONTENT__NOTES) {
@Override
protected void textChanged(String oldText, String newText) {
CompoundCommand result = new CompoundCommand();
for (EObject notesContent : getEObjects()) {
if (isAlive(notesContent)) {
Command cmd = new EObjectFeatureCommand(Messages.NotesSection_1, notesContent, ICanvasPackage.Literals.NOTES_CONTENT__NOTES, newText);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
};
fTextNotesControl.setHint(Messages.NotesSection_2);
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTextNotesControl.getTextControl(), HELP_ID);
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class MagicConnectionCreationTool method createElementAndConnection.
/**
* Create an Element and a connection in one go when user clicks on the canvas or in a non-Archimate Editpart
*/
private boolean createElementAndConnection(IDiagramModelArchimateComponent sourceDiagramModelComponent, Point location) {
// Grab this now as it will disappear after menu is shown
EditPartViewer viewer = getCurrentViewer();
// What did we click on?
GraphicalEditPart targetEditPart = (GraphicalEditPart) viewer.findObjectAt(getCurrentInput().getMouseLocation());
// Target parent (default is the diagram itself)
IDiagramModelContainer parent = sourceDiagramModelComponent.getDiagramModel();
// If we clicked on a Group EditPart use that as parent
if (targetEditPart instanceof GroupEditPart) {
parent = (IDiagramModelContainer) targetEditPart.getModel();
} else // Or did we click on something else? Then use the parent of that
if (targetEditPart instanceof AbstractBaseEditPart) {
targetEditPart = (GraphicalEditPart) targetEditPart.getParent();
parent = (IDiagramModelContainer) targetEditPart.getModel();
}
boolean elementsFirst = Preferences.isMagicConnectorPolarity();
boolean modKeyPressed = getCurrentInput().isModKeyDown(SWT.MOD1);
elementsFirst ^= modKeyPressed;
Menu menu = new Menu(getCurrentViewer().getControl());
// User will hover over element, then connection
if (elementsFirst) {
fSetRelationshipTypeWhenHoveringOnConnectionMenuItem = false;
addElementActions(menu, sourceDiagramModelComponent);
} else // User will hover over connection, then element
{
fSetRelationshipTypeWhenHoveringOnConnectionMenuItem = true;
addConnectionActions(menu, sourceDiagramModelComponent);
}
menu.setVisible(true);
// Modal menu
Display display = menu.getDisplay();
while (!menu.isDisposed() && menu.isVisible()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
// SWT Menu does not fire Selection Event when Windows touch display is enabled
if (PlatformUtils.isWindows()) {
while (display.readAndDispatch()) ;
}
if (!menu.isDisposed()) {
menu.dispose();
}
eraseSourceFeedback();
// No selection
if (getFactory().getElementType() == null || getFactory().getRelationshipType() == null) {
getFactory().clear();
return false;
}
// Create Compound Command first
CompoundCommand cmd = new CreateElementCompoundCommand((FigureCanvas) viewer.getControl(), location.x, location.y);
// If the EditPart's Figure is a Container, adjust the location to relative co-ords
if (targetEditPart.getFigure() instanceof IContainerFigure) {
((IContainerFigure) targetEditPart.getFigure()).translateMousePointToRelative(location);
} else // Or compensate for scrolled parent figure
{
IFigure contentPane = targetEditPart.getContentPane();
contentPane.translateToRelative(location);
}
CreateNewDiagramObjectCommand cmd1 = new CreateNewDiagramObjectCommand(parent, getFactory().getElementType(), location);
Command cmd2 = new CreateNewConnectionCommand(sourceDiagramModelComponent, cmd1.getNewObject(), getFactory().getRelationshipType());
cmd.add(cmd1);
cmd.add(cmd2);
executeCommand(cmd);
// Clear the factory
getFactory().clear();
return true;
}
Aggregations