use of org.eclipse.gef.commands.Command in project dbeaver by serge-rider.
the class ExtendedDirectEditManager method commit.
/**
* Commits the current value of the cell editor by getting a {@link Command}
* from the source edit part and executing it via the {@link CommandStack}.
* Finally, {@link #bringDown()}is called to perform and necessary cleanup.
*/
@Override
protected void commit() {
if (committing)
return;
committing = true;
try {
//we set the cell editor control to invisible to remove any
// possible flicker
getCellEditor().getControl().setVisible(false);
if (isDirty()) {
CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
Command command = getEditPart().getCommand(getDirectEditRequest());
if (command != null && command.canExecute())
stack.execute(command);
}
} finally {
bringDown();
committing = false;
}
}
use of org.eclipse.gef.commands.Command in project cubrid-manager by CUBRID.
the class GefViewerKeyHandler method moveHANodesByKey.
/**
* move figures by keyboard.
*
* @param event KeyEvent
* @return if handled the event return true else return false.
*/
private boolean moveHANodesByKey(KeyEvent event) {
List<?> selectedEditParts = getViewer().getSelectedEditParts();
boolean flag = false;
for (Object obj : selectedEditParts) {
if (!(obj instanceof HANodePart)) {
continue;
}
GraphicalEditPart editPart = (GraphicalEditPart) obj;
Command command = null;
if ((event.stateMask & SWT.ALT) == 0 && (event.stateMask & SWT.CTRL) == 0 && (event.stateMask & SWT.SHIFT) == 0 && (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_LEFT || event.keyCode == SWT.ARROW_RIGHT || event.keyCode == SWT.ARROW_UP)) {
HANode node = (HANode) editPart.getModel();
ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
request.setLocation(node.getLocation());
request.setEditParts(editPart);
//get move delta
Point moveDelta = null;
switch(event.keyCode) {
case SWT.ARROW_LEFT:
moveDelta = new Point(-1, 0);
break;
case SWT.ARROW_RIGHT:
moveDelta = new Point(1, 0);
break;
case SWT.ARROW_UP:
moveDelta = new Point(0, -1);
break;
case SWT.ARROW_DOWN:
moveDelta = new Point(0, 1);
break;
default:
return true;
}
request.setMoveDelta(moveDelta);
command = editPart.getCommand(request);
}
if (command != null && !(command instanceof UnexecutableCommand)) {
command.execute();
flag = true;
}
}
return flag;
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class PropertyTypeController method createComboCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
* .eclipse.swt.custom.CCombo)
*/
@Override
protected Command createComboCommand(CCombo combo) {
Connection repositoryConnection = null;
ConnectionItem repositoryConnectionItem = null;
// hwang add
FileItem repositoryFileItem = null;
String paramName = (String) combo.getData(PARAMETER_NAME);
IElementParameter param = elem.getElementParameter(paramName);
String value = combo.getText();
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
if (value.equals(param.getValue())) {
return null;
}
// Map<String, ConnectionItem> repositoryConnectionItemMap = null;
IElementParameter repositoryParam = null;
// hywang add for feature 6484
Map<String, FileItem> repositoryFileItemMap = null;
if (value.equals(EmfComponent.REPOSITORY)) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
repositoryFileItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryFileItemMap();
}
repositoryParam = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
String connectionSelected = (String) repositoryParam.getValue();
// if (repositoryConnectionItemMap.containsKey(connectionSelected)) {
try {
Item item = null;
if (!StringUtils.isEmpty(connectionSelected)) {
IRepositoryViewObject repobj = factory.getLastVersion(connectionSelected);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
if (item != null && item instanceof ConnectionItem) {
repositoryConnectionItem = (ConnectionItem) factory.getLastVersion(connectionSelected).getProperty().getItem();
repositoryConnection = repositoryConnectionItem.getConnection();
} else {
repositoryConnection = null;
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
// for ruleItem,hywang add
if (repositoryFileItemMap.containsKey(connectionSelected)) {
repositoryFileItem = repositoryFileItemMap.get(connectionSelected);
} else {
if (!repositoryFileItemMap.isEmpty()) {
repositoryFileItem = repositoryFileItemMap.values().iterator().next();
} else {
repositoryFileItem = null;
}
}
}
CompoundCommand cc = new CompoundCommand();
if (repositoryConnectionItem != null) {
initCDC(cc, repositoryConnectionItem);
}
ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, repositoryConnection, paramName, value);
cc.add(changeValuesFromRepository1);
if (repositoryConnection != null) {
ChangeValuesFromRepository changeValuesFromRepository2 = new ChangeValuesFromRepository(elem, repositoryConnection, repositoryParam.getParentParameter().getName() + ":" + repositoryParam.getName(), //$NON-NLS-1$
repositoryConnectionItem.getProperty().getId());
cc.add(changeValuesFromRepository2);
}
// hywang add for feature 6484
if (repositoryFileItem != null) {
final String id = repositoryFileItem.getProperty().getId();
cc.add(new Command() {
@Override
public void execute() {
IElementParameter elementParameter = elem.getElementParameter(EParameterName.PROPERTY_TYPE.getName());
if (elementParameter != null) {
elementParameter = elementParameter.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (elementParameter != null) {
elementParameter.setValue(id);
}
}
}
});
}
if (value.equals(EmfComponent.REPOSITORY)) {
updateDBType(cc, repositoryConnection);
}
return cc;
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class RadioController method createCommand.
private List<Command> createCommand(SelectionEvent event) {
Set<String> elementsName;
Control ctrl = (Control) event.getSource();
elementsName = hashCurControls.keySet();
List<Command> commands = new ArrayList<Command>();
for (String name : elementsName) {
Object o = hashCurControls.get(name);
if (o instanceof Control) {
ctrl = (Control) o;
if (ctrl == null) {
hashCurControls.remove(name);
return null;
}
if (ctrl.equals(event.getSource())) {
if (ctrl instanceof Button) {
// before
if (!elem.getPropertyValue(name).equals(new Boolean(((Button) ctrl).getSelection()))) {
Command cmd = null;
Boolean value = new Boolean(((Button) ctrl).getSelection());
if (name.equals(EParameterName.ACTIVATE.getName())) {
if (elem instanceof Node) {
List<Node> nodeList = new ArrayList<Node>();
nodeList.add((Node) elem);
List<Connection> connList = new ArrayList<Connection>();
cmd = new ChangeActivateStatusElementCommand(value, nodeList, connList);
commands.add(cmd);
}
} else {
IElementParameter param = elem.getElementParameter(name);
if (Boolean.TRUE.equals(value)) {
List<IElementParameter> parameters = DesignerUtilities.findRadioParamInSameGroup(elem.getElementParameters(), param);
for (IElementParameter currentRadioParam : parameters) {
if (Boolean.TRUE.equals(currentRadioParam.getValue())) {
cmd = new PropertyChangeCommand(elem, currentRadioParam.getName(), Boolean.FALSE);
commands.add(cmd);
}
}
}
cmd = new PropertyChangeCommand(elem, name, value);
commands.add(cmd);
String groupName = param.getGroup();
if (groupName != null && elem.getElementParameter(groupName) != null) {
Command cmd2 = new PropertyChangeCommand(elem, groupName, name);
commands.add(cmd2);
}
}
return commands;
}
}
}
}
}
return null;
}
use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.
the class PropertyTypeController method updateDBType.
// see bug 0004305
private void updateDBType(CompoundCommand compoundCommand, Connection repositoryConnection) {
if (repositoryConnection == null) {
return;
}
if (!(repositoryConnection instanceof DatabaseConnection)) {
return;
}
//$NON-NLS-1$
final String property = "DBTYPE";
if (elem.getElementParameter(property) == null) {
return;
}
String currentDbType = ((DatabaseConnection) repositoryConnection).getDatabaseType();
EDatabaseTypeName typeName = EDatabaseTypeName.getTypeFromDbType(currentDbType);
Command command = new PropertyChangeCommand(elem, property, typeName.getXMLType());
compoundCommand.add(command);
}
Aggregations