use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class FormatPainterTool method createCommand.
protected CompoundCommand createCommand(PaintFormat pf, IDiagramModelComponent targetComponent) {
CompoundCommand result = new CompoundCommand(Messages.FormatPainterTool_0);
// IFontAttribute
if (pf.getSourceComponent() instanceof IFontAttribute && targetComponent instanceof IFontAttribute) {
IFontAttribute source = (IFontAttribute) pf.getSourceComponent();
IFontAttribute target = (IFontAttribute) targetComponent;
Command cmd = new FontStyleCommand(target, source.getFont());
if (cmd.canExecute()) {
result.add(cmd);
}
cmd = new FontColorCommand(target, source.getFontColor());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// ILineObject
if (pf.getSourceComponent() instanceof ILineObject && targetComponent instanceof ILineObject) {
ILineObject source = (ILineObject) pf.getSourceComponent();
ILineObject target = (ILineObject) targetComponent;
Command cmd = new LineColorCommand(target, source.getLineColor());
if (cmd.canExecute()) {
result.add(cmd);
}
cmd = new LineWidthCommand(target, source.getLineWidth());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// IBorderObject
if (pf.getSourceComponent() instanceof IBorderObject && targetComponent instanceof IBorderObject) {
IBorderObject source = (IBorderObject) pf.getSourceComponent();
IBorderObject target = (IBorderObject) targetComponent;
Command cmd = new BorderColorCommand(target, source.getBorderColor());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// ITextPosition
if (pf.getSourceComponent() instanceof ITextPosition && targetComponent instanceof ITextPosition) {
ITextPosition source = (ITextPosition) pf.getSourceComponent();
ITextPosition target = (ITextPosition) targetComponent;
Command cmd = new TextPositionCommand(target, source.getTextPosition());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// ITextAlignment
if (pf.getSourceComponent() instanceof ITextAlignment && targetComponent instanceof ITextAlignment) {
ITextAlignment source = (ITextAlignment) pf.getSourceComponent();
ITextAlignment target = (ITextAlignment) targetComponent;
Command cmd = new TextAlignmentCommand(target, source.getTextAlignment());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// IDiagramModelObject
if (pf.getSourceComponent() instanceof IDiagramModelObject && targetComponent instanceof IDiagramModelObject) {
IDiagramModelObject source = (IDiagramModelObject) pf.getSourceComponent();
IDiagramModelObject target = (IDiagramModelObject) targetComponent;
// Source fill colour is null which is "default"
String fillColorString = source.getFillColor();
if (fillColorString == null) {
fillColorString = ColorFactory.convertColorToString(ColorFactory.getDefaultFillColor(source));
}
Command cmd = new FillColorCommand(target, fillColorString);
if (cmd.canExecute()) {
result.add(cmd);
}
// Alpha fill opacity
cmd = new DiagramModelObjectAlphaCommand(target, source.getAlpha());
if (cmd.canExecute()) {
result.add(cmd);
}
// Alpha line opacity
cmd = new DiagramModelObjectOutlineAlphaCommand(target, source.getLineAlpha());
if (cmd.canExecute()) {
result.add(cmd);
}
// Gradient
// $NON-NLS-1$
cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_GRADIENT, source.getGradient(), IDiagramModelObject.FEATURE_GRADIENT_DEFAULT);
if (cmd.canExecute()) {
result.add(cmd);
}
// Icon Visibility, but paste only if the target object has an icon
IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(target);
if (provider instanceof IGraphicalObjectUIProvider && ((IGraphicalObjectUIProvider) provider).hasIcon()) {
// $NON-NLS-1$
cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_ICON_VISIBLE, source.getIconVisibleState(), IDiagramModelObject.FEATURE_ICON_VISIBLE_DEFAULT);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
// Archimate objects
if (pf.getSourceComponent() instanceof IDiagramModelArchimateObject && targetComponent instanceof IDiagramModelArchimateObject) {
IDiagramModelArchimateObject source = (IDiagramModelArchimateObject) pf.getSourceComponent();
IDiagramModelArchimateObject target = (IDiagramModelArchimateObject) targetComponent;
// Image Source
Command cmd = new // $NON-NLS-1$
FeatureCommand(// $NON-NLS-1$
"", // $NON-NLS-1$
target, // $NON-NLS-1$
IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE, source.getImageSource(), IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE_DEFAULT);
if (cmd.canExecute()) {
result.add(cmd);
}
}
// IDiagramModelConnection
if (pf.getSourceComponent() instanceof IDiagramModelConnection && targetComponent instanceof IDiagramModelConnection) {
IDiagramModelConnection source = (IDiagramModelConnection) pf.getSourceComponent();
IDiagramModelConnection target = (IDiagramModelConnection) targetComponent;
// Connection text position
Command cmd = new ConnectionTextPositionCommand(target, source.getTextPosition());
if (cmd.canExecute()) {
result.add(cmd);
}
// If a non-Archimate connection, connection line type
if (!(target instanceof IDiagramModelArchimateConnection)) {
cmd = new ConnectionLineTypeCommand(target, source.getType());
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
// IIconic
if (pf.getSourceComponent() instanceof IIconic && targetComponent instanceof IIconic) {
IIconic source = (IIconic) pf.getSourceComponent();
IIconic target = (IIconic) targetComponent;
// If we have an image path and the source and target models are different, copy the image bytes
String imagePath = source.getImagePath();
if (imagePath != null && source.getArchimateModel() != target.getArchimateModel()) {
IArchiveManager sourceArchiveManager = (IArchiveManager) source.getAdapter(IArchiveManager.class);
IArchiveManager targetArchiveManager = (IArchiveManager) target.getAdapter(IArchiveManager.class);
try {
imagePath = targetArchiveManager.copyImageBytes(sourceArchiveManager, imagePath);
} catch (IOException ex) {
ex.printStackTrace();
// $NON-NLS-1$
Logger.logError("Could not copy image bytes when copying and pasting objects.", ex);
}
}
// $NON-NLS-1$
Command cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.DIAGRAM_MODEL_IMAGE_PROVIDER__IMAGE_PATH, imagePath);
if (cmd.canExecute()) {
result.add(cmd);
}
// Image position
// $NON-NLS-1$
cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.ICONIC__IMAGE_POSITION, source.getImagePosition());
if (cmd.canExecute()) {
result.add(cmd);
}
}
return result;
}
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 = ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.MAGIC_CONNECTOR_POLARITY);
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 CompoundCommand(Messages.MagicConnectionCreationTool_6);
// 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, viewer);
Command cmd2 = new CreateNewConnectionCommand(sourceDiagramModelComponent, cmd1.getNewObject(), getFactory().getRelationshipType());
cmd.add(cmd1);
cmd.add(cmd2);
executeCommand(cmd);
// Clear the factory
getFactory().clear();
return true;
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class ArchimateDNDEditPolicy method getDropCommand.
@Override
protected Command getDropCommand(DiagramDropRequest request) {
if (!(request.getData() instanceof IStructuredSelection)) {
return null;
}
// XY drop point
Point pt = getDropLocation(request);
int origin = pt.x;
int x = pt.x;
int y = pt.y;
fElementsToAdd = new ArrayList<IArchimateElement>();
fRelationsToAdd = new ArrayList<IArchimateRelationship>();
fDiagramRefsToAdd = new ArrayList<IDiagramModel>();
// Gather an actual list of elements dragged onto the container, omitting duplicates and anything already on the diagram
Object[] objects = ((IStructuredSelection) request.getData()).toArray();
getElementsToAdd(objects);
// Store the Diagram Model Components that will be added in this list
List<IDiagramModelArchimateComponent> diagramComponentsThatWereAdded = new ArrayList<IDiagramModelArchimateComponent>();
// Create a Compound Command - it has to be Non-Notifying or it's too slow (tested with Bill's UoB model!)
CompoundCommand result = new NonNotifyingCompoundCommand(Messages.ArchimateDNDEditPolicy_0);
// Add the Commands adding the Elements first
for (IArchimateElement element : fElementsToAdd) {
// Add Diagram object
IDiagramModelArchimateObject dmo = ArchimateDiagramModelFactory.createDiagramModelArchimateObject(element);
// Set location
dmo.getBounds().setLocation(x, y);
// Store it
diagramComponentsThatWereAdded.add(dmo);
// Add Command
result.add(new AddDiagramObjectCommand(getTargetContainer(), dmo));
// Increase x,y
x += 150;
if (x > origin + 400) {
x = origin;
y += 100;
}
}
// Then any Diagram Model Ref Commands
for (IDiagramModel diagramModel : fDiagramRefsToAdd) {
result.add(new AddDiagramModelReferenceCommand(getTargetContainer(), diagramModel, x, y));
x += 150;
if (x > origin + 400) {
x = origin;
y += 100;
}
}
// Add selected Relations to create connections to those elements on the diagram that don't already have them
for (IArchimateRelationship relation : fRelationsToAdd) {
// Find existing source & target components on the diagram that the new connection will link to
List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getSource());
List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getTarget());
for (IDiagramModelComponent dcSource : sources) {
for (IDiagramModelComponent dcTarget : targets) {
if (dcSource instanceof IConnectable && dcTarget instanceof IConnectable) {
// Add a new connection between dcSource & dcTarget if there isn't already one on the diagram
if (dcTarget != dcSource && !DiagramModelUtils.hasDiagramModelArchimateConnection((IConnectable) dcSource, (IConnectable) dcTarget, relation)) {
// Check that source or target is not a hiden connection
if (!((dcSource instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) dcSource)) || (dcTarget instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) dcTarget)))) {
AddDiagramArchimateConnectionCommand cmd = new AddDiagramArchimateConnectionCommand((IConnectable) dcSource, (IConnectable) dcTarget, relation);
result.add(cmd);
// Store it
diagramComponentsThatWereAdded.add(cmd.getConnection());
}
}
}
}
}
}
// Whether to add connections to elements
Boolean value = (Boolean) request.getExtendedData().get(ArchimateDiagramTransferDropTargetListener.ADD_ELEMENT_CONNECTIONS);
boolean addConnectionsToElements = value != null && value.booleanValue();
// Newly added concepts will need new connections to both existing and newly added concepts
for (IDiagramModelArchimateComponent dmComponent : diagramComponentsThatWereAdded) {
IArchimateConcept archimateConcept = dmComponent.getArchimateConcept();
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(archimateConcept)) {
/*
* If the user holds down the Copy key (Ctrl on win/lnx, Alt on Mac) then linked connections
* are not added on drag and drop. However, any selected relations' linked objects are added.
*/
if (!addConnectionsToElements && !fRelationsToAdd.contains(relation)) {
continue;
}
// Find existing objects
List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getSource());
List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getTarget());
// Add new ones too
for (IDiagramModelArchimateComponent dmComponent2 : diagramComponentsThatWereAdded) {
if (dmComponent != dmComponent2) {
IArchimateConcept archimateConcept2 = dmComponent2.getArchimateConcept();
if (archimateConcept2 == relation.getSource()) {
// Only need to add sources, not targets
sources.add(dmComponent2);
}
}
}
// Make the Commands...
for (IDiagramModelComponent dcSource : sources) {
if (dcSource instanceof IConnectable && archimateConcept == relation.getTarget()) {
result.add(new AddDiagramArchimateConnectionCommand((IConnectable) dcSource, (IConnectable) dmComponent, relation));
}
}
for (IDiagramModelComponent dcTarget : targets) {
if (dcTarget instanceof IConnectable && archimateConcept == relation.getSource()) {
result.add(new AddDiagramArchimateConnectionCommand((IConnectable) dmComponent, (IConnectable) dcTarget, relation));
}
}
}
}
// Then, if adding to an Archimate container type to create nesting, ask whether to add new relations if none exist...
if (ConnectionPreferences.createRelationWhenAddingModelTreeElement() && getTargetContainer() instanceof IDiagramModelArchimateObject) {
List<IDiagramModelArchimateObject> diagramObjectsThatWereAdded = new ArrayList<IDiagramModelArchimateObject>();
for (IDiagramModelArchimateComponent dmc : diagramComponentsThatWereAdded) {
if (dmc instanceof IDiagramModelArchimateObject) {
diagramObjectsThatWereAdded.add((IDiagramModelArchimateObject) dmc);
}
}
Command cmd = new CreateNestedArchimateConnectionsWithDialogCommand((IDiagramModelArchimateObject) getTargetContainer(), diagramObjectsThatWereAdded);
result.add(cmd);
}
// return the full compound command
return result;
}
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);
// Font
UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.PROPERTIES_TABLE_FONT, true);
// Mac Silicon Item height
UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
// Edit cell on double-click and add Tab key traversal
TableViewerEditor.create(fTableViewer, new ColumnViewerEditorActivationStrategy(fTableViewer) {
@Override
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return super.isEditorActivationEvent(event) || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION);
}
}, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK | ColumnViewerEditor.KEYBOARD_ACTIVATION);
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 ColumnWeightData(3, false));
columnBlank.getColumn().setWidth(38);
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(77, true));
columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
// Content Provider
fTableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return ((IProperties) inputElement).getProperties().toArray();
}
});
// Label Provider
fTableViewer.setLabelProvider(new LabelCellProvider());
// Enable tooltips
ColumnViewerToolTipSupport.enableFor(fTableViewer);
// Toolbar
ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.VERTICAL);
getWidgetFactory().adapt(toolBar);
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)) {
// complete any current editing
fTableViewer.applyEditorValue();
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((e) -> {
fActionRemoveProperty.setEnabled(!e.getSelection().isEmpty());
});
/*
* Table Double-click
*/
fTableViewer.getTable().addListener(SWT.MouseDoubleClick, (e) -> {
// Get Table item
Point pt = new Point(e.x, e.y);
TableItem item = fTableViewer.getTable().getItem(pt);
// Double-click into empty table creates new Property
if (item == null) {
fActionNewProperty.run();
} else // Double-clicked in column 0 with item
if (item.getData() instanceof IProperty) {
Rectangle rect = item.getBounds(0);
if (rect.contains(pt)) {
handleDoubleClick((IProperty) item.getData());
}
}
});
/*
* Edit table row on key press
*/
fTableViewer.getTable().addKeyListener(KeyListener.keyPressedAdapter(e -> {
if (e.keyCode == SWT.CR) {
Object selected = fTableViewer.getStructuredSelection().getFirstElement();
if (selected != null) {
fTableViewer.editElement(selected, 1);
}
}
}));
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());
}
Aggregations