use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class TextPositionSection method createControls.
@Override
protected void createControls(Composite parent) {
SelectionAdapter adapter = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (int i = 0; i < fPositionButtons.length; i++) {
// Select/deselects
fPositionButtons[i].setSelection(e.widget == fPositionButtons[i]);
// Commands
if (fPositionButtons[i] == e.widget) {
int position = (Integer) fPositionButtons[i].getData();
CompoundCommand result = new CompoundCommand();
for (EObject textPosition : getEObjects()) {
if (((ITextPosition) textPosition).getTextPosition() != position && isAlive(textPosition)) {
Command cmd = new TextPositionCommand((ITextPosition) textPosition, position);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
}
}
};
// $NON-NLS-1$
createLabel(parent, Messages.TextPositionSection_3 + ":", ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
Composite client = createComposite(parent, 3);
for (int i = 0; i < fPositionButtons.length; i++) {
fPositionButtons[i] = new Button(client, SWT.TOGGLE | SWT.FLAT);
// Need to do it this way for Mac
getWidgetFactory().adapt(fPositionButtons[i], true, true);
fPositionButtons[i].addSelectionListener(adapter);
}
// Top Button
fPositionButtons[0].setImage(IArchiImages.ImageFactory.getImage(IArchiImages.ICON_ALIGN_TEXT_TOP));
fPositionButtons[0].setData(ITextPosition.TEXT_POSITION_TOP);
// Middle Button
fPositionButtons[1].setImage(IArchiImages.ImageFactory.getImage(IArchiImages.ICON_ALIGN_TEXT_MIDDLE));
fPositionButtons[1].setData(ITextPosition.TEXT_POSITION_CENTRE);
// Bottom Button
fPositionButtons[2].setImage(IArchiImages.ImageFactory.getImage(IArchiImages.ICON_ALIGN_TEXT_BOTTOM));
fPositionButtons[2].setData(ITextPosition.TEXT_POSITION_BOTTOM);
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class UserPropertiesManagerDialog method okPressed.
@Override
protected void okPressed() {
super.okPressed();
CompoundCommand compoundCmd = new CompoundCommand(Messages.UserPropertiesManagerDialog_11) {
@Override
public void execute() {
BusyIndicator.showWhile(null, new Runnable() {
public void run() {
doSuperExecute();
}
});
}
@Override
public void undo() {
BusyIndicator.showWhile(null, new Runnable() {
public void run() {
doSuperUndo();
}
});
}
@Override
public void redo() {
BusyIndicator.showWhile(null, new Runnable() {
public void run() {
doSuperRedo();
}
});
}
void doSuperExecute() {
super.execute();
}
void doSuperUndo() {
super.undo();
}
void doSuperRedo() {
super.redo();
}
};
checkRenames(compoundCmd);
checkDeletions(compoundCmd);
CommandStack stack = (CommandStack) fArchimateModel.getAdapter(CommandStack.class);
stack.execute(compoundCmd.unwrap());
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class UserPropertiesSection method createTableControl.
private void createTableControl(Composite parent) {
// Table Composite
Composite tableComp = createTableComposite(parent, SWT.NULL);
TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
// Table Viewer
fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
fTableViewer.getTable().setHeaderVisible(true);
fTableViewer.getTable().setLinesVisible(true);
addDragSupport();
addDropSupport();
// Help ID on table
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
// Columns
TableViewerColumn columnBlank = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
tableLayout.setColumnData(columnBlank.getColumn(), new ColumnPixelData(24, false));
TableViewerColumn columnKey = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
columnKey.getColumn().setText(Messages.UserPropertiesSection_0);
tableLayout.setColumnData(columnKey.getColumn(), new ColumnWeightData(20, true));
columnKey.setEditingSupport(new KeyEditingSupport(fTableViewer));
// Click on Key Table Header
columnKey.getColumn().addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
sortKeys();
}
});
TableViewerColumn columnValue = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
columnValue.getColumn().setText(Messages.UserPropertiesSection_1);
tableLayout.setColumnData(columnValue.getColumn(), new ColumnWeightData(80, true));
columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
// Content Provider
fTableViewer.setContentProvider(new IStructuredContentProvider() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object inputElement) {
return ((IProperties) inputElement).getProperties().toArray();
}
});
// Label Provider
fTableViewer.setLabelProvider(new LabelCellProvider());
// Toolbar
ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.VERTICAL);
GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).applyTo(toolBar);
ToolBarManager toolBarmanager = new ToolBarManager(toolBar);
// New Property
fActionNewProperty = new Action(Messages.UserPropertiesSection_2) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
int index = -1;
IProperty selected = (IProperty) ((IStructuredSelection) fTableViewer.getSelection()).getFirstElement();
if (selected != null) {
index = fPropertiesElement.getProperties().indexOf(selected) + 1;
}
IProperty property = IArchimateFactory.eINSTANCE.createProperty();
executeCommand(new NewPropertyCommand(fPropertiesElement.getProperties(), property, index));
fTableViewer.editElement(property, 1);
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_PLUS);
}
};
// New Multiple Properties
fActionNewMultipleProperty = new Action(Messages.UserPropertiesSection_3) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
MultipleAddDialog dialog = new MultipleAddDialog(fPage.getSite().getShell());
if (dialog.open() == Window.OK) {
executeCommand(dialog.getCommand());
}
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_MUTIPLE);
}
};
// Remove Property
fActionRemoveProperty = new Action(Messages.UserPropertiesSection_4) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
CompoundCommand compoundCmd = new EObjectNonNotifyingCompoundCommand(fPropertiesElement) {
@Override
public String getLabel() {
return getCommands().size() > 1 ? Messages.UserPropertiesSection_5 : Messages.UserPropertiesSection_6;
}
};
for (Object o : ((IStructuredSelection) fTableViewer.getSelection()).toList()) {
Command cmd = new RemovePropertyCommand(fPropertiesElement.getProperties(), (IProperty) o);
compoundCmd.add(cmd);
}
executeCommand(compoundCmd);
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_SMALL_X);
}
};
fActionRemoveProperty.setEnabled(false);
// Manage
fActionShowKeyEditor = new Action(Messages.UserPropertiesSection_7) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
UserPropertiesManagerDialog dialog = new UserPropertiesManagerDialog(fPage.getSite().getShell(), getArchimateModel());
dialog.open();
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_COG);
}
};
toolBarmanager.add(fActionNewProperty);
toolBarmanager.add(fActionNewMultipleProperty);
toolBarmanager.add(fActionRemoveProperty);
toolBarmanager.add(fActionShowKeyEditor);
toolBarmanager.update(true);
/*
* Selection Listener
*/
fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
fActionRemoveProperty.setEnabled(!event.getSelection().isEmpty());
}
});
/*
* Table Double-click on cell
*/
fTableViewer.getTable().addListener(SWT.MouseDoubleClick, new Listener() {
@Override
public void handleEvent(Event event) {
// Get Table item
TableItem item = fTableViewer.getTable().getItem(new Point(event.x, event.y));
// Double-click into empty table creates new Property
if (item == null) {
fActionNewProperty.run();
} else // Handle selected item property double-clicked
{
if (item.getData() instanceof IProperty) {
handleDoubleClick((IProperty) item.getData());
}
}
}
});
hookContextMenu();
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class UserPropertiesSection method movePropertiesToIndex.
private void movePropertiesToIndex(List<IProperty> propertiesToMove, int index) {
EList<IProperty> properties = fPropertiesElement.getProperties();
// Sanity check
if (index < 0) {
index = 0;
}
if (index > properties.size()) {
index = properties.size();
}
CompoundCommand compoundCmd = new CompoundCommand(Messages.UserPropertiesSection_8);
for (IProperty property : propertiesToMove) {
int oldIndex = properties.indexOf(property);
if (index > oldIndex) {
index--;
}
if (index == oldIndex) {
break;
}
compoundCmd.add(new MovePropertyCommand(properties, property, index));
index++;
}
executeCommand(compoundCmd.unwrap());
}
use of org.eclipse.gef.commands.CompoundCommand in project knime-core by knime.
the class WorkflowSelectionDragEditPartsTracker method getCommand.
/**
* Asks each edit part in the
* {@link org.eclipse.gef.tools.AbstractTool#getOperationSet() operation set}
* to contribute to a {@link CompoundCommand} after first setting the
* request type to either {@link org.eclipse.gef.RequestConstants#REQ_MOVE}
* or {@link org.eclipse.gef.RequestConstants#REQ_ORPHAN}, depending on the
* result of {@link #isMove()}.
*
* Additionally the method creates a command to adapt connections where both
* node container are include in the drag operation.
*
* {@inheritDoc}
*/
@Override
protected Command getCommand() {
CompoundCommand command = new CompoundCommand();
command.setDebugLabel("Drag Object Tracker");
Iterator iter = getOperationSet().iterator();
Request request = getTargetRequest();
if (isCloneActive()) {
request.setType(REQ_CLONE);
} else if (isMove()) {
request.setType(REQ_MOVE);
} else {
request.setType(REQ_ORPHAN);
}
if (!isCloneActive()) {
while (iter.hasNext()) {
EditPart editPart = (EditPart) iter.next();
command.add(editPart.getCommand(request));
}
}
// now add the commands for the node-embraced connections
ConnectionContainerEditPart[] connectionsToAdapt = getEmbracedConnections(getOperationSet());
for (ConnectionContainerEditPart connectionPart : connectionsToAdapt) {
command.add(connectionPart.getBendpointAdaptionCommand(request));
}
if (!isMove() || isCloneActive()) {
if (!isCloneActive()) {
request.setType(REQ_ADD);
}
if (getTargetEditPart() == null) {
command.add(UnexecutableCommand.INSTANCE);
} else {
command.add(getTargetEditPart().getCommand(getTargetRequest()));
}
}
return command;
}
Aggregations